If you think the Android project GridListViewAdapters listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/**
* Copyright 2014-present Biraj Patel/*fromwww.java2s.com*/
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/package com.birin.cursorgridadapter.demo4;
import android.content.res.Configuration;
import android.os.Bundle;
import com.birin.cursorgridadapter.demo3.ChildAndCardClickHandlingFixedCursorItems;
import com.birin.gridlistviewadapters.utils.PositionCalculator;
import com.birin.gridlistviewadaptersdemo.common.Constants;
publicclass FixedCursorItemsRotationSupport extends
ChildAndCardClickHandlingFixedCursorItems {
// //////////////////////////////////////////////////////////////////////////////
// TO MAINTAIN CORRECT POSITION AFTER ORIENTATION CHANGE
// //////////////////////////////////////////////////////////////////////////////
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adjustScroll(savedInstanceState);
}
privateint currentOrientation = Configuration.ORIENTATION_UNDEFINED;
@Override
protectedvoid onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
int firstVisible = listView.getFirstVisiblePosition();
outState.putInt(Constants.KEY_OLD_POSITION, firstVisible);
outState.putInt(Constants.KEY_OLD_ORIENTATION, currentOrientation);
}
privatevoid adjustScroll(Bundle savedInstanceState) {
currentOrientation = getCurrentOrientation();
if (null != savedInstanceState) {
int oldPosition = savedInstanceState.getInt(
Constants.KEY_OLD_POSITION, 0);
int oldOrientation = savedInstanceState.getInt(
Constants.KEY_OLD_ORIENTATION,
Configuration.ORIENTATION_UNDEFINED);
finalint newPostion = new PositionCalculator(
Constants.MAX_CARDS_INFO)
.calculatePositionInNewOrientation(oldPosition,
oldOrientation, currentOrientation);
listView.post(new Runnable() {
@Override
publicvoid run() {
listView.setSelection(newPostion);
}
});
}
}
// //////////////////////////////////////////////////////////////////////////////
// TO MAINTAIN CORRECT POSITION AFTER ORIENTATION CHANGE
// //////////////////////////////////////////////////////////////////////////////
@Override
protected String getToastMessage() {
// Sending null to avoid showing toast.
return null;
}
}