Change saving computer connnection fragment state.
* Do it more proper way. * Do not reconnect on orientation changes without user actions. Change-Id: Ib5dcb7ef05096b9ee2899d3508961fc52f706729
This commit is contained in:
@@ -29,10 +29,12 @@ import com.actionbarsherlock.app.SherlockFragment;
|
|||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuInflater;
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
import org.libreoffice.impressremote.util.Fragments;
|
||||||
import org.libreoffice.impressremote.util.Intents;
|
import org.libreoffice.impressremote.util.Intents;
|
||||||
import org.libreoffice.impressremote.R;
|
import org.libreoffice.impressremote.R;
|
||||||
import org.libreoffice.impressremote.communication.CommunicationService;
|
import org.libreoffice.impressremote.communication.CommunicationService;
|
||||||
import org.libreoffice.impressremote.communication.Server;
|
import org.libreoffice.impressremote.communication.Server;
|
||||||
|
import org.libreoffice.impressremote.util.SavedStates;
|
||||||
|
|
||||||
public class ComputerConnectionFragment extends SherlockFragment implements ServiceConnection {
|
public class ComputerConnectionFragment extends SherlockFragment implements ServiceConnection {
|
||||||
private Server mComputer;
|
private Server mComputer;
|
||||||
@@ -51,7 +53,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
|
|||||||
private static Bundle buildArguments(Server aComputer) {
|
private static Bundle buildArguments(Server aComputer) {
|
||||||
Bundle aArguments = new Bundle();
|
Bundle aArguments = new Bundle();
|
||||||
|
|
||||||
aArguments.putParcelable("COMPUTER", aComputer);
|
aArguments.putParcelable(Fragments.Arguments.COMPUTER, aComputer);
|
||||||
|
|
||||||
return aArguments;
|
return aArguments;
|
||||||
}
|
}
|
||||||
@@ -60,7 +62,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
|
|||||||
public void onCreate(Bundle aSavedInstance) {
|
public void onCreate(Bundle aSavedInstance) {
|
||||||
super.onCreate(aSavedInstance);
|
super.onCreate(aSavedInstance);
|
||||||
|
|
||||||
mComputer = getArguments().getParcelable("COMPUTER");
|
mComputer = getArguments().getParcelable(Fragments.Arguments.COMPUTER);
|
||||||
|
|
||||||
setUpActionBarMenu();
|
setUpActionBarMenu();
|
||||||
}
|
}
|
||||||
@@ -83,10 +85,12 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadLayout(aSavedInstanceState);
|
loadLayout(aSavedInstanceState);
|
||||||
|
loadPin(aSavedInstanceState);
|
||||||
|
loadErrorMessage(aSavedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadLayout(Bundle aSavedInstanceState) {
|
private void loadLayout(Bundle aSavedInstanceState) {
|
||||||
int aLayoutIndex = aSavedInstanceState.getInt("LAYOUT");
|
int aLayoutIndex = aSavedInstanceState.getInt(SavedStates.Keys.LAYOUT_INDEX);
|
||||||
|
|
||||||
getViewAnimator().setDisplayedChild(aLayoutIndex);
|
getViewAnimator().setDisplayedChild(aLayoutIndex);
|
||||||
}
|
}
|
||||||
@@ -95,6 +99,26 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
|
|||||||
return (ViewAnimator) getView().findViewById(R.id.view_animator);
|
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
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
@@ -120,6 +144,10 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isComputerConnectionRequired()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mCommunicationService.connectTo(mComputer);
|
mCommunicationService.connectTo(mComputer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,6 +155,14 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
|
|||||||
return mCommunicationService != null;
|
return mCommunicationService != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isComputerConnectionRequired() {
|
||||||
|
return getViewAnimator().getDisplayedChild() == getViewAnimator().indexOfChild(getProgressBar());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ProgressBar getProgressBar() {
|
||||||
|
return (ProgressBar) getView().findViewById(R.id.progress_bar);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceDisconnected(ComponentName aComponentName) {
|
public void onServiceDisconnected(ComponentName aComponentName) {
|
||||||
mCommunicationService = null;
|
mCommunicationService = null;
|
||||||
@@ -194,19 +230,22 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setUpPinValidationInstructions(String aPin) {
|
private void setUpPinValidationInstructions(String aPin) {
|
||||||
TextView aPinTextView = (TextView) getView().findViewById(R.id.text_pin);
|
getPinTextView().setText(aPin);
|
||||||
aPinTextView.setText(aPin);
|
|
||||||
|
|
||||||
showPinValidationLayout();
|
showPinValidationLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPinValidationLayout() {
|
private void showPinValidationLayout() {
|
||||||
ViewAnimator aViewAnimator = getViewAnimator();
|
ViewAnimator aViewAnimator = getViewAnimator();
|
||||||
LinearLayout aValidationLayout = (LinearLayout) getView().findViewById(R.id.layout_pin_validation);
|
LinearLayout aValidationLayout = getPinValidationLayout();
|
||||||
|
|
||||||
aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aValidationLayout));
|
aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aValidationLayout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LinearLayout getPinValidationLayout() {
|
||||||
|
return (LinearLayout) getView().findViewById(R.id.layout_pin_validation);
|
||||||
|
}
|
||||||
|
|
||||||
private void setUpPresentation() {
|
private void setUpPresentation() {
|
||||||
Intent aIntent = Intents.buildSlideShowIntent(getActivity());
|
Intent aIntent = Intents.buildSlideShowIntent(getActivity());
|
||||||
startActivity(aIntent);
|
startActivity(aIntent);
|
||||||
@@ -215,7 +254,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setUpErrorMessage() {
|
private void setUpErrorMessage() {
|
||||||
TextView aSecondaryMessageTextView = (TextView) getView().findViewById(R.id.text_secondary_error_message);
|
TextView aSecondaryMessageTextView = getSecondaryErrorMessageTextView();
|
||||||
aSecondaryMessageTextView.setText(buildSecondaryErrorMessage());
|
aSecondaryMessageTextView.setText(buildSecondaryErrorMessage());
|
||||||
|
|
||||||
showErrorMessageLayout();
|
showErrorMessageLayout();
|
||||||
@@ -236,11 +275,15 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
|
|||||||
|
|
||||||
private void showErrorMessageLayout() {
|
private void showErrorMessageLayout() {
|
||||||
ViewAnimator aViewAnimator = getViewAnimator();
|
ViewAnimator aViewAnimator = getViewAnimator();
|
||||||
LinearLayout aMessageLayout = (LinearLayout) getView().findViewById(R.id.layout_error_message);
|
LinearLayout aMessageLayout = getErrorMessageLayout();
|
||||||
|
|
||||||
aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aMessageLayout));
|
aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aMessageLayout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LinearLayout getErrorMessageLayout() {
|
||||||
|
return (LinearLayout) getView().findViewById(R.id.layout_error_message);
|
||||||
|
}
|
||||||
|
|
||||||
private void refreshActionBarMenu() {
|
private void refreshActionBarMenu() {
|
||||||
getSherlockActivity().supportInvalidateOptionsMenu();
|
getSherlockActivity().supportInvalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
@@ -279,7 +322,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
|
|||||||
|
|
||||||
private void showProgressBar() {
|
private void showProgressBar() {
|
||||||
ViewAnimator aViewAnimator = getViewAnimator();
|
ViewAnimator aViewAnimator = getViewAnimator();
|
||||||
ProgressBar aProgressBar = (ProgressBar) getView().findViewById(R.id.progress_bar);
|
ProgressBar aProgressBar = getProgressBar();
|
||||||
|
|
||||||
aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aProgressBar));
|
aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aProgressBar));
|
||||||
}
|
}
|
||||||
@@ -305,12 +348,26 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
|
|||||||
super.onSaveInstanceState(aOutState);
|
super.onSaveInstanceState(aOutState);
|
||||||
|
|
||||||
saveLayout(aOutState);
|
saveLayout(aOutState);
|
||||||
|
savePin(aOutState);
|
||||||
|
saveErrorMessage(aOutState);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveLayout(Bundle aOutState) {
|
private void saveLayout(Bundle aOutState) {
|
||||||
int aLayoutIndex = getViewAnimator().getDisplayedChild();
|
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
|
@Override
|
||||||
|
@@ -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: */
|
@@ -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";
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user