List of usage examples for android.content SharedPreferences contains
boolean contains(String key);
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Tells if the preferemce exists./* w ww.ja va2s . c o m*/ * * @param ctx * @param prefName * @param key * @return */ public static Boolean prefs_existsPref(Context ctx, String prefName, String key) { SharedPreferences prefs = ctx.getSharedPreferences(prefName, Context.MODE_PRIVATE); if (prefs.contains(key)) { return true; } else { return false; } }
From source file:net.exclaimindustries.geohashdroid.activities.CentralMap.java
@SuppressLint("CommitPrefEdits") private void doStartupStuff() { // This handles all the oddities that need to be covered at startup // time, including cleaning up old preferences that have been replaced // or otherwise changed, starting the stock alarm service if it should // be up, and throwing up the version history dialog if it's a new // version.//from w w w .ja v a 2s.co m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor edit = prefs.edit(); // Let's start with the stock alarm service. Intent i = new Intent(this, AlarmService.class); if (prefs.getBoolean(GHDConstants.PREF_STOCK_ALARM, false)) { // Alarm gets set! Fire it up! i.setAction(AlarmService.STOCK_ALARM_ON); } else { // No alarm! Off it goes! i.setAction(AlarmService.STOCK_ALARM_OFF); } startService(i); // Now for preference cleanup. Unfortunately, this section will only // get bigger with time, as I can't guarantee what version the user // might've come from. The version from which the user might've come. // The Infobox is now controlled by a boolean, not a string. if (prefs.contains("InfoBoxSize")) { if (!prefs.contains(GHDConstants.PREF_INFOBOX)) { String size; try { size = prefs.getString("InfoBoxSize", "None"); } catch (ClassCastException cce) { size = "Off"; } edit.putBoolean(GHDConstants.PREF_INFOBOX, size.equals("None")); } edit.remove("InfoBoxSize"); } // These prefs either don't exist any more or we found better ways to // deal with them. edit.remove("DefaultLatitude").remove("DefaultLongitude").remove("GlobalhashMode") .remove("RememberGraticule").remove("ClosestOn").remove("AlwaysToday").remove("ClosenessReported"); // Anything edit-worthy we just did needs to be committed. edit.commit(); // We still have that prefs object. Let's see if we've got a newer // version than what we last saw. int lastVersion = prefs.getInt(GHDConstants.PREF_LAST_SEEN_VERSION, 0); int curVersion = -1; try { curVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; } catch (PackageManager.NameNotFoundException nnfe) { // Since this is OUR OWN PACKAGE NAME, this better work. } Log.d(DEBUG_TAG, "We are version " + curVersion + ", we last reported version history on version " + lastVersion); if (lastVersion < curVersion) { // Aha! We're newer! Now, let's see if there's a new version to // display. That is, if the first entry in version history is newer // than the last-seen version. ArrayList<VersionHistoryParser.VersionEntry> entries = new ArrayList<>(); try { entries = VersionHistoryParser.parseVersionHistory(this); } catch (XmlPullParserException xppe) { // You get NOTHING! } if (entries.isEmpty()) { Log.w(DEBUG_TAG, "Couldn't parse version history, not displaying anything."); } else { Log.d(DEBUG_TAG, "Newest version with an entry is " + entries.get(0).versionCode); if (entries.get(0).versionCode > lastVersion) { VersionHistoryDialogFragment frag = VersionHistoryDialogFragment.newInstance(entries); frag.show(getFragmentManager(), VERSION_HISTORY_DIALOG); } } } // In any case, update the version. edit.putInt(GHDConstants.PREF_LAST_SEEN_VERSION, curVersion); edit.apply(); }
From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.MessageCenterFragment.java
@Override public void onComposingViewCreated(MessageComposerHolder composer, final EditText composerEditText, final ApptentiveImageGridView attachments) { this.composer = composer; this.composerEditText = composerEditText; SharedPreferences prefs = ApptentiveInternal.getInstance().getSharedPrefs(); // Restore composing text editing state, such as cursor position, after rotation if (composingViewSavedState != null) { if (this.composerEditText != null) { this.composerEditText.onRestoreInstanceState(composingViewSavedState); }//w ww.j a va 2 s. com composingViewSavedState = null; SharedPreferences.Editor editor = prefs.edit(); editor.remove(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_MESSAGE).apply(); } // Restore composing text if (prefs.contains(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_MESSAGE)) { String messageText = prefs.getString(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_MESSAGE, null); if (messageText != null && this.composerEditText != null) { this.composerEditText.setText(messageText); } // Stored pending composing text has been restored, remove it from the persistent storage SharedPreferences.Editor editor = prefs.edit(); editor.remove(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_MESSAGE).apply(); } setAttachmentsInComposer(pendingAttachments); messageCenterRecyclerView.setPadding(0, 0, 0, 0); if (composerEditText != null) { composerEditText.requestFocus(); if (forceShowKeyboard) { composerEditText.post(new Runnable() { @Override public void run() { if (forceShowKeyboard) { forceShowKeyboard = false; Util.showSoftKeyboard(hostingActivityRef.get(), composerEditText); } } }); } } hideFab(); composer.setSendButtonState(); }
From source file:com.panahit.ui.Components.EmojiView.java
public void loadRecents() { SharedPreferences preferences = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE); lastGifLoadTime = preferences.getLong("lastGifLoadTime", 0); String str;/*from w w w. ja v a2 s . c o m*/ try { emojiUseHistory.clear(); if (preferences.contains("emojis")) { str = preferences.getString("emojis", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); long value = Long.parseLong(args2[0]); String string = ""; for (int a = 0; a < 4; a++) { char ch = (char) value; string = String.valueOf(ch) + string; value >>= 16; if (value == 0) { break; } } if (string.length() > 0) { emojiUseHistory.put(string, Integer.parseInt(args2[1])); } } } preferences.edit().remove("emojis").commit(); saveRecentEmoji(); } else { str = preferences.getString("emojis2", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); emojiUseHistory.put(args2[0], Integer.parseInt(args2[1])); } } } if (emojiUseHistory.isEmpty()) { String[] newRecent = new String[] { "\uD83D\uDE02", "\uD83D\uDE18", "\u2764", "\uD83D\uDE0D", "\uD83D\uDE0A", "\uD83D\uDE01", "\uD83D\uDC4D", "\u263A", "\uD83D\uDE14", "\uD83D\uDE04", "\uD83D\uDE2D", "\uD83D\uDC8B", "\uD83D\uDE12", "\uD83D\uDE33", "\uD83D\uDE1C", "\uD83D\uDE48", "\uD83D\uDE09", "\uD83D\uDE03", "\uD83D\uDE22", "\uD83D\uDE1D", "\uD83D\uDE31", "\uD83D\uDE21", "\uD83D\uDE0F", "\uD83D\uDE1E", "\uD83D\uDE05", "\uD83D\uDE1A", "\uD83D\uDE4A", "\uD83D\uDE0C", "\uD83D\uDE00", "\uD83D\uDE0B", "\uD83D\uDE06", "\uD83D\uDC4C", "\uD83D\uDE10", "\uD83D\uDE15" }; for (int i = 0; i < newRecent.length; i++) { emojiUseHistory.put(newRecent[i], newRecent.length - i); } saveRecentEmoji(); } sortEmoji(); adapters.get(0).notifyDataSetChanged(); } catch (Exception e) { FileLog.e("tmessages", e); } try { str = preferences.getString("color", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (int a = 0; a < args.length; a++) { String arg = args[a]; String[] args2 = arg.split("="); emojiColor.put(args2[0], args2[1]); } } } catch (Exception e) { FileLog.e("tmessages", e); } if (showStickers) { try { newRecentStickers.clear(); str = preferences.getString("stickers", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); final HashMap<Long, Integer> stickersUseHistory = new HashMap<>(); for (int a = 0; a < args.length; a++) { String arg = args[a]; String[] args2 = arg.split("="); Long key = Long.parseLong(args2[0]); stickersUseHistory.put(key, Integer.parseInt(args2[1])); newRecentStickers.add(key); } Collections.sort(newRecentStickers, new Comparator<Long>() { @Override public int compare(Long lhs, Long rhs) { Integer count1 = stickersUseHistory.get(lhs); Integer count2 = stickersUseHistory.get(rhs); if (count1 == null) { count1 = 0; } if (count2 == null) { count2 = 0; } if (count1 > count2) { return -1; } else if (count1 < count2) { return 1; } return 0; } }); preferences.edit().remove("stickers").commit(); saveRecentStickers(); } else { str = preferences.getString("stickers2", ""); String[] args = str.split(","); for (int a = 0; a < args.length; a++) { newRecentStickers.add(Long.parseLong(args[a])); } } sortStickers(); updateStickerTabs(); } catch (Exception e) { FileLog.e("tmessages", e); } } }
From source file:opensource.zeocompanion.ZeoCompanionApplication.java
public void dailyCheck() { // configured to allow an auto-backup? SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(this); boolean autoEmailEnabled = sPrefs.getBoolean("email_auto_enable", false); boolean sendDatabaseEnabled = sPrefs.getBoolean("email_auto_send_database", false); if (!autoEmailEnabled || !sendDatabaseEnabled) { return;/*from www . j a v a 2 s .c o m*/ } // yes, has the proper internal passed? long newTimestamp = System.currentTimeMillis(); long autoBackupLastTimestamp = sPrefs.getLong("email_auto_send_database_dest_timestamp_last_sent", 0); String autoBackupRepetitionInterval = sPrefs.getString("email_auto_send_database_repetition", "Weekly"); if (autoBackupLastTimestamp > 0) { long interval = 86400000L; if (autoBackupRepetitionInterval.equals("Weekly")) { interval = interval * 7L; } if (autoBackupLastTimestamp + interval > newTimestamp) { return; } } Log.d(_CTAG + ".dailyCheck", "Auto-backup of ZeoCompanion database invoked"); // yes, backup the database BackupReturnResults results = saveCopyOfDB("auto_"); // will not return null // is there a destination email address? String dest = ""; if (sPrefs.contains("email_auto_send_database_dest")) { dest = ObscuredPrefs.decryptString(sPrefs.getString("email_auto_send_database_dest", "")); } if (dest == null) { if (!results.rAnErrorMessage.isEmpty()) { results.rAnErrorMessage = results.rAnErrorMessage + ". "; } results.rAnErrorMessage = results.rAnErrorMessage + "A destination email address is not configured for the database backup; the backup is only stored on-device."; } else if (dest.isEmpty()) { if (!results.rAnErrorMessage.isEmpty()) { results.rAnErrorMessage = results.rAnErrorMessage + ". "; } results.rAnErrorMessage = results.rAnErrorMessage + "A destination email address is not configured for the database backup; the backup is only stored on-device."; } // send a database backup via direct email in a separate thread String subject = "ZeoCompanion database auto backup"; String body = subject + "; see attachment."; if (results.rTheBackupFile == null || !results.rAnErrorMessage.isEmpty()) { mEmailOutbox.postToOutbox(dest, subject, body, results.rTheBackupFile, results.rAnErrorMessage, null); } else { DirectEmailerThread de = new DirectEmailerThread(this); de.setName("DirectEmailerThread via " + _CTAG + ".dailyCheck"); de.configure(subject, body, results.rTheBackupFile, true); de.configureToAddress(dest); de.start(); } // remember the current timestamp of this auto-backup SharedPreferences.Editor editor = sPrefs.edit(); editor.putLong("email_auto_send_database_dest_timestamp_last_sent", newTimestamp); editor.commit(); }
From source file:com.vegnab.vegnab.MainVNActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // // start following loader, does not use UI, but only gets a value to have ready for a menu action // getSupportLoaderManager().initLoader(VNContract.Loaders.HIDDEN_VISITS, null, this); //Get a Tracker (should auto-report) ((VNApplication) getApplication()).getTracker(VNApplication.TrackerName.APP_TRACKER); // set up some default Preferences SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor prefEditor; if (!sharedPref.contains(Prefs.TARGET_ACCURACY_OF_VISIT_LOCATIONS)) { prefEditor = sharedPref.edit();/*from ww w .j a v a 2 s. co m*/ prefEditor.putFloat(Prefs.TARGET_ACCURACY_OF_VISIT_LOCATIONS, (float) 7.0); prefEditor.commit(); } if (!sharedPref.contains(Prefs.TARGET_ACCURACY_OF_MAPPED_LOCATIONS)) { prefEditor = sharedPref.edit(); prefEditor.putFloat(Prefs.TARGET_ACCURACY_OF_MAPPED_LOCATIONS, (float) 7.0); prefEditor.commit(); } if (!sharedPref.contains(Prefs.UNIQUE_DEVICE_ID)) { prefEditor = sharedPref.edit(); getUniqueDeviceId(this); // generate the ID and the source prefEditor.putString(Prefs.DEVICE_ID_SOURCE, mDeviceIdSource); prefEditor.putString(Prefs.UNIQUE_DEVICE_ID, mUniqueDeviceId); prefEditor.commit(); } // Is there a description of what "local" is (e.g. "Iowa")? Initially, no if (!sharedPref.contains(Prefs.LOCAL_SPECIES_LIST_DESCRIPTION)) { prefEditor = sharedPref.edit(); prefEditor.putString(Prefs.LOCAL_SPECIES_LIST_DESCRIPTION, this.getResources().getString(R.string.local_region_none)); prefEditor.commit(); } // Has the master species list been populated? As a default, assume not. if (!sharedPref.contains(Prefs.SPECIES_LIST_DOWNLOADED)) { prefEditor = sharedPref.edit(); prefEditor.putBoolean(Prefs.SPECIES_LIST_DOWNLOADED, false); prefEditor.commit(); } // start following loader, does not use UI, but tests if the master species list is populated getSupportLoaderManager().restartLoader(VNContract.Loaders.EXISTING_SPP, null, this); // Have the user verify each species entered as presence/absence? Initially, yes. // user will probably turn this one off each session, but turn it on on each restart prefEditor = sharedPref.edit(); prefEditor.putBoolean(Prefs.VERIFY_VEG_ITEMS_PRESENCE, true); prefEditor.commit(); // Set the default ID method to Digital Photograph if (!sharedPref.contains(Prefs.DEFAULT_IDENT_METHOD_ID)) { prefEditor = sharedPref.edit(); prefEditor.putLong(Prefs.DEFAULT_IDENT_METHOD_ID, 1); prefEditor.commit(); } // Set the default to allow species only once per subplot if (!sharedPref.contains(Prefs.SPECIES_ONCE)) { prefEditor = sharedPref.edit(); prefEditor.putBoolean(Prefs.SPECIES_ONCE, true); prefEditor.commit(); } // Set the default to use the "local species" feature if (!sharedPref.contains(Prefs.USE_LOCAL_SPP)) { prefEditor = sharedPref.edit(); prefEditor.putBoolean(Prefs.USE_LOCAL_SPP, true); prefEditor.commit(); } // Set if there is no "local" yet, use the default of not actually filtering for local species if (!sharedPref.contains(Prefs.LOCAL_SPP_CRIT)) { prefEditor = sharedPref.edit(); prefEditor.putString(Prefs.LOCAL_SPP_CRIT, "%"); prefEditor.commit(); } // set up in-app billing // following resource is in it's own file, listed in .gitignore String base64EncodedPublicKey = getString(R.string.app_license); // set up the list of products, for now only donations mSkuCkList.add(SKU_DONATE_SMALL); mSkuCkList.add(SKU_DONATE_MEDIUM); mSkuCkList.add(SKU_DONATE_LARGE); mSkuCkList.add(SKU_DONATE_XLARGE); if (LDebug.ON) Log.d(LOG_TAG, "Creating IAB helper."); mHelper = new IabHelper(this, base64EncodedPublicKey); // enable debug logging (for production application, set this to false). mHelper.enableDebugLogging(LDebug.ON); // Start setup. This is asynchronous. // The specified listener will be called once setup completes. if (LDebug.ON) Log.d(LOG_TAG, "Starting setup."); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (LDebug.ON) Log.d(LOG_TAG, "Setup finished."); if (!result.isSuccess()) { // a problem. //Toast.makeText(this, // this.getResources().getString(R.string.in_app_bill_error) + result, // Toast.LENGTH_SHORT).show(); return; } // disposed? if (mHelper == null) return; // always a good idea to query inventory // even if products were supposed to be consumed there might have been some glitch if (LDebug.ON) Log.d(LOG_TAG, "Setup done. Querying inventory."); mHelper.queryInventoryAsync(true, mSkuCkList, mGotInventoryListener); } }); setContentView(R.layout.activity_vn_main); // viewPager = (ViewPager) findViewById(R.id.data_entry_pager); // FragmentManager fm = getSupportFragmentManager(); // viewPager.setAdapter(new dataPagerAdapter(fm)); /* put conditions to test below * such as whether the container even exists in this layout * e.g. if (findViewById(R.id.fragment_container) != null) * */ if (true) { if (savedInstanceState != null) { mVisitId = savedInstanceState.getLong(ARG_VISIT_ID); mConnectionRequested = savedInstanceState.getBoolean(ARG_CONNECTION_REQUESTED); mSubplotTypeId = savedInstanceState.getLong(ARG_SUBPLOT_TYPE_ID, 0); mNewPurcRecId = savedInstanceState.getLong(ARG_PURCH_REC_ID); // if restoring from a previous state, do not create view // could end up with overlapping views return; } // create an instance of New Visit fragment NewVisitFragment newVisitFrag = new NewVisitFragment(); // in case this activity were started with special instructions from an Intent // pass the Intent's Extras to the fragment as arguments newVisitFrag.setArguments(getIntent().getExtras()); // the tag is for the fragment now being added // it will stay with this fragment when put on the backstack FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.add(R.id.fragment_container, newVisitFrag, Tags.NEW_VISIT); transaction.commit(); } }
From source file:ac.robinson.mediaphone.MediaPhoneActivity.java
public void checkDirectoriesExist() { // nothing will work, and previously saved files will not load if (MediaPhone.DIRECTORY_STORAGE == null) { // if we're not in the main activity, quit everything else and launch the narrative browser to exit if (!((Object) MediaPhoneActivity.this instanceof NarrativeBrowserActivity)) { Intent homeIntent = new Intent(this, NarrativeBrowserActivity.class); homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(homeIntent);//w w w . jav a 2s . c o m Log.d(DebugUtilities.getLogTag(this), "Couldn't open storage directory - clearing top to exit"); return; } SharedPreferences mediaPhoneSettings = getSharedPreferences(MediaPhone.APPLICATION_NAME, Context.MODE_PRIVATE); final String storageKey = getString(R.string.key_use_external_storage); if (mediaPhoneSettings.contains(storageKey)) { if (mediaPhoneSettings.getBoolean(storageKey, true)) { // defValue is irrelevant, we know value exists if (!isFinishing()) { UIUtilities.showToast(MediaPhoneActivity.this, R.string.error_opening_narrative_content_sd); } Log.d(DebugUtilities.getLogTag(this), "Couldn't open storage directory (SD card) - exiting"); finish(); return; } } if (!isFinishing()) { UIUtilities.showToast(MediaPhoneActivity.this, R.string.error_opening_narrative_content); } Log.d(DebugUtilities.getLogTag(this), "Couldn't open storage directory - exiting"); finish(); return; } // thumbnail cache won't work, but not really fatal (thumbnails will be loaded into memory on demand) if (MediaPhone.DIRECTORY_THUMBS == null) { Log.d(DebugUtilities.getLogTag(this), "Thumbnail directory not found"); } // external narrative sending (Bluetooth/YouTube etc) may not work, but not really fatal (will warn on export) if (MediaPhone.DIRECTORY_TEMP == null) { Log.d(DebugUtilities.getLogTag(this), "Temporary directory not found - will warn before narrative export"); } // bluetooth directory availability may have changed if we're calling from an SD card availability notification configureBluetoothObserver(PreferenceManager.getDefaultSharedPreferences(MediaPhoneActivity.this), getResources()); }
From source file:ir.besteveryeverapp.ui.Components.EmojiView.java
public void loadRecents() { SharedPreferences preferences = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE); lastGifLoadTime = preferences.getLong("lastGifLoadTime", 0); String str;//from w w w .j av a 2 s . c om try { emojiUseHistory.clear(); if (preferences.contains("emojis")) { str = preferences.getString("emojis", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); long value = Utilities.parseLong(args2[0]); String string = ""; for (int a = 0; a < 4; a++) { char ch = (char) value; string = String.valueOf(ch) + string; value >>= 16; if (value == 0) { break; } } if (string.length() > 0) { emojiUseHistory.put(string, Utilities.parseInt(args2[1])); } } } preferences.edit().remove("emojis").commit(); saveRecentEmoji(); } else { str = preferences.getString("emojis2", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); emojiUseHistory.put(args2[0], Utilities.parseInt(args2[1])); } } } if (emojiUseHistory.isEmpty()) { if (!preferences.getBoolean("filled_default", false)) { String[] newRecent = new String[] { "\uD83D\uDE02", "\uD83D\uDE18", "\u2764", "\uD83D\uDE0D", "\uD83D\uDE0A", "\uD83D\uDE01", "\uD83D\uDC4D", "\u263A", "\uD83D\uDE14", "\uD83D\uDE04", "\uD83D\uDE2D", "\uD83D\uDC8B", "\uD83D\uDE12", "\uD83D\uDE33", "\uD83D\uDE1C", "\uD83D\uDE48", "\uD83D\uDE09", "\uD83D\uDE03", "\uD83D\uDE22", "\uD83D\uDE1D", "\uD83D\uDE31", "\uD83D\uDE21", "\uD83D\uDE0F", "\uD83D\uDE1E", "\uD83D\uDE05", "\uD83D\uDE1A", "\uD83D\uDE4A", "\uD83D\uDE0C", "\uD83D\uDE00", "\uD83D\uDE0B", "\uD83D\uDE06", "\uD83D\uDC4C", "\uD83D\uDE10", "\uD83D\uDE15" }; for (int i = 0; i < newRecent.length; i++) { emojiUseHistory.put(newRecent[i], newRecent.length - i); } preferences.edit().putBoolean("filled_default", true).commit(); saveRecentEmoji(); } } sortEmoji(); adapters.get(0).notifyDataSetChanged(); } catch (Exception e) { FileLog.e("tmessages", e); } try { str = preferences.getString("color", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (int a = 0; a < args.length; a++) { String arg = args[a]; String[] args2 = arg.split("="); emojiColor.put(args2[0], args2[1]); } } } catch (Exception e) { FileLog.e("tmessages", e); } if (showStickers) { try { newRecentStickers.clear(); str = preferences.getString("stickers", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); final HashMap<Long, Integer> stickersUseHistory = new HashMap<>(); for (int a = 0; a < args.length; a++) { String arg = args[a]; String[] args2 = arg.split("="); Long key = Utilities.parseLong(args2[0]); stickersUseHistory.put(key, Utilities.parseInt(args2[1])); newRecentStickers.add(key); } Collections.sort(newRecentStickers, new Comparator<Long>() { @Override public int compare(Long lhs, Long rhs) { Integer count1 = stickersUseHistory.get(lhs); Integer count2 = stickersUseHistory.get(rhs); if (count1 == null) { count1 = 0; } if (count2 == null) { count2 = 0; } if (count1 > count2) { return -1; } else if (count1 < count2) { return 1; } return 0; } }); preferences.edit().remove("stickers").commit(); saveRecentStickers(); } else { str = preferences.getString("stickers2", ""); String[] args = str.split(","); for (int a = 0; a < args.length; a++) { if (args[a].length() == 0) { continue; } long id = Utilities.parseLong(args[a]); if (id != 0) { newRecentStickers.add(id); } } } sortStickers(); updateStickerTabs(); } catch (Exception e) { FileLog.e("tmessages", e); } } }
From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragment.java
/** * Download koopmannen with status = 3 (Vervanger) from the Api and log in shared preferences *///from www. jav a2s . co m private void getVervangers() { // get koopmannen with status = 3 (vervanger) final int koopmanStatusVervanger = 3; // get settings from the shared preferences SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); // check time in hours since last fetched the vervangers long diffInHours = getResources().getInteger(R.integer.makkelijkemarkt_api_vervangers_fetch_interval_hours); if (settings.contains(getContext().getString(R.string.sharedpreferences_key_koopmannen_last_fetched) + koopmanStatusVervanger)) { long lastFetchTimestamp = settings .getLong(getContext().getString(R.string.sharedpreferences_key_koopmannen_last_fetched) + koopmanStatusVervanger, 0); long differenceMs = new Date().getTime() - lastFetchTimestamp; diffInHours = TimeUnit.MILLISECONDS.toHours(differenceMs); } // if last vervangers fetched more than 12 hours ago, fetch them again if (diffInHours >= getResources() .getInteger(R.integer.makkelijkemarkt_api_vervangers_fetch_interval_hours)) { // show progress dialog mGetVervangersProcessDialog.show(); ApiGetKoopmannen getKoopmannen = new ApiGetKoopmannen(getContext()); getKoopmannen.setStatus(koopmanStatusVervanger); getKoopmannen.enqueue(); } }
From source file:com.b44t.ui.Components.EmojiView.java
public void loadRecents() { SharedPreferences preferences = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE); lastGifLoadTime = preferences.getLong("lastGifLoadTime", 0); String str;/* w w w . ja v a 2 s .com*/ try { emojiUseHistory.clear(); if (preferences.contains("emojis")) { str = preferences.getString("emojis", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); long value = Utilities.parseLong(args2[0]); String string = ""; for (int a = 0; a < 4; a++) { char ch = (char) value; string = String.valueOf(ch) + string; value >>= 16; if (value == 0) { break; } } if (string.length() > 0) { emojiUseHistory.put(string, Utilities.parseInt(args2[1])); } } } preferences.edit().remove("emojis").apply(); saveRecentEmoji(); } else { str = preferences.getString("emojis2", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); emojiUseHistory.put(args2[0], Utilities.parseInt(args2[1])); } } } if (emojiUseHistory.isEmpty()) { if (!preferences.getBoolean("filled_default", false)) { String[] newRecent = new String[] { "\uD83D\uDE02", "\uD83D\uDE18", "\u2764", "\uD83D\uDE0D", "\uD83D\uDE0A", "\uD83D\uDE01", "\uD83D\uDC4D", "\u263A", "\uD83D\uDE14", "\uD83D\uDE04", "\uD83D\uDE2D", "\uD83D\uDC8B", "\uD83D\uDE12", "\uD83D\uDE33", "\uD83D\uDE1C", "\uD83D\uDE48", "\uD83D\uDE09", "\uD83D\uDE03", "\uD83D\uDE22", "\uD83D\uDE1D", "\uD83D\uDE31", "\uD83D\uDE21", "\uD83D\uDE0F", "\uD83D\uDE1E", "\uD83D\uDE05", "\uD83D\uDE1A", "\uD83D\uDE4A", "\uD83D\uDE0C", "\uD83D\uDE00", "\uD83D\uDE0B", "\uD83D\uDE06", "\uD83D\uDC4C", "\uD83D\uDE10", "\uD83D\uDE15" }; for (int i = 0; i < newRecent.length; i++) { emojiUseHistory.put(newRecent[i], newRecent.length - i); } preferences.edit().putBoolean("filled_default", true).apply(); saveRecentEmoji(); } } sortEmoji(); adapters.get(0).notifyDataSetChanged(); } catch (Exception e) { FileLog.e("messenger", e); } try { str = preferences.getString("color", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (int a = 0; a < args.length; a++) { String arg = args[a]; String[] args2 = arg.split("="); emojiColor.put(args2[0], args2[1]); } } } catch (Exception e) { FileLog.e("messenger", e); } if (showStickers) { try { newRecentStickers.clear(); str = preferences.getString("stickers", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); final HashMap<Long, Integer> stickersUseHistory = new HashMap<>(); for (int a = 0; a < args.length; a++) { String arg = args[a]; String[] args2 = arg.split("="); Long key = Utilities.parseLong(args2[0]); stickersUseHistory.put(key, Utilities.parseInt(args2[1])); newRecentStickers.add(key); } Collections.sort(newRecentStickers, new Comparator<Long>() { @Override public int compare(Long lhs, Long rhs) { Integer count1 = stickersUseHistory.get(lhs); Integer count2 = stickersUseHistory.get(rhs); if (count1 == null) { count1 = 0; } if (count2 == null) { count2 = 0; } if (count1 > count2) { return -1; } else if (count1 < count2) { return 1; } return 0; } }); preferences.edit().remove("stickers").apply(); saveRecentStickers(); } else { str = preferences.getString("stickers2", ""); String[] args = str.split(","); for (int a = 0; a < args.length; a++) { if (args[a].length() == 0) { continue; } long id = Utilities.parseLong(args[a]); if (id != 0) { newRecentStickers.add(id); } } } sortStickers(); updateStickerTabs(); } catch (Exception e) { FileLog.e("messenger", e); } } }