-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3e45ce9
Showing
13 changed files
with
428 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/gen | ||
/assets | ||
/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>BackupRestore</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.android.ide.eclipse.adt.ApkBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.stylingandroid.backuprestore" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-sdk android:minSdkVersion="8" /> | ||
|
||
<application | ||
android:backupAgent="SaBackupAgent" | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" > | ||
<meta-data | ||
android:name="com.google.android.backup.api_key" | ||
android:value="INSERT YOUR KEY HERE" /> | ||
<activity | ||
android:name=".BackupRestoreActivity" | ||
android:label="@string/app_name" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
-optimizationpasses 5 | ||
-dontusemixedcaseclassnames | ||
-dontskipnonpubliclibraryclasses | ||
-dontpreverify | ||
-verbose | ||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* | ||
|
||
-keep public class * extends android.app.Activity | ||
-keep public class * extends android.app.Application | ||
-keep public class * extends android.app.Service | ||
-keep public class * extends android.content.BroadcastReceiver | ||
-keep public class * extends android.content.ContentProvider | ||
-keep public class * extends android.app.backup.BackupAgentHelper | ||
-keep public class * extends android.preference.Preference | ||
-keep public class com.android.vending.licensing.ILicensingService | ||
|
||
-keepclasseswithmembernames class * { | ||
native <methods>; | ||
} | ||
|
||
-keepclasseswithmembers class * { | ||
public <init>(android.content.Context, android.util.AttributeSet); | ||
} | ||
|
||
-keepclasseswithmembers class * { | ||
public <init>(android.content.Context, android.util.AttributeSet, int); | ||
} | ||
|
||
-keepclassmembers class * extends android.app.Activity { | ||
public void *(android.view.View); | ||
} | ||
|
||
-keepclassmembers enum * { | ||
public static **[] values(); | ||
public static ** valueOf(java.lang.String); | ||
} | ||
|
||
-keep class * implements android.os.Parcelable { | ||
public static final android.os.Parcelable$Creator *; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This file is automatically generated by Android Tools. | ||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED! | ||
# | ||
# This file must be checked in Version Control Systems. | ||
# | ||
# To customize properties used by the Ant build system use, | ||
# "ant.properties", and override values to adapt the script to your | ||
# project structure. | ||
|
||
# Project target. | ||
target=android-8 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:layout_gravity="center_horizontal" | ||
android:orientation="vertical" > | ||
|
||
|
||
<EditText | ||
android:id="@+id/editText" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:inputType="text"> | ||
|
||
<requestFocus /> | ||
</EditText> | ||
|
||
<LinearLayout | ||
android:id="@+id/linearLayout1" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" > | ||
|
||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:text="@string/backup_button" | ||
android:onClick="backup"/> | ||
|
||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:text="@string/restore_button" | ||
android:onClick="restore"/> | ||
|
||
</LinearLayout> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="app_name">BackupRestore</string> | ||
<string name="backup_button">Backup</string> | ||
<string name="restore_button">Restore</string> | ||
|
||
</resources> |
140 changes: 140 additions & 0 deletions
140
src/com/stylingandroid/backuprestore/BackupRestoreActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package com.stylingandroid.backuprestore; | ||
|
||
import android.app.Activity; | ||
import android.app.backup.BackupManager; | ||
import android.app.backup.RestoreObserver; | ||
import android.content.SharedPreferences; | ||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; | ||
import android.os.Bundle; | ||
import android.text.Editable; | ||
import android.text.TextWatcher; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.EditText; | ||
|
||
public class BackupRestoreActivity extends Activity implements | ||
OnSharedPreferenceChangeListener | ||
{ | ||
public static final String TAG = "BackupRestoreActivity"; | ||
|
||
public static final String PREFS = "prefs"; | ||
|
||
public static final String KEY = "key"; | ||
|
||
private EditText edit; | ||
private BackupManager backupMgr = null; | ||
|
||
private SharedPreferences sharedPrefs; | ||
|
||
@Override | ||
public void onCreate( Bundle savedInstanceState ) | ||
{ | ||
Log.d( TAG, "onCreate" ); | ||
super.onCreate( savedInstanceState ); | ||
setContentView( R.layout.main ); | ||
|
||
sharedPrefs = getSharedPreferences( BackupRestoreActivity.PREFS, | ||
MODE_PRIVATE ); | ||
|
||
edit = (EditText) findViewById( R.id.editText ); | ||
edit.addTextChangedListener( new TextWatcher() | ||
{ | ||
private int start = 0; | ||
private int end = 0; | ||
|
||
@Override | ||
public void onTextChanged( CharSequence s, int start, int before, | ||
int count ) | ||
{ | ||
SharedPreferences.Editor editor = sharedPrefs.edit(); | ||
editor.putString( BackupRestoreActivity.KEY, s.toString() ); | ||
editor.commit(); | ||
} | ||
|
||
@Override | ||
public void beforeTextChanged( CharSequence s, int start, | ||
int count, int after ) | ||
{ | ||
this.start = after; | ||
this.end = after; | ||
} | ||
|
||
@Override | ||
public void afterTextChanged( Editable s ) | ||
{ | ||
edit.setSelection( start, end ); | ||
} | ||
} ); | ||
|
||
backupMgr = new BackupManager( getApplicationContext() ); | ||
} | ||
|
||
@Override | ||
protected void onResume() | ||
{ | ||
Log.d( TAG, "onResume" ); | ||
sharedPrefs.registerOnSharedPreferenceChangeListener( this ); | ||
String val = sharedPrefs.getString( KEY, null ); | ||
if ( val != null ) | ||
{ | ||
edit.setText( val ); | ||
} | ||
super.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onPause() | ||
{ | ||
Log.d( TAG, "onPause" ); | ||
sharedPrefs.unregisterOnSharedPreferenceChangeListener( this ); | ||
super.onPause(); | ||
} | ||
|
||
public void backup( View v ) | ||
{ | ||
Log.d( TAG, "backup" ); | ||
backupMgr.dataChanged(); | ||
} | ||
|
||
public void restore( View v ) | ||
{ | ||
Log.d( TAG, "restore" ); | ||
backupMgr.requestRestore( new RestoreObserver() | ||
{ | ||
@Override | ||
public void restoreStarting( int numPackages ) | ||
{ | ||
Log.d( TAG, "restoreStarting: " + numPackages ); | ||
super.restoreStarting( numPackages ); | ||
} | ||
|
||
@Override | ||
public void restoreFinished( int error ) | ||
{ | ||
Log.d( TAG, "restoreFinished: " + error ); | ||
super.restoreFinished( error ); | ||
} | ||
|
||
@Override | ||
public void onUpdate( int nowBeingRestored, String currentPackage ) | ||
{ | ||
Log.d( TAG, "onUpdate: " + currentPackage ); | ||
super.onUpdate( nowBeingRestored, currentPackage ); | ||
} | ||
} ); | ||
} | ||
|
||
@Override | ||
public void onSharedPreferenceChanged( SharedPreferences sharedPreferences, | ||
String key ) | ||
{ | ||
if ( key.equals( KEY ) ) | ||
{ | ||
String newVal = sharedPreferences.getString( key, null ); | ||
if ( newVal != null ) | ||
{ | ||
edit.setText( newVal ); | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/com/stylingandroid/backuprestore/PrefsBackupAgent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.stylingandroid.backuprestore; | ||
|
||
import android.app.backup.BackupAgentHelper; | ||
import android.app.backup.SharedPreferencesBackupHelper; | ||
|
||
public class PrefsBackupAgent extends BackupAgentHelper | ||
{ | ||
private static final String PREFS_BACKUP_KEY = "prefs"; | ||
|
||
@Override | ||
public void onCreate() | ||
{ | ||
SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper( this, BackupRestoreActivity.PREFS ); | ||
addHelper( PREFS_BACKUP_KEY, helper ); | ||
} | ||
} |
Oops, something went wrong.