List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:com.facebook.share.internal.LikeActionController.java
private synchronized static void performFirstInitialize() { if (isInitialized) { return;/*w ww .j a v a 2 s .c o m*/ } handler = new Handler(Looper.getMainLooper()); Context appContext = FacebookSdk.getApplicationContext(); SharedPreferences sharedPreferences = appContext.getSharedPreferences(LIKE_ACTION_CONTROLLER_STORE, Context.MODE_PRIVATE); objectSuffix = sharedPreferences.getInt(LIKE_ACTION_CONTROLLER_STORE_OBJECT_SUFFIX_KEY, 1); controllerDiskCache = new FileLruCache(TAG, new FileLruCache.Limits()); registerAccessTokenTracker(); CallbackManagerImpl.registerStaticCallback(CallbackManagerImpl.RequestCodeOffset.Like.toRequestCode(), new CallbackManagerImpl.Callback() { @Override public boolean onActivityResult(int resultCode, Intent data) { return handleOnActivityResult(CallbackManagerImpl.RequestCodeOffset.Like.toRequestCode(), resultCode, data); } }); isInitialized = true; }
From source file:com.amagi82.kerbalspaceapp.MissionPlanner.java
@Override public void onResume() { super.onResume(); // This is in onResume so it refreshes deltaV when the user returns from adjusting settings SharedPreferences prefs = getSharedPreferences("settings", MODE_PRIVATE); int mClearanceValue = prefs.getInt("mClearanceValue", 1000); int mMarginsValues = prefs.getInt("mMarginsValue", 10); int mInclinationValues = prefs.getInt("mInclinationValue", 30); float mMarginsValue = (float) mMarginsValues / 100 + 1; float mInclinationValue = (float) mInclinationValues / 100; // Update OrbitalMechanics with the new values OrbitalMechanics.mClearanceValue = mClearanceValue; OrbitalMechanics.mMarginsValue = mMarginsValue; OrbitalMechanics.mInclinationValue = mInclinationValue; refreshDeltaV();//from w ww . j a va2 s . c o m }
From source file:com.gsoc.ijosa.liquidgalaxycontroller.PW.UrlDeviceDiscoveryService.java
private void restoreCache() { // Make sure we are trying to load the right version of the cache String preferencesKey = getString(R.string.discovery_service_prefs_key); SharedPreferences prefs = getSharedPreferences(preferencesKey, Context.MODE_PRIVATE); int prefsVersion = prefs.getInt(PREFS_VERSION_KEY, 0); long now = new Date().getTime(); if (prefsVersion != PREFS_VERSION) { mScanStartTime = now;// w ww .j a va 2 s. c o m return; } // Don't load the cache if it's stale mScanStartTime = prefs.getLong(SCAN_START_TIME_KEY, 0); if (now - mScanStartTime >= SCAN_STALE_TIME_MILLIS) { mScanStartTime = now; return; } // Restore the cached metadata try { JSONObject serializedCollection = new JSONObject(prefs.getString(PW_COLLECTION_KEY, null)); mPwCollection = PhysicalWebCollection.jsonDeserialize(serializedCollection); } catch (JSONException e) { Log.e(TAG, "Could not restore collection cache", e); } catch (PhysicalWebCollectionException e) { Log.e(TAG, "Could not restore collection cache", e); } }
From source file:com.example.android.wearable.mjpegviewwear.MainActivity.java
@Override public void onCreate(Bundle b) { super.onCreate(b); LOGD(TAG, "onCreate"); setContentView(R.layout.main_activity); mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.running)) .setOngoing(true);/* w w w.j a v a 2 s. c o m*/ Intent resultIntent = new Intent(this, MainActivity.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); // for MJPEG View SharedPreferences preferences = getSharedPreferences("SAVED_VALUES", MODE_PRIVATE); mWidth = preferences.getInt("width", mWidth); mHeight = preferences.getInt("height", mHeight); mIp_ad1 = preferences.getInt("ip_ad1", mIp_ad1); mIp_ad2 = preferences.getInt("ip_ad2", mIp_ad2); mIp_ad3 = preferences.getInt("ip_ad3", mIp_ad3); mIp_ad4 = preferences.getInt("ip_ad4", mIp_ad4); mIp_port = preferences.getInt("ip_port", mIp_port); mIp_command = preferences.getString("ip_command", mIp_command); mFrameSkip = preferences.getInt("frameSkip", mFrameSkip); StringBuilder sb = new StringBuilder(); String s_http = "http://"; String s_dot = "."; String s_colon = ":"; String s_slash = "/"; sb.append(s_http); sb.append(mIp_ad1); sb.append(s_dot); sb.append(mIp_ad2); sb.append(s_dot); sb.append(mIp_ad3); sb.append(s_dot); sb.append(mIp_ad4); sb.append(s_colon); sb.append(mIp_port); sb.append(s_slash); sb.append(mIp_command); mURL = new String(sb); mMv = (MjpegView) findViewById(R.id.mv); if (mMv != null) { mMv.setResolution(mWidth, mHeight); mMv.setFrameSkip(mFrameSkip); } setTitle(R.string.title_connecting); new DoRead().execute(mURL); }
From source file:com.playhaven.android.req.PlayHavenRequest.java
protected Integer getInt(SharedPreferences pref, PlayHaven.Config param, int defaultValue) { return pref.getInt(param.toString(), defaultValue); }
From source file:com.cyanogenmod.effem.FmRadio.java
/** * Required method from parent class/*from w w w . ja va2 s .co m*/ * * @param icicle - The previous instance of this app */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); context = getApplicationContext(); setContentView(R.layout.main); // restore preferences SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); mSelectedBand = settings.getInt("selectedBand", 1); mCurrentFrequency = settings.getInt("currentFrequency", 0); if (context.getResources().getBoolean(R.bool.speaker_supported)) { mSelectedOutput = settings.getInt("selectedOutput", 0) > 0 ? 1 : 0; } // misc setup setVolumeControlStream(AudioManager.STREAM_MUSIC); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // worker thread for async execution of FM stuff mWorker = new HandlerThread("EffemWorker"); mWorker.start(); mWorkerHandler = new Handler(mWorker.getLooper()); // ui preparations setupButtons(); }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void notifySecondDMs(Context context, int secondAccount) { DMDataSource data = DMDataSource.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int numberNew = sharedPrefs.getInt("dm_unread_" + secondAccount, 0); int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon;/*from w w w . j a v a 2 s . co m*/ Intent resultIntent = new Intent(context, SwitchAccountsRedirect.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc); String name; String message; String messageLong; NotificationCompat.InboxStyle inbox = null; if (numberNew == 1) { name = data.getNewestName(secondAccount); // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return; } message = context.getResources().getString(R.string.mentioned_by) + " @" + name; messageLong = "<b>@" + name + "</b>: " + data.getNewestMessage(secondAccount); largeIcon = getImage(context, name); } else { // more than one dm message = numberNew + " " + context.getResources().getString(R.string.new_mentions); messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions); largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); inbox = getDMInboxStyle(numberNew, secondAccount, context, message); } Intent markRead = new Intent(context, MarkReadSecondAccService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); AppSettings settings = AppSettings.getInstance(context); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setAutoCancel(true) .setPriority(NotificationCompat.PRIORITY_HIGH); if (inbox == null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong))); } else { mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(9, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, messageLong); } // Light Flow notification sendToLightFlow(context, title, messageLong); } }
From source file:org.opensmc.mytracks.cyclesmc.TripUploader.java
private JSONObject getUserJSON() throws JSONException { JSONObject user = new JSONObject(); Map<String, Integer> fieldMap = new HashMap<String, Integer>(); fieldMap.put(USER_EMAIL, Integer.valueOf(UserInfoActivity.PREF_EMAIL)); fieldMap.put(USER_ZIP_HOME, Integer.valueOf(UserInfoActivity.PREF_ZIPHOME)); fieldMap.put(USER_ZIP_WORK, Integer.valueOf(UserInfoActivity.PREF_ZIPWORK)); fieldMap.put(USER_ZIP_SCHOOL, Integer.valueOf(UserInfoActivity.PREF_ZIPSCHOOL)); SharedPreferences settings = this.mCtx.getSharedPreferences("PREFS", 0); for (Entry<String, Integer> entry : fieldMap.entrySet()) { user.put(entry.getKey(), settings.getString(entry.getValue().toString(), null)); }/* www .java2 s. c om*/ user.put(USER_AGE, settings.getInt("" + UserInfoActivity.PREF_AGE, 0)); user.put(USER_GENDER, settings.getInt("" + UserInfoActivity.PREF_GENDER, 0)); // TODO: setting cycling frequency properly? int freq = settings.getInt("" + UserInfoActivity.PREF_CYCLEFREQ, 0); if (freq > 0) freq /= 100; user.put(USER_CYCLING_FREQUENCY, freq); user.put(USER_ETHNICITY, settings.getInt("" + UserInfoActivity.PREF_ETHNICITY, 0)); user.put(USER_INCOME, settings.getInt("" + UserInfoActivity.PREF_INCOME, 0)); user.put(USER_RIDERTYPE, settings.getInt("" + UserInfoActivity.PREF_RIDERTYPE, 0)); user.put(USER_RIDERHISTORY, settings.getInt("" + UserInfoActivity.PREF_RIDERHISTORY, 0)); return user; }
From source file:com.andernity.launcher2.InstallShortcutReceiver.java
private static boolean installShortcut(Context context, Intent data, ArrayList<ItemInfo> items, String name, final Intent intent, final int screen, boolean shortcutExists, final SharedPreferences sharedPrefs, int[] result) { int[] tmpCoordinates = new int[2]; if (findEmptyCell(context, items, tmpCoordinates, screen)) { if (intent != null) { if (intent.getAction() == null) { intent.setAction(Intent.ACTION_VIEW); } else if (intent.getAction().equals(Intent.ACTION_MAIN) && intent.getCategories() != null && intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); }//from w w w . ja va2 s. co m // By default, we allow for duplicate entries (located in // different places) boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true); if (duplicate || !shortcutExists) { new Thread("setNewAppsThread") { public void run() { synchronized (sLock) { // If the new app is going to fall into the same page as before, // then just continue adding to the current page final int newAppsScreen = sharedPrefs.getInt(NEW_APPS_PAGE_KEY, screen); SharedPreferences.Editor editor = sharedPrefs.edit(); if (newAppsScreen == -1 || newAppsScreen == screen) { addToStringSet(sharedPrefs, editor, NEW_APPS_LIST_KEY, intent.toUri(0)); } editor.putInt(NEW_APPS_PAGE_KEY, screen); editor.commit(); } } }.start(); // Update the Launcher db LauncherApplication app = (LauncherApplication) context.getApplicationContext(); ShortcutInfo info = app.getModel().addShortcut(context, data, LauncherSettings.Favorites.CONTAINER_DESKTOP, screen, tmpCoordinates[0], tmpCoordinates[1], true); if (info == null) { return false; } } else { result[0] = INSTALL_SHORTCUT_IS_DUPLICATE; } return true; } } else { result[0] = INSTALL_SHORTCUT_NO_SPACE; } return false; }
From source file:com.ichi2.anki.dialogs.CustomStudyDialog.java
private String getDefaultValue() { SharedPreferences prefs = AnkiDroidApp.getSharedPrefs(getActivity()); switch (getArguments().getInt("id")) { case CUSTOM_STUDY_NEW: return Integer.toString(prefs.getInt("extendNew", 10)); case CUSTOM_STUDY_REV: return Integer.toString(prefs.getInt("extendRev", 50)); case CUSTOM_STUDY_FORGOT: return Integer.toString(prefs.getInt("forgottenDays", 1)); case CUSTOM_STUDY_AHEAD: return Integer.toString(prefs.getInt("aheadDays", 1)); case CUSTOM_STUDY_RANDOM: return Integer.toString(prefs.getInt("randomCards", 100)); case CUSTOM_STUDY_PREVIEW: return Integer.toString(prefs.getInt("previewDays", 1)); default://from w ww . j a v a 2 s. co m return ""; } }