List of usage examples for android.content SharedPreferences getLong
long getLong(String key, long defValue);
From source file:com.magnet.mmx.client.MMXClient.java
static long getWakeupInterval(Context context) { SharedPreferences prefs = context.getSharedPreferences(STATIC_SHARED_PREF_NAME, Context.MODE_PRIVATE); return prefs.getLong(STATIC_SHARED_PREF_KEY_WAKEUP_INTERVAL, 0l); }
From source file:org.anhonesteffort.flock.MigrationService.java
private long getTimeFirstSync(String key) { SharedPreferences settings = getBaseContext().getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE); return settings.getLong(key, -1); }
From source file:com.nextgis.firereporter.GetFiresService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); if (intent == null) return START_REDELIVER_INTENT; int nCommnad = intent.getIntExtra(COMMAND, SERVICE_START); SharedPreferences prefs = getSharedPreferences(MainActivity.PREFERENCES, MODE_PRIVATE | MODE_MULTI_PROCESS); long nUpdateInterval = prefs.getLong(SettingsActivity.KEY_PREF_INTERVAL + "_long", 30 * DateUtils.MINUTE_IN_MILLIS); //15 boolean bEnergyEconomy = prefs.getBoolean(SettingsActivity.KEY_PREF_SERVICE_BATT_SAVE, true); Log.d(MainActivity.TAG, "Received intent - id " + startId + ": " + intent + ", command:" + nCommnad); if ((nCommnad & SERVICE_START) != 0) { mUserNasaReceiver = intent.getParcelableExtra(RECEIVER); if (mUserNasaReceiver != null) { mnFilter = intent.getIntExtra(SOURCE, MainActivity.SRC_NASA | MainActivity.SRC_USER); if (mnCurrentExec < 1) { mUserNasaReceiver.send(SERVICE_START, new Bundle()); }//from www.ja v a2 s . co m Log.d(MainActivity.TAG, "GetFiresService service started"); if ((mnFilter & MainActivity.SRC_NASA) != 0) { mnCurrentExec++; GetNasaData(false); } if ((mnFilter & MainActivity.SRC_USER) != 0) { mnCurrentExec++; GetUserData(false); } } // plan next start ScheduleNextUpdate(this, SERVICE_START | SERVICE_SCANEXSTART, nUpdateInterval, bEnergyEconomy); } if ((nCommnad & SERVICE_SCANEXSTART) != 0) { mScanexReceiver = intent.getParcelableExtra(RECEIVER_SCANEX); if (mScanexReceiver != null) { if (mnCurrentExec < 1) { mScanexReceiver.send(SERVICE_SCANEXSTART, new Bundle()); } Log.d(MainActivity.TAG, "GetFiresService service started"); GetScanexData(false); } // plan next start ScheduleNextUpdate(this, SERVICE_START | SERVICE_SCANEXSTART, nUpdateInterval, bEnergyEconomy); } if ((nCommnad & SERVICE_STOP) != 0) { Log.d(MainActivity.TAG, "GetFiresService service stopped"); ScheduleNextUpdate(this, SERVICE_DESTROY, 150, true); stopSelf(); } if ((nCommnad & SERVICE_DESTROY) != 0) { stopSelf(); } if ((nCommnad & SERVICE_DATA) != 0) { mUserNasaReceiver = intent.getParcelableExtra(RECEIVER); for (FireItem item : mmoFires.values()) { SendItem(item); } } if ((nCommnad & SERVICE_SCANEXDATA) != 0) { mScanexReceiver = intent.getParcelableExtra(RECEIVER_SCANEX); for (ScanexSubscriptionItem Item : mmoSubscriptions.values()) { SendScanexItem(Item); } } if ((nCommnad & SERVICE_SCANEXDATAUPDATE) != 0) { long nSubscirbeId = intent.getLongExtra(SUBSCRIPTION_ID, -1); long nNotificationId = intent.getLongExtra(NOTIFICATION_ID, -1); ScanexSubscriptionItem subscribe = mmoSubscriptions.get(nSubscirbeId); if (subscribe != null) { ScanexNotificationItem notification = subscribe.GetItems().get(nNotificationId); if (notification != null) { notification.setWatched(true); } } } if ((nCommnad & SERVICE_NOTIFY_DISMISSED) != 0) { nUserCount = 0; nNasaCount = 0; nScanexCount = 0; mInboxStyle = new NotificationCompat.InboxStyle(); mInboxStyle.setBigContentTitle(getString(R.string.stNewFireNotificationDetailes)); ScheduleNextUpdate(this, SERVICE_START | SERVICE_SCANEXSTART, nUpdateInterval, bEnergyEconomy); } return START_REDELIVER_INTENT; }
From source file:com.rowland.hashtrace.sync.TweetHashTracerSyncAdapter.java
private void notifyWeather() { Context context = getContext(); // checking the last update and notify if its the first of the day SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String displayNotificationsKey = context.getString(R.string.pref_enable_notifications_key); boolean displayNotifications = prefs.getBoolean(displayNotificationsKey, Boolean.parseBoolean(context.getString(R.string.pref_enable_notifications_default))); if (displayNotifications) { String lastNotificationKey = context.getString(R.string.pref_last_notification); long lastSync = prefs.getLong(lastNotificationKey, 0); if (System.currentTimeMillis() - lastSync >= DAY_IN_MILLIS) { // Last sync was more than 1 day ago, let's send a notification with the tweet. String hashTagQuery = Utility.getPreferredHashTag(context); // Sort order: Ascending, by date. //String sortOrder = TweetEntry.COLUMN_TWEET_TEXT_DATE + " ASC"; Uri tweetUri = TweetEntry.buildTweetHashTagWithDate(hashTagQuery, TweetHashTracerContract.getDbDateString(new Date(), EDbDateLimit.DATE_FORMAT_MINUTE_LIMIT)); // we'll query our contentProvider, as always Cursor cursor = context.getContentResolver().query(tweetUri, NOTIFY_TWEET_PROJECTION, null, null, null);/* w ww . j a va 2s.c o m*/ if (cursor != null && cursor.moveToFirst()) { int tweetId = cursor.getInt(INDEX_TWEET_ID); String tweet_text = cursor.getString(INDEX_TWEET_TEXT); String tweet_text_date = cursor.getString(INDEX_TWEET_TEXT_DATE); String user_name = cursor.getString(INDEX_TWEET_USER_NAME); String user_name_image_url = cursor.getString(INDEX_TWEET_USER_NAME_IMAGE_URL); int smallIconId = Utility.getSmallIconResourceForTweetNotification(tweetId); Bitmap largeIcon = Utility.getLargeIconResourceForTweetNotification(user_name_image_url, context); int notificationCount = 0; String title = context.getString(R.string.app_name); // Define the text of the tweet String contentText = String.format(context.getString(R.string.format_notification), tweet_text); // NotificationCompatBuilder is a very convenient way to backward-compatible // notifications. Just throw in some data. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getContext()) .setSmallIcon(smallIconId).setContentTitle(title).setContentText(contentText) .setLargeIcon(largeIcon).setNumber(++notificationCount) .setSound(Settings.System.DEFAULT_NOTIFICATION_URI).setAutoCancel(true); // Make something interesting happen when the user clicks on // the notification. In this case, opening the app is sufficient. Intent resultIntent = new Intent(context, MainActivity.class); // The stack builder object will contain an artificial back stack for the started Activity. // This ensures that navigating backward from the Activity leads out of your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); // TWEET_NOTIFICATION_ID allows you to update the // notification later on. mNotificationManager.notify(TWEET_NOTIFICATION_ID, mBuilder.build()); // refreshing last sync SharedPreferences.Editor editor = prefs.edit(); editor.putLong(lastNotificationKey, System.currentTimeMillis()); editor.commit(); } } } }
From source file:com.artemchep.horario.content.PreferenceStore.java
public void load(@NonNull Context context) { mMap = new HashMap<>(); loadPreferencesMap(mMap);/* w ww. j a v a 2 s .c om*/ String name = getPreferenceName(); SharedPreferences sp = context.getSharedPreferences(name, Context.MODE_PRIVATE); for (Preference pref : mMap.values()) { Object value = pref.value; if (boolean.class.isAssignableFrom(pref.clazz)) { value = sp.getBoolean(pref.key, (Boolean) value); } else if (int.class.isAssignableFrom(pref.clazz)) { value = sp.getInt(pref.key, (Integer) value); } else if (float.class.isAssignableFrom(pref.clazz)) { value = sp.getFloat(pref.key, (Float) value); } else if (String.class.isAssignableFrom(pref.clazz)) { value = sp.getString(pref.key, (String) value); } else if (long.class.isAssignableFrom(pref.clazz)) { value = sp.getLong(pref.key, (Long) value); } else throw new IllegalArgumentException("Unknown option\'s type."); pref.value = value; } }
From source file:org.croudtrip.fragments.join.JoinResultsFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); layoutManager = new LinearLayoutManager(getActivity()); recyclerView.setLayoutManager(layoutManager); adapter = new JoinTripResultsAdapter(getActivity(), null); recyclerView.setAdapter(adapter);/*w w w .j av a2 s . co m*/ ((MaterialNavigationDrawer) getActivity()).getCurrentSection().setNotificationsText("..."); ((MaterialNavigationDrawer) getActivity()).setTitle(R.string.menu_my_trip); waitingView.setVisibility(View.VISIBLE); /* Start background search */ if (getArguments() != null) { startBackgroundSearch(getArguments()); } /* Stop background search */ btnStop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences prefs = getActivity().getSharedPreferences(Constants.SHARED_PREF_FILE_PREFERENCES, Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(Constants.SHARED_PREF_KEY_SEARCHING, false); editor.putBoolean(Constants.SHARED_PREF_KEY_WAITING, false); Toast.makeText(getActivity().getApplicationContext(), R.string.join_trip_results_canceled, Toast.LENGTH_LONG); //tell the server to stop the background search if (prefs.getLong(Constants.SHARED_PREF_KEY_QUERY_ID, -1) != -1) { tripsResource.deleteQuery(prefs.getLong(Constants.SHARED_PREF_KEY_QUERY_ID, -1), new Callback<Response>() { @Override public void success(Response response, Response response2) { //yeay } @Override public void failure(RetrofitError error) { Timber.e(error.getMessage()); } }); editor.putLong(Constants.SHARED_PREF_KEY_QUERY_ID, -1); } editor.apply(); Intent startingIntent = new Intent(Constants.EVENT_CHANGE_JOIN_UI); LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(startingIntent); } }); // On click of a reservation we request to join this trip. adapter.setOnJoinListener(new JoinTripResultsAdapter.OnJoinListener() { @Override public void onJoin(int position) { progressBar.setVisibility(View.VISIBLE); SuperTripReservation reservation = adapter.getItem(position); Timber.d("Clicked on reservation " + reservation.getId()); Subscription subscription = tripsResource.joinTrip(reservation.getId()) .compose(new DefaultTransformer<SuperTrip>()).subscribe(new Action1<SuperTrip>() { @Override public void call(SuperTrip joinRequest) { Toast.makeText(getActivity(), R.string.join_request_sent, Toast.LENGTH_SHORT) .show(); SharedPreferences prefs = getActivity().getSharedPreferences( Constants.SHARED_PREF_FILE_PREFERENCES, Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(Constants.SHARED_PREF_KEY_SEARCHING, false); editor.putBoolean(Constants.SHARED_PREF_KEY_WAITING, true); editor.commit(); Intent startingIntent = new Intent(Constants.EVENT_CHANGE_JOIN_UI); LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(startingIntent); progressBar.setVisibility(View.GONE); } }, new CrashCallback(JoinResultsFragment.this.getActivity(), "failed to join trip", new Action1<Throwable>() { @Override public void call(Throwable throwable) { progressBar.setVisibility(View.GONE); // TODO: Refresh this fragment. Current reservation could already // have been removed on the server (we don't know when the error happened). } })); subscriptions.add(subscription); } }); }
From source file:com.ultramegasoft.flavordex2.EntryListActivity.java
/** * Load the Shared Preferences for the Activity. * * @param prefs The default SharedPreferences */// w w w .j a v a2 s . c om private void loadPreferences(@NonNull SharedPreferences prefs) { if (prefs.getBoolean(FlavordexApp.PREF_FIRST_RUN, true)) { if (AppImportUtils.isAnyAppInstalled(this)) { AppChooserDialog.showDialog(getSupportFragmentManager(), true); } prefs.edit().putBoolean(FlavordexApp.PREF_FIRST_RUN, false).apply(); } final int oldVersion = prefs.getInt(FlavordexApp.PREF_VERSION, 0); final int newVersion = BuildConfig.VERSION_CODE; if (newVersion > oldVersion) { prefs.edit().putInt(FlavordexApp.PREF_VERSION, newVersion).apply(); } final long catId = prefs.getLong(FlavordexApp.PREF_LIST_CAT_ID, -1); if (catId > -1) { onCatSelected(catId, false); } }
From source file:com.android.talkbacktests.TestController.java
public void init(Context context) throws Exception { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final JSONObject testJson = JsonUtils.readFromRawFile(context, R.raw.test); final JSONArray tests = JsonUtils.getJsonArray(testJson, JSON_KEY_TESTS); if (tests == null || tests.length() == 0) { mTestSessions = new TestSession[0]; } else {/*from w w w. ja v a 2 s.c om*/ final int testCount = tests.length(); mTestSessions = new TestSession[testCount]; for (int i = 0; i < testCount; i++) { final JSONObject test = tests.getJSONObject(i); mTestSessions[i] = new TestSession(context, test, i); mTestSessions[i].setAccessCount(prefs.getInt(PREF_KEY_PREFIX_COUNT + i, 0)); mTestSessions[i].setLastAccessTime(prefs.getLong(PREF_KEY_PREFIX_TIME + i, 0L)); } } mOrderType = prefs.getInt(PREF_KEY_ORDER_TYPE, ORDER_DEFAULT); mKeyword = null; mTestSessionsOrderedFiltered = new ArrayList<>(mTestSessions.length); refreshData(); }
From source file:com.example.app_2.activities.ImageGridActivity.java
@SuppressLint("NewApi") @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override/* ww w . ja v a 2 s .c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_grid); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); mImageThumbSize = sharedPref.getInt("pref_img_size", 150); mImageFontSize = sharedPref.getInt("pref_img_desc_font_size", 15); mCategoryBackgroundColor = sharedPref.getInt("category_view_background", 0xff33b5e5); mContextCategoryBackgroundColor = sharedPref.getInt("context_category_view_background", 0xffe446ff); isMale = sharedPref.getInt("is_male", 1); mImageThumbSpacing = getResources().getDimensionPixelSize(R.dimen.image_thumbnail_spacing); Database db = Database.getInstance(getApplicationContext()); db.open(); //LinearLayout ll = (LinearLayout) findViewById(R.layout.activity_grid); //Utils.setWallpaper(ll, App_2.maxHeight, App_2.getMaxWidth(), null, ScalingLogic.CROP); SharedPreferences user_sharedPref = getApplicationContext().getSharedPreferences("USER", Context.MODE_PRIVATE); // pobranie informacji o zalogowanym uytkowniku logged_user_root = user_sharedPref.getLong("logged_user_root", Database.getMainRootFk()); logged_user_id = user_sharedPref.getLong("logged_user_id", 0); SharedPreferences sharedPref2 = PreferenceManager.getDefaultSharedPreferences(this); mCatBColor = sharedPref2.getInt("category_view_background", 0xff33b5e5); mCtxBColor = sharedPref2.getInt("context_category_view_background", 0xffe446ff); if (logged_user_root == Database.getMainRootFk()) //jeli kto zalogowany tryb edycji wyczony mEditMode = true; else mEditMode = false; setActionBar(); getTTS(); igf = new ImageGridFragment(); //Bundle args = new Bundle(); //if(actual_category_fk.getCategoryId()!=null) //args.putLong("CATEGORY_ID", actual_category_fk.getCategoryId()); //else if(logged_user_root != null){ // actual_category_fk.setCategoryId(logged_user_root); //args.putLong("CATEGORY_ID", logged_user_root); //} if (logged_user_root != null) actual_category_fk.setCategoryId(logged_user_root); //igf.setArguments(args); ListView categoriesListView = (ListView) findViewById(R.id.categories_list); if (categoriesListView != null) mDualPane = categoriesListView.getVisibility() == View.VISIBLE; setDrawerOrLeftList();// ustawienie drawera lub listy kategorii z lewej strony // zaadowanie do content_frame ImageGridFragment if (getSupportFragmentManager().findFragmentByTag(GRID_FRAGMENT_TAG) == null) { final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.content_frame, igf, GRID_FRAGMENT_TAG); ft.commit(); } if (getSupportFragmentManager().findFragmentByTag(EXPRESSION_FRAGMENT_TAG) == null) { elf = new ExpressionListFragment(); final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.horizontal_listview, elf); ft.commit(); } }
From source file:mobile.tiis.appv2.LoginActivity.java
private void evaluateIfFirstLogin(String userID) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = prefs.edit(); boolean sameDate = false; long mostRecentLoginDay = prefs.getLong("mostRecentLoginDay", 0); Calendar mostRecentDate = Calendar.getInstance(); mostRecentDate.setTime(new Date(mostRecentLoginDay)); Calendar today = Calendar.getInstance(); if (mostRecentDate.get(Calendar.DAY_OF_MONTH) == today.get(Calendar.DAY_OF_MONTH) && mostRecentDate.get(Calendar.MONTH) == today.get(Calendar.MONTH) && mostRecentDate.get(Calendar.YEAR) == today.get(Calendar.YEAR)) { sameDate = true;//from w ww. j av a 2 s . c om } else { sameDate = false; } if (!sameDate) { editor.putLong("mostRecentLoginDay", today.getTimeInMillis()); editor.putBoolean("firstLoginOfDaySyncNeeded", true); editor.apply(); } }