summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Tate <ctate@google.com>2010-11-16 15:41:27 -0800
committerChris Tate <ctate@google.com>2010-11-16 18:24:12 -0800
commitcdcc28a9cb49a6cf06b84130df29dae58fbceaad (patch)
tree1a6f97cfca17ee47a1b301a4829ee5fe657bfd54
parent064a7f0ad82d17d09776cd11ed46060b0edbfb27 (diff)
downloadandroid_development-cdcc28a9cb49a6cf06b84130df29dae58fbceaad.tar.gz
android_development-cdcc28a9cb49a6cf06b84130df29dae58fbceaad.tar.bz2
android_development-cdcc28a9cb49a6cf06b84130df29dae58fbceaad.zip
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
-rw-r--r--samples/BackupRestore/Android.mk2
-rw-r--r--samples/BackupRestore/proguard.flags3
-rw-r--r--samples/BackupRestore/res/layout/backup_restore.xml104
-rw-r--r--samples/BackupRestore/res/values/strings.xml2
-rw-r--r--samples/BackupRestore/src/com/example/android/backuprestore/BackupRestoreActivity.java21
5 files changed, 86 insertions, 46 deletions
diff --git a/samples/BackupRestore/Android.mk b/samples/BackupRestore/Android.mk
index c164a6c0b..abe2526be 100644
--- a/samples/BackupRestore/Android.mk
+++ b/samples/BackupRestore/Android.mk
@@ -10,4 +10,6 @@ LOCAL_PACKAGE_NAME := BackupRestore
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 000000000..f487abc52
--- /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 1459d4216..9e61b00ce 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">
-
- <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>
-
- <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"/>
+ <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"/>
- <CheckBox android:id="@+id/mayo"
- android:text="@string/mayo_text"
- android:layout_marginLeft="20dp"
- android:layout_width="match_parent"
- 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">
- <CheckBox android:id="@+id/tomato"
- android:text="@string/tomato_text"
- android:layout_marginLeft="20dp"
- 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>
+
+ <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/mayo"
+ android:text="@string/mayo_text"
+ android:layout_marginLeft="20dp"
+ 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"/>
+
+ </LinearLayout>
+
+ </ScrollView>
- </LinearLayout>
+ <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" />
-</ScrollView> \ No newline at end of file
+</LinearLayout>
diff --git a/samples/BackupRestore/res/values/strings.xml b/samples/BackupRestore/res/values/strings.xml
index 64cd7a231..b78524353 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 01c10ae0d..37c2f36eb 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 @@ package com.example.android.backuprestore;
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 @@ public class BackupRestoreActivity extends Activity {
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();
+ }
+ }
+ );
+ }
+}