diff options
4 files changed, 42 insertions, 5 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java index 56b87e7e5777..6249e228682f 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java @@ -25,6 +25,7 @@ import org.libreoffice.impressremote.util.BluetoothOperator; import org.libreoffice.impressremote.util.FragmentOperator; import org.libreoffice.impressremote.util.Intents; import org.libreoffice.impressremote.R; +import org.libreoffice.impressremote.util.Preferences; public class ComputersActivity extends SherlockFragmentActivity implements ActionBar.TabListener, ViewPager.OnPageChangeListener { private static final class TabsIndices { @@ -72,6 +73,8 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio setUpTabs(); setUpComputersPager(); + + setUpSavedTab(); } private void setUpTabs() { @@ -137,6 +140,14 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio public void onPageScrollStateChanged(int aPosition) { } + private void setUpSavedTab() { + getSupportActionBar().setSelectedNavigationItem(loadTabIndex()); + } + + private int loadTabIndex() { + return Preferences.getApplicationStatesInstance(this).getInt("saved_tab"); + } + private void setUpComputersList() { Fragment aComputersFragment = ComputersFragment.newInstance(ComputersFragment.Type.WIFI); @@ -189,6 +200,19 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio Intent aIntent = Intents.buildLicensesIntent(this); startActivity(aIntent); } + + @Override + protected void onStop() { + super.onStop(); + + saveTabIndex(); + } + + private void saveTabIndex() { + int aTabIndex = getSupportActionBar().getSelectedNavigationIndex(); + + Preferences.getApplicationStatesInstance(this).setInt("saved_tab", aTabIndex); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java b/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java index e81d3b77645f..f91fbf7163e9 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java @@ -46,11 +46,11 @@ final class PairingProvider { } private String getSavedPin(Server aServer) { - return mAuthorizedServersPreferences.get(aServer.getAddress()); + return mAuthorizedServersPreferences.getString(aServer.getAddress()); } private void savePin(Server aServer, String aPin) { - mAuthorizedServersPreferences.set(aServer.getAddress(), aPin); + mAuthorizedServersPreferences.setString(aServer.getAddress(), aPin); } public static String getPairingDeviceName(Context aContext) { diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java index 459f4e6ebee7..bb8ac0e99b8c 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java @@ -101,7 +101,7 @@ class ServersManager implements Comparator<Server> { } public void addTcpServer(String aAddress, String aName) { - mSavedServersPreferences.set(aAddress, aName); + mSavedServersPreferences.setString(aAddress, aName); } public void removeServer(Server aServer) { diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java index 9c7c7f8074b2..e39b31af07f3 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java +++ b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java @@ -20,6 +20,7 @@ public final class Preferences { public static final String AUTHORIZED_SERVERS = "authorized_servers"; public static final String SAVED_SERVERS = "saved_servers"; + public static final String APPLICATION_STATES = "application_states"; } private final SharedPreferences mPreferences; @@ -40,18 +41,30 @@ public final class Preferences { return new Preferences(aContext, Locations.SAVED_SERVERS); } + public static Preferences getApplicationStatesInstance(Context aContext) { + return new Preferences(aContext, Locations.APPLICATION_STATES); + } + public Map<String, ?> getAll() { return mPreferences.getAll(); } - public String get(String aKey) { + public String getString(String aKey) { return mPreferences.getString(aKey, null); } - public void set(String aKey, String aValue) { + public int getInt(String aKey) { + return mPreferences.getInt(aKey, 0); + } + + public void setString(String aKey, String aValue) { mPreferences.edit().putString(aKey, aValue).commit(); } + public void setInt(String aKey, int aValue) { + mPreferences.edit().putInt(aKey, aValue).commit(); + } + public void remove(String aKey) { mPreferences.edit().remove(aKey).commit(); } |