public void checkAndRemindThemToGiveMeAGoodRating() { final SharedPreferences mPrefs = PDActivity.this.getSharedPreferences(SHARED_PREFERENCES_APPSTUFF, 0); long firstopened = mPrefs.getLong("firstopened", -1); if (firstopened < 0) { firstopened = System.currentTimeMillis(); Editor e = mPrefs.edit(); e.putLong("firstopened", firstopened); e.commit(); return; } long timenow = System.currentTimeMillis(); long elapsed = timenow - firstopened; long maxtime = 1000 * 60 * 15; // 15 minute if (!(mPrefs.getBoolean("popupshown", false))) { if (elapsed > maxtime) { // if (System.currentTimeMillis() % 10 == 1) { if (getResources() .getBoolean(com.rj.processing.plasmasound.R.bool.should_bug_about_donate)) { showRatingDialog(); } Editor e = mPrefs.edit(); e.putBoolean("popupshown", true); e.commit(); } } }
public void prevactivity_skipping(View view) { if (skip_pressed == true) { SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString("Radiobuttonteaming1", "NA"); editor.putString("Radiobuttonteaming2", "NA"); editor.putString("Teamingskipped", "skipped"); editor.commit(); Intent intent = new Intent(this, RecordSkipping.class); intent.putExtra("activity", "prevskipping"); intent.putExtra("TesterName", user_name); startActivity(intent); } else { rgrp1 = (RadioGroup) findViewById(R.id.rgrp1); radioButtonID1 = rgrp1.getCheckedRadioButtonId(); rgrp2 = (RadioGroup) findViewById(R.id.rgrp2); radioButtonID2 = rgrp2.getCheckedRadioButtonId(); // if (radioButtonID1 == -1 || radioButtonID2 == -1) // Toast.makeText(getBaseContext(), "Please select one option from each type // !", Toast.LENGTH_LONG).show(); // else { SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putInt("teamingidround1", radioButtonID1); editor.putInt("teamingidround2", radioButtonID2); editor.putString("Teamingskipped", "notskipped"); editor.commit(); Intent intent = new Intent(this, RecordSkipping.class); intent.putExtra("activity", "prevskipping"); intent.putExtra("TesterName", user_name); startActivity(intent); // } } }
@Override public void storeTokenEntry(byte[] keyHandle, TokenEntry tokenEntry) { Boolean isSave = true; List<String> tokens = getTokenEntries(); for (String tokenStr : tokens) { TokenEntry token = new Gson().fromJson(tokenStr, TokenEntry.class); if (token.getIssuer().equalsIgnoreCase(tokenEntry.getIssuer())) { isSave = false; } } if (isSave) { String keyHandleKey = keyHandleToKey(keyHandle); final String tokenEntryString = new Gson().toJson(tokenEntry); if (BuildConfig.DEBUG) Log.d( TAG, "Storing new keyHandle: " + keyHandleKey + " with tokenEntry: " + tokenEntryString); final SharedPreferences keySettings = context.getSharedPreferences(U2F_KEY_PAIR_FILE, Context.MODE_PRIVATE); keySettings.edit().putString(keyHandleKey, tokenEntryString).apply(); // commit(); final SharedPreferences keyCounts = context.getSharedPreferences(U2F_KEY_COUNT_FILE, Context.MODE_PRIVATE); keyCounts.edit().putInt(keyHandleKey, 0).apply(); // commit(); } }
/** * Fetches the adress * * @param inLoc */ protected void makeUseOfLocation(Location inLoc) { lastLocation = inLoc; if (sp.getLong(Constants.KEY_LATEST_ADRESSTHREAD, -1) == -1) { sp.edit().putLong(Constants.KEY_LATEST_ADRESSTHREAD, inLoc.getTime()).commit(); if (getAdressThread != null) { try { getAdressThread.stop(); } catch (Exception e) { e.printStackTrace(); } getAdressThread = new GetAdressThread(inLoc); getAdressThread.start(); } else { getAdressThread = new GetAdressThread(inLoc); getAdressThread.start(); } } else if (inLoc.getTime() - sp.getLong(Constants.KEY_LATEST_ADRESSTHREAD, -1) > 5000) { sp.edit().putLong(Constants.KEY_LATEST_ADRESSTHREAD, inLoc.getTime()).commit(); if (getAdressThread != null) { try { getAdressThread.stop(); } catch (Exception e) { e.printStackTrace(); } getAdressThread = new GetAdressThread(inLoc); getAdressThread.start(); } else { getAdressThread = new GetAdressThread(inLoc); getAdressThread.start(); } } else { // Too soon. } }
/** * It restore the old values of wps_state ,when commit failure or wpa failure is received * * @return boolean */ public boolean setPrevValue() { defSharPref.edit().putString(L10NConstants.WPS_KEY, L10NConstants.VAL_ZERO); orgSharPref.edit().putString(L10NConstants.WPS_KEY, L10NConstants.VAL_ZERO); defSharPref.edit().commit(); orgSharPref.edit().commit(); return false; }
private void updateRule(Rule rule, String network, boolean blocked) { SharedPreferences prefs = context.getSharedPreferences(network, Context.MODE_PRIVATE); if ("wifi".equals(network)) { rule.wifi_blocked = blocked; if (rule.wifi_blocked == rule.wifi_default) { Log.i(TAG, "Removing " + rule.info.packageName + " " + network); prefs.edit().remove(rule.info.packageName).apply(); } else { Log.i(TAG, "Setting " + rule.info.packageName + " " + network + "=" + blocked); prefs.edit().putBoolean(rule.info.packageName, blocked).apply(); } } if ("other".equals(network)) { rule.other_blocked = blocked; if (rule.other_blocked == rule.other_default) { Log.i(TAG, "Removing " + rule.info.packageName + " " + network); prefs.edit().remove(rule.info.packageName).apply(); } else { Log.i(TAG, "Setting " + rule.info.packageName + " " + network + "=" + blocked); prefs.edit().putBoolean(rule.info.packageName, blocked).apply(); } } NotificationManagerCompat.from(context).cancel(rule.info.applicationInfo.uid); }
private void updateSummaries() { int t = PREFS_DEFAULT_LOCATION_TIMEOUT; try { t = Integer.parseInt( prefs.getString(PREFS_KEY_LOCATION_TIMEOUT, "" + PREFS_DEFAULT_LOCATION_TIMEOUT)); if (t < 1) { t = PREFS_DEFAULT_LOCATION_TIMEOUT; final SharedPreferences.Editor edit = prefs.edit(); edit.putString(PREFS_KEY_LOCATION_TIMEOUT, "" + t); edit.commit(); } } catch (final Exception e) { t = PREFS_DEFAULT_LOCATION_TIMEOUT; final SharedPreferences.Editor edit = prefs.edit(); edit.putString(PREFS_KEY_LOCATION_TIMEOUT, "" + t); edit.commit(); } final EditTextPreference timeout = (EditTextPreference) prefFrag.findPreference(PREFS_KEY_LOCATION_TIMEOUT); String summary = getResources().getString(R.string.pref_geolocation_timeout_summary); summary += "\nTimeout: '" + t + "'"; timeout.setSummary(summary); final Preference povider = prefFrag.findPreference(PREFS_KEY_OPENCELLID_PROVIDER); final Preference gps = prefFrag.findPreference(PREFS_KEY_GPS); final boolean en = prefs.getBoolean(PREFS_KEY_LOCATE, PREFS_DEFAULT_LOCATE); povider.setEnabled(en); timeout.setEnabled(en); gps.setEnabled(en); }
private void setPreferenceInt(String key, Integer value) { if (value == null) { sharedPreferences.edit().remove(key).apply(); } else { sharedPreferences.edit().putInt(key, value).apply(); } }
@Override protected void onPause() { super.onPause(); SharedPreferences hints = getSharedPreferences("MyPref", Context.MODE_PRIVATE); SharedPreferences.Editor hintchanger = hints.edit(); hintchanger.putInt("hints", hints.getInt("hints", 10)); hintchanger.commit(); SharedPreferences pref = getSharedPreferences("MyPref", Context.MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); editor.putInt("SoundNumber", pref.getInt("SoundNumber", 0)); editor.commit(); SharedPreferences pagenumber = getSharedPreferences("MyPref", Context.MODE_PRIVATE); SharedPreferences.Editor changer = pagenumber.edit(); changer.putInt("PageNumber", pagenumber.getInt("PageNumber", 0)); changer.commit(); SharedPreferences correctcounter = getSharedPreferences("MyPref", Context.MODE_PRIVATE); SharedPreferences.Editor counterchanger = correctcounter.edit(); counterchanger.putInt("correctno", correctcounter.getInt("correctno", 0)); counterchanger.commit(); }
@Override public void onCreate() { super.onCreate(); AVOSCloud.initialize(this, EXTRA_APP_KEY, EXTRA_MASTER_KEY); AVAnalytics.enableCrashReport(this, true); AVOSCloud.setLastModifyEnabled(true); AVOSCloud.setDebugLogEnabled(true); messageHandler = new MessageHandler(); user = this.getSharedPreferences(EXTRA_USER, MODE_PRIVATE); settings = this.getSharedPreferences(EXTRA_SETTINGS, MODE_PRIVATE); call = this.getSharedPreferences(EXTRA_CALL, MODE_PRIVATE); record = this.getSharedPreferences(EXTRA_RECORDS, MODE_PRIVATE); userEditor = user.edit(); settingsEditor = settings.edit(); callEditor = call.edit(); recordEditor = record.edit(); if (rtcEngine != null) { rtcEngine.enableNetworkTest(); } }
private void setPreferenceString(String key, String value) { if (value == null) { sharedPreferences.edit().remove(key).apply(); } else { sharedPreferences.edit().putString(key, value).apply(); } }
public static void createMessageCenterAutoMessage(Context context) { SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE); boolean shownAutoMessage = prefs.getBoolean(Constants.PREF_KEY_AUTO_MESSAGE_SHOWN_AUTO_MESSAGE, false); // Migrate old values if needed. boolean shownManual = prefs.getBoolean(Constants.PREF_KEY_AUTO_MESSAGE_SHOWN_MANUAL, false); boolean shownNoLove = prefs.getBoolean(Constants.PREF_KEY_AUTO_MESSAGE_SHOWN_NO_LOVE, false); if (!shownAutoMessage) { if (shownManual || shownNoLove) { shownAutoMessage = true; prefs.edit().putBoolean(Constants.PREF_KEY_AUTO_MESSAGE_SHOWN_AUTO_MESSAGE, true).commit(); } } AutomatedMessage message = null; if (!shownAutoMessage) { prefs.edit().putBoolean(Constants.PREF_KEY_AUTO_MESSAGE_SHOWN_AUTO_MESSAGE, true).commit(); message = AutomatedMessage.createWelcomeMessage(context); } if (message != null) { ApptentiveDatabase db = ApptentiveDatabase.getInstance(context); db.addOrUpdateMessages(message); db.addPayload(message); } }
public static void updateVersion(Context context) { SharedPreferences prefs = context.getSharedPreferences(PrefConstants.PREFERENCES, 0); // store the current version prefs.edit().putString(AppConstants.LAST_APP_VERSION, getVersion(context)).commit(); // also make sure we auto-trigger an update, since all data are now gone prefs.edit().putLong(AppConstants.LAST_SYNC_TIME, 0L).commit(); }
/** @param 增加一个 */ public void put(String cardName) { // 检查参数是否为空 if (cardName == null || cardName.length() < 1) { return; } // 本地为空直接增加 String strCardNames = sharedPreferences.getString("cardNames", ""); if (strCardNames.equals("")) { sharedPreferences.edit().putString("cardNames", cardName); return; } // 本地不为空,传进来的参数正确 String[] cardNames = get(); for (int i = 0; i < cardNames.length; i++) { if (cardNames.equals(cardName)) { // 已经存在,不予添加 return; } } strCardNames += "," + cardName.trim(); Editor editor = sharedPreferences.edit(); // 获取编辑器 editor.putString("cardNames", strCardNames.trim()); editor.commit(); }
@Override protected Payload doInBackground(Payload... args) { Payload data = doInBackgroundLoadDeck(args); if (data.returnType == DeckTask.DECK_LOADED) { double now = System.currentTimeMillis(); HashMap<String, Object> results = (HashMap<String, Object>) data.result; Deck deck = (Deck) results.get("deck"); // deck.beforeUpdateCards(); // deck.updateAllCards(); SharedDeckDownload download = (SharedDeckDownload) args[0].data[0]; SharedPreferences pref = PrefSettings.getSharedPrefs(getBaseContext()); String updatedCardsPref = "numUpdatedCards:" + mDestination + "/tmp/" + download.getTitle() + ".anki.updating"; long totalCards = deck.retrieveCardCount(); download.setNumTotalCards((int) totalCards); long updatedCards = pref.getLong(updatedCardsPref, 0); download.setNumUpdatedCards((int) updatedCards); long batchSize = Math.max(100, totalCards / 200); mRecentBatchTimings = new long[sRunningAvgLength]; mTotalBatches = ((double) totalCards) / batchSize; int currentBatch = (int) (updatedCards / batchSize); long runningAvgCount = 0; long batchStart; mElapsedTime = 0; while (updatedCards < totalCards && download.getStatus() == SharedDeckDownload.STATUS_UPDATING) { batchStart = System.currentTimeMillis(); updatedCards = deck.updateAllCardsFromPosition(updatedCards, batchSize); Editor editor = pref.edit(); editor.putLong(updatedCardsPref, updatedCards); editor.commit(); download.setNumUpdatedCards((int) updatedCards); publishProgress(); estimateTimeToCompletion( download, currentBatch, runningAvgCount, System.currentTimeMillis() - batchStart); currentBatch++; runningAvgCount++; } if (download.getStatus() == SharedDeckDownload.STATUS_UPDATING) { data.success = true; } else if (download.getStatus() == SharedDeckDownload.STATUS_PAUSED) { Editor editor = pref.edit(); String pausedPref = "paused:" + mDestination + "/tmp/" + download.getTitle() + ".anki.updating"; editor.putBoolean(pausedPref, true); editor.commit(); data.success = false; Log.i(AnkiDroidApp.TAG, "pausing deck " + download.getTitle()); } else if (download.getStatus() == SharedDeckDownload.STATUS_CANCELLED) { data.success = false; } // Log.i(AnkiDroidApp.TAG, "Time to update deck = " + download.getEstTimeToCompletion() + " // sec."); // deck.afterUpdateCards(); } else { data.success = false; } return data; }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_rate_now: pref.edit() .putString(AppConstants.APP_PREFERENCE_RATE, AppConstants.APP_PREFERENCE_NEVER) .commit(); final String packagename = context.getPackageName(); try { Uri uri = Uri.parse("market://details?id=" + packagename); Intent intent = new Intent(Intent.ACTION_VIEW, uri); context.startActivity(intent); } catch (android.content.ActivityNotFoundException ex) { Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=" + packagename); Intent intent = new Intent(Intent.ACTION_VIEW, uri); context.startActivity(intent); } break; case R.id.btn_later: boolean s = pref.edit().putInt(AppConstants.APP_PREFERENCE_OPEN_TIMES, 0).commit(); // ((BeautifulFrameActivity) context).setOpenTimes(0); // GLog.v("NOT NOW", s + ""); break; case R.id.btn_never: pref.edit() .putString(AppConstants.APP_PREFERENCE_RATE, AppConstants.APP_PREFERENCE_NEVER) .commit(); break; default: break; } dismiss(); }
private void set(Intent intent) { // Get arguments int uid = intent.getIntExtra(EXTRA_UID, 0); String network = intent.getStringExtra(EXTRA_NETWORK); String pkg = intent.getStringExtra(EXTRA_PACKAGE); boolean blocked = intent.getBooleanExtra(EXTRA_BLOCKED, false); Log.i(TAG, "Set " + pkg + " " + network + "=" + blocked); // Get defaults SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(SinkholeService.this); boolean default_wifi = settings.getBoolean("whitelist_wifi", true); boolean default_other = settings.getBoolean("whitelist_other", true); // Update setting SharedPreferences prefs = getSharedPreferences(network, Context.MODE_PRIVATE); if (blocked == ("wifi".equals(network) ? default_wifi : default_other)) prefs.edit().remove(pkg).apply(); else prefs.edit().putBoolean(pkg, blocked).apply(); // Update notification Receiver.notifyApplication(uid, SinkholeService.this); // Update UI Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED); LocalBroadcastManager.getInstance(SinkholeService.this).sendBroadcast(ruleset); }
public static BankSession newInstance(Context context, String username, String password) { // Get the session id from the store if possible, otherwise log in SharedPreferences p = context.getSharedPreferences(PaymentsActivity.PREFS_NAME, 0); String sessionId = null; String savedUsername = p.getString("username", null); MessageDigest md; try { md = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { Log.e(TAG, "SHA-256 not supported", e); return null; } md.update(password.getBytes()); String hashedPassword = Base64.encodeToString(md.digest(), Base64.DEFAULT); String savedPassword = p.getString("password", null); if (username.equals(savedUsername) && hashedPassword.equals(savedPassword)) { sessionId = p.getString("session_id", null); } // Session id not available if (sessionId == null) { sessionId = login(username, password); if (sessionId != null) { p.edit().putString("session_id", sessionId); p.edit().putString("username", username); p.edit().putString("password", hashedPassword); } } return new BankSession(sessionId); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); preferences1 = getSharedPreferences("preference1", MODE_PRIVATE); preferences1.edit().putBoolean("switch1", true).commit(); preferences1.edit().putString("strPref1", "strPref1").commit(); preferences1.edit().putFloat("floatPref1", 0.1f).commit(); preferences1.edit().putInt("intPref1", 100).commit(); preferences2 = getSharedPreferences("preference2", MODE_PRIVATE); preferences2.edit().putBoolean("switch2", false).commit(); preferences2.edit().putString("strPref2", "strPref2").commit(); preferences2.edit().putFloat("floatPref2", 0.2f).commit(); preferences2.edit().putInt("intPref2", 200).commit(); DbOpenHelper dbOpenHelper = new DbOpenHelper(this); SQLiteDatabase db = dbOpenHelper.getReadableDatabase(); Cursor cursor = db.query(StockPrice.TABLE, null, null, null, null, null, null); while (cursor.moveToNext()) { idList.add(cursor.getInt(cursor.getColumnIndex(StockPrice.ID))); nameList.add(cursor.getString(cursor.getColumnIndex(StockPrice.NAME))); askList.add(cursor.getFloat(cursor.getColumnIndex(StockPrice.ASK))); bidList.add(cursor.getFloat(cursor.getColumnIndex(StockPrice.BID))); } cursor.close(); }
/** * Shows keeping the access keys returned from Trusted Authenticator in a local store, rather than * storing user name & password, and re-authenticating each time (which is not to be done, ever). */ private void storeAuth(AndroidAuthSession session) { // Store the OAuth 2 access token, if there is one. String oauth2AccessToken = session.getOAuth2AccessToken(); Log.d(TAG, oauth2AccessToken); if (oauth2AccessToken != null) { SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0); Editor edit = prefs.edit(); edit.putString(ACCESS_KEY_NAME, "oauth2:"); edit.putString(ACCESS_SECRET_NAME, oauth2AccessToken); edit.commit(); return; } // Store the OAuth 1 access token, if there is one. This is only necessary if // you're still using OAuth 1. AccessTokenPair oauth1AccessToken = session.getAccessTokenPair(); if (oauth1AccessToken != null) { SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0); Editor edit = prefs.edit(); edit.putString(ACCESS_KEY_NAME, oauth1AccessToken.key); edit.putString(ACCESS_SECRET_NAME, oauth1AccessToken.secret); edit.commit(); return; } }
/** Listener for the On/Off switch */ @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(ONOFF_KEY)) { running = !running; Editor editor = sharedPreferences.edit(); editor.putBoolean(IS_ON, running); editor.commit(); if (running) { if (runNormal) SensorPreferenceActivity.start(SensorPreferenceActivity.this.getApplicationContext()); else SensorPreferenceActivity.startLite(SensorPreferenceActivity.this.getApplicationContext()); } else { if (runNormal) SensorPreferenceActivity.stop(SensorPreferenceActivity.this.getApplicationContext()); else SensorPreferenceActivity.stopLite(SensorPreferenceActivity.this.getApplicationContext()); } } if (key.equals(ANALYTIC_KEY)) { runNormal = !runNormal; Editor editor = sharedPreferences.edit(); editor.putBoolean(ANALYTIC_ON, runNormal); editor.commit(); if (running) { if (runNormal) { SensorPreferenceActivity.stopLite(SensorPreferenceActivity.this.getApplicationContext()); SensorPreferenceActivity.start(SensorPreferenceActivity.this.getApplicationContext()); } else { SensorPreferenceActivity.stop(SensorPreferenceActivity.this.getApplicationContext()); SensorPreferenceActivity.startLite(SensorPreferenceActivity.this.getApplicationContext()); } } } }
@Override protected void onRestart() { super.onRestart(); if (preferences.getBoolean(Constants.RELOAD_MAIN_ACTIVITY_AFTER_RESTORE_KEY, false)) reloadMainActivityAfterRestore(); else { if (preferences.getBoolean(Constants.NOTE_UPDATED_FROM_WIDGET, false)) { if (fragmentManager.findFragmentByTag(Constants.FRAGMENT_NOTE) != null) ((NoteFragment) fragmentManager.findFragmentByTag(Constants.FRAGMENT_NOTE)).reloadNote(); else if (fragmentManager.findFragmentByTag(Constants.FRAGMENT_LIST) != null) ((NoteListFragment) fragmentManager.findFragmentByTag(Constants.FRAGMENT_LIST)) .reloadList(); else if (fragmentManager.findFragmentByTag(Constants.FRAGMENT_TRASH_NOTE) != null) ((TrashNoteFragment) fragmentManager.findFragmentByTag(Constants.FRAGMENT_TRASH_NOTE)) .reloadNote(); preferences.edit().putBoolean(Constants.NOTE_UPDATED_FROM_WIDGET, false).apply(); } if (preferences.getBoolean(Constants.NOTE_TEXT_SIZE_UPDATED, false)) { if (fragmentManager.findFragmentByTag(Constants.FRAGMENT_NOTE) != null) ((NoteFragment) fragmentManager.findFragmentByTag(Constants.FRAGMENT_NOTE)) .updateNoteTextSize(); preferences.edit().putBoolean(Constants.NOTE_TEXT_SIZE_UPDATED, false).apply(); } } }
public void saveGame(int i) { // This uses Android's own internal storage-system to save all // currently relevent information to restore the game to the // beginning of the next wave of creatures. // This is probably (read: only meant to work with) best called // in between levels when the NextLevel-dialog is shown. // Never save multiplayer-status. if (multiplayergame == true || survivalGame == true) return; if (i == 1) { // Log.d("GAMEINIT", "Saving game status..."); // Save everything. SharedPreferences resume = getSharedPreferences("resume", 0); SharedPreferences.Editor editor = resume.edit(); // editor.putInt("map",... <- this is saved above, at the if (mapChoice == 0) check. editor.putInt("difficulty", gameLoop.getPlayerData().getDifficulty()); editor.putInt("health", gameLoop.getPlayerData().getHealth()); editor.putInt("level", gameLoop.getLevelNumber()); editor.putInt("money", gameLoop.getPlayerData().getMoney()); editor.putInt("resumes", resume.getInt("resumes", 0)); editor.putString("towers", gameLoop.resumeGetTowers()); editor.commit(); // Log.d("GAMEINIT","resumes: " + resume.getInt("resumes", 0)); } else { // Log.d("GAMEINIT", "Erasing saved game status."); // Dont allow resume. Clears the main resume flag! SharedPreferences resume = getSharedPreferences("resume", 0); SharedPreferences.Editor editor = resume.edit(); editor.putInt("resumes", -1); editor.commit(); // Log.d("GAMEINIT","resumes: " + -1); } }
private void processRootFail() { int failCount = mPrefs.getInt(getString(R.string.pref_root_fail_count), 0); if (failCount == 0) { // show dialog first time AlertDialog dlg = new AlertDialog.Builder(this) .setTitle(R.string.no_root) .setMessage(R.string.no_root_dialog) .setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // ok, do nothing } }) .setNeutralButton( getString(R.string.github), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.repo_url))); startActivity(intent); } }) .create(); dlg.show(); mPrefs.edit().putInt(getString(R.string.pref_root_fail_count), failCount + 1).apply(); } else if (failCount <= 3) { // show toast 3 more times Toast.makeText(this, R.string.toast_no_root, Toast.LENGTH_LONG).show(); mPrefs.edit().putInt(getString(R.string.pref_root_fail_count), failCount + 1).apply(); } }
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); try { synchronized (TAG) { // GCM Registration starts here // Initially this call goes out to the network to retrieve the token, subsequent // calls are local. InstanceID instanceID = InstanceID.getInstance(this); String token = instanceID.getToken( AppConstants.SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); registerOnThirdPartyServer(token); // subscription to topics on which the app should accept push messages subscribeTopics(token); // This boolean value indicates that the token is already sent to 3rd party server // sharedPreferences.edit().putBoolean(SENT_TOKEN_TO_SERVER, true).apply(); sharedPreferences.edit().putString(REG_ID, token).apply(); // GCM Registration ends here } } catch (IOException e) { e.printStackTrace(); sharedPreferences.edit().putBoolean(SENT_TOKEN_TO_SERVER, false).apply(); } Intent registrationComplete = new Intent(REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); }
private void handleStage() { if (mUiStage.equals("first")) { mFirstKey = key.toString(); key.setLength(0); mUiStage = "second"; updateUi(); } else if (mUiStage.equals("second")) { if (key.toString().equals(mFirstKey)) { if (customApp == null) { prefs.edit().putString(Common.LOCKING_TYPE, Common.PREF_VALUE_KNOCK_CODE).apply(); prefsKey.edit().putString(Common.KEY_PREFERENCE, Util.shaHash(key.toString())).apply(); } else { prefsPerApp .edit() .putString(customApp, Common.PREF_VALUE_KNOCK_CODE) .putString(customApp + Common.APP_KEY_PREFERENCE, Util.shaHash(key.toString())) .apply(); } } else { Toast.makeText( getActivity(), getActivity().getResources().getString(R.string.toast_password_inconsistent), Toast.LENGTH_SHORT) .show(); } getActivity().onBackPressed(); } }
private boolean passLimitConstrain(int upperBound, int showType) { synchronized (mPrefer) { long current = System.currentTimeMillis(); long start = mPrefer.getLong(NotifyAdsDef.PREFER_KEY_STARTTIME, 0); if (start == 0) { mPrefer.edit().putLong(NotifyAdsDef.PREFER_KEY_STARTTIME, current).commit(); start = current; return true; } // 如果当前和原先的limit 已经超过了一天,那么就重新设置 if (current - start > 24 * 3600 * 1000) { mPrefer.edit().putLong(NotifyAdsDef.PREFER_KEY_STARTTIME, 0).commit(); mPrefer.edit().putInt(NotifyAdsDef.PREFER_KEY_NOTIFY_SUCCESS_COUNT, 0).commit(); mPrefer.edit().putInt(NotifyAdsDef.PREFER_KEY_BUBBLE_SUCCESS_COUNT, 0).commit(); return true; } else { // 如果在一天之内,那么我们看是否超出了上限 if (showType == NotifyAdsDef.ADS_TYPE_NOTIFY) { int notifyCount = mPrefer.getInt(NotifyAdsDef.PREFER_KEY_NOTIFY_SUCCESS_COUNT, 0); if (notifyCount < upperBound) return true; } else if (showType == NotifyAdsDef.ADS_TYPE_BUBBLE) { int bubbleCount = mPrefer.getInt(NotifyAdsDef.PREFER_KEY_BUBBLE_SUCCESS_COUNT, 0); if (bubbleCount < upperBound * NotifyAdsDef.BUBBLE_LIMIT_TIMES) return true; } } LogUtils.logUpLimit("超过了每天接受广告的上限"); return false; } }
// 保存字符串数据 public void saveString(String key, String value) { if (value == null) { mSharedPreferences.edit().putString(key, "").commit(); } else { mSharedPreferences.edit().putString(key, value).commit(); } }
public static void check() { HashMap<String, String> old = new HashMap<String, String>(codecs.size()); for (Codec c : codecs) { c.update(); old.put(c.name(), c.getValue()); if (!c.isLoaded()) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext); SharedPreferences.Editor e = sp.edit(); e.putString(c.key(), "never"); e.commit(); } } for (Codec c : codecs) if (!old.get(c.name()).equals("never")) { c.init(); if (c.isLoaded()) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext); SharedPreferences.Editor e = sp.edit(); e.putString(c.key(), old.get(c.name())); e.commit(); c.init(); } else c.fail(); } }
public static boolean isFlashSupported(Camera camera, Context context) { mPreferences = PreferenceManager.getDefaultSharedPreferences(context); if (camera != null) { Camera.Parameters mParameters = camera.getParameters(); if (mParameters.getFlashMode() == null) { mPrefFlash = mPreferences.edit().putBoolean("mPrefFlash", false).commit(); return false; } List<String> mSupportedFlashModes = mParameters.getSupportedFlashModes(); if (mSupportedFlashModes == null || mSupportedFlashModes.isEmpty() || mSupportedFlashModes.size() == 1 && mSupportedFlashModes.get(0).equals(Camera.Parameters.FLASH_MODE_OFF)) { mPrefFlash = mPreferences.edit().putBoolean("mPrefFlash", false).commit(); return false; } } else { mPrefFlash = mPreferences.edit().putBoolean("mPrefFlash", false).commit(); return false; } mPrefFlash = mPreferences.edit().putBoolean("mPrefFlash", true).commit(); return true; }