From 3851fa9c8d180ca636e69b25f84fdcc294150009 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Fri, 5 Aug 2011 12:28:15 -0700 Subject: Handle rotation gracefully in the backup/restore confirmation UI We now don't automatically deny the operation if stopped, but instead allow the activity to be destroyed and recreated as usual. We retain the observer instance across that sequence so we keep getting progress reports etc. The UI now also uses the spiffy new button bar styles, and positions the deny / confirm buttons according to ICS standards. Bug 5115411 Change-Id: Ie760a0c8496c69f9d5881273a63ad5b5b76ff554 --- .../backupconfirm/BackupRestoreConfirmation.java | 40 ++++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'packages/BackupRestoreConfirmation/src') diff --git a/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java b/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java index f65a62f..5448e0b 100644 --- a/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java +++ b/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java @@ -48,6 +48,8 @@ public class BackupRestoreConfirmation extends Activity { static final String TAG = "BackupRestoreConfirmation"; static final boolean DEBUG = true; + static final String DID_ACKNOWLEDGE = "did_acknowledge"; + static final int MSG_START_BACKUP = 1; static final int MSG_BACKUP_PACKAGE = 2; static final int MSG_END_BACKUP = 3; @@ -149,7 +151,13 @@ public class BackupRestoreConfirmation extends Activity { mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService(Context.BACKUP_SERVICE)); mHandler = new ObserverHandler(getApplicationContext()); - mObserver = new FullObserver(); + final Object oldObserver = getLastNonConfigurationInstance(); + if (oldObserver == null) { + mObserver = new FullObserver(mHandler); + } else { + mObserver = (FullObserver) oldObserver; + mObserver.setHandler(mHandler); + } setContentView(layoutId); @@ -189,16 +197,24 @@ public class BackupRestoreConfirmation extends Activity { mDenyButton.setEnabled(false); } }); + + // if we're a relaunch we may need to adjust button enable state + if (icicle != null) { + mDidAcknowledge = icicle.getBoolean(DID_ACKNOWLEDGE, false); + mAllowButton.setEnabled(!mDidAcknowledge); + mDenyButton.setEnabled(!mDidAcknowledge); + } } + // Preserve the restore observer callback binder across activity relaunch @Override - public void onStop() { - super.onStop(); + public Object onRetainNonConfigurationInstance() { + return mObserver; + } - // We explicitly equate departure from the UI with refusal. This includes the - // implicit configuration-changed stop/restart cycle. - sendAcknowledgement(mToken, false, null); - finish(); + @Override + protected void onSaveInstanceState(Bundle outState) { + outState.putBoolean(DID_ACKNOWLEDGE, mDidAcknowledge); } void sendAcknowledgement(int token, boolean allow, IFullBackupRestoreObserver observer) { @@ -230,6 +246,16 @@ public class BackupRestoreConfirmation extends Activity { * the notifications onto the main thread. */ class FullObserver extends IFullBackupRestoreObserver.Stub { + private Handler mHandler; + + public FullObserver(Handler h) { + mHandler = h; + } + + public void setHandler(Handler h) { + mHandler = h; + } + // // IFullBackupRestoreObserver implementation // -- cgit v1.1