1
0
Fork 0

Add support to backup the preferences on Froyo.

This commit is contained in:
Carlos Mogas da Silva 2010-07-21 01:49:30 +01:00
parent 5dd9a27cef
commit 63ff61d155
3 changed files with 42 additions and 4 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.r3pek.pharmacies" android:versionCode="11" android:versionName="2.0.2" android:installLocation="auto"> package="org.r3pek.pharmacies" android:versionCode="11" android:versionName="2.0.2" android:installLocation="auto">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false"> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false" android:backupAgent=".backup.MyBackupAgent">
<activity android:name="MyPreferences"/> <activity android:name="MyPreferences"/>
<activity android:name="PharmacyList"/> <activity android:name="PharmacyList"/>
<activity android:name="PharmacyInfo"/> <activity android:name="PharmacyInfo"/>
@ -13,7 +13,8 @@
</activity> </activity>
<uses-library android:name="com.google.android.maps" /> <uses-library android:name="com.google.android.maps" />
<meta-data android:value="a14be6d1c69912b" android:name="ADMOB_PUBLISHER_ID"/> <meta-data android:value="a14be6d1c69912b" android:name="ADMOB_PUBLISHER_ID"/>
<meta-data android:value="false" android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" /> <meta-data android:value="false" android:name="ADMOB_ALLOW_LOCATION_FOR_ADS"/>
<meta-data android:name="com.google.android.backup.api_key" android:value="AEdPqrEAAAAIign4yF8fO3Ro9ZqlNntcf6_lVRLTzdoFbJvyLw"/>
</application> </application>
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8"/> <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8"/>
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>

View file

@ -1,18 +1,37 @@
package org.r3pek.pharmacies; package org.r3pek.pharmacies;
import org.r3pek.pharmacies.backup.WrapBackupManager;
import org.r3pek.pharmacies.widgets.SeekBarPreference; import org.r3pek.pharmacies.widgets.SeekBarPreference;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.util.Log;
public class MyPreferences extends PreferenceActivity { public class MyPreferences extends PreferenceActivity {
private static boolean isRunningInFroyo;
/* establish whether the "new" class is available to us */
static {
try {
WrapBackupManager.isAvailable();
isRunningInFroyo = true;
} catch (Throwable t) {
isRunningInFroyo = false;
}
}
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
SeekBarPreference sbp = (SeekBarPreference) findPreference("pref_gen_maxdist"); SeekBarPreference sbp = (SeekBarPreference) findPreference("pref_gen_maxdist");
sbp.setMin(1); sbp.setMin(1);
} }
@Override
public void onStop() {
super.onStop();
if (isRunningInFroyo)
WrapBackupManager.dataChanged(getPackageName());
}
} }

View file

@ -0,0 +1,18 @@
package org.r3pek.pharmacies.backup;
import android.app.backup.BackupAgentHelper;
import android.app.backup.SharedPreferencesBackupHelper;
public class MyBackupAgent extends BackupAgentHelper {
// A key to uniquely identify the set of backup data
private static final String PREFS_BACKUP_KEY = "prefs";
public void onCreate() {
// Ugly hack, but I can't get the defaultSharedPreferences filename elsewhere
final String PREFS_NAME = getPackageName() + "_preferences";
SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, PREFS_NAME);
addHelper(PREFS_BACKUP_KEY, helper);
}
}