Java Code Examples for android.content.SharedPreferences.OnSharedPreferenceChangeListener

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project QuickSnap, under directory /Camera/src/com/lightbox/android/camera/ui/.

Source file: HeadUpDisplay.java

  22 
vote

public void restorePreferences(final Parameters param){
  OnSharedPreferenceChangeListener l=mSharedPreferenceChangeListener;
  mSharedPrefs.unregisterOnSharedPreferenceChangeListener(l);
  Context context=getGLRootView().getContext();
  Editor editor=mSharedPrefs.edit();
  editor.clear();
  editor.commit();
  CameraSettings.upgradeAllPreferences(mSharedPrefs);
  CameraSettings.initialCameraPictureSize(context,param);
  reloadPreferences();
  if (mListener != null) {
    mListener.onSharedPreferencesChanged();
  }
  mSharedPrefs.registerOnSharedPreferenceChangeListener(l);
}
 

Example 2

From project zirco-browser, under directory /src/org/zirco/ui/activities/.

Source file: MainActivity.java

  22 
vote

private void registerPreferenceChangeListener(){
  mPreferenceChangeListener=new OnSharedPreferenceChangeListener(){
    @Override public void onSharedPreferenceChanged(    SharedPreferences sharedPreferences,    String key){
      if (key.equals(Constants.PREFERENCE_BOOKMARKS_DATABASE)) {
        updateBookmarksDatabaseSource();
      }
    }
  }
;
  PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(mPreferenceChangeListener);
}
 

Example 3

From project opensudoku, under directory /OpenSudoku/src/cz/romario/opensudoku/gui/.

Source file: HintsQueue.java

  21 
vote

public HintsQueue(Context context){
  mContext=context;
  mPrefs=mContext.getSharedPreferences(PREF_FILE_NAME,Context.MODE_PRIVATE);
  SharedPreferences gameSettings=PreferenceManager.getDefaultSharedPreferences(context);
  gameSettings.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener(){
    @Override public void onSharedPreferenceChanged(    SharedPreferences sharedPreferences,    String key){
      if (key.equals("show_hints")) {
        mOneTimeHintsEnabled=sharedPreferences.getBoolean("show_hints",true);
      }
    }
  }
);
  mOneTimeHintsEnabled=gameSettings.getBoolean("show_hints",true);
  mHintDialog=new AlertDialog.Builder(context).setIcon(android.R.drawable.ic_menu_info_details).setTitle(R.string.hint).setMessage("").setPositiveButton(R.string.close,mHintClosed).create();
  mHintDialog.setOnDismissListener(new OnDismissListener(){
    @Override public void onDismiss(    DialogInterface dialog){
      processQueue();
    }
  }
);
  mMessages=new LinkedList<Message>();
}
 

Example 4

From project QuasselDroid, under directory /src/com/iskrembilen/quasseldroid/gui/.

Source file: PreferenceView.java

  21 
vote

/** 
 * Called when the activity is first created. 
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  addPreferencesFromResource(R.layout.preferences);
  SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
  listener=new OnSharedPreferenceChangeListener(){
    @Override public void onSharedPreferenceChanged(    SharedPreferences sharedPreferences,    String key){
      if (key.equals(getResources().getString(R.string.preference_theme))) {
        ThemeUtil.setTheme(PreferenceView.this,sharedPreferences.getString(key,""));
      }
    }
  }
;
  preferences.registerOnSharedPreferenceChangeListener(listener);
}
 

Example 5

From project BBC-News-Reader, under directory /src/com/digitallizard/bbcnewsreader/.

Source file: ResourceService.java

  20 
vote

@Override public void onCreate(){
  loadInProgress=false;
  if (settings == null) {
    settings=getSharedPreferences(ReaderActivity.PREFS_FILE_NAME,MODE_PRIVATE);
  }
  if (database == null) {
    setDatabase(new DatabaseHandler(this));
    if (!getDatabase().isCreated()) {
      getDatabase().addCategoriesFromXml();
    }
  }
  if (getWebManager() == null) {
    setWebManager(new WebManager(this));
  }
  if (rssManager == null) {
    rssManager=new RSSManager(this);
  }
  broadcastReceiver=new BroadcastReceiver(){
    @Override public void onReceive(    Context context,    Intent intent){
      if (intent.getAction().equals("com.digitallizard.bbcnewsreader.action.LOAD_NEWS")) {
        loadData();
      }
    }
  }
;
  this.registerReceiver(broadcastReceiver,new IntentFilter(ACTION_LOAD));
  updateSettings();
  settingsChangedListener=new OnSharedPreferenceChangeListener(){
    public void onSharedPreferenceChanged(    SharedPreferences preferences,    String key){
      updateSettings();
    }
  }
;
  settings.registerOnSharedPreferenceChangeListener(settingsChangedListener);
}
 

Example 6

From project opensudoku-blackberry, under directory /opensudoku/src/net/bmagro/blackberry/opensudoku/gui/.

Source file: HintsQueue.java

  20 
vote

public HintsQueue(Context context){
  mContext=context;
  mPrefs=mContext.getSharedPreferences(PREF_FILE_NAME,Context.MODE_PRIVATE);
  SharedPreferences gameSettings=PreferenceManager.getDefaultSharedPreferences(context);
  gameSettings.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener(){
    @Override public void onSharedPreferenceChanged(    SharedPreferences sharedPreferences,    String key){
      if (key.equals("show_hints")) {
        mOneTimeHintsEnabled=sharedPreferences.getBoolean("show_hints",true);
      }
    }
  }
);
  mOneTimeHintsEnabled=gameSettings.getBoolean("show_hints",true);
  mHintDialog=new AlertDialog.Builder(context).setIcon(android.R.drawable.ic_menu_info_details).setTitle(R.string.hint).setMessage("").setPositiveButton(R.string.close,mHintClosed).create();
  mHintDialog.setOnDismissListener(new OnDismissListener(){
    @Override public void onDismiss(    DialogInterface dialog){
      processQueue();
    }
  }
);
  mMessages=new LinkedList<Message>();
}
 

Example 7

From project packages_apps_BlackICEControl, under directory /src/com/blackice/control/service/.

Source file: WeatherRefreshService.java

  20 
vote

@Override public void onCreate(){
  mContext=getApplicationContext();
  prefs=getApplicationContext().getSharedPreferences("weather",MODE_WORLD_WRITEABLE);
  alarms=(AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
  refreshIntervalInMinutes=prefs.getInt(WeatherPrefs.KEY_REFRESH,0);
  prefs.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener(){
    @Override public void onSharedPreferenceChanged(    SharedPreferences sharedPreferences,    String key){
      if (key.equals(WeatherPrefs.KEY_REFRESH)) {
        refreshIntervalInMinutes=WeatherPrefs.getRefreshInterval(mContext);
        scheduleRefresh();
      }
    }
  }
);
}
 

Example 8

From project packages_apps_ROMControl, under directory /src/com/aokp/romcontrol/weather/.

Source file: WeatherRefreshService.java

  20 
vote

@Override public void onCreate(){
  mContext=getApplicationContext();
  prefs=getApplicationContext().getSharedPreferences("weather",MODE_WORLD_WRITEABLE);
  alarms=(AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
  refreshIntervalInMinutes=prefs.getInt(WeatherPrefs.KEY_REFRESH,0);
  prefs.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener(){
    @Override public void onSharedPreferenceChanged(    SharedPreferences sharedPreferences,    String key){
      if (key.equals(WeatherPrefs.KEY_REFRESH)) {
        refreshIntervalInMinutes=WeatherPrefs.getRefreshInterval(mContext);
        scheduleRefresh();
      }
    }
  }
);
}
 

Example 9

From project QuasselDroid, under directory /src/com/iskrembilen/quasseldroid/gui/fragments/.

Source file: BufferFragment.java

  20 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  if (savedInstanceState != null) {
    restoreListPosition=savedInstanceState.getInt(LIST_POSITION_KEY);
    restoreItemPosition=savedInstanceState.getInt(ITEM_POSITION_KEY);
  }
  setHasOptionsMenu(true);
  offlineColor=getResources().getColor(R.color.buffer_offline_color);
  preferences=PreferenceManager.getDefaultSharedPreferences(getSherlockActivity());
  sharedPreferenceChangeListener=new OnSharedPreferenceChangeListener(){
    @Override public void onSharedPreferenceChanged(    SharedPreferences sharedPreferences,    String key){
      if (key.equals(getResources().getString(R.string.preference_fontsize_channel_list))) {
        bufferListAdapter.notifyDataSetChanged();
      }
    }
  }
;
  preferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
 

Example 10

From project QuasselDroid, under directory /src/com/iskrembilen/quasseldroid/gui/.

Source file: MainActivity.java

  20 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  setTheme(ThemeUtil.theme);
  super.onCreate(savedInstanceState);
  currentTheme=ThemeUtil.theme;
  setContentView(R.layout.main_layout);
  FragmentAdapter adapter=new FragmentAdapter(getSupportFragmentManager());
  pager=(ViewPager)findViewById(R.id.pager);
  pager.setOffscreenPageLimit(2);
  PagerTabStrip pagerIndicator=(PagerTabStrip)findViewById(R.id.pagerIndicator);
  pagerIndicator.setDrawFullUnderline(false);
  pagerIndicator.setTextColor(getResources().getColor(R.color.pager_indicator_text_color));
  pagerIndicator.setTabIndicatorColor(getResources().getColor(R.color.pager_indicator_color));
  pager.setOnPageChangeListener(adapter);
  pager.setAdapter(adapter);
  preferences=PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
  showLag=preferences.getBoolean(getString(R.string.preference_show_lag),false);
  sharedPreferenceChangeListener=new OnSharedPreferenceChangeListener(){
    @Override public void onSharedPreferenceChanged(    SharedPreferences sharedPreferences,    String key){
      if (key.equals(getResources().getString(R.string.preference_show_lag))) {
        showLag=preferences.getBoolean(getString(R.string.preference_show_lag),false);
        if (!showLag) {
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            setActionBarSubtitle("");
          }
 else {
            setTitle(getResources().getString(R.string.app_name));
          }
        }
      }
    }
  }
;
  preferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
 

Example 11

From project QuasselDroid, under directory /src/com/iskrembilen/quasseldroid/service/.

Source file: CoreConnService.java

  20 
vote

@Override public void onCreate(){
  super.onCreate();
  Log.i(TAG,"Service created");
  incomingHandler=new IncomingHandler();
  notificationManager=new QuasseldroidNotificationManager(this);
  preferences=PreferenceManager.getDefaultSharedPreferences(this);
  preferenceParseColors=preferences.getBoolean(getString(R.string.preference_colored_text),false);
  preferenceUseWakeLock=preferences.getBoolean(getString(R.string.preference_wake_lock),false);
  preferenceListener=new OnSharedPreferenceChangeListener(){
    @Override public void onSharedPreferenceChanged(    SharedPreferences sharedPreferences,    String key){
      if (key.equals(getString(R.string.preference_colored_text))) {
        preferenceParseColors=preferences.getBoolean(getString(R.string.preference_colored_text),false);
      }
 else       if (key.equals(getString(R.string.preference_wake_lock))) {
        preferenceUseWakeLock=preferences.getBoolean(getString(R.string.preference_wake_lock),true);
        if (!preferenceUseWakeLock)         releaseWakeLockIfExists();
 else         if (preferenceUseWakeLock && isConnected())         acquireWakeLockIfEnabled();
      }
    }
  }
;
  preferences.registerOnSharedPreferenceChangeListener(preferenceListener);
  BusProvider.getInstance().register(this);
  startForeground(R.id.NOTIFICATION,notificationManager.getConnectingNotification());
}
 

Example 12

From project Anki-Android, under directory /src/com/ichi2/anki/.

Source file: DeckPreferences.java

  19 
vote

@Override public boolean commit(){
  Log.d(AnkiDroidApp.TAG,"DeckPreferences - commit() changes back to database");
  for (  Entry<String,Object> entry : mUpdate.valueSet()) {
    if (entry.getKey().equals("newCardsPDay")) {
      AnkiDroidApp.deck().setNewCardsPerDay(Integer.parseInt(entry.getValue().toString()));
    }
 else     if (entry.getKey().equals("sessionQLimit")) {
      AnkiDroidApp.deck().setSessionRepLimit(Long.parseLong(entry.getValue().toString()));
    }
 else     if (entry.getKey().equals("sessionTLimit")) {
      AnkiDroidApp.deck().setSessionTimeLimit(60 * Long.parseLong(entry.getValue().toString()));
    }
 else     if (entry.getKey().equals("newCardOrder")) {
      AnkiDroidApp.deck().setNewCardOrder(Integer.parseInt(entry.getValue().toString()));
    }
 else     if (entry.getKey().equals("newCardSpacing")) {
      AnkiDroidApp.deck().setNewCardSpacing(Integer.parseInt(entry.getValue().toString()));
    }
 else     if (entry.getKey().equals("revCardOrder")) {
      AnkiDroidApp.deck().setRevCardOrder(Integer.parseInt(entry.getValue().toString()));
    }
  }
  cacheValues();
  for (  OnSharedPreferenceChangeListener listener : listeners) {
    listener.onSharedPreferenceChanged(DeckPreferenceHack.this,null);
  }
  return true;
}
 

Example 13

From project connectbot, under directory /src/sk/vx/connectbot/.

Source file: HostEditorActivity.java

  19 
vote

public boolean commit(){
  SQLiteDatabase db=hostdb.getWritableDatabase();
  db.update(table,update,"_id = ?",new String[]{String.valueOf(id)});
  db.close();
  cacheValues();
  for (  OnSharedPreferenceChangeListener listener : listeners) {
    listener.onSharedPreferenceChanged(CursorPreferenceHack.this,null);
  }
  return true;
}
 

Example 14

From project packages_apps_Camera_1, under directory /src/com/android/camera/.

Source file: ComboPreferences.java

  19 
vote

public ComboPreferences(Context context){
  mPrefGlobal=PreferenceManager.getDefaultSharedPreferences(context);
  mPrefGlobal.registerOnSharedPreferenceChangeListener(this);
synchronized (sMap) {
    sMap.put(context,this);
  }
  mListeners=new CopyOnWriteArrayList<OnSharedPreferenceChangeListener>();
}
 

Example 15

From project packages_apps_Camera_2, under directory /src/com/android/camera/.

Source file: ComboPreferences.java

  19 
vote

public ComboPreferences(Context context){
  mPrefGlobal=PreferenceManager.getDefaultSharedPreferences(context);
  mPrefGlobal.registerOnSharedPreferenceChangeListener(this);
synchronized (sMap) {
    sMap.put(context,this);
  }
  mListeners=new CopyOnWriteArrayList<OnSharedPreferenceChangeListener>();
}
 

Example 16

From project platform_packages_apps_camera, under directory /src/com/android/camera/.

Source file: ComboPreferences.java

  19 
vote

public ComboPreferences(Context context){
  mPrefGlobal=PreferenceManager.getDefaultSharedPreferences(context);
  mPrefGlobal.registerOnSharedPreferenceChangeListener(this);
synchronized (sMap) {
    sMap.put(context,this);
  }
  mListeners=new CopyOnWriteArrayList<OnSharedPreferenceChangeListener>();
}
 

Example 17

From project QuickSnap, under directory /Camera/src/com/lightbox/android/camera/.

Source file: ComboPreferences.java

  19 
vote

public ComboPreferences(Context context){
  mPrefGlobal=PreferenceManager.getDefaultSharedPreferences(context);
  mPrefGlobal.registerOnSharedPreferenceChangeListener(this);
synchronized (sMap) {
    sMap.put(context,this);
  }
  mListeners=new CopyOnWriteArrayList<OnSharedPreferenceChangeListener>();
}
 

Example 18

From project Sage-Mobile-Calc, under directory /src/org/connectbot/.

Source file: HostEditorActivity.java

  19 
vote

public boolean commit(){
  SQLiteDatabase db=hostdb.getWritableDatabase();
  db.update(table,update,"_id = ?",new String[]{String.valueOf(id)});
  db.close();
  cacheValues();
  for (  OnSharedPreferenceChangeListener listener : listeners) {
    listener.onSharedPreferenceChanged(CursorPreferenceHack.this,null);
  }
  return true;
}