@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SettingsActivityComponent cmp = DaggerService.getDaggerComponent(getActivity()); cmp.inject(this); mSettings.setCached(true); addPreferencesFromResource(R.xml.prefs_service); runWhen = (ListPreference) findPreference(ServiceSettings.RUN_WHEN); runWhen.setPersistent(false); runWhen.setValue(mSettings.runWhen()); runWhen.setOnPreferenceChangeListener(this); onlyOnWifi = (CheckBoxPreference) findPreference(ServiceSettings.ONLY_WIFI); onlyOnWifi.setPersistent(false); onlyOnWifi.setChecked(mSettings.onlyOnWifi()); onlyOnWifi.setOnPreferenceChangeListener(this); wifiNetwork = (MultiSelectListPreference) findPreference(ServiceSettings.WIFI_NETWORKS); wifiNetwork.setPersistent(false); String[] ssids = getWifiNetworks(); wifiNetwork.setEntries(ssids); wifiNetwork.setEntryValues(ssids); wifiNetwork.setValues(mSettings.allowedWifiNetworks()); wifiNetwork.setOnPreferenceChangeListener(this); onlyCharging = (CheckBoxPreference) findPreference(ServiceSettings.ONLY_CHARGING); onlyCharging.setPersistent(false); onlyCharging.setChecked(mSettings.onlyWhenCharging()); onlyCharging.setOnPreferenceChangeListener(this); catBetween = (PreferenceCategory) findPreference("cat_between"); hideShowRunWhenCategories(mSettings.runWhen()); scheduleStart = (TimePreference) findPreference(ServiceSettings.RANGE_START); scheduleStart.setPersistent(false); scheduleStart.setValue(mSettings.getScheduledStartTime()); scheduleStart.setOnPreferenceChangeListener(this); scheduleEnd = (TimePreference) findPreference(ServiceSettings.RANGE_END); scheduleEnd.setPersistent(false); scheduleEnd.setValue(mSettings.getScheduledEndTime()); scheduleEnd.setOnPreferenceChangeListener(this); exportConfig = findPreference("export"); exportConfig.setOnPreferenceClickListener(this); importConfig = findPreference("import"); importConfig.setOnPreferenceClickListener(this); }
@Override protected void onRestoreInstanceState(Parcelable state) { if (state == null || !state.getClass().equals(SavedState.class)) { // Didn't save state for us in onSaveInstanceState super.onRestoreInstanceState(state); return; } SavedState myState = (SavedState) state; super.onRestoreInstanceState(myState.getSuperState()); if (myState.isDialogShowing) { showDialog(myState.dialogBundle); } }
/** Listens for a change in the preferences */ @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { System.out.println("GUEEEEE ON SHARED PREFERENCE CHANGED"); if (key.equals(KEY_PREF_SYNC_CONN)) { System.out.println("key multilist changed"); MultiSelectListPreference connectionPref = (MultiSelectListPreference) findPreference(key); // Get the new values Set<String> set = sharedPreferences.getStringSet(key, null); // Set the new values on the list MainActivity.websNames = set.toArray(new String[0]); // Set the values on the list shown connectionPref.setValues(set); } }
public void onActivityDestroy() { if (mActionSheet == null) { return; } mActionSheet.dismiss(); super.onActivityDestroy(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); menuPref = (MultiSelectListPreference) findPreference("menu_list"); sitePref = (ListPreference) findPreference("site_list"); menuPref.setOnPreferenceChangeListener(this); }
@Override protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); if (positiveResult && mPreferenceChanged) { final Set<String> values = mNewValues; if (callChangeListener(values)) { setValues(values); } } mPreferenceChanged = false; }
@SuppressWarnings("deprecation") @SuppressLint("WorldReadableFiles") @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); getPreferenceManager().setSharedPreferencesMode(MODE_WORLD_READABLE); addPreferencesFromResource(R.xml.pref_general); getViews(); mPrefs = getSharedPreferences(Common.PREFS, Context.MODE_WORLD_READABLE); /* Workaround: since we now do the changes automatically as this activity * follows our XML now (overriden getSharedPreferences), emitting an intent * to update settings won't work since the changes are committed after the return. * We can workaround that in two ways: either delay the intent using a handler, * but that may cause some multiple intents to be fired for no reason, or * saving the changes manually then firing the intent. We do the latter here. */ OnPreferenceChangeListener listener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { preferenceChanged(preference, newValue); return true; } }; mEnableTagLostCheckBox.setChecked(mPrefs.getBoolean(Common.PREF_TAGLOST, true)); mEnableTagLostCheckBox.setOnPreferenceChangeListener(listener); mSoundsToPlay.setValues( mPrefs.getStringSet( Common.PREF_SOUNDS_TO_PLAY, new HashSet<String>( Arrays.asList( getResources().getStringArray(R.array.pref_default_sounds_to_play))))); mSoundsToPlay.setOnPreferenceChangeListener(listener); mEnableNfcForStatesList.setSummary(" "); // required or will not update mEnableNfcForStatesList.setSummary("%s"); mEnableNfcForStatesList.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { preferenceChanged(preference, newValue); mEnableNfcForStatesList.setSummary(" "); // required or will not update mEnableNfcForStatesList.setSummary("%s"); return true; } }); mCopyrightPreference.setOnPreferenceClickListener( new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Resources resources = getResources(); String[] contributors = resources.getStringArray(R.array.contributors); String[] methodsOfContribution = resources.getStringArray(R.array.contributors_how); String[] translators = resources.getStringArray(R.array.translators); String translatorsTitle = getString(R.string.translators_title); String contributorString = ""; for (int i = 0; i < contributors.length; i++) { if (i != 0) contributorString += "\n"; String contributor = "* %s (%s)"; contributorString += String.format(contributor, contributors[i], methodsOfContribution[i]); } if (translators.length != 0) { contributorString += "\n\n"; contributorString += translatorsTitle + ":" + "\n"; for (int i = 0; i < translators.length; i++) { if (i != 0) contributorString += "\n"; contributorString += "* " + translators[i]; } } AlertDialog.Builder alertDialog = new AlertDialog.Builder(NFCLockScreenOffEnablerActivity.this) .setTitle(R.string.contributors_title) .setMessage(contributorString); alertDialog.show(); return true; } }); /* if (mPrefs.contains(Common.PREF_PRESENCE_CHECK_TIMEOUT)) { mPresenceCheckTimeoutPreference.setSummary(getString(R.string.pref_summary_presence_check) + " " + mPrefs.getString(Common.PREF_PRESENCE_CHECK_TIMEOUT, "2000")); } mPresenceCheckTimeoutPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { preferenceChanged(preference, newValue); mPresenceCheckTimeoutPreference.setSummary(" "); mPresenceCheckTimeoutPreference.setSummary(getString(R.string.pref_summary_presence_check) + " " + newValue); return true; } }); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { mPresenceCheckTimeoutPreference.setSummary(R.string.not_supported_yet_kitkat); mPresenceCheckTimeoutPreference.setEnabled(false); } */ findPreference(Common.PREF_DEBUG_MODE).setOnPreferenceChangeListener(listener); findPreference("show_in_launcher") .setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { // Thanks to Chainfire for this // http://www.chainfire.eu/articles/133/_TUT_Supporting_multiple_icons_in_your_app/ PackageManager pm = getPackageManager(); pm.setComponentEnabledSetting( new ComponentName( getApplicationContext(), Common.MOD_PACKAGE_NAME + ".Activity-Launcher"), (Boolean) newValue ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); return true; } }); }
@Override protected void onDialogClosed(boolean isPositive) { super.onDialogClosed(isPositive); notifyChanged(); }
private void updatePrefences(Preference preference) { if (preference instanceof EditTextPreference) { if (preference.getKey().equals(MyApplication.PROFILE_NAME_KEY)) { EditTextPreference etp = (EditTextPreference) preference; if (etp.getText() != null && !etp.getText().equals("")) { profile.setName(etp.getText()); isNameSet = true; } isReady = isNameSet && isRepeatingSet && isActivatoinSet; etp.setSummary(etp.getText()); } } else if (preference instanceof ListPreference) { ListPreference lp = (ListPreference) preference; if (preference.getKey().equals(MyApplication.AUTO_ACTIVATION_KEY)) { lp.setSummary(lp.getEntry()); int idx = Integer.parseInt(lp.getValue()); switch (idx) { case 0: break; case 1: showFromDialog(); profile.setAcivationMode(MyApplication.BY_TIME); // lp.setSummary(profile.getSubTitle()); break; case 2: profile.setAcivationMode(MyApplication.BY_LOCATOIN); profile.setSubTitle("By Location "); isActivatoinSet = true; isReady = isNameSet && isRepeatingSet && isActivatoinSet; break; } lp.setSummary(profile.getSubTitle()); } else if (preference.getKey().equals(MyApplication.RING_MODE_KEY)) { lp.setSummary(lp.getEntry()); profile.setRingerMode(Integer.parseInt(lp.getValue())); } else if (preference.getKey().equals(MyApplication.CHANGE_WIFI_KEY)) { lp.setSummary(lp.getEntry()); profile.setWifiMode(Integer.parseInt(lp.getValue())); } else if (preference.getKey().equals(MyApplication.CHANGE_BLUETOOEH_KEY)) { lp.setSummary(lp.getEntry()); profile.setBlueToothMode(Integer.parseInt(lp.getValue())); } } else if (preference instanceof MultiSelectListPreference) { if (preference.getKey().equals(MyApplication.REPEATIN_DAYS_KEY)) { MultiSelectListPreference msp = (MultiSelectListPreference) preference; Set<String> selectedDays = msp.getValues(); ArrayList<Integer> selectedIndx = new ArrayList<>(); for (String day : selectedDays) { selectedIndx.add(Integer.parseInt(day)); // Toast.makeText(MyApplication.APP_CNTX,day,Toast.LENGTH_SHORT).show(); } Collections.sort(selectedIndx); String summary = ""; for (int idx : selectedIndx) { summary += MyApplication.DAYS_OF_WEEK[idx % 7].substring(0, 3) + ","; } if (summary.length() == 0) summary = "NONE"; msp.setSummary(summary); profile.setRepeatingDays(selectedIndx); isRepeatingSet = true; isReady = isNameSet && isRepeatingSet && isActivatoinSet; } } else if (preference instanceof CheckBoxPreference) { CheckBoxPreference cbp = (CheckBoxPreference) preference; if (cbp.getKey().equals(MyApplication.CHANGE_RINGTONE_KEY)) { findPreference(MyApplication.CHOOSE_RINGTONE_KEY).setEnabled(cbp.isChecked()); profile.setChangeRingtone(cbp.isChecked()); } else if (cbp.getKey().equals(MyApplication.CHANGE_NOTIFICATION_KEY)) { findPreference(MyApplication.CHOOSE_NOTIFICATION_KEY).setEnabled(cbp.isChecked()); profile.setChangeNotiTone(cbp.isChecked()); } } else if (preference instanceof RingtonePreference) { RingtonePreference rtp = (RingtonePreference) preference; if (rtp.getKey().equals(MyApplication.CHOOSE_RINGTONE_KEY)) { String ring = getRingToneURI(); Uri uri = Uri.parse(ring); Ringtone ringtone = RingtoneManager.getRingtone(MyApplication.APP_CNTX, uri); if (ringtone != null) rtp.setSummary(ringtone.getTitle(getActivity())); profile.setRingeToneURI(ring); } else if (rtp.getKey().equals(MyApplication.CHOOSE_NOTIFICATION_KEY)) { String ring = getNotiToneURI(); Uri uri = Uri.parse(ring); Ringtone ringtone = RingtoneManager.getRingtone(MyApplication.APP_CNTX, uri); if (ringtone != null) rtp.setSummary(ringtone.getTitle(getActivity())); profile.setNotiToneURI(ring); } } }
@Override public void setEntries(CharSequence[] entries) { super.setEntries(entries); if (mDialog != null) mDialog.setItems(entries); }
@Override public void onActivityDestroy() { super.onActivityDestroy(); if (mDialog != null && mDialog.isShowing()) mDialog.dismiss(); }
@Override public void onDismiss(DialogInterface dialog) { super.onDismiss(dialog); PrefUtil.unregisterOnActivityDestroyListener(this, this); }
@Override protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); setSummary(getSummary()); }