List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPush.java
/** * Based on the PREFS_NOTIFICATION_COUNT value, fetch all the stored notifications in the same order from * the shared preferences and save it onto the list. * This method will ensure that the notifications are sent to the Application in the same order in which they arrived. */// w w w. j a va 2 s.c o m public boolean getMessagesFromSharedPreferences(int notificationId) { boolean gotMessages = false; SharedPreferences sharedPreferences = appContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); int countOfStoredMessages = sharedPreferences.getInt(MFPPush.PREFS_NOTIFICATION_COUNT, 0); if (countOfStoredMessages > 0) { String key = null; try { Map<String, ?> allEntriesFromSharedPreferences = sharedPreferences.getAll(); Map<String, String> notificationEntries = new HashMap<String, String>(); for (Map.Entry<String, ?> entry : allEntriesFromSharedPreferences.entrySet()) { String rKey = entry.getKey(); if (entry.getKey().startsWith(PREFS_NOTIFICATION_MSG)) { notificationEntries.put(rKey, entry.getValue().toString()); } } for (Map.Entry<String, String> entry : notificationEntries.entrySet()) { String nKey = entry.getKey(); key = nKey; String msg = sharedPreferences.getString(nKey, null); if (msg != null) { gotMessages = true; logger.debug( "MFPPush:getMessagesFromSharedPreferences() - Messages retrieved from shared preferences."); MFPInternalPushMessage pushMessage = new MFPInternalPushMessage(new JSONObject(msg)); if (notificationId != 0) { if (notificationId == pushMessage.getNotificationId()) { isFromNotificationBar = true; messageFromBar = pushMessage; MFPPushUtils.removeContentFromSharedPreferences(sharedPreferences, nKey); MFPPushUtils.storeContentInSharedPreferences(sharedPreferences, MFPPush.PREFS_NOTIFICATION_COUNT, countOfStoredMessages - 1); break; } } else { synchronized (pending) { pending.add(pushMessage); } MFPPushUtils.removeContentFromSharedPreferences(sharedPreferences, nKey); } } } } catch (JSONException e) { MFPPushUtils.removeContentFromSharedPreferences(sharedPreferences, key); } if (notificationId == 0) { MFPPushUtils.storeContentInSharedPreferences(sharedPreferences, MFPPush.PREFS_NOTIFICATION_COUNT, 0); } } return gotMessages; }
From source file:com.ichi2.anki2.CardBrowser.java
@Override protected void onCreate(Bundle savedInstanceState) { Themes.applyTheme(this); super.onCreate(savedInstanceState); View mainView = getLayoutInflater().inflate(R.layout.card_browser, null); setContentView(mainView);/*from ww w . j ava 2s. c om*/ Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER); mCol = AnkiDroidApp.getCol(); if (mCol == null) { reloadCollection(savedInstanceState); return; } mDeckNames = new HashMap<String, String>(); for (long did : mCol.getDecks().allIds()) { mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did)); } registerExternalStorageListener(); Intent i = getIntent(); mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false); mBackground = Themes.getCardBrowserBackground(); SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO); String sflCustomFont = preferences.getString("browserEditorFont", ""); mPrefFixArabic = preferences.getBoolean("fixArabicText", false); Resources res = getResources(); mOrderByFields = res.getStringArray(R.array.card_browser_order_labels); try { mOrder = CARD_ORDER_NONE; String colOrder = mCol.getConf().getString("sortType"); for (int c = 0; c < fSortTypes.length; ++c) { if (fSortTypes[c].equals(colOrder)) { mOrder = c; break; } } if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) { mOrder = 0; } mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false); // default to descending for non-text fields if (fSortTypes[mOrder].equals("noteFld")) { mOrderAsc = !mOrderAsc; } } catch (JSONException e) { throw new RuntimeException(e); } mCards = new ArrayList<HashMap<String, String>>(); mCardsListView = (ListView) findViewById(R.id.card_browser_list); mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item, new String[] { "sfld", "deck", "flags" }, new int[] { R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont); mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object arg1, String text) { if (view.getId() == R.id.card_item) { int which = BACKGROUND_NORMAL; if (text.equals("1")) { which = BACKGROUND_SUSPENDED; } else if (text.equals("2")) { which = BACKGROUND_MARKED; } else if (text.equals("3")) { which = BACKGROUND_MARKED_SUSPENDED; } view.setBackgroundResource(mBackground[which]); return true; } else if (view.getId() == R.id.card_deck && text.length() > 0) { view.setVisibility(View.VISIBLE); } return false; } }); mCardsListView.setAdapter(mCardsAdapter); mCardsListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent editCard = new Intent(CardBrowser.this, CardEditor.class); editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT); mPositionInCardsList = position; long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id")); sCardBrowserCard = mCol.getCard(cardId); startActivityForResult(editCard, EDIT_CARD); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT); } } }); registerForContextMenu(mCardsListView); mSearchEditText = (EditText) findViewById(R.id.card_browser_search); mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { onSearch(); return true; } return false; } }); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button); mSearchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onSearch(); } }); mSearchTerms = ""; if (mWholeCollection) { mRestrictOnDeck = ""; setTitle(res.getString(R.string.card_browser_all_decks)); } else { try { String deckName = mCol.getDecks().current().getString("name"); mRestrictOnDeck = "deck:'" + deckName + "' "; setTitle(deckName); } catch (JSONException e) { throw new RuntimeException(e); } } mSelectedTags = new HashSet<String>(); if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) { searchCards(); } }
From source file:ar.com.martinrevert.argenteam.GcmIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//* www . ja v a2 s.com*/ private void generarNotification(Context context, String message, String urlimagen, String urlarticulo, String tipo, String fecha) { SharedPreferences preferencias = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); boolean vib = preferencias.getBoolean("vibraoff", false); boolean movieoff = preferencias.getBoolean("movieoff", false); boolean tvoff = preferencias.getBoolean("tvoff", false); String ringmovie = preferencias.getString("prefRingtonemovie", ""); String ringtv = preferencias.getString("prefRingtonetv", ""); //Todo traducir ticker String ticker = "Nuevo subttulo " + tipo + " en aRGENTeaM"; Random randomGenerator = new Random(); int randomInt = randomGenerator.nextInt(100); Bitmap bitmap = getRemoteImage(urlimagen, tipo); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); int dash = 500; int short_gap = 200; long[] pattern = { 0, // Start immediately dash, short_gap, dash, short_gap, dash }; Intent notificationIntent; String ringtone; int ledlight; if (tipo.equalsIgnoreCase("Movie")) { ringtone = ringmovie; notificationIntent = new Intent(context, Peli.class); ledlight = preferencias.getInt("ledMovie", 0); } else { notificationIntent = new Intent(context, Tv.class); ringtone = ringtv; ledlight = preferencias.getInt("ledTV", 0); System.out.println(ledlight); } notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("passed", urlarticulo); PendingIntent pendingIntent; pendingIntent = PendingIntent.getActivity(context, randomInt, notificationIntent, 0); Notification myNotification; myNotification = new NotificationCompat.Builder(context).setPriority(1).setContentTitle(message) .setTicker(ticker).setLights(ledlight, 300, 300).setWhen(System.currentTimeMillis()) .setContentIntent(pendingIntent).setSound(Uri.parse(ringtone)).setAutoCancel(true) .setSmallIcon(R.drawable.ic_stat_ic_argenteam_gcm).build(); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { RemoteViews views; views = new RemoteViews(getPackageName(), R.layout.custom_notification); views.setImageViewBitmap(R.id.big_picture, bitmap); views.setImageViewBitmap(R.id.big_icon, BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_ic_argenteam_gcm)); views.setTextViewText(R.id.title, message); myNotification.bigContentView = views; } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (movieoff && tipo.equalsIgnoreCase("Movie")) { if (vib) { v.vibrate(pattern, -1); } notificationManager.notify(randomInt, myNotification); } if (tvoff && tipo.equalsIgnoreCase("Serie TV")) { if (vib) { v.vibrate(pattern, -1); } notificationManager.notify(randomInt, myNotification); } }
From source file:com.mobiperf.MeasurementScheduler.java
/** * Restore measurement statistics from persistent storage. *///w ww . j a v a 2 s. co m private void restoreStats() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); completedMeasurementCnt = prefs.getInt(Config.PREF_KEY_COMPLETED_MEASUREMENTS, 0); failedMeasurementCnt = prefs.getInt(Config.PREF_KEY_FAILED_MEASUREMENTS, 0); }
From source file:com.hichinaschool.flashcards.anki.CardBrowser.java
@Override protected void onCreate(Bundle savedInstanceState) { Themes.applyTheme(this); super.onCreate(savedInstanceState); View mainView = getLayoutInflater().inflate(R.layout.card_browser, null); setContentView(mainView);//from w ww .j a va 2 s. c o m Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER); mCol = AnkiDroidApp.getCol(); if (mCol == null) { reloadCollection(savedInstanceState); return; } mDeckNames = new HashMap<String, String>(); for (long did : mCol.getDecks().allIds()) { mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did)); } registerExternalStorageListener(); Intent i = getIntent(); mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false); mBackground = Themes.getCardBrowserBackground(); SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO); String sflCustomFont = preferences.getString("browserEditorFont", ""); mPrefFixArabic = preferences.getBoolean("fixArabicText", false); Resources res = getResources(); mOrderByFields = res.getStringArray(R.array.card_browser_order_labels); try { mOrder = CARD_ORDER_NONE; String colOrder = mCol.getConf().getString("sortType"); for (int c = 0; c < fSortTypes.length; ++c) { if (fSortTypes[c].equals(colOrder)) { mOrder = c; break; } } if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) { mOrder = 0; } mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false); // default to descending for non-text fields if (fSortTypes[mOrder].equals("noteFld")) { mOrderAsc = !mOrderAsc; } } catch (JSONException e) { throw new RuntimeException(e); } mCards = new ArrayList<HashMap<String, String>>(); mCardsListView = (ListView) findViewById(R.id.card_browser_list); mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item, new String[] { "sfld", "deck", "flags" }, new int[] { R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont); mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object arg1, String text) { if (view.getId() == R.id.card_item) { int which = BACKGROUND_NORMAL; if (text.equals("1")) { which = BACKGROUND_SUSPENDED; } else if (text.equals("2")) { which = BACKGROUND_MARKED; } else if (text.equals("3")) { which = BACKGROUND_MARKED_SUSPENDED; } view.setBackgroundResource(mBackground[which]); return true; } else if (view.getId() == R.id.card_deck && text.length() > 0) { view.setVisibility(View.VISIBLE); } return false; } }); mCardsListView.setAdapter(mCardsAdapter); mCardsListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mPositionInCardsList = position; long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id")); sCardBrowserCard = mCol.getCard(cardId); Intent editCard = new Intent(CardBrowser.this, CardEditor.class); editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT); editCard.putExtra(CardEditor.EXTRA_CARD_ID, sCardBrowserCard.getId()); startActivityForResult(editCard, EDIT_CARD); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT); } } }); registerForContextMenu(mCardsListView); mSearchEditText = (EditText) findViewById(R.id.card_browser_search); mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { onSearch(); return true; } return false; } }); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button); mSearchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onSearch(); } }); mSearchTerms = ""; if (mWholeCollection) { mRestrictOnDeck = ""; setTitle(res.getString(R.string.card_browser_all_decks)); } else { try { String deckName = mCol.getDecks().current().getString("name"); mRestrictOnDeck = "deck:'" + deckName + "' "; setTitle(deckName); } catch (JSONException e) { throw new RuntimeException(e); } } mSelectedTags = new HashSet<String>(); if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) { searchCards(); } }
From source file:com.softanalle.scma.MainActivity.java
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { logger.debug("onSharedPreferenceChanged(): " + key); //Preference keyPref = findPreference(key); if (key.equalsIgnoreCase(KEY_PREF_FOCUSCOLOR)) { mFocusLedIndex = sharedPreferences.getInt(KEY_PREF_FOCUSCOLOR, 3); }/* w ww . j a v a 2s .co m*/ if (key.equalsIgnoreCase(KEY_PREF_RED_PULSEWIDTH)) { mPulseWidth[LED_INDEX_RED] = sharedPreferences.getInt(KEY_PREF_RED_PULSEWIDTH, mDefaultPulseWidth[LED_INDEX_RED]); } if (key.equalsIgnoreCase(KEY_PREF_BLUE_PULSEWIDTH)) { mPulseWidth[LED_INDEX_BLUE] = sharedPreferences.getInt(KEY_PREF_BLUE_PULSEWIDTH, mDefaultPulseWidth[LED_INDEX_BLUE]); } if (key.equalsIgnoreCase(KEY_PREF_GREEN_PULSEWIDTH)) { mPulseWidth[LED_INDEX_GREEN] = sharedPreferences.getInt(KEY_PREF_GREEN_PULSEWIDTH, mDefaultPulseWidth[LED_INDEX_GREEN]); } if (key.equalsIgnoreCase(KEY_PREF_GREEN_PULSEWIDTH)) { mPulseWidth[LED_INDEX_YELLOW] = sharedPreferences.getInt(KEY_PREF_YELLOW_PULSEWIDTH, mDefaultPulseWidth[LED_INDEX_YELLOW]); } if (key.equalsIgnoreCase(KEY_PREF_WHITE_PULSEWIDTH)) { mPulseWidth[LED_INDEX_WHITE] = sharedPreferences.getInt(KEY_PREF_WHITE_PULSEWIDTH, mDefaultPulseWidth[LED_INDEX_WHITE]); } if (key.equalsIgnoreCase(KEY_PREF_NIR_PULSEWIDTH)) { mPulseWidth[LED_INDEX_NIR] = sharedPreferences.getInt(KEY_PREF_NIR_PULSEWIDTH, mDefaultPulseWidth[LED_INDEX_NIR]); } if (key.equalsIgnoreCase(KEY_PREF_LOGLEVEL)) { String level = sharedPreferences.getString(KEY_PREF_LOGLEVEL, "DEBUG"); logger.setLevel(parseLogLevel(level)); } //if (key.equalsIgnoreCase(KEY_PREF_SAVE_JPEG)) { //saveModeJPEG = sharedPreferences.getBoolean(KEY_PREF_SAVE_JPEG, true); //} if (key.equalsIgnoreCase(KEY_PREF_SAVE_RAW)) { saveModeRAW = sharedPreferences.getBoolean(KEY_PREF_SAVE_RAW, false); } }
From source file:at.the.gogo.windig.activities.WindigActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final int applicationFlags = getApplicationInfo().flags; if ((applicationFlags & ApplicationInfo.FLAG_DEBUGGABLE) == 0) { CrashReportHandler.attach(this); }//from ww w . j a v a 2 s . co m // now switch debug mode off if Util.DEBUGMODE = ((applicationFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); wantToUseTTS = sharedPreferences.getBoolean("pref_tts_speech", true); if (savedInstanceState != null) { if (savedInstanceState.containsKey(WindigActivity.POSKEY)) { currentPage = savedInstanceState.getInt(WindigActivity.POSKEY); } } setContentView(R.layout.windigmain); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); setTitle(R.string.wetterwertetitel); getSupportActionBar().setDisplayUseLogoEnabled(false); mPagerAdapter = new MyPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.viewflipper); mViewPager.setAdapter(mPagerAdapter); mIndicator = (LinePageIndicator) findViewById(R.id.indicator); mIndicator.setViewPager(mViewPager); // mIndicator.setFooterIndicatorStyle(IndicatorStyle.Underline); int lastpageViewed = sharedPreferences.getInt("PageInFlipper", 0); if (savedInstanceState != null) { lastpageViewed = savedInstanceState.getInt("index", lastpageViewed); } mViewPager.setCurrentItem(lastpageViewed); // Set the indicator as the pageChangeListener mViewPager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) { mIndicator.onPageScrolled(position, positionOffset, positionOffsetPixels); } @Override public void onPageSelected(final int position) { mIndicator.onPageSelected(position); } @Override public void onPageScrollStateChanged(final int state) { mIndicator.onPageScrollStateChanged(state); } }); restoreUIState(); checkTTS(); }
From source file:github.daneren2005.dsub.service.RESTMusicService.java
public int processOfflineScrobbles(final Context context, final ProgressListener progressListener) throws Exception { SharedPreferences offline = Util.getOfflineSync(context); SharedPreferences.Editor offlineEditor = offline.edit(); int count = offline.getInt(Constants.OFFLINE_SCROBBLE_COUNT, 0); int retry = 0; for (int i = 1; i <= count; i++) { String id = offline.getString(Constants.OFFLINE_SCROBBLE_ID + i, null); long time = offline.getLong(Constants.OFFLINE_SCROBBLE_TIME + i, 0); if (id != null) { scrobble(id, true, time, context, progressListener); } else {//from ww w .j a va 2 s. co m String search = offline.getString(Constants.OFFLINE_SCROBBLE_SEARCH + i, ""); try { SearchCritera critera = new SearchCritera(search, 0, 0, 1); SearchResult result = searchNew(critera, context, progressListener); if (result.getSongs().size() == 1) { Log.i(TAG, "Query '" + search + "' returned song " + result.getSongs().get(0).getTitle() + " by " + result.getSongs().get(0).getArtist() + " with id " + result.getSongs().get(0).getId()); Log.i(TAG, "Scrobbling " + result.getSongs().get(0).getId() + " with time " + time); scrobble(result.getSongs().get(0).getId(), true, time, context, progressListener); } else { throw new Exception("Song not found on server"); } } catch (Exception e) { Log.e(TAG, e.toString()); retry++; } } } offlineEditor.putInt(Constants.OFFLINE_SCROBBLE_COUNT, 0); offlineEditor.commit(); return count - retry; }
From source file:github.daneren2005.dsub.service.RESTMusicService.java
public int processOfflineStars(final Context context, final ProgressListener progressListener) throws Exception { SharedPreferences offline = Util.getOfflineSync(context); SharedPreferences.Editor offlineEditor = offline.edit(); int count = offline.getInt(Constants.OFFLINE_STAR_COUNT, 0); int retry = 0; for (int i = 1; i <= count; i++) { String id = offline.getString(Constants.OFFLINE_STAR_ID + i, null); boolean starred = offline.getBoolean(Constants.OFFLINE_STAR_SETTING + i, false); if (id != null) { setStarred(id, starred, context, progressListener); } else {/*from w w w . j a v a2 s. com*/ String search = offline.getString(Constants.OFFLINE_STAR_SEARCH + i, ""); try { SearchCritera critera = new SearchCritera(search, 0, 1, 1); SearchResult result = searchNew(critera, context, progressListener); if (result.getSongs().size() == 1) { Log.i(TAG, "Query '" + search + "' returned song " + result.getSongs().get(0).getTitle() + " by " + result.getSongs().get(0).getArtist() + " with id " + result.getSongs().get(0).getId()); setStarred(result.getSongs().get(0).getId(), starred, context, progressListener); } else if (result.getAlbums().size() == 1) { Log.i(TAG, "Query '" + search + "' returned song " + result.getAlbums().get(0).getTitle() + " by " + result.getAlbums().get(0).getArtist() + " with id " + result.getAlbums().get(0).getId()); setStarred(result.getAlbums().get(0).getId(), starred, context, progressListener); } else { throw new Exception("Song not found on server"); } } catch (Exception e) { Log.e(TAG, e.toString()); retry++; } } } offlineEditor.putInt(Constants.OFFLINE_STAR_COUNT, 0); offlineEditor.commit(); return count - retry; }
From source file:com.edible.ocr.CaptureActivity.java
/** * We want the help screen to be shown automatically the first time a new version of the app is * run. The easiest way to do this is to check android:versionCode from the manifest, and compare * it to a value stored as a preference. *///from w w w .j a v a 2 s . c o m private boolean checkFirstLaunch() { try { PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0); int currentVersion = info.versionCode; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); int lastVersion = prefs.getInt(PreferencesActivity.KEY_HELP_VERSION_SHOWN, 0); if (lastVersion == 0) { isFirstLaunch = true; } else { isFirstLaunch = false; } if (currentVersion > lastVersion) { // Record the last version for which we last displayed the What's New (Help) page prefs.edit().putInt(PreferencesActivity.KEY_HELP_VERSION_SHOWN, currentVersion).commit(); Intent intent = new Intent(this, HelpActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); // Show the default page on a clean install, and the what's new page on an upgrade. String page = lastVersion == 0 ? HelpActivity.DEFAULT_PAGE : HelpActivity.WHATS_NEW_PAGE; intent.putExtra(HelpActivity.REQUESTED_PAGE_KEY, page); startActivity(intent); return true; } } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, e); } return false; }