diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f1a6014..99b166d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,7 +1,7 @@ - + @@ -13,7 +13,8 @@ - + + diff --git a/src/org/r3pek/pharmacies/MyPreferences.java b/src/org/r3pek/pharmacies/MyPreferences.java index ea53ea3..7c3b0ce 100644 --- a/src/org/r3pek/pharmacies/MyPreferences.java +++ b/src/org/r3pek/pharmacies/MyPreferences.java @@ -1,18 +1,37 @@ package org.r3pek.pharmacies; +import org.r3pek.pharmacies.backup.WrapBackupManager; import org.r3pek.pharmacies.widgets.SeekBarPreference; import android.os.Bundle; import android.preference.PreferenceActivity; +import android.util.Log; 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) { super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.preferences); SeekBarPreference sbp = (SeekBarPreference) findPreference("pref_gen_maxdist"); sbp.setMin(1); - } + } + + @Override + public void onStop() { + super.onStop(); + + if (isRunningInFroyo) + WrapBackupManager.dataChanged(getPackageName()); + } } diff --git a/src/org/r3pek/pharmacies/backup/MyBackupAgent.java b/src/org/r3pek/pharmacies/backup/MyBackupAgent.java new file mode 100644 index 0000000..b67db3a --- /dev/null +++ b/src/org/r3pek/pharmacies/backup/MyBackupAgent.java @@ -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); + } + +}