本文整理汇总了Java中android.content.SharedPreferences.OnSharedPreferenceChangeListener.onSharedPreferenceChanged方法的典型用法代码示例。如果您正苦于以下问题:Java OnSharedPreferenceChangeListener.onSharedPreferenceChanged方法的具体用法?Java OnSharedPreferenceChangeListener.onSharedPreferenceChanged怎么用?Java OnSharedPreferenceChangeListener.onSharedPreferenceChanged使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.SharedPreferences.OnSharedPreferenceChangeListener
的用法示例。
在下文中一共展示了OnSharedPreferenceChangeListener.onSharedPreferenceChanged方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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
示例3: 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);
}
}
}
示例4: commit
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //导入方法依赖的package包/类
public boolean commit() {
//Log.d(this.getClass().toString(), "commit() changes back to database");
SQLiteDatabase db = m_streamdb.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;
}
示例5: onCreate
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.user_prefs);
// Get the username Preference
mUserNamePreference = (EditTextPreference) getPreferenceManager()
.findPreference(USERNAME);
// Attach a listener to update summary when username changes
mListener = new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(
SharedPreferences sharedPreferences, String key) {
if (key.equals(USERNAME))
mUserNamePreference.setSummary(sharedPreferences.getString(
USERNAME, "None Set"));
}
};
// Get SharedPreferences object managed by the PreferenceManager for
// this Fragment
SharedPreferences prefs = getPreferenceManager()
.getSharedPreferences();
// Register a listener on the SharedPreferences object
prefs.registerOnSharedPreferenceChangeListener(mListener);
// Invoke callback manually to display the current username
mListener.onSharedPreferenceChanged(prefs, USERNAME);
}
示例6: onSharedPreferenceChanged
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //导入方法依赖的package包/类
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
for (OnSharedPreferenceChangeListener listener : mListeners) {
listener.onSharedPreferenceChanged(this, key);
}
BackupManager.dataChanged(mPackageName);
UsageStatistics.onEvent("CameraSettingsChange", null, key);
}
示例7: notifyListeners
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //导入方法依赖的package包/类
void notifyListeners(final String key) {
final List<OnSharedPreferenceChangeListener> listeners;
synchronized (this) {
listeners = new ArrayList<>(mListeners.keySet());
}
for (final OnSharedPreferenceChangeListener listener : listeners) {
Log.d(CrossProcessSharedPreferences.TAG, "Notify listener: " + listener);
listener.onSharedPreferenceChanged(this, key);
}
}
示例8: notifyListenersInternal
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //导入方法依赖的package包/类
private void notifyListenersInternal(String key) {
for (OnSharedPreferenceChangeListener listener : currentListeners) {
listener.onSharedPreferenceChanged(null, key);
}
}
示例9: notifyListeners
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //导入方法依赖的package包/类
private void notifyListeners(String key) {
for (OnSharedPreferenceChangeListener listener : listeners) {
listener.onSharedPreferenceChanged(null, key);
}
}
示例10: testPreferencesChange
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //导入方法依赖的package包/类
/**
* Tests preferences change.
*/
public void testPreferencesChange() throws Exception {
// Register two listeners
PreferencesUtils.setString(
context, R.string.stats_rate_key, PreferencesUtils.STATS_RATE_DEFAULT);
PreferencesUtils.setString(
context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
PreferencesUtils.setInt(context, R.string.recording_gps_accuracy_key,
PreferencesUtils.RECORDING_GPS_ACCURACY_DEFAULT);
PreferencesUtils.setInt(context, R.string.recording_distance_interval_key,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
dataSource.registerOnSharedPreferenceChangeListener(capture(preferenceChangeListenerCapture));
expect(trackDataListener1.onMetricUnitsChanged(true)).andReturn(false);
expect(trackDataListener1.onReportSpeedChanged(true)).andReturn(false);
expect(
trackDataListener1.onRecordingGpsAccuracy(PreferencesUtils.RECORDING_GPS_ACCURACY_DEFAULT))
.andReturn(false);
expect(trackDataListener1.onRecordingDistanceIntervalChanged(
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT)).andReturn(false);
expect(trackDataListener1.onMapTypeChanged(PreferencesUtils.MAP_TYPE_DEFAUlT)).andReturn(false);
expect(trackDataListener2.onMetricUnitsChanged(true)).andReturn(false);
expect(trackDataListener2.onReportSpeedChanged(true)).andReturn(false);
expect(
trackDataListener2.onRecordingGpsAccuracy(PreferencesUtils.RECORDING_GPS_ACCURACY_DEFAULT))
.andReturn(false);
expect(trackDataListener2.onRecordingDistanceIntervalChanged(
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT)).andReturn(false);
expect(trackDataListener2.onMapTypeChanged(PreferencesUtils.MAP_TYPE_DEFAUlT)).andReturn(false);
replay();
trackDataHub.start();
trackDataHub.registerTrackDataListener(
trackDataListener1, EnumSet.of(TrackDataType.PREFERENCE));
trackDataHub.registerTrackDataListener(
trackDataListener2, EnumSet.of(TrackDataType.PREFERENCE));
verifyAndReset();
// Change report speed to false
expect(trackDataListener1.onReportSpeedChanged(false)).andReturn(false);
expect(trackDataListener2.onReportSpeedChanged(false)).andReturn(false);
replay();
PreferencesUtils.setString(
context, R.string.stats_rate_key, context.getString(R.string.stats_rate_pace));
OnSharedPreferenceChangeListener listener = preferenceChangeListenerCapture.getValue();
listener.onSharedPreferenceChanged(
sharedPreferences, PreferencesUtils.getKey(context, R.string.stats_rate_key));
verifyAndReset();
// Change metric units to false
expect(trackDataListener1.onMetricUnitsChanged(false)).andReturn(false);
expect(trackDataListener2.onMetricUnitsChanged(false)).andReturn(false);
replay();
String imperialUnits = context.getString(R.string.stats_units_imperial);
PreferencesUtils.setString(context, R.string.stats_units_key, imperialUnits);
listener.onSharedPreferenceChanged(
sharedPreferences, PreferencesUtils.getKey(context, R.string.stats_units_key));
verifyAndReset();
}
示例11: onSharedPreferenceChanged
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //导入方法依赖的package包/类
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
for (OnSharedPreferenceChangeListener listener : mListeners) {
listener.onSharedPreferenceChanged(this, key);
}
}
示例12: callListener
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //导入方法依赖的package包/类
/**
* Wraps
* {@link android.content.SharedPreferences.OnSharedPreferenceChangeListener#onSharedPreferenceChanged(SharedPreferences, String)}
* .
*
* @param ctx
* the context the SharedPreferences belong to
* @param lis
* the listener, must not be null
* @param key
* the key we want to run onSharedPreferenceChanged on, must not
* be null
* @throws NullPointerException
* if lis or key is {@code null}
*/
public static void callListener(Context ctx,
OnSharedPreferenceChangeListener lis, String key) {
if (lis == null) {
throw new NullPointerException("Null listener");
}
if (key == null) {
throw new NullPointerException("Null keys are not permitted");
}
lis.onSharedPreferenceChanged(getPrefs(ctx), key);
}