List of usage examples for android.content SharedPreferences contains
boolean contains(String key);
From source file:org.creativecommons.thelist.utils.SharedPreferencesMethods.java
public Boolean getUserLearnedDrawer() { SharedPreferences sharedPref = mContext.getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); if (sharedPref.contains(DRAWER_USER_LEARNED)) { return sharedPref.getBoolean(DRAWER_USER_LEARNED, false); //defaults to false } else {/*ww w . j a va 2 s .c om*/ return false; } }
From source file:org.creativecommons.thelist.utils.SharedPreferencesMethods.java
public Boolean getSharedPreference(String key) { SharedPreferences sharedPref = mContext.getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); if (sharedPref.contains(key)) { return sharedPref.getBoolean(key, false); //defaults to false } else {// ww w .jav a2s . c om return false; } }
From source file:org.creativecommons.thelist.utils.SharedPreferencesMethods.java
public String getUserId() { SharedPreferences sharedPref = mContext.getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); if (sharedPref.contains(SharedPreferencesMethods.USER_ID_PREFERENCE_KEY)) { String userID = sharedPref.getString(USER_ID_PREFERENCE_KEY, null); return userID; } else {/*from ww w.j av a 2s. c om*/ return null; } }
From source file:org.creativecommons.thelist.utils.SharedPreferencesMethods.java
public int getUserItemCount() { SharedPreferences sharedPref = mContext.getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); if (sharedPref.contains(SharedPreferencesMethods.LIST_ITEM_PREFERENCE_KEY)) { String listOfValues = sharedPref.getString(LIST_ITEM_PREFERENCE_KEY, null); JsonParser parser = new JsonParser(); JsonElement element = parser.parse(listOfValues); JsonArray array = element.getAsJsonArray(); int size = array.size(); return size; } else {/*from w w w .j av a 2s. com*/ return 0; } }
From source file:org.mariotaku.twidere.app.TwidereApplication.java
private void migrateUsageStatisticsPreferences() { final SharedPreferences preferences = getSharedPreferences(); final boolean hasUsageStatistics = preferences.contains(KEY_USAGE_STATISTICS); if (hasUsageStatistics) return;/*from w ww. jav a 2 s.c o m*/ if (preferences.contains(KEY_UCD_DATA_PROFILING) || preferences.contains(KEY_SPICE_DATA_PROFILING)) { final boolean prevUsageEnabled = preferences.getBoolean(KEY_UCD_DATA_PROFILING, false) || preferences.getBoolean(KEY_SPICE_DATA_PROFILING, false); final Editor editor = preferences.edit(); editor.putBoolean(KEY_USAGE_STATISTICS, prevUsageEnabled); editor.remove(KEY_UCD_DATA_PROFILING); editor.remove(KEY_SPICE_DATA_PROFILING); editor.apply(); } }
From source file:com.apotheosis.acceleration.monitor.MainMenuActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_menu); setTitle("Acceleration Monitor"); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from w w w . j a va2 s . com File dir = new File(FileUtilities.path); if (!dir.isDirectory()) dir.mkdir(); SharedPreferences defaultPrefs = PreferenceManager.getDefaultSharedPreferences(this); if (!defaultPrefs.contains("LICENSES_ACCEPTED")) { defaultPrefs.edit().putBoolean("LICENSES_ACCEPTED", false).apply(); } setUpListView(); getSupportFragmentManager().beginTransaction().replace(R.id.recordViewContainer, new DataRecorderFragment()) .commit(); DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.mainDrawerLayout); toggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.saved_sets_title, R.string.app_name) { private String oldTitle; @Override public void onDrawerClosed(View v) { if (getSupportActionBar() != null) getSupportActionBar().setTitle(oldTitle); } @Override public void onDrawerOpened(View v) { if (getSupportActionBar() != null && getSupportActionBar().getTitle() != null) oldTitle = getSupportActionBar().getTitle().toString(); getSupportActionBar().setTitle(getResources().getString(R.string.saved_sets_title)); } }; drawerLayout.setDrawerListener(toggle); if (getSupportActionBar() != null) { getSupportActionBar().setElevation(0); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); } }
From source file:org.creativecommons.thelist.utils.SharedPreferencesMethods.java
public JSONArray getSharedPreferenceList(String key) { SharedPreferences sharedPref = mContext.getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); if (sharedPref.contains(key)) { String value = sharedPref.getString(key, null); if (value != null) { JsonParser parser = new JsonParser(); JsonElement element = parser.parse(value); JsonArray array = element.getAsJsonArray(); //Make usable as JSONArray List<String> list = new ArrayList<String>(); for (int i = 0; i < array.size(); i++) { list.add(array.get(i).getAsString()); }/*www .j a v a 2 s.c o m*/ return new JSONArray(list); } else { return null; } } else { return null; } }
From source file:com.amsterdam.marktbureau.makkelijkemarkt.MarktenFragment.java
/** * Inflate the markten_fragment layout containing the markten listview * @param inflater LayoutInflator/*from www . j ava 2 s .c o m*/ * @param container ViewGroup * @param savedInstanceState Bundle * @return View */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // get the markten fragment View mainView = inflater.inflate(R.layout.markten_fragment, container, false); // bind the elements to the view ButterKnife.bind(this, mainView); // create an adapter for the markten listview mMarktenAdapter = new SimpleCursorAdapter(getContext(), R.layout.markten_list_item, null, new String[] { MakkelijkeMarktProvider.Markt.COL_NAAM }, new int[] { R.id.markt_naam }, 0); // attach the adapter to the markten listview mMarktenListView.setAdapter(mMarktenAdapter); if (savedInstanceState == null) { // check time in hours since last fetched the markten SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); long diffInHours = getResources() .getInteger(R.integer.makkelijkemarkt_api_markten_fetch_interval_hours); if (settings.contains(getContext().getString(R.string.sharedpreferences_key_markten_last_fetched))) { long lastFetchTimestamp = settings .getLong(getContext().getString(R.string.sharedpreferences_key_markten_last_fetched), 0); long differenceMs = new Date().getTime() - lastFetchTimestamp; diffInHours = TimeUnit.MILLISECONDS.toHours(differenceMs); } // update the local markten by reloading them from the api (with an http client containing // an interceptor that will modify the response to transform the aanwezigeopties object // into an array of strings) if (diffInHours >= getResources() .getInteger(R.integer.makkelijkemarkt_api_markten_fetch_interval_hours)) { // show the progressbar mMarktenProgressBar.setVisibility(View.VISIBLE); ApiGetMarkten getMarkten = new ApiGetMarkten(getContext()); getMarkten.addAanwezigeOptiesInterceptor(); getMarkten.enqueue(this); } } // inititate loading the markten from the database getLoaderManager().initLoader(MARKTEN_LOADER, null, this); return mainView; }
From source file:de.androvdr.activities.ChannelsActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_WHATS_ON: final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.extendedchannels_whats_on); dialog.setTitle(R.string.channels_whats_on); final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); final DatePicker dp = (DatePicker) dialog.findViewById(R.id.channels_datePicker); final TimePicker tp = (TimePicker) dialog.findViewById(R.id.channels_timePicker); tp.setIs24HourView(DateFormat.is24HourFormat(getApplicationContext())); if (sp.contains("whats_on_hour")) { tp.setCurrentHour(sp.getInt("whats_on_hour", 0)); tp.setCurrentMinute(sp.getInt("whats_on_minute", 0)); }//from w w w . jav a 2 s. c om Button button = (Button) dialog.findViewById(R.id.channels_cancel); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); button = (Button) dialog.findViewById(R.id.channels_search); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Editor editor = sp.edit(); editor.putInt("whats_on_hour", tp.getCurrentHour()); editor.putInt("whats_on_minute", tp.getCurrentMinute()); editor.commit(); SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy hh:mm"); try { long time = df.parse(dp.getDayOfMonth() + "." + (dp.getMonth() + 1) + "." + dp.getYear() + " " + tp.getCurrentHour() + ":" + tp.getCurrentMinute()).getTime() / 1000; getController().whatsOn(time); } catch (ParseException e) { logger.error("Couldn't get date from pickers", e); } dialog.dismiss(); } }); return dialog; default: return super.onCreateDialog(id); } }
From source file:dynamite.zafroshops.app.fragment.AllZopsFragment.java
private void setZops(boolean force) { Activity activity = getActivity();// w w w .java 2 s.c o m adapter = new AllZopsGridViewAdapter(activity, R.id.gridItem, types); final SharedPreferences preferences = activity.getPreferences(0); final SharedPreferences.Editor editor = preferences.edit(); if (!preferences.contains(StorageKeys.ZOPCATEGORY_KEY)) { InputStream is = getResources().openRawResource(R.raw.zops); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); HashMap<String, MobileZop> temp = new HashMap<>(); types = new ArrayList<>( (ArrayList<MobileZop>) new Gson().fromJson(reader, new TypeToken<ArrayList<MobileZop>>() { }.getType())); for (MobileZop type : types) { String key = type.Type.toString(); if (!temp.containsKey(key)) { temp.put(key, type); } } types = new ArrayList<>(temp.values()); if (adapter != null) { adapter.setObjects(types); adapter.notifyDataSetChanged(); } try { FileOutputStream fos = activity.openFileOutput(StorageKeys.ZOPCATEGORY_KEY, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(types); oos.close(); fos.close(); editor.putString(StorageKeys.ZOPCATEGORY_KEY, Integer.toString(types.size())); editor.commit(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { if (preferences.contains(StorageKeys.ZOPCATEGORY_KEY)) { try { FileInputStream fis = activity.openFileInput(StorageKeys.ZOPCATEGORY_KEY); ObjectInputStream ois = new ObjectInputStream(fis); types = (ArrayList) ois.readObject(); ois.close(); fis.close(); if (adapter != null) { adapter.setObjects(types); adapter.notifyDataSetChanged(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (StreamCorruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } ListenableFuture<JsonElement> result = MainActivity.MobileClient.invokeApi("mobileZop", "GET", new ArrayList<Pair<String, String>>() { { add(new Pair<String, String>("count", "true")); } }); Futures.addCallback(result, new FutureCallback<JsonElement>() { @Override public void onSuccess(JsonElement result) { Activity activity = getActivity(); JsonArray typesAsJson = result.getAsJsonArray(); if (typesAsJson != null) { types = new Gson().fromJson(result, new TypeToken<ArrayList<MobileZop>>() { }.getType()); try { FileOutputStream fos = activity.openFileOutput(StorageKeys.ZOPCATEGORY_KEY, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(types); oos.close(); fos.close(); editor.putString(StorageKeys.ZOPCATEGORY_KEY, Integer.toString(types.size())); editor.commit(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } if (adapter != null) { adapter.setObjects(types); GridView zops = (GridView) activity.findViewById(R.id.gridViewZops); RelativeLayout loader = (RelativeLayout) activity.findViewById(R.id.relativeLayoutLoader); loader.setVisibility(View.INVISIBLE); zops.setVisibility(View.VISIBLE); adapter.notifyDataSetChanged(); } } @Override public void onFailure(@NonNull Throwable t) { Activity activity = getActivity(); if (activity != null && types.size() == 0) { GridView zops = (GridView) activity.findViewById(R.id.gridViewZops); RelativeLayout loader = (RelativeLayout) activity.findViewById(R.id.relativeLayoutLoader); zops.setVisibility(View.INVISIBLE); loader.setVisibility(View.VISIBLE); } } }); } }