当前位置: 首页>>代码示例>>Java>>正文


Java OnSharedPreferenceChangeListener.onSharedPreferenceChanged方法代码示例

本文整理汇总了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;
}
 
开发者ID:dragonlinux,项目名称:connectbot,代码行数:17,代码来源:HostEditorActivity.java

示例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);
		}
	}
}
 
开发者ID:OpenSensing,项目名称:funf-v4,代码行数:18,代码来源:AsyncSharedPrefs.java

示例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;
}
 
开发者ID:minstrelsy,项目名称:servestream,代码行数:17,代码来源:StreamEditorActivity.java

示例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);

}
 
开发者ID:abdulla-alali,项目名称:lecture_examples,代码行数:35,代码来源:PreferenceFragmentActivity.java

示例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);
}
 
开发者ID:asm-products,项目名称:nexus-camera,代码行数:10,代码来源:ComboPreferences.java

示例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);
	}
}
 
开发者ID:oasisfeng,项目名称:deagle,代码行数:11,代码来源:CrossProcessSharedPreferences.java

示例8: notifyListenersInternal

import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //导入方法依赖的package包/类
private void notifyListenersInternal(String key) {
    for (OnSharedPreferenceChangeListener listener : currentListeners) {
        listener.onSharedPreferenceChanged(null, key);
    }
}
 
开发者ID:iamironz,项目名称:binaryprefs,代码行数:6,代码来源:BroadcastEventBridge.java

示例9: notifyListeners

import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //导入方法依赖的package包/类
private void notifyListeners(String key) {
    for (OnSharedPreferenceChangeListener listener : listeners) {
        listener.onSharedPreferenceChanged(null, key);
    }
}
 
开发者ID:iamironz,项目名称:binaryprefs,代码行数:6,代码来源:SimpleEventBridge.java

示例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();
}
 
开发者ID:Plonk42,项目名称:mytracks,代码行数:66,代码来源:TrackDataHubTest.java

示例11: onSharedPreferenceChanged

import android.content.SharedPreferences.OnSharedPreferenceChangeListener; //导入方法依赖的package包/类
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
        String key) {
    for (OnSharedPreferenceChangeListener listener : mListeners) {
        listener.onSharedPreferenceChanged(this, key);
    }
}
 
开发者ID:yinglovezhuzhu,项目名称:AndroidMedia,代码行数:7,代码来源:ComboPreferences.java

示例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);
}
 
开发者ID:bytebeats,项目名称:base-android-utils,代码行数:26,代码来源:SharedPrefUtil.java


注:本文中的android.content.SharedPreferences.OnSharedPreferenceChangeListener.onSharedPreferenceChanged方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。