List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:edu.rowan.app.fragments.FoodRatingFragment.java
/** * Start pre-fetching data (load data before it is needed) * /*from w ww . java2s .c o m*/ * @param reference Activity reference required for AQuery */ public static void prefetch(Activity reference, boolean updateCache, FoodRatingFragment callback) { SharedPreferences prefs = reference.getSharedPreferences(FoodRatingFragment.PREFS, 0); if (!prefs.contains(FoodRatingFragment.USER_ID)) { // we need to get a userId getUserID(reference); } long lastUpdate = prefs.getLong(LAST_REFRESH, 0); // [difference] / (milis * seconds * minutes) int hourDifference = (int) (Calendar.getInstance().getTimeInMillis() - lastUpdate) / (1000 * 60 * 60); Log.d("FoodRatingFragment", "Hour difference: " + hourDifference); if (updateCache || hourDifference > UPDATE_INTERVAL || lastUpdate == 0) { Log.d("FoodRatingFragment", "Fetching Ratings"); fetchAllRatings(reference, callback); } else { Log.d("FoodRatingFragment", "Cached food ratings"); Log.d("Marketplace", prefs.getString(Integer.toString(prefs.getInt(TYPE_MARKETPLACE, 0)), "CACHE FAIL")); Log.d("Smokehouse", prefs.getString(Integer.toString(prefs.getInt(TYPE_SMOKEHOUSE, 0)), "CACHE FAIL")); } }
From source file:com.nextgis.firereporter.ScanexNotificationItem.java
protected void Prepare(Context c) { this.nID = -1; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); nFormat = prefs.getInt(SettingsActivity.KEY_PREF_COORD_FORMAT + "_int", Location.FORMAT_SECONDS); sCoordLat = (String) c.getResources().getText(R.string.coord_lat); sCoordLon = (String) c.getResources().getText(R.string.coord_lon); sN = (String) c.getResources().getText(R.string.compas_N); sS = (String) c.getResources().getText(R.string.compas_S); sW = (String) c.getResources().getText(R.string.compas_W); sE = (String) c.getResources().getText(R.string.compas_E); }
From source file:github.daneren2005.dsub.util.Util.java
public static int getActiveServer(Context context) { SharedPreferences prefs = getPreferences(context); return prefs.getBoolean(Constants.PREFERENCES_KEY_OFFLINE, false) ? 0 : prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); }
From source file:com.nextgis.firereporter.ScanexSubscriptionItem.java
public void UpdateFromRemote(String sCookie) { if (c == null) return;//from ww w . j a va2 s. c om //get notifications http://fires.kosmosnimki.ru/SAPI/Subscribe/GetData/55?dt=2013-08-06&CallBackName=44 Calendar calendar = Calendar.getInstance(); SharedPreferences prefs = c.getSharedPreferences(MainActivity.PREFERENCES, Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS); int nPrevDays = prefs.getInt(SettingsActivity.KEY_PREF_SEARCH_DAY_INTERVAL + "_int", PREV_DAYS); for (int i = 0; i < nPrevDays; i++) { String sDate = String.format("%04d-%02d-%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH)); Log.d(MainActivity.TAG, sDate); String sURL = GetFiresService.SCANEX_API + "/Subscribe/GetData/" + nID + "?dt=" + sDate + "&CallBackName=" + GetFiresService.USER_ID; Log.d(MainActivity.TAG, sURL); new HttpGetter(c, 5, "", mFillDataHandler, false).execute(sURL, sCookie); calendar.roll(Calendar.DAY_OF_MONTH, false); } }
From source file:com.infine.android.devoxx.service.RestService.java
@Override protected void onHandleIntent(Intent intent) { final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER); // si passage du numero de version // final int latestVersion = intent.getIntExtra(EXTRA_LASTEST_VERSION, // 1);/* w w w. j a v a 2s.co m*/ if (receiver != null) receiver.send(ServiceStatus.STATUS_RUNNING, Bundle.EMPTY); // final Context context = this; // final SharedPreferences prefs = // getSharedPreferences(Prefs.DEVOXX_SCHEDULE_SYNC, // Context.MODE_PRIVATE); // final int localVersion = prefs.getInt(Prefs.LOCAL_VERSION, // VERSION_NONE); try { // Bulk of sync work, performed by executing several fetches from // local and online sources. final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mApplicationContext); int scheduleVersion = prefs.getInt(PREFS_SCHEDULE_VERSION, -1); int sessionVersion = prefs.getInt(PREFS_SESSION_VERSION, -1); int speakerVersion = prefs.getInt(PREFS_SPEAKER_VERSION, -1); if (scheduleVersion + sessionVersion + speakerVersion < 0) { // on charge les fichiers statiques que la premiere fois // ou quand un jeu de donnes schedule ou session est pourri // verion = -1 loadStaticFiles(); } loadStaticRoom(); // Always hit remote spreadsheet for any updates loadRemoteData(); } catch (Exception e) { Log.e(TAG, "Problem while syncing", e); if (receiver != null) { // Pass back error to surface listener final Bundle bundle = new Bundle(); bundle.putString(Intent.EXTRA_TEXT, e.toString()); receiver.send(STATUS_ERROR, bundle); } } // Announce success to any surface listener if (receiver != null) receiver.send(STATUS_FINISHED, Bundle.EMPTY); }
From source file:org.fundsofhope.androidapp.activities.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getApplicationContext()); setContentView(R.layout.activity_sliding); RecyclerView recList = (RecyclerView) findViewById(R.id.cardList); recList.setHasFixedSize(true);//from w w w. j a v a2s .co m Button add; add = (Button) findViewById(R.id.fab_button); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); Log.i(TAG, "loged in as" + String.valueOf(pref.getInt("user", -1))); add.setClickable(true); //Bitmap bi; add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent inte = new Intent(MainActivity.this, GoogleLoginActivity.class); startActivity(inte); finish(); } }); // Pushbots.sharedInstance().init(this); temp = 2; final SharedPreferences ppref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); token = ppref.getString("token", ""); new LoginTask().execute(""); if (savedInstanceState == null) { FragmentTransaction transaction = getFragmentManager().beginTransaction(); SlidingTabsBasicFragment fragment = new SlidingTabsBasicFragment(); transaction.replace(R.id.sample_content_fragment, fragment); transaction.commit(); } configureToolbar(); configureDrawer(); }
From source file:com.drunkenhamster.facerecognitionfps.SnapFaceActivity.java
/** Called when the activity is first created. */ @Override/*from w w w .jav a 2 s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* GoogleAnalyticsTracker */ Log.i(TAG, "GoogleAnalytics Setup"); tracker_ = GoogleAnalyticsTracker.getInstance(); tracker_.start(getString(R.string.GoogleAnalyticsUA), this); /* set Full Screen */ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); /* set window with no title bar */ requestWindowFeature(Window.FEATURE_NO_TITLE); /* Restore preferences */ SharedPreferences settings = getSharedPreferences(getString(R.string.SnapFacePreference), 0); appMode_ = settings.getInt(getString(R.string.menu_AppMode), 0); fdetLevel_ = settings.getInt(getString(R.string.menu_Preferences), 1); //implicit intent receiver(GET_CONTENT will be invoked to add contact thumbnail) if (Intent.ACTION_GET_CONTENT.equals(getIntent().getAction())) { Log.i(TAG, "implicit intent:ACTION_GET_CONTENT"); calledACTION_GET_CONTENT_ = true; appMode_ = 0; } /* create camera view */ camPreview_ = new PreviewView(this, calledACTION_GET_CONTENT_, tracker_); camPreview_.setAppMode(appMode_); camPreview_.setfdetLevel(fdetLevel_, true); setContentView(camPreview_); /* append Overlay */ addContentView(camPreview_.getOverlay(), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); }
From source file:net.peterkuterna.android.apps.devoxxsched.service.SyncService.java
@Override protected void onHandleIntent(Intent intent) { final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER); if (receiver != null) receiver.send(STATUS_RUNNING, Bundle.EMPTY); final Context context = this; final SharedPreferences syncServicePrefs = getSharedPreferences(SyncPrefs.DEVOXXSCHED_SYNC, Context.MODE_PRIVATE); final int localVersion = syncServicePrefs.getInt(SyncPrefs.LOCAL_VERSION, VERSION_NONE); final long lastRemoteSync = syncServicePrefs.getLong(SyncPrefs.LAST_REMOTE_SYNC, 0); try {/* ww w . j a va2 s.c o m*/ // Bulk of sync work, performed by executing several fetches from // local and online sources. final long startLocal = System.currentTimeMillis(); final boolean localParse = localVersion < VERSION_LOCAL; Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_LOCAL=" + VERSION_LOCAL); if (localParse) { // Parse values from local cache first mLocalExecutor.execute(R.xml.search_suggest, new LocalSearchSuggestHandler()); mLocalExecutor.execute(context, "cache-rooms.json", new RemoteRoomsHandler()); mLocalExecutor.execute(context, "cache-presentationtypes.json", new RemoteSessionTypesHandler()); mLocalExecutor.execute(context, "cache-speakers.json", new RemoteSpeakersHandler()); mLocalExecutor.execute(context, "cache-presentations.json", new RemoteSessionsHandler()); mLocalExecutor.execute(context, "cache-schedule.json", new RemoteScheduleHandler()); // Save local parsed version syncServicePrefs.edit().putInt(SyncPrefs.LOCAL_VERSION, VERSION_LOCAL).commit(); } Log.d(TAG, "local sync took " + (System.currentTimeMillis() - startLocal) + "ms"); final long startRemote = System.currentTimeMillis(); boolean performRemoteSync = performRemoteSync(mResolver, mHttpClient, intent, context); if (performRemoteSync) { // Parse values from REST interface ArrayList<RequestHash> result = mRemoteExecutor.executeGet(new String[] { Constants.ROOMS_URL, }, new RemoteRoomsHandler()); for (RequestHash requestHash : result) { SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5()); } result = mRemoteExecutor.executeGet(new String[] { Constants.LABS_PRESENTATION_TYPES_URL, }, new RemoteSessionTypesHandler()); for (RequestHash requestHash : result) { SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5()); } result = mRemoteExecutor.executeGet( new String[] { Constants.SPEAKERS_URL, Constants.LABS_SPEAKERS_URL, }, new RemoteSpeakersHandler()); for (RequestHash requestHash : result) { SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5()); } result = mRemoteExecutor.executeGet( new String[] { Constants.PRESENTATIONS_URL, Constants.LABS_PRESENTATIONS_URL, }, new RemoteSessionsHandler()); for (RequestHash requestHash : result) { SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5()); } result = mRemoteExecutor.executeGet( new String[] { Constants.SCHEDULE_URL, Constants.LABS_SCHEDULE_URL, }, new RemoteScheduleHandler()); for (RequestHash requestHash : result) { SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5()); } // Save last remote sync time syncServicePrefs.edit().putLong(SyncPrefs.LAST_REMOTE_SYNC, startRemote).commit(); // Save remote parsed version syncServicePrefs.edit().putInt(SyncPrefs.LOCAL_VERSION, VERSION_REMOTE).commit(); } Log.d(TAG, "remote sync took " + (System.currentTimeMillis() - startRemote) + "ms"); if (!localParse && performRemoteSync) { NotificationUtils.cancelNotifications(context); NotificationUtils.notifyNewSessions(context, getContentResolver()); NotificationUtils.notifyChangedStarredSessions(context, getContentResolver()); } } catch (Exception e) { Log.e(TAG, "Problem while syncing", e); if (receiver != null) { // Pass back error to surface listener final Bundle bundle = new Bundle(); bundle.putString(Intent.EXTRA_TEXT, e.toString()); receiver.send(STATUS_ERROR, bundle); } } // Announce success to any surface listener Log.d(TAG, "sync finished"); if (receiver != null) receiver.send(STATUS_FINISHED, Bundle.EMPTY); }
From source file:com.infine.android.devoxx.service.RestService.java
private void loadRemoteData() throws HandlerException { final long startRemote = System.currentTimeMillis(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mApplicationContext); // gestion des schedules int localScheduleVersion = prefs.getInt(PREFS_SCHEDULE_VERSION, 0); int lastScheduleVersion = VersionReader.getVersion(SERVER_PATH_SCHEDULE_VERSION); if (localScheduleVersion < lastScheduleVersion) { mRemoteExecutor.executeGet(SERVER_PATH_SCHEDULE, new JsonScheduleHandler(mApplicationContext, PREFS_SCHEDULE_VERSION, lastScheduleVersion)); }// ww w . java2 s .c o m // gestion des sessions int localSessionVersion = prefs.getInt(PREFS_SESSION_VERSION, 0); int lastSessionVersion = VersionReader.getVersion(SERVER_PATH_SESSION_VERSION); if (localSessionVersion < lastSessionVersion) { mRemoteExecutor.executeGet(SERVER_PATH_SESSION, new JsonSessionHandler(mApplicationContext, PREFS_SESSION_VERSION, lastSessionVersion)); } // speaker management int localSpeakerVersion = prefs.getInt(PREFS_SPEAKER_VERSION, 0); int lastSpeakerVersion = VersionReader.getVersion(SERVER_PATH_SPEAKER_VERSION); if (localSpeakerVersion < lastSpeakerVersion) { mRemoteExecutor.executeGet(SERVER_PATH_SPEAKER, new JsonSpeakerHandler(mApplicationContext, PREFS_SPEAKER_VERSION, lastSpeakerVersion)); } if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "remote sync took " + (System.currentTimeMillis() - startRemote) + "ms"); } }
From source file:com.bullmobi.base.content.SharedList.java
protected void init(@NonNull Context context) { mList = new HashMap<>(); mPlaceholder = new ArrayList<>(3); mListeners = new ArrayList<>(6); createRecyclableFields();/*from w ww . j a v a 2s . c o m*/ // Restore previously saved list. SharedPreferences prefs = getSharedPreferences(context); final int n = prefs.getInt(KEY_NUMBER, 0); for (int i = 0; i < n; i++) { if (prefs.getBoolean(KEY_USED_ITEM + i, false)) { // Create previously saved object. V object = mSaver.get(prefs, i); mList.put(object, i); } else { // This is an empty place which we can re-use // later. mPlaceholder.add(i); } } }