Merge "Add self-restore capability to Backup/Restore sample app"

This commit is contained in:
Chris Tate
2010-11-18 12:48:45 -08:00
committed by Android (Google) Code Review
5 changed files with 83 additions and 43 deletions

View File

@@ -10,4 +10,6 @@ LOCAL_PACKAGE_NAME := BackupRestore
LOCAL_SDK_VERSION := current LOCAL_SDK_VERSION := current
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
include $(BUILD_PACKAGE) include $(BUILD_PACKAGE)

View File

@@ -0,0 +1,3 @@
-keepclassmembers class com.example.android.backuprestore.BackupRestoreActivity {
public void onRestoreButtonClick(android.view.View);
}

View File

@@ -16,58 +16,72 @@
<!-- Layout description of the BackupRestore sample's main activity --> <!-- Layout description of the BackupRestore sample's main activity -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="fill_parent"> android:layout_height="wrap_content">
<LinearLayout <ScrollView
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content"> android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:text="@string/filling_text" <LinearLayout
android:textSize="20dp" android:orientation="vertical"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content">
<RadioGroup android:id="@+id/filling_group" <TextView android:text="@string/filling_text"
android:layout_width="match_parent" android:textSize="20dp"
android:layout_height="wrap_content" android:layout_marginTop="20dp"
android:layout_marginLeft="20dp" android:layout_marginBottom="10dp"
android:orientation="vertical"> android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RadioButton android:id="@+id/bacon" <RadioGroup android:id="@+id/filling_group"
android:text="@string/bacon_label"/> android:layout_width="match_parent"
<RadioButton android:id="@+id/pastrami" android:layout_height="wrap_content"
android:text="@string/pastrami_label"/> android:layout_marginLeft="20dp"
<RadioButton android:id="@+id/hummus" android:orientation="vertical">
android:text="@string/hummus_label"/>
</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" </RadioGroup>
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" <TextView android:text="@string/extras_text"
android:text="@string/mayo_text" android:textSize="20dp"
android:layout_marginLeft="20dp" android:layout_marginTop="20dp"
android:layout_width="match_parent" android:layout_marginBottom="10dp"
android:layout_height="wrap_content"/> android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<CheckBox android:id="@+id/tomato" <CheckBox android:id="@+id/mayo"
android:text="@string/tomato_text" android:text="@string/mayo_text"
android:layout_marginLeft="20dp" android:layout_marginLeft="20dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> 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> </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>

View File

@@ -23,4 +23,6 @@
<string name="extras_text">Extras:</string> <string name="extras_text">Extras:</string>
<string name="mayo_text">Mayonnaise\?</string> <string name="mayo_text">Mayonnaise\?</string>
<string name="tomato_text">Tomato\?</string> <string name="tomato_text">Tomato\?</string>
<string name="restore_text">Restore last data</string>
</resources> </resources>

View File

@@ -18,8 +18,10 @@ package com.example.android.backuprestore;
import android.app.Activity; import android.app.Activity;
import android.app.backup.BackupManager; import android.app.backup.BackupManager;
import android.app.backup.RestoreObserver;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.RadioGroup; import android.widget.RadioGroup;
@@ -249,4 +251,21 @@ public class BackupRestoreActivity extends Activity {
mBackupManager.dataChanged(); mBackupManager.dataChanged();
} }
}
/**
* 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();
}
}
);
}
}