private void copyPrefs(String srcPrefsName, String destPrefsName) { Tool.setTimer(); SharedPreferences srcPrefs = AppCore.context().getSharedPreferences(srcPrefsName, 0); SharedPreferences destPrefs = AppCore.context().getSharedPreferences(destPrefsName, 0); if (D) Wow.d( TAG, "copyPrefs", "BACKUP copy Prefs..." + srcPrefs.getAll().size() + " from " + srcPrefsName + " to " + destPrefsName); SharedPreferences.Editor editor = destPrefs.edit(); for (Map.Entry<String, ?> entry : srcPrefs.getAll().entrySet()) { String key = entry.getKey(); Object val = entry.getValue(); // if (D) Wow.d("BACKUP", ">>>APPCORE BACKUP restore > key = "+key+", val // = "+val); if (val == null) continue; else if (val instanceof Float) editor.putFloat(key, (Float) val); else if (val instanceof Integer) editor.putInt(key, (Integer) val); else if (val instanceof Long) editor.putLong(key, (Long) val); else if (val instanceof Boolean) editor.putBoolean(key, (Boolean) val); else editor.putString(key, val.toString()); } editor.commit(); // if (D) Wow.d("BACKUP", ">>>APPCORE BACKUP copy // Prefs.. time = " + Tool.getTimer(true)); }
public PersistentCookieStore() { cookiePrefs = OkGo.getContext().getSharedPreferences(COOKIE_PREFS, Context.MODE_PRIVATE); cookies = new HashMap<>(); // 将持久化的cookies缓存到内存中,数据结构为 Map<Url.host, Map<Cookie.name, Cookie>> Map<String, ?> prefsMap = cookiePrefs.getAll(); for (Map.Entry<String, ?> entry : prefsMap.entrySet()) { if ((entry.getValue()) != null && !entry.getKey().startsWith(COOKIE_NAME_PREFIX)) { // 获取url对应的所有cookie的key,用","分割 String[] cookieNames = TextUtils.split((String) entry.getValue(), ","); for (String name : cookieNames) { // 根据对应cookie的Key,从xml中获取cookie的真实值 String encodedCookie = cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null); if (encodedCookie != null) { Cookie decodedCookie = decodeCookie(encodedCookie); if (decodedCookie != null) { if (!cookies.containsKey(entry.getKey())) cookies.put(entry.getKey(), new ConcurrentHashMap<String, Cookie>()); cookies.get(entry.getKey()).put(name, decodedCookie); } } } } } }
private CharSequence getTitleOfOtherActionAssociatedWith(Long extendedKeyCode) { /* * Collect all KeyComboPreferences. It's somewhat inefficient to iterate through all * preferences every time, but it's only done during configuration when the user presses a * key. Lazily-initializing a static list would assume that there's no way a preference * will be added after the initialization. That assumption was not true during testing, * which may have been specific to the testing environment but may also indicate that * problematic situations can arise. */ PreferenceManager preferenceManager = getPreferenceManager(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); Map<String, ?> prefMap = prefs.getAll(); String myKey = getKey(); for (String key : prefMap.keySet()) { if (!myKey.equals(key)) { Object preferenceObject = preferenceManager.findPreference(key); if (preferenceObject instanceof KeyComboPreference) { KeyComboPreference otherPref = (KeyComboPreference) preferenceObject; if (getKeyCodesForPreference(getContext(), key).contains(extendedKeyCode)) { return preferenceManager.findPreference(key).getTitle(); } } } } return null; }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.cartlayout, container, false); prefs = getActivity().getSharedPreferences("cart", Context.MODE_PRIVATE); Map<String, ?> prods = prefs.getAll(); index = 0; items = new String[prods.size()]; prices = new String[prods.size()]; icons = new int[prods.size()]; for (Map.Entry<String, ?> entry : prods.entrySet()) { String[] s = entry.getKey().split("$"); items[index] = s[0]; prices[index] = s[1]; icons[index] = Integer.parseInt(s[2]); index++; } // ItemViewAdapter adapter = new ItemViewAdapter(getActivity()) return v; }
// metodo chamado no momento em que a view vai ser criada @TargetApi(Build.VERSION_CODES.M) @Override public void onViewCreated( final View view, Bundle savedInstanceState) { // chamado quando a view do fragment vai ser criada view.findViewById(R.id.picture) .setOnClickListener(this); // setando listeners nos btoes que estao sendo criados view.findViewById(R.id.info).setOnClickListener(this); view.findViewById(R.id.mudacam).setOnClickListener(this); view.findViewById(R.id.flash).setOnClickListener(this); view.findViewById(R.id.dividetela).setOnClickListener(this); textureView = (TextureView) view.findViewById(R.id.texture); // try { verificaCameras(); } catch (CameraAccessException e) { e.printStackTrace(); } cameraEscolhida = idCameras[0]; // inicia com primeira camera activity = getActivity(); manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); verificaPreferenciasIndice(); sensoresEscolhios = getContext().getSharedPreferences(sensores, 0); Map<String, String> retorno = (Map<String, String>) sensoresEscolhios.getAll(); Collection<String> valores = retorno.values(); sm = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE); List<Sensor> listaSensores = sm.getSensorList(Sensor.TYPE_ALL); for (String elem : valores) { for (Sensor aux : listaSensores) if (aux.getName().compareTo(elem) == 0) sens.add(aux); } ativaListenersSensores(sens); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); PackageManager pm = getPackageManager(); ComponentName pluggedReceiver = new ComponentName(getApplicationContext(), PluggedReceiver.class); ComponentName unpluggedReceiver = new ComponentName(getApplication(), UnpluggedReceiver.class); pm.setComponentEnabledSetting( pluggedReceiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting( unpluggedReceiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); myListView = (ListView) findViewById(R.id.contactView); listItems = new ArrayList<String>(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Map<String, ?> keys = prefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { listItems.add(entry.getKey().toString()); } adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems); myListView.setAdapter(adapter); }
@Override public void onReceive(Context context, Intent intent) { if (!Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { SharedPreferences setting = context.getSharedPreferences(PurgeActivity.PREF, 0); if (!setting.getBoolean(PurgeActivity.KEY_AUTO_ENABLED, false)) { Log.e(PurgeActivity.TAG, "onReceive: auto purge disabled!"); return; } Map<String, ?> values = setting.getAll(); if (values.containsKey(PurgeActivity.KEY_AUTO_DAYS) && values.containsKey(PurgeActivity.KEY_AUTO_CALL_LOG) && values.containsKey(PurgeActivity.KEY_AUTO_SMS) && values.containsKey(PurgeActivity.KEY_AUTO_MMS) && values.containsKey(PurgeActivity.KEY_AUTO_LOCKED_SMS)) { int days = setting.getInt(PurgeActivity.KEY_AUTO_DAYS, -1); boolean call = setting.getBoolean(PurgeActivity.KEY_AUTO_CALL_LOG, true); boolean sms = setting.getBoolean(PurgeActivity.KEY_AUTO_SMS, true); boolean mms = setting.getBoolean(PurgeActivity.KEY_AUTO_MMS, true); boolean locked = setting.getBoolean(PurgeActivity.KEY_AUTO_LOCKED_SMS, false); PurgeActivity.purge(context, days, call, sms, mms, locked); } else { Log.e(PurgeActivity.TAG, "onReceive: settings missing."); } } registerAlarm(context); }
@Override public void onReceive(Context context, Intent intent) { if (prefs == null) { prefs = context.getSharedPreferences("serval", 0); } if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); int opp = (info.getType() == ConnectivityManager.TYPE_WIFI) ? ConnectivityManager.TYPE_MOBILE : ConnectivityManager.TYPE_WIFI; NetworkInfo other = connManager.getNetworkInfo(opp); Map<String, ?> idMap = prefs.getAll(); /* Connected, add rules back */ if (info.getState().equals(NetworkInfo.State.CONNECTED)) { performAction(context, idMap, AppHostCtrl.SERVICE_REMOVE); performAction(context, idMap, AppHostCtrl.SERVICE_ADD); } /* Disconnected, remove rules */ else if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) { performAction(context, idMap, AppHostCtrl.SERVICE_REMOVE); /* Make rules available, since other interface is up */ if (other.isConnectedOrConnecting()) { performAction(context, idMap, AppHostCtrl.SERVICE_ADD); } } } }
private Cursor queryUsage(int uid, List<String> listRestriction, String methodName) { MatrixCursor cursor = new MatrixCursor( new String[] {COL_UID, COL_RESTRICTION, COL_METHOD, COL_RESTRICTED, COL_USED}); if (uid == 0) { // All for (String restrictionName : PrivacyManager.getRestrictions(true)) { SharedPreferences prefs = getContext() .getSharedPreferences( PREF_USAGE + "." + restrictionName, Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS); for (String prefName : prefs.getAll().keySet()) if (prefName.startsWith(COL_USED)) { String[] prefParts = prefName.split("\\."); int rUid = Integer.parseInt(prefParts[1]); String rMethodName = prefParts[2]; getUsage(rUid, restrictionName, rMethodName, cursor); } } } else { // Selected restrictions/methods for (String restrictionName : listRestriction) if (methodName == null) for (PrivacyManager.MethodDescription md : PrivacyManager.getMethods(restrictionName)) getUsage(uid, restrictionName, md.getMethodName(), cursor); else getUsage(uid, restrictionName, methodName, cursor); } return cursor; }
public ListViewExtended(Activity activity, ListView view) { /* Creates a new instance of the class with a specified activity and ListView. Initially, the there are no tasks in the app. */ ArrayList<Task> tasks = new ArrayList<>(); listView = view; keys = new ArrayList<>(); // Getting hold of activity`s preference file. appData = activity.getPreferences(Context.MODE_PRIVATE); HashMap map = (HashMap) appData.getAll(); if (!(map.size() == 0)) { Set key_set = map.keySet(); for (Object key : key_set) keys.add((String) key); for (String key : keys) {; String name, description = ""; String[] info = appData.getString(key, "").split("\n"); name = info[0]; for (int i = 1; i < info.length; i++) description += info[i] + "\n"; tasks.add(new Task(key, name, description)); } } adapter = new ArrayAdapter<>(activity, R.layout.activity_list_view_item, tasks); listView.setAdapter(adapter); }
@Override protected Void doInBackground(Context... ctxt) { localPrefs = PreferenceManager.getDefaultSharedPreferences(ctxt[0]); localPrefs.getAll(); return (null); }
public void a(int i) { Object obj = ((gqz) hlp.a(a, gqz)).a(i); if (((grb) (obj)).b()) { if (!((grb) (obj)).d("sms_only")) { obj = b.edit(); ((android.content.SharedPreferences.Editor) (obj)).remove(c(i)); String s = b(i); Iterator iterator = b.getAll().keySet().iterator(); do { if (!iterator.hasNext()) { break; } String s1 = (String) iterator.next(); if (s1.startsWith(s)) { ((android.content.SharedPreferences.Editor) (obj)).remove(s1); } } while (true); ((android.content.SharedPreferences.Editor) (obj)).apply(); } } else if (((grb) (obj)).a() && !b.contains(c(i))) { gwu gwu1 = (gwu) hlp.a(a, gwu); b.edit().putLong(c(i), gwu1.a()).apply(); a(i, 2590); return; } }
private void updateProjectCache() { // Ensure we have a cache at all: initProjectCache(); // Loop through project path preference keys: for (Map.Entry<String, ?> entry : preferences.getAll().entrySet()) if (entry.getKey().startsWith(PREF_PROJECT_PATH_PREFIX) && entry.getKey().endsWith(PREF_PROJECT_PATH_POSTFIX)) { int projectID = getProjectID(entry.getKey()); int projectFingerPrint = getProjectFingerPrint(entry.getKey()); if (getCachedProject(projectID, projectFingerPrint) == null) { // Parse the project if it is not already in the cache: Project p = ProjectLoader.ParseProject(entry.getValue().toString()); if (p != null) { if (p.getFingerPrint() != projectFingerPrint) { Log.w( TAG, "XML finger print of project " + p.toString() + " has changed, possibly the " + ProjectLoader.PROJECT_FILE + " file (located in " + entry.getValue().toString() + ") was manually edited!"); // Remove old pref key: removeProjectPathPrefKey(projectID, projectFingerPrint); // Add new pref key: storeProjectPathPrefKey(p); } // Cache the project object: cacheProject(p); } } } }
public static boolean saveSharedPreferencesToFile(File dst, Context context) { boolean res = false; ObjectOutputStream output = null; try { if (!dst.getParentFile().exists()) { dst.getParentFile().mkdirs(); dst.createNewFile(); } output = new ObjectOutputStream(new FileOutputStream(dst)); SharedPreferences pref = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); output.writeObject(pref.getAll()); res = true; } catch (Exception e) { } finally { try { if (output != null) { output.flush(); output.close(); } } catch (Exception e) { } } return res; }
@Override public List<byte[]> getKeyHandlesByIssuerAndAppId(String issuer, String application) { List<byte[]> result = new ArrayList<byte[]>(); final SharedPreferences keySettings = context.getSharedPreferences(U2F_KEY_PAIR_FILE, Context.MODE_PRIVATE); Map<String, String> keyTokens = (Map<String, String>) keySettings.getAll(); for (Map.Entry<String, String> keyToken : keyTokens.entrySet()) { String tokenEntryString = keyToken.getValue(); TokenEntry tokenEntry = new Gson().fromJson(tokenEntryString, TokenEntry.class); if (((issuer == null) || issuer.equals(tokenEntry.getIssuer())) && ((application == null) || application.equals(tokenEntry.getApplication()))) { String keyHandleKey = keyToken.getKey(); try { byte[] keyHandle = keyToKeyHandle(keyHandleKey); result.add(keyHandle); } catch (DecoderException ex) { Log.e(TAG, "Invalid keyHandle: " + keyHandleKey, ex); } } } return result; }
public List<Todo> getAll() { List<Todo> todos = new ArrayList<>(); for (String item : (Collection<String>) prefs.getAll().values()) { todos.add(new Todo(item)); } return todos; }
private void updateEnableState() { final SharedPreferences prefs = getSharedPreferences(); if (prefs == null || mDependencyKey == null || mDependencyValues == null) return; final Map<String, ?> all = prefs.getAll(); final String valueString = ParseUtils.parseString(all.get(mDependencyKey), mDependencyValueDefault); setEnabled(ArrayUtils.contains(mDependencyValues, valueString)); }
public ContactsManager(SharedPreferences savedSelectedContacts) { mContactsList = new ArrayList<Contact>(); mContactsMap = new HashMap<String, Contact>(); mConnectionManager = SynchronizedConnectionManager.getInstance(); mSavedSelectedContacts = savedSelectedContacts; mSelectedContacts = new HashSet<String>((Set<String>) (mSavedSelectedContacts.getAll().keySet())); }
public static synchronized void initialize() { Context ctx = AppMasterApplication.getInstance(); final File file = ctx.getSharedPrefsFile(ctx.getPackageName() + "_preferences"); if (!file.exists()) { return; } LeoLog.d(TAG, "<ls>start initialize...."); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx); Map<String, ?> values = preferences.getAll(); Map<String, Object> highPriority = new HashMap<String, Object>(); Map<String, Object> normal = new HashMap<String, Object>(); for (String s : values.keySet()) { Object obj = values.get(s); if (obj == null) { continue; } if (ISettings.isHighPriority(s)) { highPriority.put(s, obj); } else { normal.put(s, obj); } } LeoLog.d( TAG, "<ls>initialize....high size: " + highPriority.size() + " | normal size: " + normal.size()); if (highPriority.size() > 0) { mPreference.setBundleMap( highPriority, new ISettings.OnBundleSavedListener() { @Override public void onBundleSaved() { LeoLog.d(TAG, "<ls>initialize, onBundleSaved preference..."); sPreferenceInited = true; deleteIfNeeded(file); } }); } else { sPreferenceInited = true; } if (normal.size() > 0) { mDatabase.setBundleMap( normal, new ISettings.OnBundleSavedListener() { @Override public void onBundleSaved() { LeoLog.d(TAG, "<ls>initialize, onBundleSaved database..."); sDatabaseInited = true; deleteIfNeeded(file); } }); } else { sDatabaseInited = true; } deleteIfNeeded(file); }
private void printFile(PrintStream writer, String prefsName, String keyPrefix) { writer.println(prefsName + ":"); SharedPreferences preferences = getSharedPreferences(prefsName); for (Map.Entry<String, ?> entry : preferences.getAll().entrySet()) { if (entry.getKey().startsWith(keyPrefix)) { writer.println(" " + entry.getKey() + " = " + entry.getValue()); } } }
/** * Returns the mapping of a specified key, in String format. If key does not exist, returns the * default value. * * @param key the lookup key. * @param def the default value. * @return mapping of key, or default value. * @module.api */ public String getString(String key, String def) { if (DBG) { Log.d(LCAT, "getString called with key:" + key + ", def:" + def); } if (!preferences.contains(key)) return def; return preferences.getAll().get(key).toString(); }
private ArrayList<FileInfo> getFileList() { SharedPreferences sp = mJecEditor.getSharedPreferences(JecEditor.PREF_HISTORY, Context.MODE_PRIVATE); ArrayList<FileInfo> fl = new ArrayList<FileInfo>(); Map<String, ?> map = sp.getAll(); for (Entry<String, ?> entry : map.entrySet()) { Object val = entry.getValue(); if (val instanceof String) { String[] vals = ((String) val).split(","); if (vals.length >= 3) { try { FileInfo fi = new FileInfo(); fi.path = entry.getKey(); fi.sel_start = Integer.parseInt(vals[0]); fi.sel_end = Integer.parseInt(vals[1]); fi.access_time = Long.parseLong(vals[2]); fl.add(fi); } catch (Exception e) { } } } } // end for if (fl.size() == 0) { return fl; } Collections.sort( fl, new Comparator<FileInfo>() { public int compare(FileInfo object1, FileInfo object2) { if (object2.access_time < object1.access_time) { return -1; } else if (object2.access_time > object1.access_time) { return 1; } return 0; } }); int historymax = fl.size(); if (historymax > 20) { historymax = 20; } ArrayList<FileInfo> items = new ArrayList<FileInfo>(); int max = fl.size(); for (int i = 0; i < max; i++) { if (i >= historymax) { // 限制最近打开历史记录条数 sp.edit().remove(fl.get(i).path); } else { items.add(fl.get(i)); } } sp.edit().commit(); return items; }
public AndroidKeyDataStore(Context context) { this.context = context; // Prepare empty U2F key pair store final SharedPreferences keySettings = context.getSharedPreferences(U2F_KEY_PAIR_FILE, Context.MODE_PRIVATE); if (keySettings.getAll().size() == 0) { if (BuildConfig.DEBUG) Log.d(TAG, "Creating empty U2K key pair store"); keySettings.edit().apply(); // commit(); } // Prepare empty U2F key counter store final SharedPreferences keyCounts = context.getSharedPreferences(U2F_KEY_COUNT_FILE, Context.MODE_PRIVATE); if (keyCounts.getAll().size() == 0) { if (BuildConfig.DEBUG) Log.d(TAG, "Creating empty U2K key counter store"); keyCounts.edit().apply(); // commit(); } }
/** * Returns the mapping of a specified key, in String format. If key does not exist, returns the * default value. * * @param key the lookup key. * @param def the default value. * @return mapping of key, or default value. * @module.api */ public String getString(String key, String def) { LogHelpers.DebugLog("getString called with key:" + key + ", def:" + def); Object value = preferences.getAll().get(key); if (value != null) { return value.toString(); } else { return def; } }
public static Map<String, ?> getMap(Context ct, String prefName) { try { SharedPreferences sp = ct.getSharedPreferences(prefName, Context.MODE_PRIVATE); Map<String, ?> rsMap = sp.getAll(); return rsMap; } catch (Exception e) { return null; } }
private void saveNewProfile(SharedPreferences AeroProfile) { // Just to be save, loading default again; mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences.Editor editor = AeroProfile.edit(); // Get all our preferences; final Map<String, ?> allKeys = mPrefs.getAll(); saveProfile(allKeys, editor); }
@Override public List<LogInfo> getLogs() { final SharedPreferences logSettings = context.getSharedPreferences(LOGS_STORE, Context.MODE_PRIVATE); Map<String, String> logsMap = (Map<String, String>) logSettings.getAll(); List<LogInfo> logs = new ArrayList<LogInfo>(); for (Map.Entry<String, String> log : logsMap.entrySet()) { logs.add(new Gson().fromJson(log.getValue(), LogInfo.class)); } return logs; }
String[] getAvailableStyles() { final SharedPreferences prefs = getContext().getSharedPreferences("userStyles", Activity.MODE_PRIVATE); Map<String, ?> data = prefs.getAll(); List<String> names = new ArrayList<String>(data.keySet()); Collections.sort(names); names.addAll(styleTitles); names.add(defaultStyleTitle); names.add(autoStyleTitle); return names.toArray(new String[names.size()]); }
public static void loadTable(Context context) { SharedPreferences sp = context.getSharedPreferences(Const.ALARM_SP, Context.MODE_PRIVATE); Map<String, String> tempMap = (Map<String, String>) sp.getAll(); for (Map.Entry<String, String> entry : tempMap.entrySet()) { String ac = entry.getKey(); if (null != ac && 0 != ac.trim().length()) { ALARM_ACTIONS.put(ac, ac); } } isTableLoaded = true; }
public void onClick(View v) { SharedPreferences.Editor preferencesEditor = favoritespref.edit(); preferencesEditor.clear(); preferencesEditor.apply(); arrayIndex = 0; // head.removeAllViews(); favoritespref = getSharedPreferences("favorites", MODE_PRIVATE); favorites = favoritespref.getAll().keySet().toArray(new String[0]); genView(favorites); }