use of net.grandcentrix.tray.AppPreferences in project tray by grandcentrix.
the class TrayProviderHelperTest method testClearButFails.
public void testClearButFails() throws Exception {
Uri uri = new TrayUri(getProviderMockContext()).get();
MockContentProvider mockContentProvider = new MockContentProvider(getProviderMockContext()) {
@Override
public int delete(final Uri uri, final String selection, final String[] selectionArgs) {
throw new IllegalStateException("something serious is wrong");
}
};
getProviderMockContext().addProvider(uri.getAuthority(), mockContentProvider);
getProviderMockContext().enableMockResolver(true);
assertFalse(mProviderHelper.clearBut(new AppPreferences(getProviderMockContext())));
}
use of net.grandcentrix.tray.AppPreferences in project tray by grandcentrix.
the class MultiProcessService method onCreate.
@Override
public void onCreate() {
super.onCreate();
mTrayPreferences = new AppPreferences(this);
mSharedPreferences = getSharedPreferences(SampleActivity.SHARED_PREF_NAME, Context.MODE_MULTI_PROCESS);
}
use of net.grandcentrix.tray.AppPreferences in project tray by grandcentrix.
the class SampleActivity method onCreate.
@SuppressLint("CommitPrefEdits")
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample);
mAppPrefs = new AppPreferences(this);
mSharedPreferences = getSharedPreferences(SHARED_PREF_NAME, Context.MODE_MULTI_PROCESS);
int startupCount = mAppPrefs.getInt(STARTUP_COUNT, 0);
if (startupCount == 0) {
// save some "old" preferences which get migrated into the ImportTrayPreferences.
// this works only the very first time ImportTrayPreferences gets created. You need to
// wipe (clean is not enough) ImportTrayPreferences or delete the app data to retrigger
// the call to ImportTrayPreferences#onCreate()
mSharedPreferences.edit().putString("userToken", UUID.randomUUID().toString()).putString("gcmToken", UUID.randomUUID().toString()).commit();
}
if (savedInstanceState == null) {
mAppPrefs.put(STARTUP_COUNT, ++startupCount);
}
testAutoBackup();
mImportPreference = new ImportTrayPreferences(this);
final TextView text = (TextView) findViewById(android.R.id.text1);
text.setText(getString(R.string.sample_launched_x_times, startupCount));
final Button resetBtn = (Button) findViewById(R.id.reset);
resetBtn.setOnClickListener(this);
final Button writeSharedPref = (Button) findViewById(R.id.write_shared_pref);
writeSharedPref.setOnClickListener(this);
final Button importInTray = (Button) findViewById(R.id.import_shared_pref);
importInTray.setOnClickListener(this);
final Button multiprocessIncreaser = (Button) findViewById(R.id.increase_multiprocess_counter);
multiprocessIncreaser.setOnClickListener(this);
final Button multiprocessIncreaserOther = (Button) findViewById(R.id.increase_multiprocess_counter_other_process);
multiprocessIncreaserOther.setOnClickListener(this);
}
use of net.grandcentrix.tray.AppPreferences in project tray by grandcentrix.
the class TrayProviderHelperTest method testClearBut.
public void testClearBut() throws Exception {
// We need a package name in this test, thus creating our own mock context
final IsolatedContext context = getProviderMockContext();
assertTrue(mProviderHelper.persist(MODULE_A, KEY_A, STRING_A));
assertTrue(mProviderHelper.persist(MODULE_A, KEY_B, STRING_B));
assertTrue(mProviderHelper.persist(MODULE_B, KEY_A, STRING_A));
assertTrue(mProviderHelper.persist(MODULE_B, KEY_B, STRING_B));
assertTrue(mProviderHelper.persist(MODULE_C, KEY_A, STRING_A));
assertTrue(mProviderHelper.persist(MODULE_C, KEY_B, STRING_B));
assertTrue(mProviderHelper.persist(context.getPackageName(), KEY_A, STRING_A));
assertTrue(mProviderHelper.persist(context.getPackageName(), KEY_B, STRING_B));
assertUserDatabaseSize(8);
mProviderHelper.clearBut(new AppPreferences(context), new TestTrayModulePreferences(context, MODULE_A), new TestTrayModulePreferences(context, MODULE_B));
assertUserDatabaseSize(6);
mProviderHelper.clearBut(new TestTrayModulePreferences(context, MODULE_A), new TestTrayModulePreferences(context, MODULE_B));
assertUserDatabaseSize(4);
mProviderHelper.clearBut(new TestTrayModulePreferences(context, MODULE_A));
assertUserDatabaseSize(2);
mProviderHelper.clearBut((TrayPreferences) null);
assertUserDatabaseSize(0);
assertTrue(mProviderHelper.persist(MODULE_A, KEY_A, STRING_A));
assertTrue(mProviderHelper.persist(MODULE_A, KEY_B, STRING_B));
assertTrue(mProviderHelper.persist(context.getPackageName(), KEY_A, STRING_A));
assertTrue(mProviderHelper.persist(context.getPackageName(), KEY_B, STRING_B));
mProviderHelper.clearBut(new AppPreferences(context));
assertUserDatabaseSize(2);
// Also test empty values (= clear everything)
assertTrue(mProviderHelper.persist(MODULE_A, KEY_A, STRING_A));
assertTrue(mProviderHelper.persist(MODULE_A, KEY_B, STRING_B));
mProviderHelper.clearBut((TrayPreferences) null);
assertUserDatabaseSize(0);
}
Aggregations