mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-02-14 16:17:51 +01:00
DroidFish: Remember previous scroll location in preferences.
This commit is contained in:
parent
be610c97f4
commit
595cb247ae
|
@ -22,12 +22,21 @@ import org.petero.droidfish.R;
|
||||||
import org.petero.droidfish.Util;
|
import org.petero.droidfish.Util;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.SharedPreferences.Editor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AbsListView;
|
||||||
|
import android.widget.AbsListView.OnScrollListener;
|
||||||
|
import android.widget.ListView;
|
||||||
|
|
||||||
public class Preferences extends PreferenceActivity {
|
public class Preferences extends PreferenceActivity {
|
||||||
|
private static int currentItem = -1;
|
||||||
|
private static int initialItem = -1;
|
||||||
|
|
||||||
public static class Fragment extends PreferenceFragment {
|
public static class Fragment extends PreferenceFragment {
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,15 +44,56 @@ public class Preferences extends PreferenceActivity {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
View v = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
if (v == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
final ListView lv = (ListView) v.findViewById(android.R.id.list);
|
||||||
|
if (lv != null) {
|
||||||
|
lv.setOnScrollListener(new OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onScroll(AbsListView view, int firstVisibleItem,
|
||||||
|
int visibleItemCount, int totalItemCount) {
|
||||||
|
currentItem = firstVisibleItem;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
lv.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (initialItem >= 0)
|
||||||
|
lv.setSelection(initialItem);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
initialItem = settings.getInt("prefsViewInitialItem", -1);
|
||||||
getFragmentManager().beginTransaction()
|
getFragmentManager().beginTransaction()
|
||||||
.replace(android.R.id.content, new Fragment())
|
.replace(android.R.id.content, new Fragment())
|
||||||
.commit();
|
.commit();
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
Util.setFullScreenMode(this, settings);
|
Util.setFullScreenMode(this, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
Editor editor = settings.edit();
|
||||||
|
editor.putInt("prefsViewInitialItem", currentItem);
|
||||||
|
editor.commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user