List of usage examples for android.content SharedPreferences getBoolean
boolean getBoolean(String key, boolean defValue);
From source file:au.com.wallaceit.reddinator.ViewRedditActivity.java
/** * Step 2: Setup TabHost//from w w w.java2s . co m */ private void initialiseTabHost(Bundle args) { Bundle rargs = new Bundle(); rargs.putBoolean("loadcom", true); //rargs.putString("cookie", global.mRedditData.getSessionCookie()); mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup(); if (prefs.getString("widgetthemepref", "1").equals("1")) { mTabHost.getTabWidget().setBackgroundColor(Color.parseColor("#CEE3F8")); // set light theme } else { mTabHost.getTabWidget().setBackgroundColor(Color.parseColor("#5F99CF")); // set dark theme } // add tabs TabInfo tabInfo; ViewRedditActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator("Content"), (tabInfo = new TabInfo("Tab1", TabWebFragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); ViewRedditActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator("Reddit"), (tabInfo = new TabInfo("Tab2", TabWebFragment.class, rargs))); this.mapTabInfo.put(tabInfo.tag, tabInfo); // Default to first tab // get shared preferences SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ViewRedditActivity.this); if (prefs.getBoolean("commentsfirstpref", false)) { this.mTabHost.setCurrentTab(1); this.onTabChanged("Tab2"); // load comments tab first } else { this.onTabChanged("Tab1"); } // set change listener mTabHost.setOnTabChangedListener(this); }
From source file:org.herrlado.websms.connector.magtifunge.ConnectorMagtifun.java
/** * {@inheritDoc}//from www . java2s .c o m */ @Override public final ConnectorSpec updateSpec(final Context context, final ConnectorSpec connectorSpec) { final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); if (p.getBoolean(Preferences.ENABLED, false)) { if (p.getString(Preferences.PASSWORD, "").length() > 0) { connectorSpec.setReady(); } else { connectorSpec.setStatus(ConnectorSpec.STATUS_ENABLED); } } else { connectorSpec.setStatus(ConnectorSpec.STATUS_INACTIVE); } return connectorSpec; }
From source file:org.deviceconnect.android.uiapp.DConnectActivity.java
/** * SSL??./*from w w w . j av a 2s. com*/ * @return SSL???true????false */ public boolean isSSL() { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); boolean isSSL = prefs.getBoolean(getString(R.string.key_settings_dconn_ssl), false); return isSSL; }
From source file:com.sakisds.icymonitor.fragments.graph.GraphContainerFragment.java
private void refreshSettings() { SharedPreferences settings = getActivity().getSharedPreferences(MainViewActivity.SHAREDPREFS_FILE, 0); // Is 'keep screen on' enabled boolean isKeepScreenOn = settings.getBoolean("keep_on", false); if (isKeepScreenOn) { toggleKeepScreenOn();//from w ww . j a v a 2 s . co m } // Refresh rate mRefreshRate = Integer.valueOf(settings.getString(getString(R.string.key_refresh_rate), "1000")); }
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();//w ww . j a v a2 s . com // 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); } } }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Prompt the user to rate the app.// www .j a v a2 s .co m * * @param context */ public static void displayRating(final Launcher context) { SharedPreferences prefs = context.getSharedPreferences(Launcher.PREFERENCES_NAME, Activity.MODE_PRIVATE); if (prefs.getBoolean(DONT_SHOW_RATING_AGAIN, false)) { return; } final SharedPreferences.Editor editor = prefs.edit(); // Get date of first launch Long date_firstLaunch = prefs.getLong(DATE_FIRST_LAUNCHED, 0); if (date_firstLaunch == 0) { date_firstLaunch = System.currentTimeMillis(); editor.putLong(DATE_FIRST_LAUNCHED, date_firstLaunch); } // Wait at least n days before opening if (System.currentTimeMillis() >= date_firstLaunch + (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.confirmation); TextView confirmationTextView = (TextView) dialog.findViewById(R.id.confirmationText); confirmationTextView.setText(context.getString(R.string.rating_message)); Button buttonYes = (Button) dialog.findViewById(R.id.button1); buttonYes.setText(context.getString(R.string.dialog_yes)); buttonYes.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.entertailion.android.launcher")); context.startActivity(intent); if (editor != null) { editor.putBoolean(DONT_SHOW_RATING_AGAIN, true); editor.commit(); } Analytics.logEvent(Analytics.RATING_YES); context.showCover(false); dialog.dismiss(); } }); Button buttonNo = (Button) dialog.findViewById(R.id.button2); buttonNo.setText(context.getString(R.string.dialog_no)); buttonNo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (editor != null) { editor.putBoolean(DONT_SHOW_RATING_AGAIN, true); editor.commit(); } Analytics.logEvent(Analytics.RATING_NO); context.showCover(false); dialog.dismiss(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); } editor.commit(); }
From source file:com.pseudosudostudios.jdd.activities.GameActivity.java
/** * This handles the initial display and writing the boolean to the shared prefs *///w ww .j a v a 2 s . c o m private void showInstructions() { if (bg.isReadyToPlay()) return; final SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); boolean skipInstructions = prefs.getBoolean(instructionString, false); if (!skipInstructions) { Builder d = new Builder(this); d.setCancelable(false).setMessage(R.string.instructions).setTitle(R.string.instructions_title) .setCancelable(false) .setPositiveButton("Show next time", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Editor edit = prefs.edit(); edit.putBoolean(instructionString, false); edit.commit(); } }).setNegativeButton("Don't show again", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Editor edit = prefs.edit(); edit.putBoolean(instructionString, true); edit.commit(); } }).show(); } }
From source file:com.svpino.longhorn.MarketCollectorService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sharedPreferences = getSharedPreferences(Constants.PREFERENCES, Context.MODE_PRIVATE); long lastUpdate = sharedPreferences.getLong(Constants.PREFERENCE_COLLECTOR_LAST_UPDATE, 0); boolean retrying = sharedPreferences.getBoolean(Constants.PREFERENCE_COLLECTOR_RETRYING, false); int retries = sharedPreferences.getInt(Constants.PREFERENCE_COLLECTOR_RETRIES, 0); boolean wereWeWaitingForConnectivity = sharedPreferences .getBoolean(Constants.PREFERENCE_STATUS_WAITING_FOR_CONNECTIVITY, false); boolean isGlobalCollection = intent.getExtras() == null || (intent.getExtras() != null && !intent.getExtras().containsKey(EXTRA_TICKER)); if (wereWeWaitingForConnectivity) { Editor editor = sharedPreferences.edit(); editor.putBoolean(Constants.PREFERENCE_STATUS_WAITING_FOR_CONNECTIVITY, false); editor.commit();/*w w w . java 2s. co m*/ } if (retrying && isGlobalCollection) { Editor editor = sharedPreferences.edit(); editor.putBoolean(Constants.PREFERENCE_COLLECTOR_RETRYING, false); editor.putInt(Constants.PREFERENCE_COLLECTOR_RETRIES, 0); editor.commit(); ((AlarmManager) getSystemService(Context.ALARM_SERVICE)) .cancel(Extensions.createPendingIntent(this, Constants.SCHEDULE_RETRY)); } long currentTime = System.currentTimeMillis(); if (retrying || wereWeWaitingForConnectivity || !isGlobalCollection || (isGlobalCollection && currentTime - lastUpdate > Constants.COLLECTOR_MIN_REFRESH_INTERVAL)) { String[] tickers = null; if (isGlobalCollection) { Log.d(LOG_TAG, "Executing global market information collection..."); tickers = DataProvider.getStockDataTickers(this); } else { String ticker = intent.getExtras().containsKey(EXTRA_TICKER) ? intent.getExtras().getString(EXTRA_TICKER) : null; Log.d(LOG_TAG, "Executing market information collection for ticker " + ticker + "."); tickers = new String[] { ticker }; } try { collect(tickers); if (isGlobalCollection) { Editor editor = sharedPreferences.edit(); editor.putLong(Constants.PREFERENCE_COLLECTOR_LAST_UPDATE, System.currentTimeMillis()); editor.commit(); } DataProvider.notifyDataCollectionIsFinished(this, tickers); Log.d(LOG_TAG, "Market information collection was successfully completed"); } catch (Exception e) { Log.e(LOG_TAG, "Market information collection failed.", e); if (Extensions.areWeOnline(this)) { Log.d(LOG_TAG, "Scheduling an alarm for retrying a global market information collection..."); retries++; Editor editor = sharedPreferences.edit(); editor.putBoolean(Constants.PREFERENCE_COLLECTOR_RETRYING, true); editor.putInt(Constants.PREFERENCE_COLLECTOR_RETRIES, retries); editor.commit(); long interval = Constants.COLLECTOR_MIN_RETRY_INTERVAL * retries; if (interval > Constants.COLLECTOR_MAX_REFRESH_INTERVAL) { interval = Constants.COLLECTOR_MAX_REFRESH_INTERVAL; } ((AlarmManager) getSystemService(Context.ALARM_SERVICE)).set(AlarmManager.RTC, System.currentTimeMillis() + interval, Extensions.createPendingIntent(this, Constants.SCHEDULE_RETRY)); } else { Log.d(LOG_TAG, "It appears that we are not online, so let's start listening for connectivity updates."); Editor editor = sharedPreferences.edit(); editor.putBoolean(Constants.PREFERENCE_STATUS_WAITING_FOR_CONNECTIVITY, true); editor.commit(); ComponentName componentName = new ComponentName(this, ConnectivityBroadcastReceiver.class); getPackageManager().setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } } } else if (isGlobalCollection && currentTime - lastUpdate <= Constants.COLLECTOR_MIN_REFRESH_INTERVAL) { Log.d(LOG_TAG, "Global market information collection will be skipped since it was performed less than " + (Constants.COLLECTOR_MIN_REFRESH_INTERVAL / 60 / 1000) + " minutes ago."); } stopSelf(); }
From source file:de.stadtrallye.rallyesoft.MainActivity.java
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals("auto_upload")) { pref_autoUpload = sharedPreferences.getBoolean("auto_upload", true);//TODO prettier }//from w w w . j a v a2 s . co m }