Kaydet (Commit) 08157e4b authored tarafından Artur Dryomov's avatar Artur Dryomov

Add saving state for ComputerConnectionFragment.

This change should provide more smooth rotation change.

Change-Id: I3d530485752069fb5f6d4683b68b83ef97f87808
üst 429148c5
...@@ -74,6 +74,27 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv ...@@ -74,6 +74,27 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
return aInflater.inflate(R.layout.fragment_computer_connection, aContainer, false); return aInflater.inflate(R.layout.fragment_computer_connection, aContainer, false);
} }
@Override
public void onViewStateRestored(Bundle aSavedInstanceState) {
super.onViewStateRestored(aSavedInstanceState);
if (aSavedInstanceState == null) {
return;
}
loadLayout(aSavedInstanceState);
}
private void loadLayout(Bundle aSavedInstanceState) {
int aLayoutIndex = aSavedInstanceState.getInt("LAYOUT");
getViewAnimator().setDisplayedChild(aLayoutIndex);
}
private ViewAnimator getViewAnimator() {
return (ViewAnimator) getView().findViewById(R.id.view_animator);
}
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
...@@ -89,7 +110,6 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv ...@@ -89,7 +110,6 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
@Override @Override
public void onServiceConnected(ComponentName aComponentName, IBinder aBinder) { public void onServiceConnected(ComponentName aComponentName, IBinder aBinder) {
CommunicationService.CBinder aServiceBinder = (CommunicationService.CBinder) aBinder; CommunicationService.CBinder aServiceBinder = (CommunicationService.CBinder) aBinder;
mCommunicationService = aServiceBinder.getService(); mCommunicationService = aServiceBinder.getService();
connectToComputer(); connectToComputer();
...@@ -181,7 +201,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv ...@@ -181,7 +201,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
} }
private void showPinValidationLayout() { private void showPinValidationLayout() {
ViewAnimator aViewAnimator = (ViewAnimator) getView().findViewById(R.id.view_animator); ViewAnimator aViewAnimator = getViewAnimator();
LinearLayout aValidationLayout = (LinearLayout) getView().findViewById(R.id.layout_pin_validation); LinearLayout aValidationLayout = (LinearLayout) getView().findViewById(R.id.layout_pin_validation);
aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aValidationLayout)); aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aValidationLayout));
...@@ -215,7 +235,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv ...@@ -215,7 +235,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
} }
private void showErrorMessageLayout() { private void showErrorMessageLayout() {
ViewAnimator aViewAnimator = (ViewAnimator) getView().findViewById(R.id.view_animator); ViewAnimator aViewAnimator = getViewAnimator();
LinearLayout aMessageLayout = (LinearLayout) getView().findViewById(R.id.layout_error_message); LinearLayout aMessageLayout = (LinearLayout) getView().findViewById(R.id.layout_error_message);
aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aMessageLayout)); aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aMessageLayout));
...@@ -240,9 +260,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv ...@@ -240,9 +260,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
return false; return false;
} }
ViewAnimator aViewAnimator = (ViewAnimator) getView().findViewById(R.id.view_animator); return getViewAnimator().getCurrentView().getId() == R.id.layout_error_message;
return aViewAnimator.getCurrentView().getId() == R.id.layout_error_message;
} }
@Override @Override
...@@ -260,7 +278,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv ...@@ -260,7 +278,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
} }
private void showProgressBar() { private void showProgressBar() {
ViewAnimator aViewAnimator = (ViewAnimator) getView().findViewById(R.id.view_animator); ViewAnimator aViewAnimator = getViewAnimator();
ProgressBar aProgressBar = (ProgressBar) getView().findViewById(R.id.progress_bar); ProgressBar aProgressBar = (ProgressBar) getView().findViewById(R.id.progress_bar);
aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aProgressBar)); aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aProgressBar));
...@@ -282,6 +300,19 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv ...@@ -282,6 +300,19 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
} }
} }
@Override
public void onSaveInstanceState(Bundle aOutState) {
super.onSaveInstanceState(aOutState);
saveLayout(aOutState);
}
private void saveLayout(Bundle aOutState) {
int aLayoutIndex = getViewAnimator().getDisplayedChild();
aOutState.putInt("LAYOUT", aLayoutIndex);
}
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment