List of usage examples for android.content SharedPreferences contains
boolean contains(String key);
From source file:com.sssemil.sonyirremote.ir.ir.java
public void firstRunChecker() { boolean isFirstRun = true; SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); if (!settings.contains("isFirstRun")) { isFirstRun = true;/* w ww .ja v a2 s .c o m*/ } else { isFirstRun = settings.getBoolean("isFirstRun", false); } if (isFirstRun) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.welcome)); builder.setMessage(getString(R.string.fr)); builder.setPositiveButton("OK", null); builder.show(); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("isFirstRun", false); editor.commit(); } }
From source file:org.tomahawk.tomahawk_android.activities.TomahawkMainActivity.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); PipeLine.get();//from w ww . java 2 s.c o m UserCollection userCollection = (UserCollection) CollectionManager.get() .getCollection(TomahawkApp.PLUGINNAME_USERCOLLECTION); userCollection.loadMediaItems(true); mSavedInstanceState = savedInstanceState; setContentView(R.layout.tomahawk_main_activity); setVolumeControlStream(AudioManager.STREAM_MUSIC); mSmoothProgressBar = (SmoothProgressBar) findViewById(R.id.smoothprogressbar); mTitle = mDrawerTitle = getTitle().toString().toUpperCase(); getSupportActionBar().setTitle(""); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mSlidingUpPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout); mSlidingUpPanelLayout.setPanelSlideListener(this); mPlaybackPanel = (PlaybackPanel) findViewById(R.id.playback_panel); mActionBarBg = findViewById(R.id.action_bar_background); if (mDrawerLayout != null) { mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getSupportActionBar().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle(mDrawerTitle); if (mSearchItem != null) { MenuItemCompat.collapseActionView(mSearchItem); } } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); } // set customization variables on the ActionBar final ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowCustomEnabled(true); // Set default preferences SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); if (!preferences.contains(PreferenceAdvancedFragment.FAKEPREFERENCEFRAGMENT_KEY_SCROBBLEEVERYTHING)) { preferences.edit() .putBoolean(PreferenceAdvancedFragment.FAKEPREFERENCEFRAGMENT_KEY_SCROBBLEEVERYTHING, true) .commit(); } mRunAfterInit = new Runnable() { @Override public void run() { handleIntent(getIntent()); } }; }
From source file:eu.basicairdata.graziano.gpslogger.GPSApplication.java
private void LoadPreferences() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); // ---------Conversion from the previous versions of GPS Logger preferences if (preferences.contains("prefShowImperialUnits")) { // The old boolean setting for imperial units in v.1.1.5 Log.w("myApp", "[#] GPSApplication.java - Old setting prefShowImperialUnits present. Converting to new preference PrefUM."); boolean imperialUM = preferences.getBoolean("prefShowImperialUnits", false); SharedPreferences.Editor editor = preferences.edit(); editor.putString("prefUM", (imperialUM ? "8" : "0")); editor.remove("prefShowImperialUnits"); editor.commit();//from ww w. j a va 2 s. c o m } // ----------------------------------------------------------------------- //prefKeepScreenOn = preferences.getBoolean("prefKeepScreenOn", true); prefShowDecimalCoordinates = preferences.getBoolean("prefShowDecimalCoordinates", false); prefUM = Integer.valueOf(preferences.getString("prefUM", "0")) + Integer.valueOf(preferences.getString("prefUMSpeed", "1")); prefGPSdistance = Float.valueOf(preferences.getString("prefGPSdistance", "0")); prefEGM96AltitudeCorrection = preferences.getBoolean("prefEGM96AltitudeCorrection", false); prefAltitudeCorrection = Double.valueOf(preferences.getString("prefAltitudeCorrection", "0")); Log.w("myApp", "[#] GPSApplication.java - Manual Correction set to " + prefAltitudeCorrection + " m"); prefExportKML = preferences.getBoolean("prefExportKML", true); prefExportGPX = preferences.getBoolean("prefExportGPX", true); prefExportTXT = preferences.getBoolean("prefExportTXT", false); prefKMLAltitudeMode = Integer.valueOf(preferences.getString("prefKMLAltitudeMode", "1")); prefGPXVersion = Integer.valueOf(preferences.getString("prefGPXVersion", "100")); // Default value = v.1.0 prefShowTrackStatsType = Integer.valueOf(preferences.getString("prefShowTrackStatsType", "0")); prefShowDirections = Integer.valueOf(preferences.getString("prefShowDirections", "0")); StoragePermissionChecked = preferences.getBoolean("prefIsStoragePermissionChecked", false); long oldGPSupdatefrequency = prefGPSupdatefrequency; prefGPSupdatefrequency = Long.valueOf(preferences.getString("prefGPSupdatefrequency", "1000")); // ---------------------------------------------- Update the GPS Update Frequency if needed if (oldGPSupdatefrequency != prefGPSupdatefrequency) updateGPSLocationFrequency(); // ---------------------------------------------------------------- Load EGM Grid if needed EGM96 egm96 = EGM96.getInstance(); if (egm96 != null) { if (!egm96.isEGMGridLoaded()) { egm96.LoadGridFromFile(Environment.getExternalStorageDirectory() + "/GPSLogger/AppData/WW15MGH.DAC", getApplicationContext().getFilesDir() + "/WW15MGH.DAC"); } } // ------------------------------------------------------------------- Request of UI Update EventBus.getDefault().post(EventBusMSG.APPLY_SETTINGS); EventBus.getDefault().post(EventBusMSG.UPDATE_FIX); EventBus.getDefault().post(EventBusMSG.UPDATE_TRACK); EventBus.getDefault().post(EventBusMSG.UPDATE_TRACKLIST); }
From source file:it.geosolutions.geocollect.android.core.mission.PendingMissionListFragment.java
/** * Creates the actionBar buttons/* ww w . ja va2s. c om*/ */ @Override public void onCreateOptionsMenu(final Menu menu, MenuInflater inflater) { PendingMissionListActivity activity = (PendingMissionListActivity) getSherlockActivity(); // Are we on a tablet? boolean mTwoPane = activity.findViewById(R.id.pendingmission_detail_container) != null; // upload if (missionTemplate != null && missionTemplate.schema_sop != null && missionTemplate.schema_sop.localFormStore != null) { String newFeaturesTableName = missionTemplate.schema_seg.localSourceStore + MissionTemplate.NEW_NOTICE_SUFFIX; String surveysTableName = missionTemplate.schema_sop.localFormStore; HashMap<String, ArrayList<String>> uploadables = PersistenceUtils.loadUploadables(activity); if ((uploadables.containsKey(newFeaturesTableName) && uploadables.get(newFeaturesTableName).size() > 0) || (uploadables.containsKey(surveysTableName) && uploadables.get(surveysTableName).size() > 0)) { // there are uploadable entries, add a menu item inflater.inflate(R.menu.uploadable, menu); } } // Display the Search only if it is not already filtered inflater.inflate(R.menu.searchable, menu); // get searchview and add querylistener // menu.findItem(R.id.search).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); searchView = (SearchView) menu.findItem(R.id.search).getActionView(); searchView.setQueryHint(getString(R.string.search_missions)); searchView.setOnQueryTextListener(this); searchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { // keyboard was closed, collapse search action view menu.findItem(R.id.search).collapseActionView(); } } }); // If SRID is set, a filter exists SharedPreferences sp = activity.getSharedPreferences(SQLiteCascadeFeatureLoader.PREF_NAME, Context.MODE_PRIVATE); if (sp.contains(SQLiteCascadeFeatureLoader.FILTER_SRID)) { inflater.inflate(R.menu.filterable, menu); } // TODO use the FAB on the main layout instead of inside the list fragment if (mTwoPane && missionTemplate != null) { if (missionTemplate.schema_seg != null) { inflater.inflate(R.menu.creating, menu); } } inflater.inflate(R.menu.map_full, menu); if (missionTemplate != null) { if (missionTemplate.schema_sop != null && (missionTemplate.schema_sop.orderingField != null || missionTemplate.orderingField != null)) { inflater.inflate(R.menu.orderable, menu); if (sp.getBoolean(SQLiteCascadeFeatureLoader.REVERSE_ORDER_PREF, false)) { MenuItem orderButton = menu.findItem(R.id.order); orderButton.setIcon(R.drawable.ic_action_sort_by_size); } } } // Creating the Overflow Menu SubMenu subMenu1 = menu.addSubMenu(0, R.id.overflow_menu, 90, "Overflow Menu"); //add sort by edit item MenuItem editItem = subMenu1.add(0, R.id.overflow_prefer_edited, Menu.NONE, R.string.prefer_edited); editItem.setCheckable(true); editItem.setChecked(sp.getBoolean(SQLiteCascadeFeatureLoader.PREFER_EDITED, false)); SubMenu subMenu2 = subMenu1.addSubMenu(0, R.id.overflow_order, Menu.NONE, R.string.order_by_ellipsis); subMenu2.setGroupCheckable(1, true, true); subMenu2.add(1, R.id.overflow_order_az, Menu.NONE, R.string.ordering_az) .setChecked(!sp.getBoolean(SQLiteCascadeFeatureLoader.ORDER_BY_DISTANCE, false)); subMenu2.add(1, R.id.overflow_order_distance, Menu.NONE, R.string.ordering_distance) .setChecked(sp.getBoolean(SQLiteCascadeFeatureLoader.ORDER_BY_DISTANCE, false)); subMenu2.setGroupCheckable(1, true, true); subMenu1.add(0, R.id.overflow_refresh, Menu.NONE, R.string.update); MenuItem subMenu1Item = subMenu1.getItem(); subMenu1Item.setIcon(R.drawable.ic_action_overflow); subMenu1Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); }
From source file:com.esri.squadleader.view.SquadLeaderActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { SharedPreferences prefs = getPreferences(MODE_PRIVATE); String key = getString(R.string.pref_labels); if (!prefs.contains(key)) { prefs.edit().putBoolean(key, true).commit(); }// ww w . jav a2s. c o m boolean labelsOn = prefs.getBoolean(key, true); if (null != mil2525cController) { mil2525cController.setShowLabels(labelsOn); } MenuItem menuItem_toggleLabels = menu.findItem(R.id.toggle_labels); menuItem_toggleLabels.setIcon(labelsOn ? R.drawable.ic_action_labels : R.drawable.ic_action_labels_off); menuItem_toggleLabels.setChecked(labelsOn); return super.onPrepareOptionsMenu(menu); }
From source file:com.mobicage.rogerthat.MainService.java
private void initPreferences() { T.UI();//from w w w.j a v a 2 s. c om final SharedPreferences options = PreferenceManager.getDefaultSharedPreferences(this); if (!options.getBoolean(PREFERENCES_READY, false) || !options.contains(PREFERENCE_EMAIL)) { setPreferences(); } }
From source file:com.coincide.alphafitness.ui.Fragment_Main.java
@Override public void onResume() { super.onResume(); // getActivity().getActionBar().setDisplayHomeAsUpEnabled(false); Database db = Database.getInstance(getActivity()); if (BuildConfig.DEBUG) db.logState();//from ww w . j a va2 s .co m // read todays offset todayOffset = db.getSteps(Util.getToday()); SharedPreferences prefs = getActivity().getSharedPreferences("pedometer", Context.MODE_PRIVATE); goal = prefs.getInt("goal", Fragment_Settings.DEFAULT_GOAL); since_boot = db.getCurrentSteps(); // do not use the value from the sharedPreferences int pauseDifference = since_boot - prefs.getInt("pauseCount", since_boot); // register a sensorlistener to live update the UI if a step is taken if (!prefs.contains("pauseCount")) { SensorManager sm = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); Sensor sensor = sm.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); if (sensor == null) { new AlertDialog.Builder(getActivity()).setTitle(R.string.no_sensor) .setMessage(R.string.no_sensor_explain) .setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(final DialogInterface dialogInterface) { getActivity().finish(); } }).setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).create().show(); } else { sm.registerListener(this, sensor, SensorManager.SENSOR_DELAY_UI, 0); } } since_boot -= pauseDifference; total_start = db.getTotalWithoutToday(); total_days = db.getDays(); db.close(); SharedPreferences sharedpreferences = getActivity().getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE); mBodyWeight = Float.parseFloat(sharedpreferences.getString(sp_weight, "0")); stepsDistanceChanged(); }
From source file:com.almalence.opencam.PluginManagerBase.java
protected Mode getMode() { Mode mode = null;//from w ww .j a v a2 s. c om // checks preferences SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext()); if (prefs.contains(ApplicationScreen.sDefaultModeName)) { String defaultModeName = prefs.getString(ApplicationScreen.sDefaultModeName, ""); mode = ConfigParser.getInstance().getMode(defaultModeName); } else { // set default mode - get this val from mode.xml and later control // in preerences mode = ConfigParser.getInstance().getDefaultMode(); Editor prefsEditor = prefs.edit(); prefsEditor.putString(ApplicationScreen.sDefaultModeName, mode.modeID); prefsEditor.commit(); } return mode; }
From source file:dynamite.zafroshops.app.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); EXTRA_ID = getApplicationContext().getPackageName() + ".id"; titles = new CharSequence[] { getString(R.string.title_section1), getString(R.string.title_section2), getString(R.string.title_section5) }; mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager() .findFragmentById(R.id.navigation_drawer); NewZopOpenings = new ArrayList(); NewZopServices = new ArrayList(); depth = 1;//from w ww . j a v a2 s . c o m locationToggleDefault = true; // Set up the drawer. mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); SharedPreferences preferences = getPreferences(0); final SharedPreferences.Editor editor = preferences.edit(); Switch locationToggle = (Switch) findViewById(R.id.location_toggle); locationToggle.setChecked(preferences.getBoolean(StorageKeys.LOCATION_TOGGLE_KEY, locationToggleDefault)); locationToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { editor.putBoolean(StorageKeys.LOCATION_TOGGLE_KEY, b); editor.commit(); if (b) { getLocation(true); getAddress(true); } } }); if (!preferences.contains(StorageKeys.COUNTRY_KEY)) { editor.putString(StorageKeys.COUNTRY_KEY, ""); editor.commit(); } try { // Create the Mobile Service Client instance, using the provided // Mobile Service URL and key MobileClient = new MobileServiceClient(getString(R.string.azure_site), getString(R.string.azure_mobile_service_app_key), this); } catch (MalformedURLException ignored) { } NotificationsManager.handleNotifications(this, getString(R.string.google_api_name), PushHandler.class); registerWithNotificationHubs(); googleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(LocationServices.API).build(); Bundle bundle = getIntent().getExtras(); if (bundle != null && bundle.containsKey(EXTRA_ID)) { nextMenu(ZopItemFragment.newInstance(bundle.getString(EXTRA_ID)), false, 100); } // setup ads adView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build(); adView.loadAd(adRequest); Interstitial = new InterstitialAd(this); Interstitial.setAdUnitId(getString(R.string.ads_interstitial_unit_id)); Interstitial.setAdListener(new AdListener() { @Override public void onAdClosed() { requestNewInterstitial(); } }); requestNewInterstitial(); // setup in app package if (!getResources().getBoolean(R.bool.debug)) { inAppHelper = new IabHelper(this, getString(R.string.inappkey)); inAppHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (!result.isSuccess()) { return; } if (inAppHelper == null) { return; } inAppHelper.queryInventoryAsync(gotInventoryListener); } }); } DataVersion = 0; Versions = new Hashtable<>(); Counts = new Hashtable<>(); setDataVersion(); openHelpDialog(null); }
From source file:com.facebook.stetho.inspector.protocol.module.DOMStorage.java
@ChromeDevtoolsMethod public void setDOMStorageItem(JsonRpcPeer peer, JSONObject params) throws JSONException, JsonRpcException { StorageId storage = mObjectMapper.convertValue(params.getJSONObject("storageId"), StorageId.class); String key = params.getString("key"); String value = params.getString("value"); if (storage.isLocalStorage) { SharedPreferences prefs = mContext.getSharedPreferences(storage.securityOrigin, Context.MODE_PRIVATE); Object existingValue = prefs.getAll().get(key); try {/*www . j a v a 2s. c o m*/ if (existingValue == null) { throw new DOMStorageAssignmentException( "Unsupported: cannot add new key " + key + " due to lack of type inference"); } else { SharedPreferences.Editor editor = prefs.edit(); try { assignByType(editor, key, SharedPreferencesHelper.valueFromString(value, existingValue)); editor.apply(); } catch (IllegalArgumentException e) { throw new DOMStorageAssignmentException( String.format(Locale.US, "Type mismatch setting %s to %s (expected %s)", key, value, existingValue.getClass().getSimpleName())); } } } catch (DOMStorageAssignmentException e) { CLog.writeToConsole(mDOMStoragePeerManager, Console.MessageLevel.ERROR, Console.MessageSource.STORAGE, e.getMessage()); // Force the DevTools UI to refresh with the old value again (it assumes that the set // operation succeeded). Note that we should be able to do this by throwing // JsonRpcException but the UI doesn't respect setDOMStorageItem failure. if (prefs.contains(key)) { mDOMStoragePeerManager.signalItemUpdated(storage, key, value, SharedPreferencesHelper.valueToString(existingValue)); } else { mDOMStoragePeerManager.signalItemRemoved(storage, key); } } } }