use of android.support.v7.widget.AppCompatEditText in project MTweaks-KernelAdiutorMOD by morogoku.
the class SettingsFragment method editPasswordDialog.
private void editPasswordDialog(final String oldPass) {
mOldPassword = oldPass;
LinearLayout linearLayout = new LinearLayout(getActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setGravity(Gravity.CENTER);
int padding = Math.round(getResources().getDimension(R.dimen.dialog_padding));
linearLayout.setPadding(padding, padding, padding, padding);
final AppCompatEditText oldPassword = new AppCompatEditText(getActivity());
if (!oldPass.isEmpty()) {
oldPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
oldPassword.setHint(getString(R.string.old_password));
linearLayout.addView(oldPassword);
}
final AppCompatEditText newPassword = new AppCompatEditText(getActivity());
newPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
newPassword.setHint(getString(R.string.new_password));
linearLayout.addView(newPassword);
final AppCompatEditText confirmNewPassword = new AppCompatEditText(getActivity());
confirmNewPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
confirmNewPassword.setHint(getString(R.string.confirm_new_password));
linearLayout.addView(confirmNewPassword);
new Dialog(getActivity()).setView(linearLayout).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
}).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (!oldPass.isEmpty() && !oldPassword.getText().toString().equals(Utils.decodeString(oldPass))) {
Utils.toast(getString(R.string.old_password_wrong), getActivity());
return;
}
if (newPassword.getText().toString().isEmpty()) {
Utils.toast(getString(R.string.password_empty), getActivity());
return;
}
if (!newPassword.getText().toString().equals(confirmNewPassword.getText().toString())) {
Utils.toast(getString(R.string.password_not_match), getActivity());
return;
}
if (newPassword.getText().toString().length() > 32) {
Utils.toast(getString(R.string.password_too_long), getActivity());
return;
}
Prefs.saveString("password", Utils.encodeString(newPassword.getText().toString()), getActivity());
if (mFingerprint != null) {
mFingerprint.setEnabled(true);
}
}
}).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
mOldPassword = null;
}
}).show();
}
use of android.support.v7.widget.AppCompatEditText in project MTweaks-KernelAdiutorMOD by morogoku.
the class SettingsFragment method deletePasswordDialog.
private void deletePasswordDialog(final String password) {
if (password.isEmpty()) {
Utils.toast(getString(R.string.set_password_first), getActivity());
return;
}
mDeletePassword = password;
LinearLayout linearLayout = new LinearLayout(getActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setGravity(Gravity.CENTER);
int padding = Math.round(getResources().getDimension(R.dimen.dialog_padding));
linearLayout.setPadding(padding, padding, padding, padding);
final AppCompatEditText mPassword = new AppCompatEditText(getActivity());
mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
mPassword.setHint(getString(R.string.password));
linearLayout.addView(mPassword);
new Dialog(getActivity()).setView(linearLayout).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (!mPassword.getText().toString().equals(Utils.decodeString(password))) {
Utils.toast(getString(R.string.password_wrong), getActivity());
return;
}
Prefs.saveString("password", "", getActivity());
if (mFingerprint != null) {
mFingerprint.setEnabled(false);
}
}
}).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
mDeletePassword = null;
}
}).show();
}
use of android.support.v7.widget.AppCompatEditText in project MTweaks-KernelAdiutorMOD by morogoku.
the class ViewUtils method dialogEditText.
public static Dialog dialogEditText(String text, final DialogInterface.OnClickListener negativeListener, final OnDialogEditTextListener onDialogEditTextListener, int inputType, Context context) {
LinearLayout layout = new LinearLayout(context);
int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding);
layout.setPadding(padding, padding, padding, padding);
final AppCompatEditText editText = new AppCompatEditText(context);
editText.setGravity(Gravity.CENTER);
editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
if (text != null) {
editText.append(text);
}
editText.setSingleLine(true);
if (inputType >= 0) {
editText.setInputType(inputType);
}
layout.addView(editText);
Dialog dialog = new Dialog(context).setView(layout);
if (negativeListener != null) {
dialog.setNegativeButton(context.getString(R.string.cancel), negativeListener);
}
if (onDialogEditTextListener != null) {
dialog.setPositiveButton(context.getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onDialogEditTextListener.onClick(editText.getText().toString());
}
}).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (negativeListener != null) {
negativeListener.onClick(dialog, 0);
}
}
});
}
return dialog;
}
use of android.support.v7.widget.AppCompatEditText in project AmazeFileManager by TeamAmaze.
the class FoldersPref method loadCreateDialog.
private void loadCreateDialog() {
int fab_skin = activity.getColorPreference().getColor(ColorUsage.ACCENT);
LayoutInflater li = LayoutInflater.from(activity);
// TODO: 29/4/2017 make this null not null
final View v = li.inflate(R.layout.dialog_twoedittexts, null);
((TextInputLayout) v.findViewById(R.id.text_input1)).setHint(getString(R.string.name));
((TextInputLayout) v.findViewById(R.id.text_input2)).setHint(getString(R.string.directory));
final AppCompatEditText editText1 = ((AppCompatEditText) v.findViewById(R.id.text1)), editText2 = ((AppCompatEditText) v.findViewById(R.id.text2));
final MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).title(R.string.create_shortcut).theme(activity.getAppTheme().getMaterialDialogTheme()).positiveColor(fab_skin).positiveText(R.string.create).negativeColor(fab_skin).negativeText(android.R.string.cancel).customView(v, false).build();
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
disableButtonIfTitleEmpty(editText1, dialog);
disableButtonIfNotPath(editText2, dialog);
dialog.getActionButton(DialogAction.POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PathSwitchPreference p = new PathSwitchPreference(getActivity());
p.setTitle(editText1.getText());
p.setSummary(editText2.getText());
p.setOnPreferenceClickListener(FoldersPref.this);
position.put(p, dataUtils.getBooks().size());
getPreferenceScreen().addPreference(p);
String[] values = new String[] { editText1.getText().toString(), editText2.getText().toString() };
dataUtils.addBook(values);
AppConfig.runInBackground(new Runnable() {
@Override
public void run() {
utilsHandler.addBookmark(editText1.getText().toString(), editText2.getText().toString());
}
});
dialog.dismiss();
}
});
dialog.show();
}
use of android.support.v7.widget.AppCompatEditText in project AmazeFileManager by TeamAmaze.
the class SmbConnectDialog method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final boolean edit = getArguments().getBoolean("edit", false);
final String path = getArguments().getString("path");
final String name = getArguments().getString("name");
context = getActivity();
emptyAddress = String.format(getString(R.string.cantbeempty), getString(R.string.ip));
emptyName = String.format(getString(R.string.cantbeempty), getString(R.string.connectionname));
invalidDomain = String.format(getString(R.string.invalid), getString(R.string.domain));
invalidUsername = String.format(getString(R.string.invalid), getString(R.string.username).toLowerCase());
if (getActivity() instanceof SmbConnectionListener) {
smbConnectionListener = (SmbConnectionListener) getActivity();
}
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
final MaterialDialog.Builder ba3 = new MaterialDialog.Builder(context);
ba3.title((R.string.smb_con));
ba3.autoDismiss(false);
final View v2 = getActivity().getLayoutInflater().inflate(R.layout.smb_dialog, null);
final TextInputLayout connectionTIL = (TextInputLayout) v2.findViewById(R.id.connectionTIL);
final TextInputLayout ipTIL = (TextInputLayout) v2.findViewById(R.id.ipTIL);
final TextInputLayout domainTIL = (TextInputLayout) v2.findViewById(R.id.domainTIL);
final TextInputLayout usernameTIL = (TextInputLayout) v2.findViewById(R.id.usernameTIL);
final AppCompatEditText conName = (AppCompatEditText) v2.findViewById(R.id.connectionET);
conName.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void afterTextChanged(Editable s) {
if (conName.getText().toString().length() == 0)
connectionTIL.setError(emptyName);
else
connectionTIL.setError("");
}
});
final AppCompatEditText ip = (AppCompatEditText) v2.findViewById(R.id.ipET);
ip.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void afterTextChanged(Editable s) {
if (ip.getText().toString().length() == 0)
ipTIL.setError(emptyAddress);
else
ipTIL.setError("");
}
});
final AppCompatEditText domain = (AppCompatEditText) v2.findViewById(R.id.domainET);
domain.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void afterTextChanged(Editable s) {
if (domain.getText().toString().contains(";"))
domainTIL.setError(invalidDomain);
else
domainTIL.setError("");
}
});
final AppCompatEditText user = (AppCompatEditText) v2.findViewById(R.id.usernameET);
user.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void afterTextChanged(Editable s) {
if (user.getText().toString().contains(":"))
usernameTIL.setError(invalidUsername);
else
usernameTIL.setError("");
}
});
int accentColor = utilsProvider.getColorPreference().getColor(ColorUsage.ACCENT);
final AppCompatEditText pass = (AppCompatEditText) v2.findViewById(R.id.passwordET);
final AppCompatCheckBox ch = (AppCompatCheckBox) v2.findViewById(R.id.checkBox2);
TextView help = (TextView) v2.findViewById(R.id.wanthelp);
EditTextColorStateUtil.setTint(context, conName, accentColor);
EditTextColorStateUtil.setTint(context, user, accentColor);
EditTextColorStateUtil.setTint(context, pass, accentColor);
Utils.setTint(context, ch, accentColor);
help.setOnClickListener(v -> {
int accentColor1 = ((ThemedActivity) getActivity()).getColorPreference().getColor(ColorUsage.ACCENT);
GeneralDialogCreation.showSMBHelpDialog(context, accentColor1);
});
ch.setOnClickListener(view -> {
if (ch.isChecked()) {
user.setEnabled(false);
pass.setEnabled(false);
} else {
user.setEnabled(true);
pass.setEnabled(true);
}
});
if (edit) {
String userp = "", passp = "", ipp = "", domainp = "";
conName.setText(name);
try {
jcifs.Config.registerSmbURLHandler();
URL a = new URL(path);
String userinfo = a.getUserInfo();
if (userinfo != null) {
String inf = URLDecoder.decode(userinfo, "UTF-8");
int domainDelim = !inf.contains(";") ? 0 : inf.indexOf(';');
domainp = inf.substring(0, domainDelim);
if (domainp != null && domainp.length() > 0)
inf = inf.substring(domainDelim + 1);
userp = inf.substring(0, inf.indexOf(":"));
passp = inf.substring(inf.indexOf(":") + 1, inf.length());
domain.setText(domainp);
user.setText(userp);
pass.setText(passp);
} else
ch.setChecked(true);
ipp = a.getHost();
ip.setText(ipp);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
} else if (path != null && path.length() > 0) {
conName.setText(name);
ip.setText(path);
user.requestFocus();
} else {
conName.setText(R.string.smb_con);
conName.requestFocus();
}
ba3.customView(v2, true);
ba3.theme(utilsProvider.getAppTheme().getMaterialDialogTheme());
ba3.neutralText(R.string.cancel);
ba3.positiveText(R.string.create);
if (edit)
ba3.negativeText(R.string.delete);
ba3.positiveColor(accentColor).negativeColor(accentColor).neutralColor(accentColor);
ba3.onPositive((dialog, which) -> {
String[] s;
String ipa = ip.getText().toString();
String con_nam = conName.getText().toString();
String sDomain = domain.getText().toString();
String username = user.getText().toString();
TextInputLayout firstInvalidField = null;
if (con_nam == null || con_nam.length() == 0) {
connectionTIL.setError(emptyName);
firstInvalidField = connectionTIL;
}
if (ipa == null || ipa.length() == 0) {
ipTIL.setError(emptyAddress);
if (firstInvalidField == null)
firstInvalidField = ipTIL;
}
if (sDomain.contains(";")) {
domainTIL.setError(invalidDomain);
if (firstInvalidField == null)
firstInvalidField = domainTIL;
}
if (username.contains(":")) {
usernameTIL.setError(invalidUsername);
if (firstInvalidField == null)
firstInvalidField = usernameTIL;
}
if (firstInvalidField != null) {
firstInvalidField.requestFocus();
return;
}
SmbFile smbFile;
String domaind = domain.getText().toString();
if (ch.isChecked())
smbFile = createSMBPath(new String[] { ipa, "", "", domaind }, true);
else {
String useraw = user.getText().toString();
String useru = useraw.replaceAll(" ", "\\ ");
String passp = pass.getText().toString();
smbFile = createSMBPath(new String[] { ipa, useru, passp, domaind }, false);
}
if (smbFile == null)
return;
try {
s = new String[] { conName.getText().toString(), SmbUtil.getSmbEncryptedPath(getActivity(), smbFile.getPath()) };
} catch (GeneralSecurityException | IOException e) {
e.printStackTrace();
Toast.makeText(getActivity(), getResources().getString(R.string.error), Toast.LENGTH_LONG).show();
return;
}
if (smbConnectionListener != null) {
// encrypted path means path with encrypted pass
smbConnectionListener.addConnection(edit, s[0], smbFile.getPath(), s[1], name, path);
}
dismiss();
});
ba3.onNegative((dialog, which) -> {
if (smbConnectionListener != null) {
smbConnectionListener.deleteConnection(name, path);
}
dismiss();
});
ba3.onNeutral((dialog, which) -> dismiss());
return ba3.build();
}
Aggregations