List of usage examples for android.content SharedPreferences getAll
Map<String, ?> getAll();
From source file:com.ehret.mixit.fragment.PeopleDetailFragment.java
private void addPeopleSession(Member membre) { //On recupere aussi la liste des sessions de l'utilisateur List<Talk> conferences = ConferenceFacade.getInstance().getSessionMembre(membre, getActivity()); //On vide les lments sessionLayout.removeAllViews();/* w w w . j a v a2s . c om*/ //On affiche les liens que si on a recuperer des choses if (conferences != null && !conferences.isEmpty()) { //On ajoute un table layout TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams( TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT); TableLayout tableLayout = new TableLayout(getActivity().getBaseContext()); tableLayout.setLayoutParams(tableParams); if (mInflater != null) { for (final Talk conf : conferences) { LinearLayout row = (LinearLayout) mInflater.inflate(R.layout.item_talk, tableLayout, false); row.setBackgroundResource(R.drawable.row_transparent_background); //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans TextView horaire = (TextView) row.findViewById(R.id.talk_horaire); TextView talkImageText = (TextView) row.findViewById(R.id.talkImageText); TextView talkSalle = (TextView) row.findViewById(R.id.talk_salle); ImageView imageFavorite = (ImageView) row.findViewById(R.id.talk_image_favorite); ImageView langImage = (ImageView) row.findViewById(R.id.talk_image_language); ((TextView) row.findViewById(R.id.talk_name)).setText(conf.getTitle()); ((TextView) row.findViewById(R.id.talk_shortdesciptif)).setText(conf.getSummary().trim()); SimpleDateFormat sdf = new SimpleDateFormat("EEE"); if (conf.getStart() != null && conf.getEnd() != null) { horaire.setText(String.format(getResources().getString(R.string.periode), sdf.format(conf.getStart()), DateFormat.getTimeInstance(DateFormat.SHORT).format(conf.getStart()), DateFormat.getTimeInstance(DateFormat.SHORT).format(conf.getEnd()))); } else { horaire.setText(getResources().getString(R.string.pasdate)); } if (conf.getLang() != null && "ENGLISH".equals(conf.getLang())) { langImage.setImageDrawable(getResources().getDrawable(R.drawable.en)); } else { langImage.setImageDrawable(getResources().getDrawable(R.drawable.fr)); } Salle salle = Salle.INCONNU; if (conf instanceof Talk && Salle.INCONNU != Salle.getSalle(conf.getRoom())) { salle = Salle.getSalle(conf.getRoom()); } talkSalle.setText(String.format(getResources().getString(R.string.Salle), salle.getNom())); talkSalle.setBackgroundColor(getResources().getColor(salle.getColor())); if (conf instanceof Talk) { if ("Workshop".equals(((Talk) conf).getFormat())) { talkImageText.setText("Atelier"); } else { talkImageText.setText("Talk"); } } else { talkImageText.setText("L.Talk"); } row.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { TypeFile typeFile; int page = 6; if (conf instanceof Talk) { if ("Workshop".equals(((Talk) conf).getFormat())) { typeFile = TypeFile.workshops; page = 4; } else { typeFile = TypeFile.talks; page = 3; } } else { typeFile = TypeFile.lightningtalks; } ((HomeActivity) getActivity()).changeCurrentFragment(SessionDetailFragment.newInstance( typeFile.toString(), conf.getIdSession(), page), typeFile.toString()); } }); //On regarde si la conf fait partie des favoris SharedPreferences settings = getActivity().getSharedPreferences(UIUtils.PREFS_FAVORITES_NAME, 0); boolean trouve = false; for (String key : settings.getAll().keySet()) { if (key.equals(String.valueOf(conf.getIdSession()))) { trouve = true; imageFavorite.setImageDrawable( getActivity().getResources().getDrawable(R.drawable.ic_action_important)); break; } } if (!trouve) { imageFavorite.setImageDrawable( getActivity().getResources().getDrawable(R.drawable.ic_action_not_important)); } tableLayout.addView(row); } } sessionLayout.addView(tableLayout); } else { titleSessions.getLayoutParams().height = 0; } }
From source file:picframe.at.picframe.activities.SettingsActivity.java
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (sharedPreferences != null && key != null) { debug("CHANGED| Key:" + key + " ++ Value: " + sharedPreferences.getAll().get(key)); }//from www . j a va 2s . c o m if (editableTitleFields.contains(key)) { //update display/transition title updateFieldTitle(key); if (getString(R.string.sett_key_srctype).equals(key)) { createCat2Fields(); alarmScheduler.scheduleAlarm(); } else if (getString(R.string.sett_key_username).equals(key) || getString(R.string.sett_key_password).equals(key) || getString(R.string.sett_key_srcpath_owncloud).equals(key)) { setLoginStatus(false); if (!AppData.getUserName().equals("") && !AppData.getUserPassword().equals("") && !AppData.getSourcePath().equals("") && !AppData.getSourcePath().equals( SettingsDefaults.getDefaultValueForKey(R.string.sett_key_srcpath_owncloud))) { new Handler().post(new ConnectionCheck_OC()); } } else if (getString(R.string.sett_key_loginCheckButton).equals(key) || getString(R.string.sett_key_downloadInterval).equals(key)) { alarmScheduler.scheduleAlarm(); } } }
From source file:jackpal.androidterm.TermPreferences.java
private boolean writePrefs(String filename) { AlertDialog.Builder bld = new AlertDialog.Builder(this); bld.setIcon(android.R.drawable.ic_dialog_info); bld.setPositiveButton(this.getString(android.R.string.ok), null); FileOutputStream fos;//from w w w. ja va 2 s . c o m try { fos = new FileOutputStream(filename); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); XmlUtils.writeMapXml(pref.getAll(), fos); } catch (Exception e) { bld.setMessage(this.getString(R.string.prefs_write_info_failure)); bld.create().show(); return false; } bld.setMessage(this.getString(R.string.prefs_write_info_success) + "\n\n" + filename); bld.create().show(); return true; }
From source file:android_network.hetnet.vpn_service.ActivityLog.java
@Override public void onSharedPreferenceChanged(SharedPreferences prefs, String name) { Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name)); if ("log".equals(name)) { // Get enabled boolean log = prefs.getBoolean(name, false); // Display disabled warning TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled); tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE); // Check switch state SwitchCompat swEnabled = (SwitchCompat) getSupportActionBar().getCustomView() .findViewById(R.id.swEnabled); if (swEnabled.isChecked() != log) swEnabled.setChecked(log);/*from ww w .j a va 2 s . c om*/ ServiceSinkhole.reload("changed " + name, ActivityLog.this); } }
From source file:eu.faircode.netguard.ActivityLog.java
@Override public void onSharedPreferenceChanged(SharedPreferences prefs, String name) { Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name)); if ("log".equals(name)) { // Get enabled boolean log = prefs.getBoolean(name, false); // Display disabled warning TextView tvDisabled = findViewById(R.id.tvDisabled); tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE); // Check switch state SwitchCompat swEnabled = getSupportActionBar().getCustomView().findViewById(R.id.swEnabled); if (swEnabled.isChecked() != log) swEnabled.setChecked(log);//from ww w. j a v a 2 s . co m ServiceSinkhole.reload("changed " + name, ActivityLog.this, false); } }
From source file:com.trigger_context.Main_Service.java
private boolean testConditions(String mac) { SharedPreferences conditions = getSharedPreferences(mac, MODE_PRIVATE); Map<String, ?> cond_map = conditions.getAll(); Set<String> key_set = cond_map.keySet(); boolean takeAction = true; if (key_set.contains("bluetooth")) { // checking the current state against the state set by the user final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); takeAction = new Boolean(bluetoothAdapter.isEnabled()) .equals(conditions.getString("bluetooth", "false")); }/*from www . j a v a2s .c o m*/ if (takeAction && key_set.contains("wifi")) { final WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); takeAction = new Boolean(wm.isWifiEnabled()) == conditions.getBoolean("wifi", false); } if (takeAction && key_set.contains("gps")) { final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); takeAction = new Boolean(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) .equals(conditions.getString("gps", "false")); } if (takeAction && key_set.contains("sms")) { final Uri SMS_INBOX = Uri.parse("content://sms/inbox"); Cursor c = getContentResolver().query(SMS_INBOX, null, "read = 0", null, null); if (c != null) { int unreadMessagesCount = c.getCount(); c.close(); takeAction = new Boolean(unreadMessagesCount > 0).equals(conditions.getString("sms", "false")); } else { takeAction = false; } } // "NOT TESTED" head set, missed call, accelerometer, proximity, gyro, // orientation if (takeAction && key_set.contains("headset")) { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); takeAction = am.isMusicActive() == conditions.getBoolean("headset", false); // am.isWiredHeadsetOn() is deprecated } /* * if(takeAction && key_set.contains("missedCall")) { final String[] * projection = null; final String selection = null; final String[] * selectionArgs = null; final String sortOrder = * android.provider.CallLog.Calls.DATE + " DESC"; Cursor cursor = null; * try{ cursor = getApplicationContext().getContentResolver().query( * Uri.parse("content://call_log/calls"), projection, selection, * selectionArgs, sortOrder); while (cursor.moveToNext()) { String * callLogID = * cursor.getString(cursor.getColumnIndex(android.provider.CallLog * .Calls._ID)); String callNumber = * cursor.getString(cursor.getColumnIndex * (android.provider.CallLog.Calls.NUMBER)); String callDate = * cursor.getString * (cursor.getColumnIndex(android.provider.CallLog.Calls.DATE)); String * callType = * cursor.getString(cursor.getColumnIndex(android.provider.CallLog * .Calls.TYPE)); String isCallNew = * cursor.getString(cursor.getColumnIndex * (android.provider.CallLog.Calls.NEW)); if(Integer.parseInt(callType) * == android.provider.CallLog.Calls.MISSED_CALL_TYPE && * Integer.parseInt(isCallNew) > 0){ * * } } }catch(Exception ex){ }finally{ cursor.close(); } * * } */ return takeAction; }
From source file:org.opendatakit.common.android.logic.PropertiesSingleton.java
public void clearSettings() { try {// w ww. j a v a 2 s . c o m File f; f = new File(ODKFileUtils.getDataFolder(mAppName), DEVICE_PROPERTIES_FILENAME); if (f.exists()) { f.delete(); } // and now go through the shared preferences and delete any that pertain to this appName SharedPreferences sharedPreferences = getSharedPreferences(mBaseContext); if (sharedPreferences != null) { Map<String, ?> allPreferences = sharedPreferences.getAll(); for (String key : allPreferences.keySet()) { if (key.startsWith(mAppName + "_")) { sharedPreferences.edit().remove(key).commit(); } } } else { throw new IllegalStateException("Clearing settings should only be done within ODK Services"); } } finally { init(); } }
From source file:com.wubydax.romcontrol.MainViewActivity.java
private void backupPreferences() { //we go into the shared_prefs folder and we read the files name's File prefdir = new File("/data/data/com.wubydax.romcontrol/shared_prefs"); File filesdir = new File("/data/data/com.wubydax.romcontrol/files/FilePrefs"); if (bkpdir.listFiles() != null) { for (File deleteBkp : bkpdir.listFiles()) { deleteBkp.delete();/*from w w w .ja va 2 s . c o m*/ } } for (File f : prefdir.listFiles()) { if (f.isFile()) { String name = f.getName(); //if file is defult pref we don't backup as it doesn't go in the bd if (!name.equals("com.wubydax.romcontrol_preferences.xml")) { //we remove the xml suffix from filename and we assign it in the loop to the shared prefs //this way we can use the getAll method of shared prefs for all the existing files in the folder name = name.replace(".xml", ""); SharedPreferences pref = getSharedPreferences(name, MODE_PRIVATE); //now we write to the backup file Map<String, ?> allEntries = pref.getAll(); for (Map.Entry<String, ?> entry : allEntries.entrySet()) { try (PrintWriter out = new PrintWriter( new BufferedWriter(new FileWriter(bkpdir + "/prefs.txt", true)))) { out.println(entry.getKey() + ": " + entry.getValue().toString()); } catch (IOException e) { } } } } } if (filesdir.exists()) { for (File files : filesdir.listFiles()) { if (files.isFile()) { String name = files.getName(); if (!name.contains("com.wubydax")) { File filebackup = new File(bkpdir + "/" + name); try { filebackup.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } } } } finish(); this.overridePendingTransition(0, R.animator.fadeout); startActivity(new Intent(this, MainViewActivity.class)); this.overridePendingTransition(R.animator.fadein, 0); }
From source file:com.zhengde163.netguard.ActivityLog.java
@Override public void onSharedPreferenceChanged(SharedPreferences prefs, String name) { Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name)); if ("log".equals(name)) { // Get enabled boolean log = prefs.getBoolean(name, false); // Display disabled warning // TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled); // tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE); LinearLayout ly = (LinearLayout) findViewById(R.id.lldisable); ly.setVisibility(log ? View.GONE : View.VISIBLE); // Check switch state // SwitchCompat swEnabled = (SwitchCompat) getSupportActionBar().getCustomView().findViewById(R.id.swEnabled); ImageView ivEnabled = (ImageView) findViewById(R.id.ivEnabled); if (ivEnabled != null) { if (log) { ivEnabled.setImageResource(R.drawable.on); } else { ivEnabled.setImageResource(R.drawable.off); }/* ww w . jav a 2 s . co m*/ } // if (swEnabled.isChecked() != log) // swEnabled.setChecked(log); ServiceSinkhole.reload("changed " + name, ActivityLog.this); } }
From source file:edu.pdx.cecs.orcycle.UserInfoUploader.java
/** * * @return//w w w . j av a 2 s . co m * @throws JSONException */ private JSONArray getUserResponsesJSON() throws JSONException { // Create a JSON array to hold all of the answers JSONArray jsonAnswers = new JSONArray(); SharedPreferences settings = mCtx.getSharedPreferences(UserInfoActivity.PREFS_USER_INFO_UPLOAD, Context.MODE_PRIVATE); Map<String, ?> prefs = settings.getAll(); String riderTypeOther = null; String occupationOther = null; String bikeTypeOther = null; String genderOther = null; String ethnicityOther = null; for (Entry<String, ?> p : prefs.entrySet()) { int key = Integer.parseInt(p.getKey()); // CharSequence value = (CharSequence) p.getValue(); switch (key) { case UserInfoActivity.PREF_RIDER_TYPE_OTHER: riderTypeOther = (String) p.getValue(); break; case UserInfoActivity.PREF_OCCUPATION_OTHER: occupationOther = (String) p.getValue(); break; case UserInfoActivity.PREF_BIKE_TYPE_OTHER: bikeTypeOther = (String) p.getValue(); break; case UserInfoActivity.PREF_GENDER_OTHER: genderOther = (String) p.getValue(); break; case UserInfoActivity.PREF_ETHNICITY_OTHER: ethnicityOther = (String) p.getValue(); break; } } for (Entry<String, ?> p : prefs.entrySet()) { int key = Integer.parseInt(p.getKey()); // CharSequence value = (CharSequence) p.getValue(); switch (key) { case UserInfoActivity.PREF_EMAIL: email = (String) p.getValue(); break; case UserInfoActivity.PREF_RIDER_ABILITY: putInt(jsonAnswers, DbQuestions.USER_INFO_RIDER_ABILITY, DbAnswers.userInfoRiderAbility, -1, null, p); break; case UserInfoActivity.PREF_RIDER_TYPE: putInt(jsonAnswers, DbQuestions.USER_INFO_RIDER_TYPE, DbAnswers.userInfoRiderType, DbAnswers.userInfoRiderTypeOther, riderTypeOther, p); break; case UserInfoActivity.PREF_CYCLE_FREQUENCY: putInt(jsonAnswers, DbQuestions.USER_INFO_CYCLING_FREQ, DbAnswers.userInfoCyclingFreq, -1, null, p); break; case UserInfoActivity.PREF_CYCLE_WEATHER: putInt(jsonAnswers, DbQuestions.USER_INFO_CYCLING_WEATHER, DbAnswers.userInfoCyclingWeather, -1, null, p); break; case UserInfoActivity.PREF_NUM_BIKES: putInt(jsonAnswers, DbQuestions.USER_INFO_NUM_BIKES, DbAnswers.userInfoNumBikes, -1, null, p); break; case UserInfoActivity.PREF_BIKE_TYPES: putMultiInt(jsonAnswers, DbQuestions.USER_INFO_BIKE_TYPES, DbAnswers.userInfoBikeTypes, DbAnswers.userInfoBikeTypeOther, bikeTypeOther, p); break; case UserInfoActivity.PREF_OCCUPATION: putInt(jsonAnswers, DbQuestions.USER_INFO_OCCUPATION, DbAnswers.userInfoOccupation, DbAnswers.userInfoOccupationOther, occupationOther, p); break; case UserInfoActivity.PREF_AGE: putInt(jsonAnswers, DbQuestions.USER_INFO_AGE, DbAnswers.userInfoAge, -1, null, p); break; case UserInfoActivity.PREF_GENDER: putInt(jsonAnswers, DbQuestions.USER_INFO_GENDER, DbAnswers.userInfoGender, DbAnswers.userInfoGenderOther, genderOther, p); break; case UserInfoActivity.PREF_VEHICLES: putInt(jsonAnswers, DbQuestions.USER_INFO_VEHICLES, DbAnswers.userInfoHHVehicles, -1, null, p); break; case UserInfoActivity.PREF_WORKERS: putInt(jsonAnswers, DbQuestions.USER_INFO_WORKERS, DbAnswers.userInfoHHWorkers, -1, null, p); break; case UserInfoActivity.PREF_ETHNICITY: putInt(jsonAnswers, DbQuestions.USER_INFO_ETHNICITY, DbAnswers.userInfoEthnicity, DbAnswers.userInfoEthnicityOther, ethnicityOther, p); break; case UserInfoActivity.PREF_INCOME: putInt(jsonAnswers, DbQuestions.USER_INFO_INCOME, DbAnswers.userInfoIncome, -1, null, p); break; case UserInfoActivity.PREF_INSTALLED: installed = (String) p.getValue(); break; case UserInfoActivity.PREF_DEVICE_MODEL: deviceModel = (String) p.getValue(); break; case UserInfoActivity.PREF_APP_VERSION: appVersion = (String) p.getValue(); break; } } return jsonAnswers; }