List of usage examples for android.content SharedPreferences contains
boolean contains(String key);
From source file:com.rvce.rvce8thmile.driver.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gps = new GPSTracker(getApplicationContext()); busno = (EditText) findViewById(R.id.editText); license = (EditText) findViewById(R.id.editText2); mybtn = (Button) findViewById(R.id.mybtn); mybtn.setOnClickListener(new View.OnClickListener() { @Override/*from ww w.j a v a2 s .c o m*/ public void onClick(View v) { final SharedPreferences prefs = getSharedPreferences(MainActivity.class.getSimpleName(), Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); if (!busno.getText().equals("")) { if (prefs.contains("busno")) editor.remove("busno"); editor.putString("busno", busno.getText().toString()); } if (!license.getText().equals("")) { if (prefs.contains("license")) editor.remove("license"); editor.putString("license", license.getText().toString()); } editor.apply(); // check if GPS enabled if (gps.canGetLocation()) { latitude = gps.getLatitude(); longitude = gps.getLongitude(); } else { // can't get location // GPS or Network is not enabled // Ask user to enable GPS/network in settings gps.showSettingsAlert(); } Thread t = new Thread(new Runnable() { @Override public void run() { HttpClient httpClient = new DefaultHttpClient(); //HttpPost httpPost=new HttpPost("https://rotaractrvce.com/bidn/updateuser.php"); HttpPost httpPost = new HttpPost("http://rotaractrvce.com/bidn/updatebus.php"); BasicResponseHandler responseHandler = new BasicResponseHandler(); List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(4); nameValuePair.add(new BasicNameValuePair("busno", busno.getText().toString())); nameValuePair.add(new BasicNameValuePair("license", license.getText().toString())); nameValuePair.add(new BasicNameValuePair("x", Double.toString(latitude))); nameValuePair.add(new BasicNameValuePair("y", Double.toString(longitude))); try { httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair)); } catch (UnsupportedEncodingException e) { // log exception e.printStackTrace(); } try { ans = httpClient.execute(httpPost, responseHandler); //Toast.makeText(getApplicationContext(),response,Toast.LENGTH_LONG).show(); } catch (IOException e) { e.printStackTrace(); } } }); t.start(); try { t.join(); } catch (InterruptedException e) { e.printStackTrace(); } Toast.makeText(getApplicationContext(), latitude.toString() + " : " + longitude.toString(), Toast.LENGTH_SHORT).show(); startService(new Intent(MainActivity.this, TTSService.class)); } }); }
From source file:org.mozilla.gecko.home.HomeConfigPrefsBackend.java
@Override public State load() { final SharedPreferences prefs = getSharedPreferences(); final String key = (prefs.contains(PREFS_CONFIG_KEY_OLD) ? PREFS_CONFIG_KEY_OLD : PREFS_CONFIG_KEY); final String jsonString = prefs.getString(key, null); final State configState; if (TextUtils.isEmpty(jsonString)) { configState = loadDefaultConfig(); } else {/*from w w w. j a v a 2 s . c om*/ configState = loadConfigFromString(jsonString); } return configState; }
From source file:com.bellman.bible.service.device.speak.SpeakTextProvider.java
/** * restore state to allow long pauses//from w w w . j a v a2s. c o m * * @return state restored */ public boolean restoreState() { boolean isRestored = false; SharedPreferences sharedPreferences = CommonUtils.getSharedPreferences(); if (sharedPreferences.contains(PERSIST_SPEAK_TEXT)) { mTextToSpeak = new ArrayList<String>(Arrays.asList( sharedPreferences.getString(PERSIST_SPEAK_TEXT, "").split(PERSIST_SPEAK_TEXT_SEPARATOR))); nextTextToSpeak = sharedPreferences.getInt(PERSIST_NEXT_TEXT, 0); fractionOfNextSentenceSpoken = sharedPreferences.getFloat(PERSIST_FRACTION_SPOKEN, 0); clearPersistedState(); isRestored = true; } return isRestored; }
From source file:org.gdgsp.fragment.CheckinFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); view = inflater.inflate(R.layout.fragment_checkin, container, false); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); ImageView qr = (ImageView) view.findViewById(R.id.checkin_qrcode); byte[] qrBase64 = Base64.decode(preferences.getString("qr_code", ""), Base64.DEFAULT); Bitmap qrImage = BitmapFactory.decodeByteArray(qrBase64, 0, qrBase64.length); qr.setImageBitmap(qrImage);/* ww w .java 2 s . c om*/ if (preferences.contains("member_profile")) { Gson gson = new Gson(); Type datasetListType = new TypeToken<Person>() { }.getType(); Person person = gson.fromJson(preferences.getString("member_profile", ""), datasetListType); TextView name = (TextView) view.findViewById(R.id.name); name.setText(person.getName()); } activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); return view; }
From source file:org.creativecommons.thelist.utils.SharedPreferencesMethods.java
public String getKey() { SharedPreferences sharedPref = mContext.getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); if (sharedPref.contains(SharedPreferencesMethods.USER_KEY)) { return sharedPref.getString(USER_KEY + getUserId(), null); } else {/* ww w . j av a2 s .c o m*/ return null; } }
From source file:org.creativecommons.thelist.utils.SharedPreferencesMethods.java
public Boolean getAnalyticsViewed() { SharedPreferences sharedPref = mContext.getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); if (sharedPref.contains(SharedPreferencesMethods.ANALYTICS_VIEWED)) { return sharedPref.getBoolean(ANALYTICS_VIEWED, false); //defaults to false } else {/*w ww . j a va2s.co m*/ return false; } }
From source file:org.creativecommons.thelist.utils.SharedPreferencesMethods.java
public int getSurveyCount() { SharedPreferences sharedPref = mContext.getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); if (sharedPref.contains(SharedPreferencesMethods.SURVEY_COUNT)) { return sharedPref.getInt(SURVEY_COUNT, 0); //defaults to 0 } else {/* w w w. j a va 2s. c om*/ return 0; } }
From source file:org.creativecommons.thelist.utils.SharedPreferencesMethods.java
public int getUploadCount() { SharedPreferences sharedPref = mContext.getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); if (sharedPref.contains(SharedPreferencesMethods.UPLOAD_COUNT)) { return sharedPref.getInt(UPLOAD_COUNT, 0); //defaults to 0 } else {//from www . j a v a 2s . co m return 0; } }
From source file:org.creativecommons.thelist.utils.SharedPreferencesMethods.java
public Boolean getSurveyTaken() { SharedPreferences sharedPref = mContext.getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); if (sharedPref.contains(SharedPreferencesMethods.SURVEY_TAKEN)) { return sharedPref.getBoolean(SURVEY_TAKEN, false); //defaults to false } else {/*w w w.j a v a 2 s.co m*/ return false; } }
From source file:org.creativecommons.thelist.utils.SharedPreferencesMethods.java
public Boolean getCategoryHelperViewed() { SharedPreferences sharedPref = mContext.getSharedPreferences(APP_PREFERENCES_KEY, Context.MODE_PRIVATE); if (sharedPref.contains(SharedPreferencesMethods.CATEGORY_HELPER_VIEWED)) { return sharedPref.getBoolean(CATEGORY_HELPER_VIEWED, false); //defaults to false } else {//from ww w .ja v a2 s . c o m return false; } }