當前位置: 首頁>>代碼示例>>Java>>正文


Java SharedPreferences.OnSharedPreferenceChangeListener方法代碼示例

本文整理匯總了Java中android.content.SharedPreferences.OnSharedPreferenceChangeListener方法的典型用法代碼示例。如果您正苦於以下問題:Java SharedPreferences.OnSharedPreferenceChangeListener方法的具體用法?Java SharedPreferences.OnSharedPreferenceChangeListener怎麽用?Java SharedPreferences.OnSharedPreferenceChangeListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.SharedPreferences的用法示例。


在下文中一共展示了SharedPreferences.OnSharedPreferenceChangeListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import android.content.SharedPreferences; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    persistence = new Persistence(getActivity().getApplicationContext());

    SharedPreferences.OnSharedPreferenceChangeListener spChanged = new SharedPreferences.OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            // If the buy schedule has changed, cancel and recreate the alarms.
            if (key.equals("preference_frequency")) {
                try {
                    persistence.setLastBuyTime(0);
                    BuyScheduler.setAlarm(getActivity().getApplicationContext());
                } catch (Exception e) {
                    //
                }
            }
        }
    };

    PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()).registerOnSharedPreferenceChangeListener(spChanged);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);
}
 
開發者ID:aomega08,項目名稱:Keep-HODLing,代碼行數:27,代碼來源:SettingsFragment.java

示例2: testRegisterListener

import android.content.SharedPreferences; //導入方法依賴的package包/類
public void testRegisterListener(View view) {
  String testValue = "myTestString";
  final String testKey = "testR";

  final SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

      Assert.assertEquals(testKey, key);

      showSuccess();
    }
  };
  getPreferences().registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);

  getPreferences().edit().putString(testKey, testValue).apply();

  getPreferences().unregisterOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
}
 
開發者ID:marius-bardan,項目名稱:encryptedprefs,代碼行數:20,代碼來源:MainActivity.java

示例3: onCreate

import android.content.SharedPreferences; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
    addPreferencesFromResource(R.xml.board_preferences);

    mBoardTitlePreference = (EditTextPreference) findPreference(BoardUtils.BOARD_TITLE_KEY);

    setBoardTitlePreference();

    mListenerOptions = new SharedPreferences.OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

            switch (key) {
                case BoardUtils.BOARD_TITLE_KEY:
                    updateBoardTitlePreferenceSummary();
                    break;
                case BoardUtils.CUSTOM_APP_KEY:
                    manageCustomAppPreference();
                    break;
            }
        }
    };

    mCustomAppPreference = findPreference(BoardUtils.CUSTOM_APP_PREF_KEY);
    manageCustomAppPreference();
    mCustomAppPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(getActivity(), MultiSelectRecyclerViewActivity.class);
            getActivity().startActivity(intent);
            return false;
        }
    });
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:37,代碼來源:BoardActivity.java

示例4: onCreate

import android.content.SharedPreferences; //導入方法依賴的package包/類
@Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         // Carrega preferences a partir de um XML
         addPreferencesFromResource(R.xml.user_prefs);

         // pega a Preference especifica do username
         mUserNamePreference = (Preference) getPreferenceManager()
                 .findPreference(USERNAME);

         // Define um listener para atualizar descricao ao modificar preferences
         mListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
             @Override
             public void onSharedPreferenceChanged(
                     SharedPreferences sharedPreferences, String key) {
                 mUserNamePreference.setSummary(sharedPreferences.getString(
                         USERNAME, "Nada ainda"));
             }
         };

         // Pega objeto SharedPreferences gerenciado pelo PreferenceManager para este Fragmento
         SharedPreferences prefs = getPreferenceManager()
                 .getSharedPreferences();

         // Registra listener no objeto SharedPreferences
         prefs.registerOnSharedPreferenceChangeListener(mListener);

         // Invoca callback manualmente para exibir username atual
         //mListener.onSharedPreferenceChanged(prefs, USERNAME);
/**/


     }
 
開發者ID:if710,項目名稱:2017.2-codigo,代碼行數:35,代碼來源:PrefsMenuActivity.java

示例5: registerOnSharedPreferenceChangeListener

import android.content.SharedPreferences; //導入方法依賴的package包/類
public void registerOnSharedPreferenceChangeListener() {
            SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
                @Override
                public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
                    boolean notifIsOn = sharedPreferences.getBoolean(getString(R.string.pref_title_new_message_notifications), true);
                    // TODO
//                    SwitchPreference notifSwitchPreference = (SwitchPreference) getFragmentManager().
                    if (notifIsOn) {
                    } else {

                    }
                }
            };
        }
 
開發者ID:Chan4077,項目名稱:StudyBuddy,代碼行數:15,代碼來源:SettingsActivity.java

示例6: unregisterOnSharedPreferenceChangeListener

import android.content.SharedPreferences; //導入方法依賴的package包/類
@Override
public void unregisterOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener) {
    delegate.unregisterOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
}
 
開發者ID:schul-cloud,項目名稱:schulcloud-mobile-android,代碼行數:5,代碼來源:ObscuredSharedPreferences.java

示例7: registerListener

import android.content.SharedPreferences; //導入方法依賴的package包/類
public void registerListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
    androidSharedPreferences.registerOnSharedPreferenceChangeListener(listener);
}
 
開發者ID:ponewheel,項目名稱:android-ponewheel,代碼行數:4,代碼來源:SharedPreferencesUtil.java

示例8: unregisterOnSharedPreferenceChangeListener

import android.content.SharedPreferences; //導入方法依賴的package包/類
public void unregisterOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
    _sharedPreferences.unregisterOnSharedPreferenceChangeListener(listener);
}
 
開發者ID:CoryCharlton,項目名稱:BittrexApi,代碼行數:4,代碼來源:Settings.java

示例9: unregisterPreferenceChangedListener

import android.content.SharedPreferences; //導入方法依賴的package包/類
public void unregisterPreferenceChangedListener(final SharedPreferences pref, SharedPreferences.OnSharedPreferenceChangeListener value) {
    pref.unregisterOnSharedPreferenceChangeListener(value);
}
 
開發者ID:gsantner,項目名稱:memetastic,代碼行數:4,代碼來源:AppSettingsBase.java

示例10: registerPreferenceChangedListener

import android.content.SharedPreferences; //導入方法依賴的package包/類
public void registerPreferenceChangedListener(final SharedPreferences pref, SharedPreferences.OnSharedPreferenceChangeListener value) {
    pref.registerOnSharedPreferenceChangeListener(value);
}
 
開發者ID:gsantner,項目名稱:markor,代碼行數:4,代碼來源:AppSettingsBase.java

示例11: unregisterListener

import android.content.SharedPreferences; //導入方法依賴的package包/類
public void unregisterListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
    prefs.unregisterOnSharedPreferenceChangeListener(listener);
}
 
開發者ID:Genius,項目名稱:genius-groupie,代碼行數:4,代碼來源:Prefs.java

示例12: registerOnSharedPreferenceChangeListener

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * Register SharedPreferences change listener
 *
 * @param listener listener object of OnSharedPreferenceChangeListener
 */
public void registerOnSharedPreferenceChangeListener(
        SharedPreferences.OnSharedPreferenceChangeListener listener) {

    preferences.registerOnSharedPreferenceChangeListener(listener);
}
 
開發者ID:IdeaTrackerPlus,項目名稱:IdeaTrackerPlus,代碼行數:11,代碼來源:TinyDB.java

示例13: registerOnSharedPreferenceChangeListener

import android.content.SharedPreferences; //導入方法依賴的package包/類
public void registerOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
    _sharedPreferences.registerOnSharedPreferenceChangeListener(listener);
}
 
開發者ID:CoryCharlton,項目名稱:BittrexApi,代碼行數:4,代碼來源:Settings.java

示例14: registerOnSharedPreferenceChangedListener

import android.content.SharedPreferences; //導入方法依賴的package包/類
public void registerOnSharedPreferenceChangedListener(SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener) {
    mPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
 
開發者ID:aliumujib,項目名稱:Orin,代碼行數:4,代碼來源:PreferenceUtil.java

示例15: registerListener

import android.content.SharedPreferences; //導入方法依賴的package包/類
public void registerListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
    prefs.registerOnSharedPreferenceChangeListener(listener);
}
 
開發者ID:Genius,項目名稱:genius-groupie,代碼行數:4,代碼來源:Prefs.java


注:本文中的android.content.SharedPreferences.OnSharedPreferenceChangeListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。