本文整理汇总了Java中android.content.SharedPreferences.getStringSet方法的典型用法代码示例。如果您正苦于以下问题:Java SharedPreferences.getStringSet方法的具体用法?Java SharedPreferences.getStringSet怎么用?Java SharedPreferences.getStringSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.SharedPreferences
的用法示例。
在下文中一共展示了SharedPreferences.getStringSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recreateAgents
import android.content.SharedPreferences; //导入方法依赖的package包/类
private void recreateAgents(SharedPreferences settings) {
Message request = Message.obtain();
request.what = Environment.RECREATE_AGENTS;
request.replyTo = replyMessenger;
Bundle bundle = new Bundle();
HashSet<String> agentNamesFromActivity = (HashSet<String>)
settings.getStringSet(ACTIVITY_NAME, new HashSet<String>());
bundle.putSerializable(AGENT_NAMES, agentNamesFromActivity);
request.setData(bundle);
try {
requestMessenger.send(request);
} catch (RemoteException ex) {
ex.printStackTrace();
}
}
示例2: saveKeyHistory
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* 将搜索有记录的 关键字 存起来(订单搜索界面 外销发票号 模糊搜索的历史记录)
*
* @param keyword
*/
private void saveKeyHistory(String keyword) {
// 存入进行搜索过的关键字
SharedPreferences searchHistorySp = MyApplication_.getInstance().getSearchHistorySp();
Set<String> search_history = searchHistorySp.getStringSet(AppDelegate.HISTORY_SALE_INVOICE_ACCOUNT_SEARCH, null);
if (search_history == null) {
Set<String> newSet = new TreeSet<>();
newSet.add(keyword);
searchHistorySp.edit().putStringSet(AppDelegate.HISTORY_SALE_INVOICE_ACCOUNT_SEARCH, newSet).commit();
} else {
Set<String> sets = new TreeSet<>();
String[] strings = search_history.toArray(new String[]{});
for (int i = 0; i < strings.length; i++) {
sets.add(strings[i]);
}
sets.add(keyword);
searchHistorySp.edit().putStringSet(AppDelegate.HISTORY_SALE_INVOICE_ACCOUNT_SEARCH, sets).commit();
}
}
示例3: onNotificationsReceived
import android.content.SharedPreferences; //导入方法依赖的package包/类
private void onNotificationsReceived(List<Notification> notificationList) {
SharedPreferences notificationsPreferences = context.getSharedPreferences(
"Notifications", Context.MODE_PRIVATE);
//make a copy of the string set, the returned instance should not be modified
Set<String> currentIds = new HashSet<>(notificationsPreferences.getStringSet(
"current_ids", Collections.emptySet()));
for (Notification notification : notificationList) {
String id = notification.id;
if (!currentIds.contains(id)) {
currentIds.add(id);
NotificationManager.make(context, NOTIFY_ID, notification);
}
}
notificationsPreferences.edit()
.putStringSet("current_ids", currentIds)
.apply();
}
示例4: removeFromInstallQueue
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static void removeFromInstallQueue(Context context, HashSet<String> packageNames,
UserHandleCompat user) {
if (packageNames.isEmpty()) {
return;
}
SharedPreferences sp = Utilities.getPrefs(context);
synchronized(sLock) {
Set<String> strings = sp.getStringSet(APPS_PENDING_INSTALL, null);
if (DBG) {
Log.d(TAG, "APPS_PENDING_INSTALL: " + strings
+ ", removing packages: " + packageNames);
}
if (strings != null) {
Set<String> newStrings = new HashSet<String>(strings);
Iterator<String> newStringsIter = newStrings.iterator();
while (newStringsIter.hasNext()) {
String encoded = newStringsIter.next();
PendingInstallShortcutInfo info = decode(encoded, context);
if (info == null || (packageNames.contains(info.getTargetPackage())
&& user.equals(info.user))) {
newStringsIter.remove();
}
}
sp.edit().putStringSet(APPS_PENDING_INSTALL, newStrings).apply();
}
}
}
示例5: removeFromWaitingList
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static void removeFromWaitingList(UQI uqi, Set<String> fileNamesToRemove) {
synchronized (dropboxWaitingListMutex) {
SharedPreferences pref = uqi.getContext().getApplicationContext().getSharedPreferences(Consts.LIB_TAG, Context.MODE_PRIVATE);
Set<String> waitingList = pref.getStringSet(DROPBOX_WAITING_LIST, new HashSet<String>());
waitingList.removeAll(fileNamesToRemove);
SharedPreferences.Editor editor = pref.edit();
editor.clear();
editor.putStringSet(DROPBOX_WAITING_LIST, waitingList);
editor.apply();
Logging.debug(LOG_TAG + "Removed files from waiting list: " + fileNamesToRemove);
}
}
示例6: onServiceConnected
import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
public void onServiceConnected(ComponentName name, IBinder binder) {
requestMessenger = new Messenger(binder);
SharedPreferences settings = getSharedPreferences(MagpieService.MAGPIE_PREFS, MODE_PRIVATE);
Set<String> agentNames = settings.getStringSet(ACTIVITY_NAME, new HashSet<String>());
if (agentNames.isEmpty()) {
onEnvironmentConnected();
} else {
recreateAgents(settings);
}
}
示例7: getPinnedProperties
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static HashSet<Integer> getPinnedProperties(SharedPreferences pref) {
Set<String> stringVals = pref.getStringSet(prefKeyPinnedProperties, new HashSet<>());
HashSet<Integer> result = new HashSet<>();
for (String s : stringVals)
result.add(Integer.parseInt(s));
return result;
}
示例8: removePinnedProperty
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static void removePinnedProperty(SharedPreferences pref, int id) {
Set<String> stringVals = pref.getStringSet(prefKeyPinnedProperties, new HashSet<>());
String sRemove = String.format(Locale.US, "%d", id);
if (!stringVals.contains(sRemove))
return;
// Can't modify the returned set; need to create a new one.
HashSet<String> newSet = new HashSet<>(stringVals);
newSet.remove(sRemove);
SharedPreferences.Editor e = pref.edit();
e.putStringSet(prefKeyPinnedProperties, newSet);
e.apply();
}
示例9: shouldStartService
import android.content.SharedPreferences; //导入方法依赖的package包/类
private static boolean shouldStartService(Context context, int mediaType, int tabId) {
if (mediaType != MEDIATYPE_NO_MEDIA) return true;
SharedPreferences sharedPreferences =
ContextUtils.getAppSharedPreferences();
Set<String> notificationIds =
sharedPreferences.getStringSet(WEBRTC_NOTIFICATION_IDS, null);
if (notificationIds != null
&& !notificationIds.isEmpty()
&& notificationIds.contains(String.valueOf(tabId))) {
return true;
}
return false;
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:14,代码来源:MediaCaptureNotificationService.java
示例10: onCreate
import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 取得地圖物件
setContentView(R.layout.activity_maps);
mLayoutContainer = (ViewGroup) findViewById(R.id.layout_container);
mMapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
mMapFragment.getMapAsync(this);
// For tracking, Create an instance of GoogleAPIClient and LocationRequest.
configGoogleApiClient();
configLocationRequest();
// Buttons on map
mSwitchBtn = (Button) findViewById(R.id.btn_switch);
mTrackingBtn = (Button) findViewById(R.id.btn_tracking);
mPickTilesBtn = (Button) findViewById(R.id.btn_pick_tiles);
mGpxManagerBtn = (Button) findViewById(R.id.btn_gpx_files_list);
mPoiSearchBtn = (Button) findViewById(R.id.btn_search);
mBtnsSet.add(mPickTilesBtn);
mBtnsSet.add(mTrackingBtn);
mBtnsSet.add(mGpxManagerBtn);
mBtnsSet.add(mPoiSearchBtn);
mSwitchBtn.setOnClickListener(this);
for (View btn : mBtnsSet) {
btn.setOnClickListener(this);
}
// Add center cross into main map
mCrossSet.add(MAP_CODE_MAIN, (ImageView) findViewById(R.id.cross));
// 取得ActionBar
mActionBar = getSupportActionBar();
// 還原各項設定
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);
// 檢查是否紀錄航跡中
mTrackingBtn.setSelected(prefs.getBoolean("isTracking", false));
if (mTrackingBtn.isSelected()) {
// bind TrackingService
Intent bindIntent = new Intent(this, TrackingService.class);
bindService(bindIntent, this, BIND_AUTO_CREATE);
}
// 取得上次相機位置
LatLng lastTarget = new LatLng(prefs.getFloat(
"cameraLat", (float) TAIWAN_CENTER.latitude),
prefs.getFloat("cameraLon", (float) TAIWAN_CENTER.longitude));
Float lastZoom = prefs.getFloat("cameraZoom", STARTING_ZOOM);
lastCameraPosition = new CameraPosition(lastTarget, lastZoom, 0, 0);
// 取得已開啟的GPX檔案
mGpxFileList = prefs.getStringSet("gpxFiles", mGpxFileList);
// 取得POI檔案
poiFile = prefs.getString("poiFile", null);
// 取得離線地圖檔案
mapFile = prefs.getString("mapFile", null);
themeFile = prefs.getString("themeFile", null);
// 還原座標表示設定
CoorSysList.coorSetting = prefs.getInt("coorSetting", COOR_WGS84_D);
}
示例11: getStringSet
import android.content.SharedPreferences; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public static Set<String> getStringSet(String name, Set<String> defaultValue){
SharedPreferences sp=getSP(name);
if (sp==null)return defaultValue;
return sp.getStringSet(name, defaultValue);
}
示例12: getArrayPref
import android.content.SharedPreferences; //导入方法依赖的package包/类
public static Set<String> getArrayPref(Context context, String name) {
SharedPreferences prefs = context.getSharedPreferences(
"com.luca89.search_history", Context.MODE_PRIVATE);
return prefs.getStringSet(name, new HashSet<String>());
}
示例13: isFollowing
import android.content.SharedPreferences; //导入方法依赖的package包/类
static boolean isFollowing(Context context, String username) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
Set<String> followedStreamers = settings.getStringSet(followingKeyName, new HashSet<String>());
return followedStreamers.contains(username);
}
示例14: getFavoriteContacts
import android.content.SharedPreferences; //导入方法依赖的package包/类
/** Restituisce l'insieme dei numeri di contatti preferiti dell'utente. */
public static Set<String> getFavoriteContacts(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getStringSet(SettingsActivity.PREFERENCES_CONTACTS_KEY, new HashSet<String>());
}
示例15: handleDisturbanceNotification
import android.content.SharedPreferences; //导入方法依赖的package包/类
private void handleDisturbanceNotification(String network, String line,
String id, String status, boolean downtime,
long msgtime) {
Log.d("MainService", "handleDisturbanceNotification");
SharedPreferences sharedPref = getSharedPreferences("notifsettings", MODE_PRIVATE);
Set<String> linePref = sharedPref.getStringSet("pref_notifs_lines", null);
Network snetwork;
synchronized (lock) {
if (!networks.containsKey(network)) {
return;
}
snetwork = networks.get(network);
}
Line sline = snetwork.getLine(line);
if (sline == null) {
return;
}
if (downtime) {
lineStatusCache.markLineAsDown(sline, new Date(msgtime));
} else {
lineStatusCache.markLineAsUp(sline);
}
if (linePref != null && !linePref.contains(line)) {
// notifications disabled for this line
return;
}
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (!downtime && !sharedPref.getBoolean("pref_notifs_service_resumed", true)) {
// notifications for normal service resumed disabled
notificationManager.cancel(id.hashCode());
return;
}
Realm realm = Realm.getDefaultInstance();
for (NotificationRule rule : realm.where(NotificationRule.class).findAll()) {
if (rule.isEnabled() && rule.applies(new Date(msgtime))) {
realm.close();
return;
}
}
realm.close();
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(MainActivity.EXTRA_INITIAL_FRAGMENT, "nav_disturbances");
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
String title = String.format(getString(R.string.notif_disturbance_title), sline.getName());
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.setBigContentTitle(title);
bigTextStyle.bigText(status);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setStyle(bigTextStyle)
.setSmallIcon(R.drawable.ic_disturbance_notif)
.setColor(sline.getColor())
.setContentTitle(title)
.setContentText(status)
.setAutoCancel(true)
.setWhen(msgtime)
.setSound(Uri.parse(sharedPref.getString(downtime ? "pref_notifs_ringtone" : "pref_notifs_regularization_ringtone", "content://settings/system/notification_sound")))
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setContentIntent(pendingIntent);
if (sharedPref.getBoolean(downtime ? "pref_notifs_vibrate" : "pref_notifs_regularization_vibrate", false)) {
notificationBuilder.setVibrate(new long[]{0, 100, 100, 150, 150, 200});
} else {
notificationBuilder.setVibrate(new long[]{0l});
}
notificationManager.notify(id.hashCode(), notificationBuilder.build());
}