use of androidx.appcompat.widget.AppCompatEditText in project J2ME-Loader by nikita36078.
the class TextFieldImpl method getView.
EditText getView(Context context, Item item) {
if (textview == null) {
textview = new AppCompatEditText(context);
setMaxSize(maxSize);
setConstraints(constraints);
setString(text);
textview.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
text = s.toString();
}
});
if (item != null) {
textview.setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus)
item.notifyStateChanged();
});
} else {
textview.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
textview.setGravity(Gravity.TOP);
}
}
return textview;
}
use of androidx.appcompat.widget.AppCompatEditText in project AmazeFileManager by TeamAmaze.
the class WarnableTextInputValidatorTest method testValidate.
@Test
public void testValidate() {
EditText textfield = new AppCompatEditText(context);
WarnableTextInputLayout layout = new WarnableTextInputLayout(context, Robolectric.buildAttributeSet().build());
Button button = new AppCompatButton(context);
WarnableTextInputValidator.OnTextValidate validator = text -> ("Pass".equals(text)) ? new WarnableTextInputValidator.ReturnState(WarnableTextInputValidator.ReturnState.STATE_NORMAL, R.string.ok) : new WarnableTextInputValidator.ReturnState(WarnableTextInputValidator.ReturnState.STATE_ERROR, R.string.error);
WarnableTextInputValidator target = new WarnableTextInputValidator(ApplicationProvider.getApplicationContext(), textfield, layout, button, validator);
textfield.setText("");
target.performClick();
assertFalse(button.isEnabled());
assertEquals(context.getString(R.string.error), layout.getError());
textfield.setText("pass");
target.performClick();
assertFalse(button.isEnabled());
assertEquals(context.getString(R.string.error), layout.getError());
textfield.setText("Pass");
target.performClick();
assertTrue(button.isEnabled());
assertNull(layout.getError());
}
use of androidx.appcompat.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 = getString(R.string.cant_be_empty, getString(R.string.ip));
emptyName = getString(R.string.cant_be_empty, getString(R.string.connection_name));
invalidDomain = getString(R.string.invalid, getString(R.string.domain));
invalidUsername = 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_connection));
ba3.autoDismiss(false);
final View v2 = getActivity().getLayoutInflater().inflate(R.layout.smb_dialog, null);
final TextInputLayout connectionTIL = v2.findViewById(R.id.connectionTIL);
final TextInputLayout ipTIL = v2.findViewById(R.id.ipTIL);
final TextInputLayout domainTIL = v2.findViewById(R.id.domainTIL);
final TextInputLayout usernameTIL = v2.findViewById(R.id.usernameTIL);
final TextInputLayout passwordTIL = v2.findViewById(R.id.passwordTIL);
final AppCompatEditText conName = v2.findViewById(R.id.connectionET);
ExtensionsKt.makeRequired(connectionTIL);
ExtensionsKt.makeRequired(ipTIL);
ExtensionsKt.makeRequired(usernameTIL);
ExtensionsKt.makeRequired(passwordTIL);
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 = 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 share = v2.findViewById(R.id.shareET);
final AppCompatEditText domain = 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 = 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 = ((ThemedActivity) getActivity()).getAccent();
final AppCompatEditText pass = v2.findViewById(R.id.passwordET);
final AppCompatCheckBox chkSmbAnonymous = v2.findViewById(R.id.chkSmbAnonymous);
final AppCompatCheckBox chkSmbDisableIpcSignature = v2.findViewById(R.id.chkSmbDisableIpcSignature);
TextView help = v2.findViewById(R.id.wanthelp);
EditTextColorStateUtil.setTint(context, conName, accentColor);
EditTextColorStateUtil.setTint(context, user, accentColor);
EditTextColorStateUtil.setTint(context, pass, accentColor);
Utils.setTint(context, chkSmbAnonymous, accentColor);
help.setOnClickListener(v -> {
int accentColor1 = ((ThemedActivity) getActivity()).getAccent();
GeneralDialogCreation.showSMBHelpDialog(context, accentColor1);
});
chkSmbAnonymous.setOnClickListener(view -> {
if (chkSmbAnonymous.isChecked()) {
user.setEnabled(false);
pass.setEnabled(false);
} else {
user.setEnabled(true);
pass.setEnabled(true);
}
});
if (edit) {
String userp = "";
String passp = "";
String ipp = "";
String domainp = "";
String sharep = "";
conName.setText(name);
try {
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 {
chkSmbAnonymous.setChecked(true);
}
ipp = a.getHost();
sharep = a.getPath().replaceFirst("/", "").replaceAll("/$", "");
ip.setText(ipp);
share.setText(sharep);
UrlQuerySanitizer sanitizer = new UrlQuerySanitizer(path);
if (sanitizer.hasParameter(PARAM_DISABLE_IPC_SIGNING_CHECK)) {
chkSmbDisableIpcSignature.setChecked(Boolean.parseBoolean(sanitizer.getValue(PARAM_DISABLE_IPC_SIGNING_CHECK)));
}
} 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_connection);
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 sShare = share.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 (chkSmbAnonymous.isChecked())
smbFile = createSMBPath(new String[] { ipa, "", "", domaind, sShare }, true, false);
else {
String useraw = user.getText().toString();
String useru = useraw.replaceAll(" ", "\\ ");
String passp = pass.getText().toString();
smbFile = createSMBPath(new String[] { ipa, useru, passp, domaind, sShare }, false, false);
}
if (smbFile == null)
return;
StringBuilder extraParams = new StringBuilder();
if (chkSmbDisableIpcSignature.isChecked())
extraParams.append(PARAM_DISABLE_IPC_SIGNING_CHECK).append('=').append(true);
try {
s = new String[] { conName.getText().toString(), SmbUtil.getSmbEncryptedPath(getActivity(), smbFile.getPath()) };
} catch (GeneralSecurityException | IOException e) {
e.printStackTrace();
Toast.makeText(getActivity(), getString(R.string.error), Toast.LENGTH_LONG).show();
return;
}
if (smbConnectionListener != null) {
// encrypted path means path with encrypted pass
String qs = extraParams.length() > 0 ? extraParams.insert(0, '?').toString() : "";
smbConnectionListener.addConnection(edit, s[0], smbFile.getPath() + qs, s[1] + qs, name, path);
}
dismiss();
});
ba3.onNegative((dialog, which) -> {
if (smbConnectionListener != null) {
smbConnectionListener.deleteConnection(name, path);
}
dismiss();
});
ba3.onNeutral((dialog, which) -> dismiss());
return ba3.build();
}
use of androidx.appcompat.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), (dialogInterface, i) -> {
}).setPositiveButton(getString(R.string.ok), (dialogInterface, 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;
}
AppSettings.savePassword(Utils.encodeString(newPassword.getText().toString()), getActivity());
if (mFingerprint != null) {
mFingerprint.setEnabled(true);
}
}).setOnDismissListener(dialogInterface -> mOldPassword = null).show();
}
use of androidx.appcompat.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), (dialogInterface, i) -> {
if (!mPassword.getText().toString().equals(Utils.decodeString(password))) {
Utils.toast(getString(R.string.password_wrong), getActivity());
return;
}
AppSettings.resetPassword(getActivity());
if (mFingerprint != null) {
mFingerprint.setEnabled(false);
}
}).setOnDismissListener(dialogInterface -> mDeletePassword = null).show();
}
Aggregations