List of usage examples for android.content SharedPreferences getLong
long getLong(String key, long defValue);
From source file:com.vegnab.vegnab.MainVNActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. Tracker optionsMenuTracker = ((VNApplication) getApplication()) .getTracker(VNApplication.TrackerName.APP_TRACKER); FragmentManager fm = getSupportFragmentManager(); DialogFragment editProjDlg;//from www . jav a 2 s . co m switch (item.getItemId()) { // some of these are from Fragments, but handled here in the Activity case R.id.action_app_info: Toast.makeText(getApplicationContext(), "''App Info'' is not implemented yet", Toast.LENGTH_SHORT) .show(); return true; case R.id.action_legal_notices: // following is required, to use Drive API String legalInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this); AlertDialog.Builder legalInfoDialog = new AlertDialog.Builder(this); legalInfoDialog.setTitle(this.getResources().getString(R.string.action_legal_notices)); legalInfoDialog.setMessage(legalInfo); legalInfoDialog.show(); return true; case R.id.action_edit_proj: // EditProjectDialog editProjDlg = new EditProjectDialog(); /* fm.executePendingTransactions(); // assure all are done NewVisitFragment newVis = (NewVisitFragment) fm.findFragmentByTag("NewVisitScreen"); if (newVis == null) { Toast.makeText(getApplicationContext(), "Can't get New Visit Screen fragment", Toast.LENGTH_SHORT).show(); return true; } // wait, we don't need to regenerate the default project Id, it's stored in Preferences*/ SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE); long defaultProjId = sharedPref.getLong(Prefs.DEFAULT_PROJECT_ID, 1); editProjDlg = EditProjectDialog.newInstance(defaultProjId); editProjDlg.show(fm, "frg_edit_proj"); return true; case R.id.action_new_proj: editProjDlg = EditProjectDialog.newInstance(0); editProjDlg.show(fm, "frg_new_proj"); return true; case R.id.action_del_proj: DelProjectDialog delProjDlg = new DelProjectDialog(); delProjDlg.show(fm, "frg_del_proj"); return true; case R.id.action_new_plottype: // Toast.makeText(getApplicationContext(), "''New Plot Type'' is still under construction", Toast.LENGTH_SHORT).show(); showWebViewScreen(Tags.WEBVIEW_PLOT_TYPES); /* public static final String WEBVIEW_TUTORIAL = "WebviewTutorial"; public static final String WEBVIEW_PLOT_TYPES = "WebviewPlotTypes"; public static final String WEBVIEW_REGIONAL_LISTS = "WebviewSppLists"; */ return true; case R.id.action_get_species: goToGetSppScreen(); return true; case R.id.action_export_db: exportDB(); return true; // following, moved to NewVisit fragment // case R.id.action_unhide_visits: // from New Visit fragment // if (mCtHiddenVisits == 0) { // Toast.makeText(this, // this.getResources().getString(R.string.new_visit_unhide_visit_none), // Toast.LENGTH_SHORT).show(); // } else { //// Toast.makeText(getApplicationContext(), mCtHiddenVisits + " hidden visit(s), but " //// + "''Un-hide Visits'' is not implemented yet", Toast.LENGTH_SHORT).show(); // UnHideVisitDialog unHideVisDlg = new UnHideVisitDialog(); // unHideVisDlg.show(fm, "frg_unhide_vis"); // } // return true; case R.id.action_settings: if (LDebug.ON) Log.d(LOG_TAG, "Showing 'Settings' dialog"); optionsMenuTracker.send(new HitBuilders.EventBuilder().setCategory("Options Menu").setAction("Settings") .setLabel("Show Settings").setValue(1).build()); Bundle settingsArgs = new Bundle(); // we don't do anything with this yet SettingsDialog settingsDlg = SettingsDialog.newInstance(settingsArgs); settingsDlg.show(getSupportFragmentManager(), "frg_show_settings"); return true; case R.id.action_donate: goToDonateScreen(); return true; } return super.onOptionsItemSelected(item); }
From source file:org.computeforcancer.android.client.Monitor.java
/** * Reads client status via RPCs//from www.j ava 2 s . c om * Optimized to retrieve only subset of information (required to determine wakelock state) if screen is turned off * @param forceCompleteUpdate forces update of entire status information, regardless of screen status */ private synchronized void readClientStatus(Boolean forceCompleteUpdate) { try { CcStatus status; // read independently of screen status // complete status read, depending on screen status // screen off: only read computing status to adjust wakelock, do not send broadcast // screen on: read complete status, set ClientStatus, send broadcast // forceCompleteUpdate: read complete status, independently of screen setting if (screenOn || forceCompleteUpdate) { // complete status read, with broadcast if (Logging.VERBOSE) Log.d(Logging.TAG, "readClientStatus(): screen on, get complete status"); status = clientInterface.getCcStatus(); CcState state = clientInterface.getState(); ArrayList<Transfer> transfers = clientInterface.getFileTransfers(); AcctMgrInfo acctMgrInfo = clientInterface.getAcctMgrInfo(); ArrayList<Notice> newNotices = clientInterface .getNotices(Monitor.getClientStatus().getMostRecentNoticeSeqNo()); if ((status != null) && (state != null) && (state.results != null) && (state.projects != null) && (transfers != null) && (state.host_info != null) && (acctMgrInfo != null)) { Monitor.getClientStatus().setClientStatus(status, state.results, state.projects, transfers, state.host_info, acctMgrInfo, newNotices); } else { String nullValues = ""; try { if (state == null) nullValues += "state,"; if (state.results == null) nullValues += "state.results,"; if (state.projects == null) nullValues += "state.projects,"; if (transfers == null) nullValues += "transfers,"; if (state.host_info == null) nullValues += "state.host_info,"; if (acctMgrInfo == null) nullValues += "acctMgrInfo,"; } catch (NullPointerException e) { } ; if (Logging.ERROR) Log.e(Logging.TAG, "readClientStatus(): connection problem, null: " + nullValues); } // update notices notification //NoticeNotification.getInstance(getApplicationContext()).update(Monitor.getClientStatus().getRssNotices(), Monitor.getAppPrefs().getShowNotificationForNotices()); // check whether monitor is still intended to update, if not, skip broadcast and exit... if (updateBroadcastEnabled) { Intent clientStatus = new Intent(); clientStatus.setAction("org.computeforcancer.android.clientstatus"); getApplicationContext().sendBroadcast(clientStatus); } } else { // read only ccStatus to adjust wakelocks and service state independently of screen status status = clientInterface.getCcStatus(); } // independent of screen on off: // wake locks and foreground enabled when Client is not suspended, therefore also during // idle. // treat cpu throttling as if it was computing. Boolean computing = (status.task_suspend_reason == BOINCDefs.SUSPEND_NOT_SUSPENDED) || (status.task_suspend_reason == BOINCDefs.SUSPEND_REASON_CPU_THROTTLE); if (Logging.VERBOSE) Log.d(Logging.TAG, "readClientStatus(): computation enabled: " + computing); Monitor.getClientStatus().setWifiLock(computing); Monitor.getClientStatus().setWakeLock(computing); SharedPreferences mSharedPreferences = getApplicationContext().getSharedPreferences( "org.computeforcancer.android", Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS); //Log.d("TEST", "deviceStatus.getStatus().user_active " + deviceStatus.getStatus().user_active); if (computing && !deviceStatus.getStatus().user_active) { //Log.d("TEST", "computing"); currTime = System.currentTimeMillis(); if (currTime - prevTime < 14000) { temp = mSharedPreferences.getLong( SharedPrefs.DONATION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), 0); ; //Log.d("TEST", "1get DONATION_TIME " + temp); //Log.d("TEST", "1put DONATION_TIME " + (temp + // currTime - prevTime)); mSharedPreferences.edit() .putLong( SharedPrefs.DONATION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), temp + currTime - prevTime) .commit(); } prevTime = currTime; //Log.d("TEST", "1get START_SESSION_TIME " + startSessionTime); if (startSessionTime == 0) { //Log.d("TEST", "1put START_SESSION_TIME " + currTime); startSessionTime = currTime; } } else { //Log.d("TEST", "2get START_SESSION_TIME " + startSessionTime); if (startSessionTime != 0) { currTime = System.currentTimeMillis(); mSharedPreferences.edit() .putLong( SharedPrefs.LAST_SESSION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), currTime - startSessionTime) .commit(); //Log.d("TEST", "2get DONATION_TIME " + mSharedPreferences.getLong(SharedPrefs.DONATION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), 0)); temp = mSharedPreferences.getLong( SharedPrefs.DONATION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), 0); ; mSharedPreferences.edit() .putLong( SharedPrefs.DONATION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), temp + currTime - prevTime) .commit(); prevTime = currTime; sendDonationTimeMessage( mSharedPreferences.getLong(SharedPrefs.LAST_SESSION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), 0), mSharedPreferences.getLong(SharedPrefs.DONATION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), 0), mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, "")); //Log.d("TEST", "2put START_SESSION_TIME " + 0); startSessionTime = 0; //Log.d("TEST", "System.currentTimeMillis() " + System.currentTimeMillis()); //Log.d("TEST", "System.getLastNotification() " + mSharedPreferences.getLong(SharedPrefs.LAST_NOTIFICATION, 0)); //Log.d("TEST", "System.getNotificationDelay() " + mSharedPreferences.getLong(SharedPrefs.NOTIFICATION_DELAY, Long.MAX_VALUE)); if (currTime - mSharedPreferences.getLong(SharedPrefs.LAST_NOTIFICATION, 0) > mSharedPreferences .getLong(SharedPrefs.NOTIFICATION_DELAY, Long.MAX_VALUE)) { mSharedPreferences.edit().putLong(SharedPrefs.LAST_NOTIFICATION, System.currentTimeMillis()) .commit(); //Log.d("TEST", "get DONATION_TIME " + mSharedPreferences.getLong(SharedPrefs.DONATION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), 0)); sendNotification(mSharedPreferences.getLong(SharedPrefs.DONATION_TIME + mSharedPreferences.getString(SharedPrefs.CURRENT_EMAIL, ""), 0)); } } } //ClientNotification.getInstance(getApplicationContext()).update(Monitor.getClientStatus(), this, computing); } catch (Exception e) { if (Logging.ERROR) Log.e(Logging.TAG, "Monitor.readClientStatus excpetion: " + e.getMessage(), e); } }
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 . j a va2 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 = 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); } } }
From source file:com.irccloud.android.Notifications.java
@SuppressLint("NewApi") private android.app.Notification buildNotification(String ticker, int bid, long[] eids, String title, String text, Spanned big_text, int count, Intent replyIntent, Spanned wear_text, String network, String auto_messages[]) { SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()); NotificationCompat.Builder builder = new NotificationCompat.Builder( IRCCloudApplication.getInstance().getApplicationContext()) .setContentTitle(title + ((network != null) ? (" (" + network + ")") : "")) .setContentText(Html.fromHtml(text)).setAutoCancel(true).setTicker(ticker) .setWhen(eids[0] / 1000).setSmallIcon(R.drawable.ic_stat_notify) .setColor(IRCCloudApplication.getInstance().getApplicationContext().getResources() .getColor(R.color.dark_blue)) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setPriority(NotificationCompat.PRIORITY_HIGH).setOnlyAlertOnce(false); if (ticker != null && (System.currentTimeMillis() - prefs.getLong("lastNotificationTime", 0)) > 10000) { if (prefs.getBoolean("notify_vibrate", true)) builder.setDefaults(android.app.Notification.DEFAULT_VIBRATE); String ringtone = prefs.getString("notify_ringtone", "content://settings/system/notification_sound"); if (ringtone != null && ringtone.length() > 0) builder.setSound(Uri.parse(ringtone)); }// w ww .ja v a 2 s . c o m int led_color = Integer.parseInt(prefs.getString("notify_led_color", "1")); if (led_color == 1) { if (prefs.getBoolean("notify_vibrate", true)) builder.setDefaults( android.app.Notification.DEFAULT_LIGHTS | android.app.Notification.DEFAULT_VIBRATE); else builder.setDefaults(android.app.Notification.DEFAULT_LIGHTS); } else if (led_color == 2) { builder.setLights(0xFF0000FF, 500, 500); } SharedPreferences.Editor editor = prefs.edit(); editor.putLong("lastNotificationTime", System.currentTimeMillis()); editor.commit(); Intent i = new Intent(); i.setComponent(new ComponentName(IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), "com.irccloud.android.MainActivity")); i.putExtra("bid", bid); i.setData(Uri.parse("bid://" + bid)); Intent dismiss = new Intent(IRCCloudApplication.getInstance().getApplicationContext().getResources() .getString(R.string.DISMISS_NOTIFICATION)); dismiss.setData(Uri.parse("irccloud-dismiss://" + bid)); dismiss.putExtra("bid", bid); dismiss.putExtra("eids", eids); PendingIntent dismissPendingIntent = PendingIntent.getBroadcast( IRCCloudApplication.getInstance().getApplicationContext(), 0, dismiss, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent( PendingIntent.getActivity(IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setDeleteIntent(dismissPendingIntent); if (replyIntent != null) { WearableExtender extender = new WearableExtender(); PendingIntent replyPendingIntent = PendingIntent.getService( IRCCloudApplication.getInstance().getApplicationContext(), bid + 1, replyIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT); extender.addAction( new NotificationCompat.Action.Builder(R.drawable.ic_reply, "Reply", replyPendingIntent) .addRemoteInput( new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()) .build()); if (count > 1 && wear_text != null) extender.addPage( new NotificationCompat.Builder(IRCCloudApplication.getInstance().getApplicationContext()) .setContentText(wear_text).extend(new WearableExtender().setStartScrollBottom(true)) .build()); NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( title + ((network != null) ? (" (" + network + ")") : "")) .setReadPendingIntent(dismissPendingIntent).setReplyAction(replyPendingIntent, new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()); if (auto_messages != null) { for (String m : auto_messages) { if (m != null && m.length() > 0) { unreadConvBuilder.addMessage(m); } } } else { unreadConvBuilder.addMessage(text); } unreadConvBuilder.setLatestTimestamp(eids[count - 1] / 1000); builder.extend(extender) .extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConvBuilder.build())); } if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) { i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class); i.setData(Uri.parse("irccloud-bid://" + bid)); i.putExtras(replyIntent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent quickReplyIntent = PendingIntent.getActivity( IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(R.drawable.ic_action_reply, "Quick Reply", quickReplyIntent); } android.app.Notification notification = builder.build(); RemoteViews contentView = new RemoteViews( IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), R.layout.notification); contentView.setTextViewText(R.id.title, title + " (" + network + ")"); contentView.setTextViewText(R.id.text, (count == 1) ? Html.fromHtml(text) : (count + " unread highlights.")); contentView.setLong(R.id.time, "setTime", eids[0] / 1000); notification.contentView = contentView; if (Build.VERSION.SDK_INT >= 16 && big_text != null) { RemoteViews bigContentView = new RemoteViews( IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), R.layout.notification_expanded); bigContentView.setTextViewText(R.id.title, title + (!title.equals(network) ? (" (" + network + ")") : "")); bigContentView.setTextViewText(R.id.text, big_text); bigContentView.setLong(R.id.time, "setTime", eids[0] / 1000); if (count > 3) { bigContentView.setViewVisibility(R.id.more, View.VISIBLE); bigContentView.setTextViewText(R.id.more, "+" + (count - 3) + " more"); } else { bigContentView.setViewVisibility(R.id.more, View.GONE); } if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) { bigContentView.setViewVisibility(R.id.actions, View.VISIBLE); bigContentView.setViewVisibility(R.id.action_divider, View.VISIBLE); i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class); i.setData(Uri.parse("irccloud-bid://" + bid)); i.putExtras(replyIntent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent quickReplyIntent = PendingIntent.getActivity( IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT); bigContentView.setOnClickPendingIntent(R.id.action_reply, quickReplyIntent); } notification.bigContentView = bigContentView; } return notification; }
From source file:com.nextgis.maplibui.formcontrol.DateTime.java
@Override public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, SharedPreferences preferences) throws JSONException { JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); mFieldName = attributes.getString(JSON_FIELD_NAME_KEY); mIsShowLast = ControlHelper.isSaveLastValue(attributes); if (!ControlHelper.isEnabled(fields, mFieldName)) { setEnabled(false);//from www . ja va 2 s.c om getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_ATOP); } if (attributes.has(JSON_DATE_TYPE_KEY)) { mPickerType = attributes.getInt(JSON_DATE_TYPE_KEY); } switch (mPickerType) { case 0: mDateFormat = (SimpleDateFormat) DateFormat.getDateInstance(); mPickerType = GeoConstants.FTDate; break; case 1: mDateFormat = (SimpleDateFormat) DateFormat.getTimeInstance(); mPickerType = GeoConstants.FTTime; break; default: mPickerType = FTDateTime; case 2: mDateFormat = (SimpleDateFormat) DateFormat.getDateTimeInstance(); mPickerType = GeoConstants.FTDateTime; break; } long timestamp = System.currentTimeMillis(); if (ControlHelper.hasKey(savedState, mFieldName)) { timestamp = savedState.getLong(ControlHelper.getSavedStateKey(mFieldName)); } else if (null != featureCursor) { // feature exists int column = featureCursor.getColumnIndex(mFieldName); if (column >= 0) { timestamp = featureCursor.getLong(column); } } else { // new feature if (attributes.has(JSON_TEXT_KEY) && !TextUtils.isEmpty(attributes.getString(JSON_TEXT_KEY).trim())) { String defaultValue = attributes.getString(JSON_TEXT_KEY); timestamp = parseDateTime(defaultValue, mPickerType); } if (mIsShowLast) { timestamp = preferences.getLong(mFieldName, timestamp); } } mCalendar.setTimeInMillis(timestamp); setText(mDateFormat.format(mCalendar.getTime())); setSingleLine(true); setFocusable(false); setOnClickListener(getDateUpdateWatcher(mPickerType)); String pattern = mDateFormat.toLocalizedPattern(); setHint(pattern); }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
public static Object prefs_readPreference(Context ctx, String prefName, String key, Class<?> valueType) { SharedPreferences prefs = ctx.getSharedPreferences(prefName, Context.MODE_PRIVATE); if (valueType == Long.class) { return prefs.getLong(key, Long.valueOf(-1)); } else if (valueType == Boolean.class) { return prefs.getBoolean(key, Boolean.valueOf(false)); } else if (valueType == Float.class) { return prefs.getFloat(key, Float.valueOf(-1)); } else if (valueType == Integer.class) { return prefs.getInt(key, Integer.valueOf(-1)); } else if (valueType == String.class) { return prefs.getString(key, null); } else if (valueType == Set.class) { //return prefs.getStringSet(key, null); //Only from 11 API level. return getSetListFromCommaSeparatedString(ctx, prefName, key); }/*w ww .ja v a 2 s . c o m*/ return null; }
From source file:com.ywesee.amiko.MainActivity.java
private void checkTimeSinceLastUpdate() { SharedPreferences settings = getSharedPreferences(AMIKO_PREFS_FILE, 0); long timeMillisSince1970 = settings.getLong(PREF_DB_UPDATE_DATE_DE, 0); long timeDiff = (System.currentTimeMillis() - timeMillisSince1970) / 1000; // That's 30 days in seconds ;) if (timeDiff > 60 * 60 * 24 * 30) showDownloadAlert(1);//from ww w .ja va2s. c o m if (Constants.DEBUG) Log.d(TAG, "Time since last update: " + timeDiff + " sec"); }
From source file:org.videolan.vlc.PlaybackService.java
private synchronized void loadLastPlaylist() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); String currentMedia = prefs.getString("current_media", ""); if (currentMedia.equals("")) return;//from w ww. j a v a 2 s. com String[] locations = prefs.getString("media_list", "").split(" "); List<String> mediaPathList = new ArrayList<String>(locations.length); for (int i = 0; i < locations.length; ++i) mediaPathList.add(Uri.decode(locations[i])); mShuffling = prefs.getBoolean("shuffling", false); mRepeating = RepeatType.values()[prefs.getInt("repeating", RepeatType.None.ordinal())]; int position = prefs.getInt("position_in_list", Math.max(0, mediaPathList.indexOf(currentMedia))); long time = prefs.getLong("position_in_song", -1); // load playlist try { mInterface.loadLocations(mediaPathList, position); if (time > 0) mInterface.setTime(time); } catch (RemoteException e) { e.printStackTrace(); } finally { SharedPreferences.Editor editor = prefs.edit(); editor.putInt("position_in_list", 0); editor.putLong("position_in_song", 0); Util.commitPreferences(editor); } }
From source file:org.mariotaku.twidere.util.Utils.java
public static long getDefaultAccountId(final Context context) { if (context == null) return -1; final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); return prefs.getLong(PREFERENCE_KEY_DEFAULT_ACCOUNT_ID, -1); }
From source file:com.ichi2.anki.DeckPicker.java
private void automaticSync() { SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); // Check whether the option is selected, the user is signed in and last sync was AUTOMATIC_SYNC_TIME ago // (currently 10 minutes) String hkey = preferences.getString("hkey", ""); long lastSyncTime = preferences.getLong("lastSyncTime", 0); if (hkey.length() != 0 && preferences.getBoolean("automaticSyncMode", false) && Connection.isOnline() && Utils.intNow(1000) - lastSyncTime > AUTOMATIC_SYNC_MIN_INTERVAL) { sync();/* www . j ava 2 s . c om*/ } }