use of android.text.InputFilter in project NoteText by ViWu.
the class MainMenu method renameDialog.
private void renameDialog(String setName) {
final EditText textField = new EditText(MainMenu.this);
AlertDialog.Builder alert = new AlertDialog.Builder(MainMenu.this);
alert.setMessage("Enter New Name of the Set");
alert.setTitle("Rename Set");
alert.setView(textField);
textField.setText(setName);
int cursorPos = setName.length();
textField.setSelection(cursorPos);
textField.setSelectAllOnFocus(true);
textField.requestFocus();
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
textField.setFilters(new InputFilter[] { new InputFilter.LengthFilter(25) });
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String newName = textField.getText().toString();
if (newName.length() > 0)
fileRename(Names.get(position), newName);
else {
String msg = "Rename set failed! Set names need to be at least one character long!";
errorDialog(msg);
}
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, InputMethodManager.RESULT_UNCHANGED_SHOWN);
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, InputMethodManager.RESULT_UNCHANGED_SHOWN);
}
});
alert.show();
}
use of android.text.InputFilter in project MLib by DaoBillTang.
the class CommonTextView method initText.
/**
* 初始化textView
*
* @param textView 对象
* @param layoutParams 对象
* @param id id
* @param textColor 颜色值
* @param textSize 字体大小
* @return 返回
*/
public TextView initText(TextView textView, LayoutParams layoutParams, int id, int textColor, int textSize) {
if (textView == null) {
textView = new TextView(mContext);
textView.setId(id);
textView.setLayoutParams(layoutParams);
textView.setTextColor(textColor);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
// textView.setGravity(Gravity.CENTER);
textView.setLines(mSetLines);
textView.setSingleLine(mSetSingleLine);
// textView.setMaxEms(mSetMaxEms);
// textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mSetMaxEms) });
addView(textView);
}
return textView;
}
use of android.text.InputFilter in project collect by opendatakit.
the class FormEndView method init.
private void init(Context context, boolean instanceComplete) {
inflate(context, R.layout.form_entry_end, this);
((TextView) findViewById(R.id.description)).setText(context.getString(R.string.save_enter_data_description, formTitle));
EditText saveAs = findViewById(R.id.save_name);
// disallow carriage returns in the name
InputFilter returnFilter = (source, start, end, dest, dstart, dend) -> FormNameUtils.normalizeFormName(source.toString().substring(start, end), true);
saveAs.setFilters(new InputFilter[] { returnFilter });
saveAs.setText(defaultInstanceName);
saveAs.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
listener.onSaveAsChanged(s.toString());
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
final CheckBox markAsFinalized = findViewById(R.id.mark_finished);
markAsFinalized.setChecked(instanceComplete);
findViewById(R.id.save_exit_button).setOnClickListener(v -> {
listener.onSaveClicked(markAsFinalized.isChecked());
});
}
use of android.text.InputFilter in project collect by opendatakit.
the class ServerPreferencesFragment method addGooglePreferences.
public void addGooglePreferences() {
addPreferencesFromResource(R.xml.google_preferences);
selectedGoogleAccountPreference = findPreference(KEY_SELECTED_GOOGLE_ACCOUNT);
EditTextPreference googleSheetsUrlPreference = (EditTextPreference) findPreference(ProjectKeys.KEY_GOOGLE_SHEETS_URL);
googleSheetsUrlPreference.setOnBindEditTextListener(editText -> editText.setFilters(new InputFilter[] { new ControlCharacterFilter(), new WhitespaceFilter() }));
googleSheetsUrlPreference.setOnPreferenceChangeListener(createChangeListener());
String currentGoogleSheetsURL = googleSheetsUrlPreference.getText();
if (currentGoogleSheetsURL != null && currentGoogleSheetsURL.length() > 0) {
googleSheetsUrlPreference.setSummary(currentGoogleSheetsURL + "\n\n" + getString(R.string.google_sheets_url_hint));
}
initAccountPreferences();
}
use of android.text.InputFilter in project collect by opendatakit.
the class StringWidgetUtils method adjustEditTextAnswerToDecimalWidget.
public static void adjustEditTextAnswerToDecimalWidget(EditText answerText, FormEntryPrompt prompt) {
boolean useThousandSeparator = Appearances.useThousandSeparator(prompt);
if (useThousandSeparator) {
answerText.addTextChangedListener(new ThousandsSeparatorTextWatcher(answerText));
}
answerText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
// only numbers are allowed
answerText.setKeyListener(new DigitsKeyListener(true, true));
// only 15 characters allowed
InputFilter[] fa = new InputFilter[1];
fa[0] = new InputFilter.LengthFilter(15);
if (useThousandSeparator) {
fa[0] = new InputFilter.LengthFilter(19);
}
answerText.setFilters(fa);
Double d = getDoubleAnswerValueFromIAnswerData(prompt.getAnswerValue());
if (d != null) {
// truncate to 15 digits max in US locale
// use US locale because DigitsKeyListener can't be localized before API 26
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
nf.setMaximumFractionDigits(15);
nf.setMaximumIntegerDigits(15);
nf.setGroupingUsed(false);
String formattedValue = nf.format(d);
answerText.setText(formattedValue);
Selection.setSelection(answerText.getText(), answerText.getText().length());
}
}
Aggregations