本文整理汇总了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);
}