List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:com.farmerbb.secondscreen.util.U.java
public static boolean runSizeCommand(Context context, String requestedRes) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display disp = wm.getDefaultDisplay(); disp.getRealMetrics(metrics);//www . j a v a 2 s .com SharedPreferences prefMain = getPrefMain(context); String currentRes = " "; String nativeRes; if (prefMain.getBoolean("landscape", false)) nativeRes = Integer.toString(prefMain.getInt("height", 0)) + "x" + Integer.toString(prefMain.getInt("width", 0)); else nativeRes = Integer.toString(prefMain.getInt("width", 0)) + "x" + Integer.toString(prefMain.getInt("height", 0)); if (prefMain.getBoolean("debug_mode", false)) { SharedPreferences prefCurrent = getPrefCurrent(context); currentRes = prefCurrent.getString("size", "reset"); if ("reset".equals(currentRes)) currentRes = nativeRes; } else { if ((context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT && !prefMain.getBoolean("landscape", false)) || (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE && prefMain.getBoolean("landscape", false))) { currentRes = Integer.toString(metrics.widthPixels) + "x" + Integer.toString(metrics.heightPixels); } else if ((context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE && !prefMain.getBoolean("landscape", false)) || (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT && prefMain.getBoolean("landscape", false))) { currentRes = Integer.toString(metrics.heightPixels) + "x" + Integer.toString(metrics.widthPixels); } } if (requestedRes.equals("reset")) requestedRes = nativeRes; return !requestedRes.equals(currentRes); }
From source file:net.peterkuterna.android.apps.devoxxsched.service.NewsSyncService.java
@Override protected void doSync(Intent intent) throws Exception { Log.d(TAG, "Start news sync"); final Context context = this; final SharedPreferences settings = Prefs.get(context); final int localVersion = settings.getInt(DevoxxPrefs.NEWS_LOCAL_VERSION, VERSION_NONE); final long startLocal = System.currentTimeMillis(); final boolean localParse = localVersion < VERSION_CURRENT; Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT); if (localParse) { mLocalExecutor.execute(context, "cache-news.json", new NewsHandler()); // Save local parsed version settings.edit().putInt(DevoxxPrefs.NEWS_LOCAL_VERSION, VERSION_CURRENT).commit(); final ContentValues values = new ContentValues(); values.put(News.NEWS_NEW, 0);/*from w ww. j a v a2 s .c om*/ getContentResolver().update(News.CONTENT_NEW_URI, values, null, null); } Log.d(TAG, "Local sync took " + (System.currentTimeMillis() - startLocal) + "ms"); final CfpSyncManager syncManager = new CfpSyncManager(context); if (syncManager.shouldPerformRemoteSync(Intent.ACTION_SYNC.equals(intent.getAction()))) { Log.d(TAG, "Should perform remote sync"); final long startRemote = System.currentTimeMillis(); mRemoteExecutor.executeGet(NEWS_URL, new NewsHandler()); Log.d(TAG, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms"); } else { Log.d(TAG, "Should not perform remote sync"); } final NotifierManager notifierManager = new NotifierManager(this); notifierManager.notifyNewNewsItems(); Log.d(TAG, "News sync finished"); }
From source file:foam.zizim.android.BoskoiService.java
public static void loadSettings(Context context) { final SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0); savePath = "/data/data/foam.zizim.android/files/";// settings.getString("savePath","/data/data/com.boskoi.android.app/files/"); // domain = settings.getString("Domain", ""); domain = "http://borrowed-scenery.org/zizim"; firstname = settings.getString("Firstname", ""); lastname = settings.getString("Lastname", ""); lastUpdate = settings.getString("LastUpdate", ""); lastId = settings.getLong("LastId", 0); email = settings.getString("Email", ""); countries = settings.getInt("Countries", 0); AutoUpdateDelay = settings.getInt("AutoUpdateDelay", 5); // AutoFetch = settings.getBoolean("AutoFetch", false); AutoFetch = true;//w w w . ja v a 2 s.c om totalReports = settings.getString("TotalReports", ""); smsUpdate = settings.getBoolean("SmsUpdate", false); username = settings.getString("Username", ""); password = settings.getString("Password", ""); language = settings.getString("Language", ""); lastVersion = settings.getString("LastVersion", ""); blogLastUpdate = settings.getLong("BlogLastUpdate", 0); // make sure folder exists final File dir = new File(BoskoiService.savePath); dir.mkdirs(); if (!dir.exists()) { // Log.i("SavePath ","does not exist"); try { dir.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:adapter.notification.MyFcmListenerService.java
@Override public void onMessageReceived(RemoteMessage message) { String from = message.getFrom(); RemoteMessage.Notification notification = message.getNotification(); String tag = notification.getTag(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = sp.edit(); int count = sp.getInt(tag, 0); editor.putInt(tag, count + 1);//from w w w . j a va 2s .c o m editor.apply(); sendNotification(notification); }
From source file:bander.notepad.Notepad.java
/** * Sets the color of the {@link android.support.v7.widget.Toolbar} * * @param activity Used similarly to {@link android.content.Context} *//*from ww w . j a v a 2 s . com*/ public static void setToolbarColor(final ActionBarActivity activity) { SharedPreferences mSettings = PreferenceManager.getDefaultSharedPreferences(activity); /** * The lighter toolbar color {@link com.devin.notepad.R.array.color500} */ TypedArray m500ta = activity.getResources().obtainTypedArray(R.array.color500); final int[] mToolbarColors = new int[m500ta.length()]; for (int i = 0; i < m500ta.length(); i++) { mToolbarColors[i] = m500ta.getColor(i, 0); } m500ta.recycle(); /** * The darker status bar color. {@link com.devin.notepad.R.array.color700} */ TypedArray m700ta = activity.getResources().obtainTypedArray(R.array.color700); int[] statusBarColors = new int[m700ta.length()]; for (int i = 0; i < m700ta.length(); i++) { statusBarColors[i] = m700ta.getColor(i, 0); } m700ta.recycle(); final int abc = mSettings.getInt("actionBarColor", 0); Toolbar mToolbar = (Toolbar) activity.findViewById(R.id.toolbar); if (mToolbar != null) mToolbar.setBackgroundColor(mToolbarColors[abc]); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { activity.getWindow().setStatusBarColor(statusBarColors[abc]); } }
From source file:com.data.CheckForDataUpdateTask.java
@Override protected Object doInBackground(Object[] params) { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams httpParams = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 5000); HttpConnectionParams.setSoTimeout(httpParams, 5000); BufferedReader in = null;/*from w w w .j ava2s. c om*/ String line = ""; try { HttpResponse response = httpClient.execute(new HttpGet(Constants.DATA_VERSION_URL)); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); line = in.readLine(); } catch (IOException e) { return false; } finally { if (in != null) { try { in.close(); } catch (IOException e) { return false; } } } int remoteVersion; if (line.matches("^DataVersion:\\d+$")) { remoteVersion = Integer.parseInt(line.split(":")[1].trim()); } else { return false; } SharedPreferences spData = ((Activity) params[0]).getApplicationContext().getSharedPreferences("Data", 0); int localVersion = spData.getInt("DataVersion", 0); spData.edit().putInt("DataVersionRemote", remoteVersion).apply(); if (remoteVersion > localVersion) { return true; } return false; }
From source file:com.playhaven.android.req.OpenRequest.java
@Override protected UriComponentsBuilder createUrl(android.content.Context context) throws PlayHavenException { UriComponentsBuilder builder = super.createUrl(context); builder.queryParam("tz", TimeZoneFormatter.getDefaultTimezone()); SharedPreferences pref = PlayHaven.getPreferences(context); int scount = pref.getInt(SCOUNT, 0); long ssum = pref.getLong(SSUM, 0); long stime = pref.getLong(STIME, 0); ssum += stime;/*w w w . j a v a 2 s . co m*/ builder.queryParam(SCOUNT, scount); builder.queryParam(SSUM, ssum); SharedPreferences.Editor edit = pref.edit(); // Increment count scount++; edit.putInt(SCOUNT, scount); // Clear current game time edit.putLong(STIME, 0); // Don't alter the previous sum until success // Save a start time Calendar rightNow = Calendar.getInstance(); Date date = rightNow.getTime(); edit.putLong(SSTART, date.getTime()); // Commit changes edit.commit(); return builder; }
From source file:github.daneren2005.dsub.util.Util.java
public static int getServerCount(Context context) { SharedPreferences prefs = getPreferences(context); return prefs.getInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1); }
From source file:github.daneren2005.dsub.util.Util.java
public static int offlineScrobblesCount(Context context) { SharedPreferences offline = getOfflineSync(context); return offline.getInt(Constants.OFFLINE_SCROBBLE_COUNT, 0); }
From source file:github.daneren2005.dsub.util.Util.java
public static int offlineStarsCount(Context context) { SharedPreferences offline = getOfflineSync(context); return offline.getInt(Constants.OFFLINE_STAR_COUNT, 0); }