本文整理匯總了Java中android.content.SharedPreferences.OnSharedPreferenceChangeListener類的典型用法代碼示例。如果您正苦於以下問題:Java OnSharedPreferenceChangeListener類的具體用法?Java OnSharedPreferenceChangeListener怎麽用?Java OnSharedPreferenceChangeListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
OnSharedPreferenceChangeListener類屬於android.content.SharedPreferences包,在下文中一共展示了OnSharedPreferenceChangeListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: compareWithConfig
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
/**
* 檢查當token信息與配置文件是否保持一致,若不一致則對當前的token信息進行初始化
*/
private void compareWithConfig() {
if (this.context == null) {
return;
}
/**
* 對配置的權限信息進行監控,保持多個AccessTokenManager對象之間的,權限信息一致。
*/
final SharedPreferences sp = this.context.getSharedPreferences(BAIDU_OAUTH_CONFIG, Context.MODE_PRIVATE);
sp.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
String acToken = sp.getString(OauthConfig.PrefenenceKey.SP_ACCESS_TOKEN, null);
if (accessToken != null && !accessToken.equals(acToken)) {
initToken();
}
}
});
}
示例2: onCreate
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
final SubScreenFragment fragment = SubScreenFragment.this;
final Context context = fragment.getActivity();
if (context == null || fragment.getPreferenceScreen() == null) {
final String tag = fragment.getClass().getSimpleName();
// TODO: Introduce a static function to register this class and ensure that
// onCreate must be called before "onSharedPreferenceChanged" is called.
Log.w(tag, "onSharedPreferenceChanged called before activity starts.");
return;
}
new BackupManager(context).dataChanged();
fragment.onSharedPreferenceChanged(prefs, key);
}
};
getSharedPreferences().registerOnSharedPreferenceChangeListener(
mSharedPreferenceChangeListener);
}
示例3: PreferencesService
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
@Inject
public PreferencesService(@ApplicationContext Context context) {
mPrefs = context.getSharedPreferences(PREFS_FILE_NAME, Context.MODE_PRIVATE);
mChangedKeys = Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(final Subscriber<? super String> subscriber) {
final OnSharedPreferenceChangeListener listener = new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
subscriber.onNext(key);
}
};
Subscription subscription = Subscriptions.create(new Action0() {
@Override public void call() {
mPrefs.unregisterOnSharedPreferenceChangeListener(listener);
}
});
subscriber.add(subscription);
mPrefs.registerOnSharedPreferenceChangeListener(listener);
}
}).share();
}
示例4: BroadcastEventBridge
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
public BroadcastEventBridge(Context context,
String prefName,
CacheCandidateProvider cacheCandidateProvider,
CacheProvider cacheProvider,
SerializerFactory serializerFactory,
TaskExecutor taskExecutor,
ValueEncryption valueEncryption,
DirectoryProvider directoryProvider,
Map<String, List<OnSharedPreferenceChangeListener>> allListeners) {
this.context = context;
this.prefName = prefName;
this.cacheCandidateProvider = cacheCandidateProvider;
this.cacheProvider = cacheProvider;
this.serializerFactory = serializerFactory;
this.taskExecutor = taskExecutor;
this.valueEncryption = valueEncryption;
this.updateActionName = createUpdateActionName(directoryProvider);
this.removeActionName = createRemoveActionName(directoryProvider);
this.currentListeners = putIfAbsentListeners(prefName, allListeners);
this.updateReceiver = createUpdateReceiver();
this.removeReceiver = createRemoveReceiver();
this.processId = Process.myPid();
}
示例5: commit
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
public boolean commit() {
//Log.d(this.getClass().toString(), "commit() changes back to database");
SQLiteDatabase db = hostdb.getWritableDatabase();
db.update(table, update, "_id = ?", new String[] { String.valueOf(id) });
db.close();
// make sure we refresh the parent cached values
cacheValues();
// and update any listeners
for(OnSharedPreferenceChangeListener listener : listeners) {
listener.onSharedPreferenceChanged(CursorPreferenceHack.this, null);
}
return true;
}
示例6: a
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
public static SharedPreferences.OnSharedPreferenceChangeListener a(Context paramContext, Runnable paramRunnable)
{
hvu localhvu = (hvu)mbb.a(paramContext, hvu.class);
if (hwa.d == localhvu.c())
{
if (!efj.j()) {
break label68;
}
paramRunnable.run();
}
for (;;)
{
hvw localhvw = new hvw(paramContext, paramRunnable);
a.add(localhvw);
localhvu.b.registerOnSharedPreferenceChangeListener(localhvw);
localhvu.b();
return localhvw;
label68:
efj.m().post(paramRunnable);
}
}
示例7: onSharedPreferenceChanged
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
Set<OnSharedPreferenceChangeListener> listeners = new HashSet<OnSharedPreferenceChangeListener>();
synchronized (this) {
if (prefs.contains(key)) {
mMap.put(key, sharedPreferences.getAll().get(key));
} else {
mMap.remove(key);
}
listeners.addAll(mListeners.keySet());
}
for (OnSharedPreferenceChangeListener listener : listeners) {
if (listener != null) {
listener.onSharedPreferenceChanged(this, key);
}
}
}
開發者ID:chauhansaurabhb,項目名稱:EndUserInteractioion_RequestResponse_Command,代碼行數:19,代碼來源:AsyncSharedPrefs.java
示例8: addListener
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
/**
* Add an OnSettingChangedListener to the SettingsManager, which will
* execute onSettingsChanged when any SharedPreference has been updated.
*/
public void addListener(final OnSettingChangedListener listener) {
if (listener == null) {
throw new IllegalArgumentException("OnSettingChangedListener cannot be null.");
}
if (mListeners.contains(listener)) {
return;
}
mListeners.add(listener);
OnSharedPreferenceChangeListener sharedPreferenceListener =
getSharedPreferenceListener(listener);
mSharedPreferenceListeners.add(sharedPreferenceListener);
mDefaultPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceListener);
if (mCustomPreferences != null) {
mCustomPreferences.registerOnSharedPreferenceChangeListener(
sharedPreferenceListener);
}
Log.v(TAG, "listeners: " + mListeners);
}
示例9: removeListener
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
/**
* Remove a specific SettingsListener. This should be done in onPause if a
* listener has been set.
*/
public void removeListener(OnSettingChangedListener listener) {
if (listener == null) {
throw new IllegalArgumentException();
}
if (!mListeners.contains(listener)) {
return;
}
int index = mListeners.indexOf(listener);
mListeners.remove(listener);
OnSharedPreferenceChangeListener sharedPreferenceListener =
mSharedPreferenceListeners.get(index);
mSharedPreferenceListeners.remove(index);
mDefaultPreferences.unregisterOnSharedPreferenceChangeListener(
sharedPreferenceListener);
if (mCustomPreferences != null) {
mCustomPreferences.unregisterOnSharedPreferenceChangeListener(
sharedPreferenceListener);
}
}
示例10: ComboPreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
public ComboPreferences(Context context) {
mPackageName = context.getPackageName();
mPrefGlobal = context.getSharedPreferences(
getGlobalSharedPreferencesName(context), Context.MODE_PRIVATE);
mPrefGlobal.registerOnSharedPreferenceChangeListener(this);
synchronized (sMap) {
sMap.put(context, this);
}
mListeners = new CopyOnWriteArrayList<OnSharedPreferenceChangeListener>();
// The global preferences was previously stored in the default
// shared preferences file. They should be stored in the camera-specific
// shared preferences file so we can backup them solely.
SharedPreferences oldprefs =
PreferenceManager.getDefaultSharedPreferences(context);
if (!mPrefGlobal.contains(CameraSettings.KEY_VERSION)
&& oldprefs.contains(CameraSettings.KEY_VERSION)) {
moveGlobalPrefsFrom(oldprefs);
}
}
示例11: onCreate
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
mSharedPreferences = MultiprocessSharedPreferences.getSharedPreferences(this, SP_NAME, Context.MODE_PRIVATE);
Log.d(TAG, "onCreate." + SP_KEY + " = " + mSharedPreferences.getString(SP_KEY, null));
mOnSharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
String msg = "onSharedPreferenceChanged." + SP_KEY + " = " + sharedPreferences.getString(SP_KEY, null);
Log.d(TAG, msg);
Toast.makeText(CoreService.this, msg, Toast.LENGTH_SHORT).show();
}
};
mSharedPreferences.registerOnSharedPreferenceChangeListener(mOnSharedPreferenceChangeListener);
}
示例12: onCreate
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplication());
sharedPrefs.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
BackupManager.dataChanged(getPackageName());
}
});
Utils.setStrictMode(true);
setContentView(getLayoutResource());
initUI();
}
示例13: PersistentProperties
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
public PersistentProperties(Future<SharedPreferences> paramFuture1, Future<SharedPreferences> paramFuture2)
{
this.mLoadReferrerPreferences = paramFuture1;
this.mLoadStoredPreferences = paramFuture2;
this.mSuperPropertiesCache = null;
this.mReferrerPropertiesCache = null;
this.mIdentitiesLoaded = false;
this.mReferrerChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener()
{
public void onSharedPreferenceChanged(SharedPreferences paramAnonymousSharedPreferences, String paramAnonymousString)
{
synchronized (PersistentProperties.sReferrerPrefsLock)
{
PersistentProperties.this.readReferrerProperties();
PersistentProperties.access$202(false);
return;
}
}
};
}
示例14: onCreate
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
CancelAllNotif();
Log.d(LOG_TAG, "Service started");
//handle preference
UpdatePref();
prefs = PreferenceManager.getDefaultSharedPreferences(this);
listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Log.d(LOG_TAG, "Preference changed");
UpdatePref();
}
};
prefs.registerOnSharedPreferenceChangeListener(listener);
}
示例15: restorePreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //導入依賴的package包/類
public void restorePreferences(final Parameters param) {
// Do synchronization in "reloadPreferences()"
OnSharedPreferenceChangeListener l =
mSharedPreferenceChangeListener;
// Unregister the listener since "upgrade preference" will
// change bunch of preferences. We can handle them with one
// onSharedPreferencesChanged();
mSharedPrefs.unregisterOnSharedPreferenceChangeListener(l);
Context context = getGLRootView().getContext();
Editor editor = mSharedPrefs.edit();
editor.clear();
editor.apply();
CameraSettings.upgradeAllPreferences(mSharedPrefs);
CameraSettings.initialCameraPictureSize(context, param);
reloadPreferences();
if (mListener != null) {
mListener.onSharedPreferencesChanged();
}
mSharedPrefs.registerOnSharedPreferenceChangeListener(l);
}