use of android.text.InputFilter in project AndroidChromium by JackyAndroid.
the class EditorView method addFieldViewToEditor.
private View addFieldViewToEditor(ViewGroup parent, final EditorFieldModel fieldModel) {
View childView = null;
if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_ICONS) {
childView = new EditorIconsField(mContext, parent, fieldModel).getLayout();
} else if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_LABEL) {
childView = new EditorLabelField(mContext, parent, fieldModel).getLayout();
} else if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_DROPDOWN) {
Runnable prepareEditorRunnable = new Runnable() {
@Override
public void run() {
// The fields may have changed.
prepareEditor();
if (mObserverForTest != null)
mObserverForTest.onPaymentRequestReadyToEdit();
}
};
EditorDropdownField dropdownView = new EditorDropdownField(mContext, parent, fieldModel, prepareEditorRunnable);
mFieldViews.add(dropdownView);
mDropdownFields.add(dropdownView.getDropdown());
childView = dropdownView.getLayout();
} else if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_CHECKBOX) {
final CheckBox checkbox = new CheckBox(mLayout.getContext());
checkbox.setId(R.id.payments_edit_checkbox);
checkbox.setText(fieldModel.getLabel());
checkbox.setChecked(fieldModel.isChecked());
checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
fieldModel.setIsChecked(isChecked);
if (mObserverForTest != null)
mObserverForTest.onPaymentRequestReadyToEdit();
}
});
childView = checkbox;
} else {
InputFilter filter = null;
TextWatcher formatter = null;
if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_CREDIT_CARD) {
filter = mCardNumberInputFilter;
formatter = mCardNumberFormatter;
} else if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_PHONE) {
formatter = mPhoneFormatter;
}
EditorTextField inputLayout = new EditorTextField(mContext, fieldModel, mEditorActionListener, filter, formatter, mObserverForTest);
mFieldViews.add(inputLayout);
EditText input = inputLayout.getEditText();
mEditableTextFields.add(input);
if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_CREDIT_CARD) {
assert mCardInput == null;
mCardInput = input;
} else if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_PHONE) {
assert mPhoneInput == null;
mPhoneInput = input;
}
childView = inputLayout;
}
parent.addView(childView);
return childView;
}
use of android.text.InputFilter in project hypertrack-live-android by hypertrack.
the class Verify method initView.
private void initView() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
otpEditText = (EditText) findViewById(R.id.otp_edit_text);
verifyOTP = (Button) findViewById(R.id.verify_otp);
progressBar = (ProgressBar) findViewById(R.id.progress_bar);
timerText = (TextView) findViewById(R.id.timer);
verifyOTP.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (HTTextUtils.isEmpty(otpEditText.getText().toString())) {
Toast.makeText(Verify.this, "Please enter OTP", Toast.LENGTH_SHORT).show();
return;
}
showProgress(true);
presenter.verifyOTP(otpEditText.getText().toString(), Verify.this);
}
});
timerText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (timerText.isClickable()) {
presenter.resendOTP(Verify.this);
showProgress(true);
}
}
});
otpEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(4) });
otpEditText.requestFocus();
otpEditText.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) {
if (!HTTextUtils.isEmpty(otpEditText.getText().toString())) {
if (otpEditText.getText().length() == 4) {
showProgress(true);
presenter.verifyOTP(otpEditText.getText().toString(), Verify.this);
verifyOTP.setText("Verifying...");
} else {
verifyOTP.setText("Verify");
}
} else {
verifyOTP.setText("Verify");
}
}
});
Utils.showKeyboard(this, otpEditText);
}
use of android.text.InputFilter in project android_packages_apps_Settings by SudaMod.
the class Utf8ByteLengthFilterTest method testFilter.
@SmallTest
public void testFilter() {
// Define the variables
CharSequence source;
SpannableStringBuilder dest;
// Constructor to create a LengthFilter
InputFilter lengthFilter = new Utf8ByteLengthFilter(10);
InputFilter[] filters = { lengthFilter };
// filter() implicitly invoked. If the total length > filter length, the filter will
// cut off the source CharSequence from beginning to fit the filter length.
source = "abc";
dest = new SpannableStringBuilder("abcdefgh");
dest.setFilters(filters);
dest.insert(1, source);
String expectedString1 = "aabbcdefgh";
assertEquals(expectedString1, dest.toString());
dest.replace(5, 8, source);
String expectedString2 = "aabbcabcgh";
assertEquals(expectedString2, dest.toString());
dest.insert(2, source);
assertEquals(expectedString2, dest.toString());
dest.delete(1, 3);
String expectedString3 = "abcabcgh";
assertEquals(expectedString3, dest.toString());
dest.append("12345");
String expectedString4 = "abcabcgh12";
assertEquals(expectedString4, dest.toString());
// 2 Chinese chars == 6 bytes in UTF-8
source = "\u60a8\u597d";
dest.replace(8, 10, source);
assertEquals(expectedString3, dest.toString());
dest.replace(0, 1, source);
String expectedString5 = "\u60a8bcabcgh";
assertEquals(expectedString5, dest.toString());
dest.replace(0, 4, source);
String expectedString6 = "\u60a8\u597dbcgh";
assertEquals(expectedString6, dest.toString());
// 2 Latin-1 chars == 4 bytes in UTF-8
source = "\u00a3\u00a5";
dest.delete(2, 6);
dest.insert(0, source);
String expectedString7 = "\u00a3\u00a5\u60a8\u597d";
assertEquals(expectedString7, dest.toString());
dest.replace(2, 3, source);
String expectedString8 = "\u00a3\u00a5\u00a3\u597d";
assertEquals(expectedString8, dest.toString());
dest.replace(3, 4, source);
String expectedString9 = "\u00a3\u00a5\u00a3\u00a3\u00a5";
assertEquals(expectedString9, dest.toString());
// filter() explicitly invoked
dest = new SpannableStringBuilder("abcdefgh");
CharSequence beforeFilterSource = "TestLengthFilter";
String expectedAfterFilter = "TestLength";
CharSequence actualAfterFilter = lengthFilter.filter(beforeFilterSource, 0, beforeFilterSource.length(), dest, 0, dest.length());
assertEquals(expectedAfterFilter, actualAfterFilter);
}
use of android.text.InputFilter in project malp by gateship-one.
the class EditProfileFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_edit_profile, container, false);
mProfilenameView = rootView.findViewById(R.id.fragment_profile_profilename);
mHostnameView = rootView.findViewById(R.id.fragment_profile_hostname);
mPasswordView = rootView.findViewById(R.id.fragment_profile_password);
mPortView = rootView.findViewById(R.id.fragment_profile_port);
mStreamingURLView = rootView.findViewById(R.id.fragment_profile_streaming_url);
mStreamingEnabledView = rootView.findViewById(R.id.fragment_profile_streaming_enabled);
mHTTPCoverRegexView = rootView.findViewById(R.id.fragment_profile_cover_regex);
mHTTPCoverEnabledView = rootView.findViewById(R.id.fragment_profile_http_covers_enabled);
// Set to maximum tcp port
InputFilter portFilter = new PortNumberFilter();
mPortView.setFilters(new InputFilter[] { portFilter });
/* Check if an artistname/albumame was given in the extras */
Bundle args = getArguments();
if (null != args) {
mOldProfile = args.getParcelable(EXTRA_PROFILE);
if (mOldProfile != null) {
mProfilename = mOldProfile.getProfileName();
mHostname = mOldProfile.getHostname();
mPassword = mOldProfile.getPassword();
mPort = mOldProfile.getPort();
mStreamingURL = mOldProfile.getStreamingURL();
mStreamingEnabled = mOldProfile.getStreamingEnabled();
mHTTPCoverRegex = mOldProfile.getHTTPRegex();
mHTTPCoverEnabled = mOldProfile.getHTTPCoverEnabled();
mProfilenameView.setText(mProfilename);
} else {
mHostname = "";
mProfilename = "";
mPassword = "";
mPort = 6600;
mStreamingEnabled = false;
mStreamingURL = "";
mHTTPCoverEnabled = false;
mHTTPCoverRegex = "";
mProfilenameView.setText(getString(R.string.fragment_profile_default_name));
}
}
mHostnameView.setText(mHostname);
mPasswordView.setText(mPassword);
mPortView.setText(String.valueOf(mPort));
// Show/Hide streaming url view depending on state
mStreamingEnabledView.setChecked(mStreamingEnabled);
mStreamingEnabledView.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
if (mStreamingURLView.getText().toString().isEmpty()) {
// Check if a text was already set otherwise show an example
mStreamingURL = "http://" + mHostnameView.getText().toString() + ":8080";
mStreamingURLView.setText(mStreamingURL);
}
mStreamingURLView.setVisibility(View.VISIBLE);
} else {
mStreamingURLView.setVisibility(View.GONE);
}
});
if (!mStreamingEnabled) {
mStreamingURLView.setVisibility(View.GONE);
}
mStreamingURLView.setText(mStreamingURL);
// Show/Hide HTTP cover regex view depending on state
mHTTPCoverEnabledView.setChecked(mHTTPCoverEnabled);
mHTTPCoverEnabledView.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
mHTTPCoverRegexView.setText(mHTTPCoverRegex);
mHTTPCoverRegexView.setVisibility(View.VISIBLE);
} else {
mHTTPCoverRegexView.setVisibility(View.GONE);
}
});
if (!mHTTPCoverEnabled) {
mHTTPCoverRegexView.setVisibility(View.GONE);
}
mHTTPCoverRegexView.setText(mHTTPCoverRegex);
mProfilenameView.setSelectAllOnFocus(true);
setHasOptionsMenu(true);
// Return the ready inflated and configured fragment view.
return rootView;
}
use of android.text.InputFilter in project SightRemote by TebbeUbben.
the class EditBRProfileActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
} else if (item.getItemId() == R.id.edit_br_nav_done) {
(confirmationDialog = new ConfirmationDialog(this, HTMLUtil.getHTML(R.string.edit_br_profile_confirmation), () -> {
showManualOverlay();
List<ConfigurationBlock> blocks = new ArrayList<>();
blocks.add(nameBlock);
profileBlock.setProfileBlocks(FixedSizeProfileBlock.convertToRelative(profileBlocks));
blocks.add(profileBlock);
WriteConfigurationTaskRunner taskRunner = new WriteConfigurationTaskRunner(getServiceConnector(), blocks);
showLoadingIndicator();
taskRunner.fetch(this);
})).show();
} else if (item.getItemId() == R.id.edit_br_nav_edit_name) {
EditText editName = new EditText(this);
editName.setInputType(InputType.TYPE_CLASS_TEXT);
editName.setFilters(new InputFilter[] { new InputFilter.LengthFilter(21) });
editName.setText(nameBlock.getName());
AlertDialog alertDialog = new AlertDialog.Builder(this).setTitle(R.string.edit_name).setMessage(R.string.leave_empty_for_default_value).setView(editName).setPositiveButton(R.string.okay, ((dialog, which) -> {
nameBlock.setName(editName.getText().toString());
adjustTitle();
})).setNegativeButton(R.string.cancel, null).create();
alertDialog.show();
}
return super.onOptionsItemSelected(item);
}
Aggregations