use of com.takisoft.fix.support.v7.preference.EditTextPreference in project RespawnIRC-Android by FranckRJ.
the class SettingsFragment method onSharedPreferenceChanged.
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Preference pref = findPreference(key);
if (pref instanceof EditTextPreference) {
EditTextPreference editTextPref = (EditTextPreference) pref;
MinMaxInfos prefMinMax = listOfMinMaxInfos.get(editTextPref.getKey());
if (prefMinMax != null) {
int prefValue = 0;
if (!editTextPref.getText().isEmpty()) {
try {
prefValue = Integer.parseInt(editTextPref.getText());
} catch (Exception e) {
prefValue = 999999999;
}
}
if (prefValue < prefMinMax.min) {
prefValue = prefMinMax.min;
} else if (prefValue > prefMinMax.max) {
prefValue = prefMinMax.max;
}
editTextPref.setText(String.valueOf(prefValue));
}
} else if (key.equals(getString(R.string.settingsThemeUsed))) {
ThemeManager.updateThemeUsed();
if (getActivity() != null) {
getActivity().recreate();
}
} else if (key.equals(getString(R.string.settingsInvertToolbarTextColor))) {
ThemeManager.updateToolbarTextColor();
if (getActivity() != null) {
getActivity().recreate();
}
} else if (key.equals(getString(R.string.settingsPrimaryColorOfLightTheme)) || key.equals(getString(R.string.settingsTopicNameAndAccentColorOfLightTheme))) {
if (getActivity() != null) {
ThemeManager.updateColorsUsed(getResources());
getActivity().recreate();
}
} else if (key.startsWith("settings.customColor.")) {
if (getActivity() != null) {
ThemeManager.updateColorsUsed(getResources());
}
}
updatePrefSummary(pref);
}
use of com.takisoft.fix.support.v7.preference.EditTextPreference in project RespawnIRC-Android by FranckRJ.
the class SettingsFragment method updatePrefSummary.
private void updatePrefSummary(Preference pref) {
if (pref instanceof EditTextPreference) {
EditTextPreference editTextPref = (EditTextPreference) pref;
MinMaxInfos prefMinMax = listOfMinMaxInfos.get(editTextPref.getKey());
if (prefMinMax != null) {
editTextPref.setSummary("Entre " + String.valueOf(prefMinMax.min) + " et " + String.valueOf(prefMinMax.max) + " : " + editTextPref.getText());
}
}
}
use of com.takisoft.fix.support.v7.preference.EditTextPreference in project RespawnIRC-Android by FranckRJ.
the class SettingsFragment method updatePrefDefaultValue.
/* Le but de la clef temporaire est de ne pas sauvegarder l'option par défaut si c'est celle ci
* qui est retourné par "PrefsManager.getX()". La clef temporaire n'est pas vide pour empêcher
* des possibles crash (des histoires de requireKey() etc). Elle est unique par type de pref pour
* ne pas causer de crash lors de l'assignation d'un string à ce qui était précédement un bool.
* La persistance est temporairement à false pour plus de sécurité, au cas où, dans le doute,
* mais ça reste plutôt assez moche comme solution au final. */
private static void updatePrefDefaultValue(Preference pref) {
String realPrefKey = pref.getKey();
pref.setPersistent(false);
if (pref instanceof CheckBoxPreference) {
pref.setKey("tmpKeyBool");
CheckBoxPreference checkBoxPref = (CheckBoxPreference) pref;
checkBoxPref.setChecked(PrefsManager.getBool(realPrefKey));
} else if (pref instanceof SwitchPreferenceCompat) {
pref.setKey("tmpKeyBool");
SwitchPreferenceCompat switchPref = (SwitchPreferenceCompat) pref;
switchPref.setChecked(PrefsManager.getBool(realPrefKey));
} else if (pref instanceof EditTextPreference) {
pref.setKey("tmpKeyString");
EditTextPreference editTextPref = (EditTextPreference) pref;
editTextPref.setText(PrefsManager.getString(realPrefKey));
} else if (pref instanceof ListPreference) {
pref.setKey("tmpKeyString");
ListPreference listPref = (ListPreference) pref;
listPref.setValue(PrefsManager.getString(realPrefKey));
}
pref.setPersistent(true);
pref.setKey(realPrefKey);
}
use of com.takisoft.fix.support.v7.preference.EditTextPreference in project ring-client-android by savoirfairelinux.
the class GeneralAccountFragment method setPreferenceDetails.
private void setPreferenceDetails(AccountConfig details) {
for (ConfigKey confKey : details.getKeys()) {
Preference pref = findPreference(confKey.key());
if (pref == null) {
continue;
}
if (!confKey.isTwoState()) {
String val = details.get(confKey);
((EditTextPreference) pref).setText(val);
if (pref instanceof PasswordPreference) {
StringBuilder tmp = new StringBuilder();
for (int i = 0; i < val.length(); ++i) {
tmp.append("*");
}
pref.setSummary(tmp.toString());
} else {
pref.setSummary(val);
}
} else {
((TwoStatePreference) pref).setChecked(details.getBool(confKey));
}
}
}
use of com.takisoft.fix.support.v7.preference.EditTextPreference in project MPW by shineangelic.
the class SettingsFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.preferences);
// Crashlytics.getInstance().crash();
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
mFirebaseAnalytics = FirebaseAnalytics.getInstance(getActivity());
PoolEnum mPool = PoolEnum.valueOf(prefs.getString("poolEnum", ""));
CurrencyEnum mCur = CurrencyEnum.valueOf(prefs.getString("curEnum", ""));
final android.support.v7.preference.SwitchPreferenceCompat globalNotifications = (SwitchPreferenceCompat) findPreference("pref_notify");
final android.support.v7.preference.EditTextPreference walletAddr = (EditTextPreference) findPreference("wallet_addr");
final android.support.v7.preference.SwitchPreferenceCompat service = (SwitchPreferenceCompat) findPreference("pref_sync");
final android.support.v7.preference.ListPreference listFreqPreference = (ListPreference) findPreference("pref_sync_freq");
final android.support.v7.preference.SwitchPreferenceCompat offlineNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_offline");
final android.support.v7.preference.SwitchPreferenceCompat blockNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_block");
final android.support.v7.preference.SwitchPreferenceCompat paymentNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_payment");
// Service Enabled listener
Preference.OnPreferenceChangeListener listenerServ = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// newValue is the value you choose
listFreqPreference.setEnabled((Boolean) newValue);
Boolean nv = (Boolean) newValue;
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(getActivity()));
dispatcher.cancelAll();
if (nv) {
Job myJob = MPWService.getJobUpdate(prefs, dispatcher, true);
int res = dispatcher.schedule(myJob);
if (res != dispatcher.SCHEDULE_RESULT_SUCCESS) {
Toast.makeText(getActivity(), "Cannot enable service. Is Play Services up to date? Notifications won't work", Toast.LENGTH_SHORT).show();
return false;
}
Log.w(Constants.TAG, "SERVICE ACTIVE, schedule res: " + res);
}
// firebase log event
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, nv.toString());
mFirebaseAnalytics.logEvent("service_active", bundle);
return true;
}
};
service.setOnPreferenceChangeListener(listenerServ);
// Service FREQ listener
Preference.OnPreferenceChangeListener listenerServF = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Integer nv = Integer.valueOf((String) newValue);
// newValue is the value you choose
Log.w(Constants.TAG, "Changed FREQ setting to: " + nv);
// pezza perche il val ancora non c'e
prefs.edit().putString("pref_sync_freq", "" + nv).apply();
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(getActivity()));
Job myJob = MPWService.getJobUpdate(prefs, dispatcher, true);
dispatcher.schedule(myJob);
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "" + nv);
mFirebaseAnalytics.logEvent("service_freq", bundle);
return true;
}
};
listFreqPreference.setOnPreferenceChangeListener(listenerServF);
// Notification global
Preference.OnPreferenceChangeListener listener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Log.w(Constants.TAG, "Changed NOTIF setting to: " + newValue);
Boolean nv = (Boolean) newValue;
// newValue is the value you choose
blockNotifications.setEnabled(nv);
offlineNotifications.setEnabled(nv);
paymentNotifications.setEnabled(nv);
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "" + nv);
mFirebaseAnalytics.logEvent("service_notifications", bundle);
return true;
}
};
globalNotifications.setOnPreferenceChangeListener(listener);
// Listener x controllo correttezza
walletAddr.setOnPreferenceChangeListener(new WalletPrefChangeListener(getActivity(), mPool, mCur));
walletAddr.setSummary(getString(R.string.wallet_info, mPool.toString(), mCur.toString()));
walletAddr.setDialogTitle(mPool.toString() + " Network Login");
}
Aggregations