示例#1
0
 private void initPrefs() {
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
   SharedPreferences.Editor edit = prefs.edit();
   boolean changes = false;
   if (!prefs.contains(PREFS_VIBRATE_KEY)) {
     changes = true;
     edit.putString(PREFS_VIBRATE_KEY, PREFS_VIBRATE_DEFAULT);
   }
   if (!prefs.contains(PREFS_SERVER_HOST_KEY)) {
     changes = true;
     edit.putString(PREFS_SERVER_HOST_KEY, PREFS_SERVER_HOST_DEFAULT);
   }
   if (!prefs.contains(PREFS_SERVER_PORT_KEY)) {
     changes = true;
     edit.putString(PREFS_SERVER_PORT_KEY, PREFS_SERVER_PORT_DEFAULT);
   }
   if (!prefs.contains(PREFS_LAYOUT_KEY)) {
     changes = true;
     edit.putString(PREFS_LAYOUT_KEY, PREFS_LAYOUT_DEFAULT);
   }
   try {
     layoutManager.getLayoutResource(prefs.getString(PREFS_LAYOUT_KEY, ""));
   } catch (NoSuchElementException e) {
     changes = true;
     edit.putString(PREFS_LAYOUT_KEY, PREFS_LAYOUT_DEFAULT);
   }
   if (changes) {
     edit.commit();
   }
 }
示例#2
0
 private int getContentView() {
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
   String layoutUri = prefs.getString(PREFS_LAYOUT_KEY, PREFS_LAYOUT_DEFAULT);
   return layoutManager.getLayoutResource(layoutUri);
 }