List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:com.netease.qa.emmagee.service.EmmageeService.java
/** * read configuration file./*from www . j a va 2s. co m*/ * * @throws IOException */ private void readSettingInfo() { SharedPreferences preferences = Settings.getDefaultSharedPreferences(getApplicationContext()); int interval = preferences.getInt(Settings.KEY_INTERVAL, 3); delaytime = interval * 1000; isFloating = preferences.getBoolean(Settings.KEY_ISFLOAT, true); sender = preferences.getString(Settings.KEY_SENDER, BLANK_STRING); password = preferences.getString(Settings.KEY_PASSWORD, BLANK_STRING); recipients = preferences.getString(Settings.KEY_RECIPIENTS, BLANK_STRING); receivers = recipients.split("\\s+"); smtp = preferences.getString(Settings.KEY_SMTP, BLANK_STRING); isRoot = preferences.getBoolean(Settings.KEY_ROOT, false); isAutoStop = preferences.getBoolean(Settings.KEY_AUTO_STOP, true); }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void newInteractions(User interactor, Context context, SharedPreferences sharedPrefs, String type) {//from w ww . ja v a 2 s . c om String title = ""; String text = ""; String smallText = ""; Bitmap icon = null; AppSettings settings = AppSettings.getInstance(context); Intent resultIntent = new Intent(context, RedirectToDrawer.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); int newFollowers = sharedPrefs.getInt("new_followers", 0); int newRetweets = sharedPrefs.getInt("new_retweets", 0); int newFavorites = sharedPrefs.getInt("new_favorites", 0); int newQuotes = sharedPrefs.getInt("new_quotes", 0); // set title if (newFavorites + newRetweets + newFollowers > 1) { title = context.getResources().getString(R.string.new_interactions); } else { title = context.getResources().getString(R.string.new_interaction_upper); } // set text String currText = sharedPrefs.getString("old_interaction_text", ""); if (!currText.equals("")) { currText += "<br>"; } if (settings.displayScreenName) { text = currText + "<b>" + interactor.getScreenName() + "</b> " + type; } else { text = currText + "<b>" + interactor.getName() + "</b> " + type; } sharedPrefs.edit().putString("old_interaction_text", text).commit(); // set icon int types = 0; if (newFavorites > 0) { types++; } if (newFollowers > 0) { types++; } if (newRetweets > 0) { types++; } if (newQuotes > 0) { types++; } if (types > 1) { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_icon); } else { if (newFavorites > 0) { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_heart_dark); } else if (newRetweets > 0) { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_repeat_dark); } else { icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } } // set shorter text int total = newFavorites + newFollowers + newRetweets + newQuotes; if (total > 1) { smallText = total + " " + context.getResources().getString(R.string.new_interactions_lower); } else { smallText = text; } Intent markRead = new Intent(context, ReadInteractionsService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(Html.fromHtml( settings.addonTheme ? smallText.replaceAll("FF8800", settings.accentColor) : smallText)) .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(icon).setContentIntent(resultPendingIntent) .setTicker(title).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true); if (context.getResources().getBoolean(R.bool.expNotifications)) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText( Html.fromHtml(settings.addonTheme ? text.replaceAll("FF8800", settings.accentColor) : text))); } 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(4, 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, text); } // Light Flow notification sendToLightFlow(context, title, text); } }
From source file:com.laquysoft.droidconnl.Hunt.java
/** Loads player progress. */ public void restore(Resources res, Context context) { SharedPreferences sharedPref = context.getSharedPreferences(res.getString(R.string.preference_file_key), Context.MODE_PRIVATE); for (String tag : tags.keySet()) { Boolean val = sharedPref.getBoolean(tag, false); tagsFound.put(tag, val); }/*from w w w. j a v a2s .c o m*/ hasSeenIntro = sharedPref.getBoolean(HAS_SEEN_INTRO_KEY, false); questionState = sharedPref.getInt(QUESTION_STATE_KEY, QUESTION_STATE_NONE); finishTime = sharedPref.getLong(FINISH_TIME_KEY, 0); }
From source file:com.piusvelte.taplock.client.core.TapLockService.java
@Override public void onCreate() { super.onCreate(); int currVer = 0; try {/*w ww . j a v a2 s . c o m*/ currVer = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } SharedPreferences sp = (SharedPreferences) getSharedPreferences(KEY_PREFS, MODE_PRIVATE); if (!sp.contains(KEY_VERSION) || (currVer > sp.getInt(KEY_VERSION, 0))) { sp.edit().putInt(KEY_VERSION, currVer).commit(); (new BackupManager(this)).dataChanged(); } onSharedPreferenceChanged(getSharedPreferences(KEY_PREFS, MODE_PRIVATE), KEY_DEVICES); mBtAdapter = BluetoothAdapter.getDefaultAdapter(); }
From source file:com.aegamesi.steamtrade.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (!assertSteamConnection()) return;// www.ja v a 2 s .c o m setContentView(R.layout.activity_main); instance = this; // inform the user about SteamGuard restrictions if (SteamService.extras != null && SteamService.extras.getBoolean("alertSteamGuard", false)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (SteamService.extras != null) SteamService.extras.putBoolean("alertSteamGuard", false); } }); builder.setMessage(R.string.steamguard_new); builder.show(); } // get the standard steam handlers SteamService.singleton.messageHandler = this; steamTrade = SteamService.singleton.steamClient.getHandler(SteamTrading.class); steamUser = SteamService.singleton.steamClient.getHandler(SteamUser.class); steamFriends = SteamService.singleton.steamClient.getHandler(SteamFriends.class); steamGC = SteamService.singleton.steamClient.getHandler(SteamGameCoordinator.class); steamNotifications = SteamService.singleton.steamClient.getHandler(SteamNotifications.class); // set up the toolbar progressBar = (ProgressBar) findViewById(R.id.progress_bar); tabs = (TabLayout) findViewById(R.id.tabs); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); NavigationView navigationView = (NavigationView) findViewById(R.id.navigation); navigationView.setNavigationItemSelectedListener(this); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, 0); } }; // drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close); drawerLayout.setDrawerListener(drawerToggle); // set up View drawerHeaderView = navigationView.getHeaderView(0); drawerAvatar = (ImageView) drawerHeaderView.findViewById(R.id.drawer_avatar); drawerName = (TextView) drawerHeaderView.findViewById(R.id.drawer_name); drawerStatus = (TextView) drawerHeaderView.findViewById(R.id.drawer_status); drawerNotifyCard = (CardView) drawerHeaderView.findViewById(R.id.notify_card); drawerNotifyText = (TextView) drawerHeaderView.findViewById(R.id.notify_text); drawerHeaderView.findViewById(R.id.drawer_profile).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { browseToFragment(new FragmentMe(), true); } }); } // set up the nav drawer updateDrawerProfile(); if (savedInstanceState == null) { browseToFragment(new FragmentMe(), false); } SteamService.singleton.tradeManager.setupTradeStatus(); SteamService.singleton.tradeManager.updateTradeStatus(); if (getIntent().getBooleanExtra("isLoggingIn", false)) { tracker().send(new HitBuilders.EventBuilder().setCategory("Steam").setAction("Login").build()); } // handle our URL stuff if (getIntent() != null && ((getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_VIEW)) || getIntent().getStringExtra("url") != null)) { String url; url = getIntent().getStringExtra("url"); if (url == null) { url = getIntent().getData().toString(); } /* else { url = url.substring(url.indexOf("steamcommunity.com") + ("steamcommunity.com".length())); }*/ Log.d("Ice", "Received url: " + url); if (url.contains("steamcommunity.com/linkfilter/?url=")) { // don't filter these... String new_url = url.substring(url.indexOf("/linkfilter/?url=") + "/linkfilter/?url=".length()); Log.d("Ice", "Passing through linkfilter url: '" + new_url + "'"); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(new_url)); startActivity(browserIntent); } else if (url.contains("steamcommunity.com/tradeoffer/new")) { Fragment fragment = new FragmentOffersList(); Bundle bundle = new Bundle(); bundle.putString("new_offer_url", url); fragment.setArguments(bundle); browseToFragment(fragment, true); } else if (url.contains("steamcommunity.com/id/") || url.contains("steamcommunity.com/profiles/")) { Fragment fragment = new FragmentProfile(); Bundle bundle = new Bundle(); bundle.putString("url", url); fragment.setArguments(bundle); browseToFragment(fragment, true); } else { // default to steam browser FragmentWeb.openPage(this, url, false); } } // set up billing processor billingProcessor = new BillingProcessor(this, getString(R.string.iab_license_key), this); billingProcessor.loadOwnedPurchasesFromGoogle(); // "rate this app!" final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final int num_launches = prefs.getInt("num_launches", 0) + 1; prefs.edit().putInt("num_launches", num_launches).apply(); boolean rated = prefs.getBoolean("rated", false); if (num_launches > 0 && (num_launches % 10 == 0) && !rated && num_launches <= (10 * 5)) { // show the snackbar Snackbar.make(findViewById(android.R.id.content), R.string.rate_snackbar_text, Snackbar.LENGTH_LONG) .setAction(R.string.rate_snackbar_action, new View.OnClickListener() { @Override public void onClick(View v) { prefs.edit().putBoolean("rated", true).apply(); Uri marketUri = Uri.parse("market://details?id=" + getPackageName()); startActivity(new Intent(Intent.ACTION_VIEW).setData(marketUri)); } }).show(); } // setup amazon ads //AdRegistration.enableLogging(debug_amazon_ads); //AdRegistration.enableTesting(debug_amazon_ads); }
From source file:net.nightwhistler.pageturner.Configuration.java
public int getLastPosition(String fileName) { SharedPreferences bookPrefs = getPrefsForBook(fileName); int pos = bookPrefs.getInt(KEY_POS, -1); if (pos != -1) { return pos; }/*from ww w. j av a2 s . co m*/ //Fall-back to older settings String bookHash = Integer.toHexString(fileName.hashCode()); pos = settings.getInt(KEY_POS + bookHash, -1); if (pos != -1) { return pos; } // Fall-back for even older settings. return settings.getInt(KEY_POS + fileName, -1); }
From source file:net.nightwhistler.pageturner.Configuration.java
public int getLastIndex(String fileName) { SharedPreferences bookPrefs = getPrefsForBook(fileName); int pos = bookPrefs.getInt(KEY_IDX, -1); if (pos != -1) { return pos; }/* www . j av a2 s.c om*/ //Fall-backs to older setting in central file String bookHash = Integer.toHexString(fileName.hashCode()); pos = settings.getInt(KEY_IDX + bookHash, -1); if (pos != -1) { return pos; } // Fall-back for even older settings. return settings.getInt(KEY_IDX + fileName, -1); }
From source file:com.alboteanu.android.sunshine.app.MainActivity.java
/** * Gets the current registration ID for application on GCM service. * <p>/*from ww w . ja v a2s .com*/ * If result is empty, the app needs to register. * * @return registration ID, or empty string if there is no existing * registration ID. */ private String getRegistrationId(Context context) { final SharedPreferences prefs = getGCMPreferences(context); String registrationId = prefs.getString(PROPERTY_REG_ID, ""); if (registrationId.isEmpty()) { Log.i(LOG_TAG, "GCM Registration not found."); return ""; } // Check if app was updated; if so, it must clear the registration ID // since the existing registration ID is not guaranteed to work with // the new app version. int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE); int currentVersion = getAppVersion(context); if (registeredVersion != currentVersion) { Log.i(LOG_TAG, "App version changed."); return ""; } return registrationId; }
From source file:ac.robinson.mediaphone.activity.NarrativeBrowserActivity.java
@Override protected void onResume() { super.onResume(); // reload previous scroll position SharedPreferences rotationSettings = getSharedPreferences(MediaPhone.APPLICATION_NAME, Context.MODE_PRIVATE); mNarratives.setSelectionFromTop(rotationSettings.getInt(getString(R.string.key_narrative_list_top), 0), rotationSettings.getInt(getString(R.string.key_narrative_list_position), 0)); // scroll to the last edited frame (but make sure we can't do it again to stop annoyance) String frameId = loadLastEditedFrame(); if (mCurrentSelectedNarrativeId != null && frameId != null) { postDelayedScrollToSelectedFrame(mCurrentSelectedNarrativeId, frameId); // delayed so list has time to load }//from w w w . ja va 2s . c o m mCurrentSelectedNarrativeId = null; postDelayedUpdateNarrativeIcons(); // in case any icons were in the process of loading when we rotated }
From source file:com.aujur.ebookreader.Configuration.java
public int getLastPosition(String fileName) { SharedPreferences bookPrefs = getPrefsForBook(fileName); int pos = bookPrefs.getInt(KEY_POS, -1); if (pos != -1) { return pos; }/* w ww . jav a 2 s. com*/ // Fall-back to older settings String bookHash = Integer.toHexString(fileName.hashCode()); pos = settings.getInt(KEY_POS + bookHash, -1); if (pos != -1) { return pos; } // Fall-back for even older settings. return settings.getInt(KEY_POS + fileName, -1); }