Add self-restore capability to Backup/Restore sample app

The Backup/Restore sample application now provides a "restore my own
last-known-good data" button.  When it is clicked the app will run the
standard public BackupManager.requestRestore() operation.

(This was the one aspect of the public API that was not previously
exercised by the sample app.)

Change-Id: I8abcfbad4b27b35fe9fafbbb97f89bac1d7a668c
diff --git a/samples/BackupRestore/Android.mk b/samples/BackupRestore/Android.mk
index c164a6c..abe2526 100644
--- a/samples/BackupRestore/Android.mk
+++ b/samples/BackupRestore/Android.mk
@@ -10,4 +10,6 @@
 
 LOCAL_SDK_VERSION := current
 
+LOCAL_PROGUARD_FLAG_FILES := proguard.flags
+
 include $(BUILD_PACKAGE)
diff --git a/samples/BackupRestore/proguard.flags b/samples/BackupRestore/proguard.flags
new file mode 100644
index 0000000..f487abc
--- /dev/null
+++ b/samples/BackupRestore/proguard.flags
@@ -0,0 +1,3 @@
+-keepclassmembers class com.example.android.backuprestore.BackupRestoreActivity {
+    public void onRestoreButtonClick(android.view.View);
+}
diff --git a/samples/BackupRestore/res/layout/backup_restore.xml b/samples/BackupRestore/res/layout/backup_restore.xml
index 1459d42..9e61b00 100644
--- a/samples/BackupRestore/res/layout/backup_restore.xml
+++ b/samples/BackupRestore/res/layout/backup_restore.xml
@@ -16,58 +16,72 @@
 
 <!-- Layout description of the BackupRestore sample's main activity -->
 
-
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
-    android:layout_width="fill_parent"
-    android:layout_height="fill_parent">
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
 
-    <LinearLayout
+    <ScrollView
         android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content">
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:layout_weight="1">
 
-        <TextView android:text="@string/filling_text"
-            android:textSize="20dp"
-            android:layout_marginTop="20dp"
-            android:layout_marginBottom="10dp"
+        <LinearLayout
+            android:orientation="vertical"
             android:layout_width="match_parent"
-            android:layout_height="wrap_content"/>
+            android:layout_height="wrap_content">
 
-        <RadioGroup android:id="@+id/filling_group"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_marginLeft="20dp"
-            android:orientation="vertical">
+            <TextView android:text="@string/filling_text"
+                android:textSize="20dp"
+                android:layout_marginTop="20dp"
+                android:layout_marginBottom="10dp"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"/>
 
-            <RadioButton android:id="@+id/bacon"
-                android:text="@string/bacon_label"/>
-            <RadioButton android:id="@+id/pastrami"
-                android:text="@string/pastrami_label"/>
-            <RadioButton android:id="@+id/hummus"
-                android:text="@string/hummus_label"/>
+            <RadioGroup android:id="@+id/filling_group"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="20dp"
+                android:orientation="vertical">
 
-        </RadioGroup>
+                <RadioButton android:id="@+id/bacon"
+                    android:text="@string/bacon_label"/>
+                <RadioButton android:id="@+id/pastrami"
+                    android:text="@string/pastrami_label"/>
+                <RadioButton android:id="@+id/hummus"
+                    android:text="@string/hummus_label"/>
 
-        <TextView android:text="@string/extras_text"
-            android:textSize="20dp"
-            android:layout_marginTop="20dp"
-            android:layout_marginBottom="10dp"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"/>
+            </RadioGroup>
 
-        <CheckBox android:id="@+id/mayo"
-            android:text="@string/mayo_text"
-            android:layout_marginLeft="20dp"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"/>
+            <TextView android:text="@string/extras_text"
+                android:textSize="20dp"
+                android:layout_marginTop="20dp"
+                android:layout_marginBottom="10dp"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"/>
 
-        <CheckBox android:id="@+id/tomato"
-            android:text="@string/tomato_text"
-            android:layout_marginLeft="20dp"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"/>
+            <CheckBox android:id="@+id/mayo"
+                android:text="@string/mayo_text"
+                android:layout_marginLeft="20dp"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"/>
 
-    </LinearLayout>
+            <CheckBox android:id="@+id/tomato"
+                android:text="@string/tomato_text"
+                android:layout_marginLeft="20dp"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"/>
 
-</ScrollView>
\ No newline at end of file
+        </LinearLayout>
+
+    </ScrollView>
+
+    <Button android:id="@+id/restore_button"
+        android:text="@string/restore_text"
+        android:onClick="onRestoreButtonClick"
+        android:layout_height="wrap_content"
+        android:layout_width="wrap_content"
+        android:layout_weight="0" />
+
+</LinearLayout>
diff --git a/samples/BackupRestore/res/values/strings.xml b/samples/BackupRestore/res/values/strings.xml
index 64cd7a2..b785243 100644
--- a/samples/BackupRestore/res/values/strings.xml
+++ b/samples/BackupRestore/res/values/strings.xml
@@ -23,4 +23,6 @@
   <string name="extras_text">Extras:</string>
   <string name="mayo_text">Mayonnaise\?</string>
   <string name="tomato_text">Tomato\?</string>
+
+  <string name="restore_text">Restore last data</string>
 </resources>
diff --git a/samples/BackupRestore/src/com/example/android/backuprestore/BackupRestoreActivity.java b/samples/BackupRestore/src/com/example/android/backuprestore/BackupRestoreActivity.java
index 01c10ae..37c2f36 100644
--- a/samples/BackupRestore/src/com/example/android/backuprestore/BackupRestoreActivity.java
+++ b/samples/BackupRestore/src/com/example/android/backuprestore/BackupRestoreActivity.java
@@ -18,8 +18,10 @@
 
 import android.app.Activity;
 import android.app.backup.BackupManager;
+import android.app.backup.RestoreObserver;
 import android.os.Bundle;
 import android.util.Log;
+import android.view.View;
 import android.widget.CheckBox;
 import android.widget.CompoundButton;
 import android.widget.RadioGroup;
@@ -249,4 +251,21 @@
 
         mBackupManager.dataChanged();
     }
-}
\ No newline at end of file
+
+    /**
+     * Click handler, designated in the layout, that runs a restore of the app's
+     * most recent data when the button is pressed.
+     */
+    public void onRestoreButtonClick(View v) {
+        Log.v(TAG, "Requesting restore of our most recent data");
+        mBackupManager.requestRestore(
+                new RestoreObserver() {
+                    public void restoreFinished(int error) {
+                        /** Done with the restore!  Now draw the new state of our data */
+                        Log.v(TAG, "Restore finished, error = " + error);
+                        populateUI();
+                    }
+                }
+        );
+    }
+}