diff options
author | Artur Dryomov <artur.dryomov@gmail.com> | 2013-09-01 21:10:14 +0300 |
---|---|---|
committer | Artur Dryomov <artur.dryomov@gmail.com> | 2013-09-03 12:22:48 +0300 |
commit | 20eb1462b69d5d3d3ea04c14cdcf21fdbf205b3d (patch) | |
tree | 3dbc07d76a4e85b60b4291b4f3bdb59497d4291d | |
parent | 7b6720c3f1c4e5407b1fc9151ea09341973e2038 (diff) |
Change saving computer connnection fragment state.
* Do it more proper way.
* Do not reconnect on orientation changes without user actions.
Change-Id: Ib5dcb7ef05096b9ee2899d3508961fc52f706729
3 files changed, 106 insertions, 10 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputerConnectionFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputerConnectionFragment.java index 2779370bcd5b..acd9e60470bb 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputerConnectionFragment.java +++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputerConnectionFragment.java @@ -29,10 +29,12 @@ import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; +import org.libreoffice.impressremote.util.Fragments; import org.libreoffice.impressremote.util.Intents; import org.libreoffice.impressremote.R; import org.libreoffice.impressremote.communication.CommunicationService; import org.libreoffice.impressremote.communication.Server; +import org.libreoffice.impressremote.util.SavedStates; public class ComputerConnectionFragment extends SherlockFragment implements ServiceConnection { private Server mComputer; @@ -51,7 +53,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv private static Bundle buildArguments(Server aComputer) { Bundle aArguments = new Bundle(); - aArguments.putParcelable("COMPUTER", aComputer); + aArguments.putParcelable(Fragments.Arguments.COMPUTER, aComputer); return aArguments; } @@ -60,7 +62,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv public void onCreate(Bundle aSavedInstance) { super.onCreate(aSavedInstance); - mComputer = getArguments().getParcelable("COMPUTER"); + mComputer = getArguments().getParcelable(Fragments.Arguments.COMPUTER); setUpActionBarMenu(); } @@ -83,10 +85,12 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv } loadLayout(aSavedInstanceState); + loadPin(aSavedInstanceState); + loadErrorMessage(aSavedInstanceState); } private void loadLayout(Bundle aSavedInstanceState) { - int aLayoutIndex = aSavedInstanceState.getInt("LAYOUT"); + int aLayoutIndex = aSavedInstanceState.getInt(SavedStates.Keys.LAYOUT_INDEX); getViewAnimator().setDisplayedChild(aLayoutIndex); } @@ -95,6 +99,26 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv return (ViewAnimator) getView().findViewById(R.id.view_animator); } + private void loadPin(Bundle aSavedInstanceState) { + String aPin = aSavedInstanceState.getString(SavedStates.Keys.PIN); + + getPinTextView().setText(aPin); + } + + private TextView getPinTextView() { + return (TextView) getView().findViewById(R.id.text_pin); + } + + private void loadErrorMessage(Bundle aSavedInstanceState) { + String aErrorMessage = aSavedInstanceState.getString(SavedStates.Keys.ERROR_MESSAGE); + + getSecondaryErrorMessageTextView().setText(aErrorMessage); + } + + private TextView getSecondaryErrorMessageTextView() { + return (TextView) getView().findViewById(R.id.text_secondary_error_message); + } + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); @@ -120,6 +144,10 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv return; } + if (!isComputerConnectionRequired()) { + return; + } + mCommunicationService.connectTo(mComputer); } @@ -127,6 +155,14 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv return mCommunicationService != null; } + private boolean isComputerConnectionRequired() { + return getViewAnimator().getDisplayedChild() == getViewAnimator().indexOfChild(getProgressBar()); + } + + private ProgressBar getProgressBar() { + return (ProgressBar) getView().findViewById(R.id.progress_bar); + } + @Override public void onServiceDisconnected(ComponentName aComponentName) { mCommunicationService = null; @@ -194,19 +230,22 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv } private void setUpPinValidationInstructions(String aPin) { - TextView aPinTextView = (TextView) getView().findViewById(R.id.text_pin); - aPinTextView.setText(aPin); + getPinTextView().setText(aPin); showPinValidationLayout(); } private void showPinValidationLayout() { ViewAnimator aViewAnimator = getViewAnimator(); - LinearLayout aValidationLayout = (LinearLayout) getView().findViewById(R.id.layout_pin_validation); + LinearLayout aValidationLayout = getPinValidationLayout(); aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aValidationLayout)); } + private LinearLayout getPinValidationLayout() { + return (LinearLayout) getView().findViewById(R.id.layout_pin_validation); + } + private void setUpPresentation() { Intent aIntent = Intents.buildSlideShowIntent(getActivity()); startActivity(aIntent); @@ -215,7 +254,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv } private void setUpErrorMessage() { - TextView aSecondaryMessageTextView = (TextView) getView().findViewById(R.id.text_secondary_error_message); + TextView aSecondaryMessageTextView = getSecondaryErrorMessageTextView(); aSecondaryMessageTextView.setText(buildSecondaryErrorMessage()); showErrorMessageLayout(); @@ -236,11 +275,15 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv private void showErrorMessageLayout() { ViewAnimator aViewAnimator = getViewAnimator(); - LinearLayout aMessageLayout = (LinearLayout) getView().findViewById(R.id.layout_error_message); + LinearLayout aMessageLayout = getErrorMessageLayout(); aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aMessageLayout)); } + private LinearLayout getErrorMessageLayout() { + return (LinearLayout) getView().findViewById(R.id.layout_error_message); + } + private void refreshActionBarMenu() { getSherlockActivity().supportInvalidateOptionsMenu(); } @@ -279,7 +322,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv private void showProgressBar() { ViewAnimator aViewAnimator = getViewAnimator(); - ProgressBar aProgressBar = (ProgressBar) getView().findViewById(R.id.progress_bar); + ProgressBar aProgressBar = getProgressBar(); aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aProgressBar)); } @@ -305,12 +348,26 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv super.onSaveInstanceState(aOutState); saveLayout(aOutState); + savePin(aOutState); + saveErrorMessage(aOutState); } private void saveLayout(Bundle aOutState) { int aLayoutIndex = getViewAnimator().getDisplayedChild(); - aOutState.putInt("LAYOUT", aLayoutIndex); + aOutState.putInt(SavedStates.Keys.LAYOUT_INDEX, aLayoutIndex); + } + + private void savePin(Bundle aOutState) { + String aPin = getPinTextView().getText().toString(); + + aOutState.putString(SavedStates.Keys.PIN, aPin); + } + + private void saveErrorMessage(Bundle aOutState) { + String aErrorMessage = getSecondaryErrorMessageTextView().getText().toString(); + + aOutState.putString(SavedStates.Keys.ERROR_MESSAGE, aErrorMessage); } @Override diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Fragments.java b/android/sdremote/src/org/libreoffice/impressremote/util/Fragments.java new file mode 100644 index 000000000000..b7dbe6dd764e --- /dev/null +++ b/android/sdremote/src/org/libreoffice/impressremote/util/Fragments.java @@ -0,0 +1,23 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.libreoffice.impressremote.util; + +public final class Fragments { + private Fragments() { + } + + public static final class Arguments { + private Arguments() { + } + + public static final String COMPUTER = "COMPUTER"; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/SavedStates.java b/android/sdremote/src/org/libreoffice/impressremote/util/SavedStates.java new file mode 100644 index 000000000000..0b7a1bbc4165 --- /dev/null +++ b/android/sdremote/src/org/libreoffice/impressremote/util/SavedStates.java @@ -0,0 +1,16 @@ +package org.libreoffice.impressremote.util; + +public final class SavedStates { + private SavedStates() { + } + + public static final class Keys { + private Keys() { + } + + public static final String LAYOUT_INDEX = "LAYOUT_INDEX"; + + public static final String PIN = "PIN"; + public static final String ERROR_MESSAGE = "ERROR_MESSAGE"; + } +} |