use of android.preference.EditTextPreference in project android_packages_apps_Dialer by LineageOS.
the class ConfigOverrideFragment method loadCurrentConfig.
/**
* Loads the config for the currently carrier into the override values, from the dialer or the
* carrier config app. This is a "reset" button to load the defaults.
*/
private void loadCurrentConfig() {
Context context = getActivity();
PhoneAccountHandle phoneAccountHandle = context.getSystemService(TelecomManager.class).getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_VOICEMAIL);
PersistableBundle config = VoicemailComponent.get(context).getVoicemailClient().getConfig(context, phoneAccountHandle);
for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
Preference preference = getPreferenceScreen().getPreference(i);
String key = preference.getKey();
if (!key.startsWith(CONFIG_OVERRIDE_KEY_PREFIX)) {
continue;
}
String configKey = key.substring(CONFIG_OVERRIDE_KEY_PREFIX.length());
if (configKey.endsWith("bool")) {
((SwitchPreference) preference).setChecked(config.getBoolean(configKey));
} else if (configKey.endsWith("int")) {
((EditTextPreference) preference).setText(String.valueOf(config.getInt(configKey)));
} else if (configKey.endsWith("string")) {
((EditTextPreference) preference).setText(config.getString(configKey));
} else if (configKey.endsWith("string_array")) {
((EditTextPreference) preference).setText(toCsv(config.getStringArray(configKey)));
} else {
throw Assert.createAssertionFailException("unknown type for key " + configKey);
}
updatePreference(preference);
}
}
use of android.preference.EditTextPreference in project android_packages_apps_Dialer by LineageOS.
the class ConfigOverrideFragment method updatePreference.
private void updatePreference(Preference preference) {
if (preference instanceof EditTextPreference) {
EditTextPreference editTextPreference = (EditTextPreference) preference;
editTextPreference.setSummary(editTextPreference.getText());
}
}
use of android.preference.EditTextPreference in project fdroidclient by f-droid.
the class PreferencesFragment method updateSummary.
private void updateSummary(String key, boolean changing) {
switch(key) {
case Preferences.PREF_UPD_INTERVAL:
ListPreference listPref = (ListPreference) findPreference(Preferences.PREF_UPD_INTERVAL);
int interval = Integer.parseInt(listPref.getValue());
Preference onlyOnWifi = findPreference(Preferences.PREF_UPD_WIFI_ONLY);
onlyOnWifi.setEnabled(interval > 0);
if (interval == 0) {
listPref.setSummary(R.string.update_interval_zero);
} else {
listPref.setSummary(listPref.getEntry());
}
break;
case Preferences.PREF_UPD_WIFI_ONLY:
checkSummary(key, R.string.automatic_scan_wifi_on);
break;
case Preferences.PREF_UPD_NOTIFY:
checkSummary(key, R.string.notify_on);
break;
case Preferences.PREF_THEME:
entrySummary(key);
if (changing) {
Activity activity = getActivity();
fdroidApp = (FDroidApp) activity.getApplication();
fdroidApp.reloadTheme();
fdroidApp.applyTheme(activity);
fdroidApp.forceChangeTheme(activity);
}
break;
case Preferences.PREF_SHOW_INCOMPAT_VERSIONS:
checkSummary(key, R.string.show_incompat_versions_on);
break;
case Preferences.PREF_SHOW_ROOT_APPS:
checkSummary(key, R.string.show_root_apps_on);
break;
case Preferences.PREF_SHOW_ANTI_FEATURE_APPS:
checkSummary(key, R.string.show_anti_feature_apps_on);
break;
case Preferences.PREF_FORCE_TOUCH_APPS:
checkSummary(key, R.string.force_touch_apps_on);
break;
case Preferences.PREF_LOCAL_REPO_NAME:
textSummary(key, R.string.local_repo_name_summary);
break;
case Preferences.PREF_LOCAL_REPO_HTTPS:
checkSummary(key, R.string.local_repo_https_on);
break;
case Preferences.PREF_LANGUAGE:
entrySummary(key);
if (changing) {
Activity activity = getActivity();
Languages.setLanguage(activity);
RepoProvider.Helper.clearEtags(getContext());
UpdateService.updateNow(getContext());
Languages.forceChangeLanguage(activity);
}
break;
case Preferences.PREF_KEEP_CACHE_TIME:
entrySummary(key);
if (changing && currentKeepCacheTime != Preferences.get().getKeepCacheTime()) {
CleanCacheService.schedule(getContext());
}
break;
case Preferences.PREF_EXPERT:
checkSummary(key, R.string.expert_on);
break;
case Preferences.PREF_PRIVILEGED_INSTALLER:
// We may have removed this preference if it is not suitable to show the user.
// So lets check it is here first.
final CheckBoxPreference pref = (CheckBoxPreference) findPreference(Preferences.PREF_PRIVILEGED_INSTALLER);
if (pref != null) {
checkSummary(key, R.string.system_installer_on);
}
break;
case Preferences.PREF_ENABLE_PROXY:
CheckBoxPreference checkPref = (CheckBoxPreference) findPreference(key);
checkPref.setSummary(R.string.enable_proxy_summary);
break;
case Preferences.PREF_PROXY_HOST:
EditTextPreference textPref = (EditTextPreference) findPreference(key);
String text = Preferences.get().getProxyHost();
if (TextUtils.isEmpty(text) || text.equals(Preferences.DEFAULT_PROXY_HOST)) {
textPref.setSummary(R.string.proxy_host_summary);
} else {
textPref.setSummary(text);
}
break;
case Preferences.PREF_PROXY_PORT:
EditTextPreference textPref2 = (EditTextPreference) findPreference(key);
int port = Preferences.get().getProxyPort();
if (port == Preferences.DEFAULT_PROXY_PORT) {
textPref2.setSummary(R.string.proxy_port_summary);
} else {
textPref2.setSummary(String.valueOf(port));
}
break;
case Preferences.PREF_KEEP_INSTALL_HISTORY:
CheckBoxPreference p = (CheckBoxPreference) findPreference(key);
if (p.isChecked()) {
InstallHistoryService.register(getContext());
} else {
InstallHistoryService.unregister(getContext());
}
break;
}
}
use of android.preference.EditTextPreference in project fdroidclient by f-droid.
the class PreferencesFragment method textSummary.
private void textSummary(String key, int resId) {
EditTextPreference pref = (EditTextPreference) findPreference(key);
pref.setSummary(getString(resId, pref.getText()));
}
use of android.preference.EditTextPreference in project samourai-wallet-android by Samourai-Wallet.
the class SettingsActivity2 method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey("branch")) {
String strBranch = extras.getString("branch");
if (strBranch.equals("prefs")) {
addPreferencesFromResource(R.xml.settings_prefs);
Preference fiatPref = (Preference) findPreference("fiat");
fiatPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
getExchange();
return true;
}
});
Preference explorersPref = (Preference) findPreference("explorer");
explorersPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
getBlockExplorer();
return true;
}
});
} else if (strBranch.equals("txs")) {
addPreferencesFromResource(R.xml.settings_txs);
final CheckBoxPreference cbPref0 = (CheckBoxPreference) findPreference("segwit");
cbPref0.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (cbPref0.isChecked()) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.USE_SEGWIT, false);
} else {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.USE_SEGWIT, true);
}
return true;
}
});
final CheckBoxPreference cbPref15 = (CheckBoxPreference) findPreference("likeTypedChange");
cbPref15.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (cbPref15.isChecked()) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.USE_LIKE_TYPED_CHANGE, false);
} else {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.USE_LIKE_TYPED_CHANGE, true);
}
return true;
}
});
final CheckBoxPreference cbPref7 = (CheckBoxPreference) findPreference("bip126");
cbPref7.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (cbPref7.isChecked()) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.USE_BIP126, false);
} else {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.USE_BIP126, true);
}
return true;
}
});
final CheckBoxPreference cbPref9 = (CheckBoxPreference) findPreference("rbf");
cbPref9.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (cbPref9.isChecked()) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.RBF_OPT_IN, false);
} else {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.RBF_OPT_IN, true);
}
return true;
}
});
Preference trustedNodePref = (Preference) findPreference("trustedNode");
trustedNodePref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
getTrustedNode();
return true;
}
});
final CheckBoxPreference cbPref8 = (CheckBoxPreference) findPreference("useTrustedNode");
if (TrustedNodeUtil.getInstance().isSet() && TrustedNodeUtil.getInstance().isValidated()) {
cbPref8.setEnabled(true);
} else {
cbPref8.setEnabled(false);
}
cbPref8.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (cbPref8.isChecked()) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.USE_TRUSTED_NODE, false);
} else if (TrustedNodeUtil.getInstance().isSet() && TrustedNodeUtil.getInstance().isValidated()) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.USE_TRUSTED_NODE, true);
} else {
Toast.makeText(SettingsActivity2.this, R.string.trusted_node_not_valid, Toast.LENGTH_SHORT).show();
cbPref8.setEnabled(false);
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.USE_TRUSTED_NODE, false);
}
return true;
}
});
Preference feeproviderPref = (Preference) findPreference("feeProvider");
feeproviderPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
getFeeProvider();
return true;
}
});
final CheckBoxPreference cbPref10 = (CheckBoxPreference) findPreference("broadcastTx");
cbPref10.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (cbPref10.isChecked()) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.BROADCAST_TX, false);
} else {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.BROADCAST_TX, true);
}
return true;
}
});
Preference broadcastHexPref = (Preference) findPreference("broadcastHex");
broadcastHexPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
doBroadcastHex();
return true;
}
});
} else if (strBranch.equals("stealth")) {
addPreferencesFromResource(R.xml.settings_stealth);
final CheckBoxPreference cbPref1 = (CheckBoxPreference) findPreference("stealthDisplay");
cbPref1.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final ComponentName component = new ComponentName(getApplicationContext().getPackageName(), "com.samourai.wallet.Launcher");
if (component != null) {
if (cbPref1.isChecked()) {
getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.ICON_HIDDEN, false);
stopService(new Intent(SettingsActivity2.this, BroadcastReceiverService.class));
startService(new Intent(SettingsActivity2.this, BroadcastReceiverService.class));
AppUtil.getInstance(SettingsActivity2.this).restartApp();
} else {
String strMsg = SettingsActivity2.this.getString(R.string.options_stealth_display2);
new AlertDialog.Builder(SettingsActivity2.this).setIcon(R.drawable.ic_launcher).setTitle(R.string.options_stealth_display).setMessage(strMsg).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
// @Override
public void onClick(DialogInterface dialog, int which) {
steathActivating = true;
getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.ICON_HIDDEN, true);
stopService(new Intent(SettingsActivity2.this, BroadcastReceiverService.class));
startService(new Intent(SettingsActivity2.this, BroadcastReceiverService.class));
try {
PayloadUtil.getInstance(SettingsActivity2.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(SettingsActivity2.this).getGUID() + AccessFactory.getInstance(SettingsActivity2.this).getPIN()));
} catch (Exception e) {
;
}
}
}).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
// @Override
public void onClick(DialogInterface dialog, int which) {
cbPref1.setChecked(false);
}
}).show();
}
}
return true;
}
});
final Preference remotePinPref = (Preference) findPreference("remote_pin");
remotePinPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
if (steathActivating) {
Toast.makeText(SettingsActivity2.this, R.string.alternative_pin_wait, Toast.LENGTH_SHORT).show();
} else {
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.alternative_pin_create).setCancelable(false).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
final EditText pin = new EditText(SettingsActivity2.this);
pin.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.pin_5_8).setView(pin).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
final String _pin = pin.getText().toString();
if (_pin != null && _pin.length() >= AccessFactory.MIN_PIN_LENGTH && _pin.length() <= AccessFactory.MAX_PIN_LENGTH) {
final EditText pin2 = new EditText(SettingsActivity2.this);
pin2.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.pin_5_8_confirm).setView(pin2).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String _pin2 = pin2.getText().toString();
if (_pin2 != null && _pin2.equals(_pin)) {
String hash = AccessFactory.getInstance(SettingsActivity2.this).getHash(AccessFactory.getInstance(SettingsActivity2.this).getGUID(), new CharSequenceX(_pin), AESUtil.DefaultPBKDF2Iterations);
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.ACCESS_HASH2, hash);
AccessFactory.getInstance(SettingsActivity2.this).setPIN2(_pin2);
try {
PayloadUtil.getInstance(SettingsActivity2.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(SettingsActivity2.this).getGUID() + AccessFactory.getInstance(SettingsActivity2.this).getPIN()));
} catch (JSONException je) {
je.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} catch (DecryptionException de) {
de.printStackTrace();
} finally {
Toast.makeText(SettingsActivity2.this.getApplicationContext(), R.string.success_change_pin, Toast.LENGTH_SHORT).show();
}
}
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
} else {
AccessFactory.getInstance(SettingsActivity2.this).setPIN2("");
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.ACCESS_HASH2, PrefsUtil.getInstance(SettingsActivity2.this).getValue(PrefsUtil.ACCESS_HASH, ""));
Toast.makeText(SettingsActivity2.this, R.string.alternative_pin_deleted, Toast.LENGTH_SHORT).show();
}
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
}
}).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
}
return true;
}
});
} else if (strBranch.equals("remote")) {
addPreferencesFromResource(R.xml.settings_remote);
final CheckBoxPreference cbPref2 = (CheckBoxPreference) findPreference("stealthRemote");
final CheckBoxPreference cbPref3 = (CheckBoxPreference) findPreference("trustedLock");
final CheckBoxPreference cbPref4 = (CheckBoxPreference) findPreference("sim_switch");
final EditTextPreference textPref1 = (EditTextPreference) findPreference("alertSMSNo");
cbPref2.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (cbPref2.isChecked()) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.ACCEPT_REMOTE, false);
stopService(new Intent(SettingsActivity2.this, BroadcastReceiverService.class));
startService(new Intent(SettingsActivity2.this, BroadcastReceiverService.class));
} else {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.ACCEPT_REMOTE, true);
stopService(new Intent(SettingsActivity2.this, BroadcastReceiverService.class));
startService(new Intent(SettingsActivity2.this, BroadcastReceiverService.class));
}
return true;
}
});
cbPref3.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (cbPref3.isChecked()) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.TRUSTED_LOCK, false);
} else {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.TRUSTED_LOCK, true);
}
return true;
}
});
cbPref4.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (cbPref4.isChecked()) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.CHECK_SIM, false);
} else {
SIMUtil.getInstance(SettingsActivity2.this).setStoredSIM();
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.CHECK_SIM, true);
}
return true;
}
});
textPref1.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
String telno = newValue.toString();
if (telno != null && telno.length() > 0) {
String s = telno.replaceAll("[^\\+0-9]", "");
if (s.matches("^\\+[0-9]+$")) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.ALERT_MOBILE_NO, s);
cbPref3.setEnabled(true);
cbPref4.setEnabled(true);
} else {
Toast.makeText(SettingsActivity2.this, "Use international dialing format. Ex.:'+447385555555'", Toast.LENGTH_SHORT).show();
}
} else {
cbPref3.setEnabled(false);
cbPref3.setChecked(false);
cbPref4.setEnabled(false);
cbPref4.setChecked(false);
}
return true;
}
});
} else if (strBranch.equals("wallet")) {
addPreferencesFromResource(R.xml.settings_wallet);
Preference mnemonicPref = (Preference) findPreference("mnemonic");
mnemonicPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
getHDSeed(true);
return true;
}
});
Preference xpubPref = (Preference) findPreference("xpub");
xpubPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
getXPUB();
return true;
}
});
Preference ypubPref = (Preference) findPreference("ypub");
ypubPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
getYPUB();
return true;
}
});
Preference wipePref = (Preference) findPreference("wipe");
wipePref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.sure_to_erase).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
final ProgressDialog progress = new ProgressDialog(SettingsActivity2.this);
progress.setTitle(R.string.app_name);
progress.setMessage(SettingsActivity2.this.getResources().getString(R.string.securely_wiping_wait));
progress.setCancelable(false);
progress.show();
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
AppUtil.getInstance(SettingsActivity2.this).wipeApp();
Toast.makeText(SettingsActivity2.this, R.string.wallet_erased, Toast.LENGTH_SHORT).show();
AppUtil.getInstance(SettingsActivity2.this).restartApp();
if (progress != null && progress.isShowing()) {
progress.dismiss();
}
Looper.loop();
}
}).start();
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
return true;
}
});
final CheckBoxPreference cbPref5 = (CheckBoxPreference) findPreference("scramblePin");
cbPref5.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (cbPref5.isChecked()) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.SCRAMBLE_PIN, false);
} else {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.SCRAMBLE_PIN, true);
}
return true;
}
});
final CheckBoxPreference cbPref11 = (CheckBoxPreference) findPreference("haptic");
cbPref11.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (cbPref11.isChecked()) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.HAPTIC_PIN, false);
} else {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.HAPTIC_PIN, true);
}
return true;
}
});
Preference changePinPref = (Preference) findPreference("change_pin");
changePinPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.confirm_change_pin).setCancelable(false).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
final EditText pin = new EditText(SettingsActivity2.this);
pin.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.pin_enter).setView(pin).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String _pin = pin.getText().toString();
if (_pin != null && _pin.length() >= AccessFactory.MIN_PIN_LENGTH && _pin.length() <= AccessFactory.MAX_PIN_LENGTH) {
String hash = PrefsUtil.getInstance(SettingsActivity2.this).getValue(PrefsUtil.ACCESS_HASH, "");
if (AccessFactory.getInstance(SettingsActivity2.this).validateHash(hash, AccessFactory.getInstance(SettingsActivity2.this).getGUID(), new CharSequenceX(_pin), AESUtil.DefaultPBKDF2Iterations)) {
final EditText pin = new EditText(SettingsActivity2.this);
pin.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.pin_5_8).setView(pin).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
final String _pin = pin.getText().toString();
if (_pin != null && _pin.length() >= AccessFactory.MIN_PIN_LENGTH && _pin.length() <= AccessFactory.MAX_PIN_LENGTH) {
final EditText pin2 = new EditText(SettingsActivity2.this);
pin2.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.pin_5_8_confirm).setView(pin2).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String _pin2 = pin2.getText().toString();
if (_pin2 != null && _pin2.equals(_pin)) {
String accessHash = PrefsUtil.getInstance(SettingsActivity2.this).getValue(PrefsUtil.ACCESS_HASH, "");
String accessHash2 = PrefsUtil.getInstance(SettingsActivity2.this).getValue(PrefsUtil.ACCESS_HASH2, "");
String hash = AccessFactory.getInstance(SettingsActivity2.this).getHash(AccessFactory.getInstance(SettingsActivity2.this).getGUID(), new CharSequenceX(_pin), AESUtil.DefaultPBKDF2Iterations);
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.ACCESS_HASH, hash);
if (accessHash.equals(accessHash2)) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.ACCESS_HASH2, hash);
}
AccessFactory.getInstance(SettingsActivity2.this).setPIN(_pin2);
try {
PayloadUtil.getInstance(SettingsActivity2.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(SettingsActivity2.this).getGUID() + _pin));
} catch (JSONException je) {
je.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} catch (DecryptionException de) {
de.printStackTrace();
} finally {
Toast.makeText(SettingsActivity2.this.getApplicationContext(), R.string.success_change_pin, Toast.LENGTH_SHORT).show();
}
}
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
}
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
} else {
Toast.makeText(SettingsActivity2.this.getApplicationContext(), R.string.pin_error, Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(SettingsActivity2.this.getApplicationContext(), R.string.pin_error, Toast.LENGTH_SHORT).show();
}
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
}
}).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
return true;
}
});
final CheckBoxPreference cbPref6 = (CheckBoxPreference) findPreference("autoBackup");
if (!SamouraiWallet.getInstance().hasPassphrase(SettingsActivity2.this)) {
cbPref6.setChecked(false);
cbPref6.setEnabled(false);
} else {
cbPref6.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (cbPref6.isChecked()) {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.AUTO_BACKUP, false);
} else {
PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.AUTO_BACKUP, true);
}
return true;
}
});
}
} else if (strBranch.equals("networking")) {
addPreferencesFromResource(R.xml.settings_networking);
Preference vpnPref = (Preference) findPreference("VPN");
vpnPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
PackageManager pm = SettingsActivity2.this.getPackageManager();
try {
pm.getPackageInfo(AppUtil.OPENVPN_PACKAGE_ID, 0);
Intent intent = getPackageManager().getLaunchIntentForPackage(AppUtil.OPENVPN_PACKAGE_ID);
startActivity(intent);
} catch (PackageManager.NameNotFoundException nnfe) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + AppUtil.OPENVPN_PACKAGE_ID));
startActivity(intent);
}
return true;
}
});
final Preference torPref = (Preference) findPreference("Tor");
if (!OrbotHelper.isOrbotInstalled(SettingsActivity2.this)) {
torPref.setSummary(R.string.tor_install);
} else if (TorUtil.getInstance(SettingsActivity2.this).statusFromBroadcast()) {
torPref.setSummary(R.string.tor_routing_on);
} else {
torPref.setSummary(R.string.tor_routing_off);
}
torPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
if (!OrbotHelper.isOrbotInstalled(SettingsActivity2.this)) {
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.you_must_have_orbot).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Intent intent = OrbotHelper.getOrbotInstallIntent(SettingsActivity2.this);
startActivity(intent);
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
} else if (TorUtil.getInstance(SettingsActivity2.this).statusFromBroadcast()) {
TorUtil.getInstance(SettingsActivity2.this).setStatusFromBroadcast(false);
torPref.setSummary(R.string.tor_routing_off);
} else {
OrbotHelper.requestStartTor(SettingsActivity2.this);
TorUtil.getInstance(SettingsActivity2.this).setStatusFromBroadcast(true);
torPref.setSummary(R.string.tor_routing_on);
}
return true;
}
});
} else if (strBranch.equals("troubleshoot")) {
addPreferencesFromResource(R.xml.settings_troubleshoot);
Preference troubleshootPref = (Preference) findPreference("troubleshoot");
troubleshootPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
doTroubleshoot();
return true;
}
});
Preference sendBackupPref = (Preference) findPreference("send_backup_support");
sendBackupPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.prompt_send_backup_to_support).setCancelable(false).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
doSendBackup();
}
}).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
return true;
}
});
} else if (strBranch.equals("other")) {
addPreferencesFromResource(R.xml.settings_other);
Preference hashPref = (Preference) findPreference("hash");
hashPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
try {
File apk = new File(SettingsActivity2.this.getPackageCodePath());
MessageDigest md = MessageDigest.getInstance("SHA-256");
FileInputStream fis = new FileInputStream(apk);
byte[] dataBytes = new byte[1024 * 8];
int nread = 0;
while ((nread = fis.read(dataBytes)) != -1) {
md.update(dataBytes, 0, nread);
}
;
byte[] hval = md.digest();
String hash = Hex.toHexString(hval);
TextView showText = new TextView(SettingsActivity2.this);
showText.setText(hash);
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setView(showText).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
} catch (Exception e) {
;
}
return true;
}
});
Preference aboutPref = (Preference) findPreference("about");
aboutPref.setSummary("Samourai," + " " + getResources().getString(R.string.version_name));
aboutPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(SettingsActivity2.this, AboutActivity.class);
startActivity(intent);
return true;
}
});
} else {
finish();
}
} else {
finish();
}
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
Aggregations