@Override protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); penClient = PenClientCtrl.getInstance( getApplicationContext() ); if(penClient.getProtocolVersion() == 1) addPreferencesFromResource( R.xml.pref_settings ); else addPreferencesFromResource( R.xml.pref_settings2 ); mPasswordPref = (EditTextPreference) getPreferenceScreen().findPreference( Const.Setting.KEY_PASSWORD ); EditText myEditText = (EditText) mPasswordPref.getEditText(); myEditText.setKeyListener( DigitsKeyListener.getInstance( false, true ) ); }
private void updateDropDownTextView() { if (dropDown != null) { if (currentPasswordType == 0) { dropDown.setText(LocaleController.getString("PasscodePIN", R.string.PasscodePIN)); } else if (currentPasswordType == 1) { dropDown.setText(LocaleController.getString("PasscodePassword", R.string.PasscodePassword)); } } if (type == 1 && currentPasswordType == 0 || type == 2 && UserConfig.passcodeType == 0) { InputFilter[] filterArray = new InputFilter[1]; filterArray[0] = new InputFilter.LengthFilter(4); passwordEditText.setFilters(filterArray); passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE); passwordEditText.setKeyListener(DigitsKeyListener.getInstance("1234567890")); } else if (type == 1 && currentPasswordType == 1 || type == 2 && UserConfig.passcodeType == 1) { passwordEditText.setFilters(new InputFilter[0]); passwordEditText.setKeyListener(null); passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); } passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); }
@Override public void setInputType(int type) { if (type == -1) { type = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_PASSWORD; } if (type == InputType.TYPE_CLASS_NUMBER || type == InputType.TYPE_NUMBER_FLAG_SIGNED || type == InputType.TYPE_NUMBER_FLAG_DECIMAL || type == InputType.TYPE_CLASS_PHONE) { final String symbolExceptions = getSymbolExceptions(); this.setKeyListener(DigitsKeyListener.getInstance("0123456789." + symbolExceptions)); } else { super.setInputType(type); } }
protected void updateInputMethod() { boolean hasNumberField = mNumberField != null; setEnabled(hasNumberField); if (hasNumberField) { int imeOptions = InputType.TYPE_CLASS_NUMBER; StringBuilder allowedChars = new StringBuilder("0123456789"); if (mAllowExponent) { allowedChars.append("e"); } if (mNumberField.getMinimumValue() < 0) { imeOptions |= InputType.TYPE_NUMBER_FLAG_SIGNED; allowedChars.append("-"); } if (!mNumberField.isInteger()) { imeOptions |= InputType.TYPE_NUMBER_FLAG_DECIMAL; allowedChars.append(mLocalizedDecimalSymbols.getDecimalSeparator()); } allowedChars.append(mLocalizedDecimalSymbols.getGroupingSeparator()); setImeOptions(imeOptions); setKeyListener(DigitsKeyListener.getInstance(allowedChars.toString())); } }
public void setMode(EditMode value) { m_editMode = value; switch (EffectiveMode()) { case HHMM: this.setHint(R.string.emptyWaterMarkHHMM); this.setInputType(InputType.TYPE_CLASS_NUMBER); setKeyListener(DigitsKeyListener.getInstance(false, false)); break; case INTEGER: this.setHint(R.string.emptyWaterMarkInt); this.setInputType(InputType.TYPE_CLASS_NUMBER); this.setKeyListener(DigitsKeyListener.getInstance(false, false)); // setKeyListener(DigitsKeyListener.getInstance("01234567890")); break; case DECIMAL: // See Android bug #2626 (http://code.google.com/p/android/issues/detail?id=2626&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars) // Using SetKeyListener this.setHint(String.format(Locale.getDefault(), "%.1f", 0.0)); this.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); this.setKeyListener(DigitsKeyListener.getInstance(false, true)); // should work but bug above means it will ALWAYS use a period. break; } }
@Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); //Construct the preferences screen form XML config addPreferencesFromResource(R.xml.task_preferences); //Use the number keyboard when editing the time preference EditTextPreference timeDefault = (EditTextPreference)findPreference(getString(R.string.pref_default_time_from_now_key)); timeDefault.getEditText().setKeyListener(DigitsKeyListener.getInstance()); findPreference(this.getString(R.string.title_instructions)).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(getActivity(), IntroActivity.class); startActivity(intent); return false; } }); }
public ExIntegerWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); mAnswer.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED); // only allows numbers and no periods mAnswer.setKeyListener(new DigitsKeyListener(true, false)); // ints can only hold 2,147,483,648. we allow 999,999,999 InputFilter[] fa = new InputFilter[1]; fa[0] = new InputFilter.LengthFilter(9); mAnswer.setFilters(fa); Integer i = getIntegerAnswerValue(); if (i != null) { mAnswer.setText(i.toString()); } }
private void setDiscoveryDelay() { final EditText input = new EditText(this); input.setHint(this.getString(R.string.hint_discoverydelay)); input.setText(Integer.toString(nfc.getDiscoveryDelay())); input.setInputType(EditorInfo.TYPE_CLASS_NUMBER); input.setKeyListener(DigitsKeyListener.getInstance("01234567890")); input.setSingleLine(true); SetDelayHelper helper = new SetDelayHelper(nfc, input); new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT) .setTitle(R.string.action_discoverydelay) .setMessage(R.string.lab_discoverydelay).setView(input) .setPositiveButton(R.string.action_ok, helper) .setNegativeButton(R.string.action_cancel, helper).show(); }
/** gets the key listener by type */ private static KeyListener getKeyListenerForType(NumericType type) { switch (type) { case DIALPAD: return new DialerKeyListener(); case INTEGER: return new DigitsKeyListener(); case SIGNED: return new DigitsKeyListener(true, false); case DECIMAL: return new DigitsKeyListener(true, true); case NONE: default: return null; } }
private void init(AttributeSet attrs, int defStyle) { // @formatter:off final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.PinputView, defStyle, 0); // @formatter:on setFocusableInTouchMode(false); setKeyListener(DigitsKeyListener.getInstance(false, false)); mPinLen = a.getInt(R.styleable.PinputView_pinputview_len, 4); mCharPadding = (int) a.getDimension(R.styleable.PinputView_pinputview_characterPadding, getResources().getDimension(R.dimen.pinputview_default_char_padding)); int foregroundColor = a.getColor(R.styleable.PinputView_pinputview_foregroundColor, Color.BLUE); int backgroundColor = a.getColor(R.styleable.PinputView_pinputview_backgroundColor, Color.GRAY); a.recycle(); initDrawables(foregroundColor, backgroundColor); initFilters(); initializeAnimator(); }
/** gets the key listener by type */ protected static KeyListener getKeyListenerForType(NumericType type) { switch (type) { case DIALPAD: return new DialerKeyListener(); case INTEGER: return new DigitsKeyListener(); case SIGNED: return new DigitsKeyListener(true, false); case DECIMAL: return new DigitsKeyListener(true, true); case NONE: default: return null; } }
private void setEditable(boolean editable) { if (editable) { etInput.setFocusable(true); etInput.setKeyListener(new DigitsKeyListener()); } else { etInput.setFocusable(false); etInput.setKeyListener(null); } }
private void DynamicTimeSet(final SharedPreferences sp) { int num = sp.getInt("DynamicReloadTime", 1000); LayoutInflater inflater = LayoutInflater.from(getActivity()); View view = inflater.inflate(R.layout.dialog_text, null); AlertDialog.Builder set = new AlertDialog.Builder(getActivity()); set.setTitle(R.string.xml_global_dynamicword_reload_time); final EditText et = (EditText) view.findViewById(R.id.dialog_text_edittext); et.setText(String.valueOf(num)); et.setKeyListener(new DigitsKeyListener(false, true)); set.setPositiveButton(R.string.done, new DialogInterface.OnClickListener() { public void onClick(DialogInterface d, int i) { String str = et.getText().toString(); if (!str.isEmpty()) { int get = Integer.valueOf(str); if (get < 500) { Toast.makeText(getActivity(), R.string.num_err, Toast.LENGTH_SHORT).show(); } else { sp.edit().putInt("DynamicReloadTime", get).apply(); Toast.makeText(getActivity(), R.string.restart_to_apply, Toast.LENGTH_LONG).show(); } } } }); set.setNegativeButton(R.string.cancel, null); set.setView(view); set.show(); }
private void setEditable(boolean editable) { if (editable) { mCount.setFocusable(true); mCount.setKeyListener(new DigitsKeyListener()); } else { mCount.setFocusable(false); mCount.setKeyListener(null); } }
private void initKeyboardButton(View view) { final Button toggleKeyboardButton = view.findViewById(R.id.toggleKeyboard); if(toggleKeyboardButton != null) { toggleKeyboardButton.setText("abc"); toggleKeyboardButton.setOnClickListener(v -> { View focus = getActivity().getCurrentFocus(); if(focus != null && focus instanceof EditText) { EditText input = (EditText) focus; if ((input.getInputType() & InputType.TYPE_CLASS_NUMBER) != 0) { input.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); toggleKeyboardButton.setText("123"); } else { input.setInputType(InputType.TYPE_CLASS_NUMBER); input.setKeyListener(DigitsKeyListener.getInstance("0123456789.,- /")); toggleKeyboardButton.setText("abc"); } InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT); } }); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.task_preferences); // Set the time default to a numeric number only EditTextPreference timeDefault = (EditTextPreference) findPreference(getString(R.string.pref_default_time_from_now_key)); timeDefault.getEditText().setKeyListener(DigitsKeyListener.getInstance()); }
public ExDecimalWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); mAnswer.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL); // only allows numbers and no periods mAnswer.setKeyListener(new DigitsKeyListener(true, true)); // only 15 characters allowed InputFilter[] fa = new InputFilter[1]; fa[0] = new InputFilter.LengthFilter(15); mAnswer.setFilters(fa); Double d = getDoubleAnswerValue(); // apparently an attempt at rounding to no more than 15 digit precision??? NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(15); nf.setMaximumIntegerDigits(15); nf.setGroupingUsed(false); if (d != null) { // truncate to 15 digits max... String dString = nf.format(d); d = Double.parseDouble(dString.replace(',', '.')); // in case , is decimal pt mAnswer.setText(d.toString()); } }
public StringNumberWidget(Context context, FormEntryPrompt prompt, boolean readOnlyOverride) { super(context, prompt, readOnlyOverride, true); mAnswer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mAnswer.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED); // needed to make long readonly text scroll mAnswer.setHorizontallyScrolling(false); mAnswer.setSingleLine(false); mAnswer.setKeyListener(new DigitsKeyListener() { @Override protected char[] getAcceptedChars() { char[] accepted = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '-', '+', ' ', ',' }; return accepted; } }); if (prompt.isReadOnly()) { setBackgroundDrawable(null); setFocusable(false); setClickable(false); } String s = null; if (prompt.getAnswerValue() != null) s = (String) prompt.getAnswerValue().getValue(); if (s != null) { mAnswer.setText(s); } setupChangeListener(); }
public IntegerWidget(Context context, FormEntryPrompt prompt, boolean readOnlyOverride) { super(context, prompt, readOnlyOverride, true); mAnswer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mAnswer.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED); // needed to make long readonly text scroll mAnswer.setHorizontallyScrolling(false); mAnswer.setSingleLine(false); // only allows numbers and no periods mAnswer.setKeyListener(new DigitsKeyListener(true, false)); // ints can only hold 2,147,483,648. we allow 999,999,999 InputFilter[] fa = new InputFilter[1]; fa[0] = new InputFilter.LengthFilter(9); mAnswer.setFilters(fa); if (prompt.isReadOnly()) { setBackgroundDrawable(null); setFocusable(false); setClickable(false); } Integer i = getIntegerAnswerValue(); if (i != null) { mAnswer.setText(i.toString()); } setupChangeListener(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Construct the preferences screen from the XML config addPreferencesFromResource(R.xml.task_preferences); // Use the number keyboard when editing the time preference EditTextPreference timeDefault = (EditTextPreference) findPreference(getString(R.string .pref_default_time_from_now_key)); timeDefault.getEditText().setKeyListener(DigitsKeyListener .getInstance()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); calculator_result = (TextView) findViewById(R.id.calculator_result); button_one = (Button) findViewById(R.id.number_one); button_two = (Button) findViewById(R.id.number_two); button_three = (Button) findViewById(R.id.number_three); button_four = (Button) findViewById(R.id.number_four); button_five = (Button) findViewById(R.id.number_five); button_six = (Button) findViewById(R.id.number_six); button_seven = (Button) findViewById(R.id.number_seven); button_eight = (Button) findViewById(R.id.number_eight); button_nine = (Button) findViewById(R.id.number_nine); button_zero = (Button) findViewById(R.id.number_zero); button_plus = (Button) findViewById(R.id.button_plus); button_minus = (Button) findViewById(R.id.button_minus); button_multiply = (Button) findViewById(R.id.button_multiply); button_divide = (Button) findViewById(R.id.button_divide); button_power = (Button) findViewById(R.id.button_power); button_root = (Button) findViewById(R.id.button_root); button_abs = (Button) findViewById(R.id.button_abs); button_clear = (Button) findViewById(R.id.button_clear); button_equals = (Button) findViewById(R.id.button_equals); calculator_result.setKeyListener(DigitsKeyListener.getInstance(true,true)); registerListeners(); }
@Override public void applyTextFilterIfNeeded(EditText e) { e.setInputType(InputType.TYPE_CLASS_NUMBER); e.setKeyListener(new DigitsKeyListener(true, false)); if (minimumValue != null && maximumValue != null) { setMinMaxFilterFor(e, minimumValue, maximumValue); } }
public StringNumberWidget(Context context, FormEntryPrompt prompt, boolean secret) { super(context, prompt, secret); mAnswer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontSize); mAnswer.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_NEXT); // needed to make long readonly text scroll mAnswer.setHorizontallyScrolling(false); if (!secret) { mAnswer.setSingleLine(false); } mAnswer.setKeyListener(new DigitsKeyListener(true, true) { @Override protected char[] getAcceptedChars() { return new char[]{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '-', '+', ' ' }; } }); if (prompt.isReadOnly()) { setBackgroundDrawable(null); setFocusable(false); setClickable(false); } //This might be redundant, but I assume that it's about there being a difference //between a display value somewhere. We should double check if (prompt.getAnswerValue() != null) { String curAnswer = getCurrentAnswer().getValue().toString().trim(); try { mAnswer.setText(curAnswer); } catch (Exception NumberFormatException) { } } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.graph_preferences); regressionLine = (CheckBoxPreference) findPreference(PREFERENCE_KEY_REGRESSION_LINE); regressionLineOrder = (EditTextPreference) findPreference(PREFERENCE_KEY_REGRESSION_LINE_ORDER); regressionLineOrder.getEditText().setKeyListener(new DigitsKeyListener()); updateGraphPreferences(); initSummary(getPreferenceScreen()); }
private View createMeetingLengthTextBox() { meetingLengthEditText = new EditText(this); meetingLengthEditText.setGravity(Gravity.CENTER); meetingLengthEditText.setKeyListener(new DigitsKeyListener()); meetingLengthEditText.setRawInputType(InputType.TYPE_CLASS_PHONE); meetingLengthEditText.setLayoutParams(new LayoutParams(dipsToPixels(60), LayoutParams.WRAP_CONTENT)); meetingLengthEditText.setText(Integer.toString(meetingLength)); meetingLengthEditText.setLines(1); meetingLengthSpinner = null; return meetingLengthEditText; }
/** Sets the default values for the preference screen */ private void initPreferences() { // Binary file location EditTextPreference binaryFileLocation = (EditTextPreference) findPreference(Constants.PREFERENCE_STORAGE_DIRECTORY); if (TextUtils.isEmpty(binaryFileLocation.getText())) { binaryFileLocation.setText(EnvironmentUtil.getProcedureDirectory()); } // Image downscale factor EditTextPreference imageDownscale = (EditTextPreference) findPreference(Constants.PREFERENCE_IMAGE_SCALE); if (TextUtils.isEmpty(imageDownscale.getText())) { imageDownscale.setText("" + Constants.IMAGE_SCALE_FACTOR); } imageDownscale.getEditText().setKeyListener(new DigitsKeyListener()); // View all edu resources PreferenceScreen resourcePref = (PreferenceScreen) findPreference("s_education_resource"); Intent intent = EducationResourceList.getIntent(Intent.ACTION_PICK, Audience.ALL); intent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_VIEW)); resourcePref.setIntent(intent); // SD card loading procedures PreferenceScreen intentPref = (PreferenceScreen) findPreference("s_procedures"); intentPref.setIntent(new Intent("org.sana.android.activity.IMPORT_PROCEDURE")); //intentPref.setIntent(new Intent(ResourceSettings.this, // ProcedureSdImporter.class)); }
public StringNumberWidget(Context context, FormEntryPrompt prompt) { super(context, prompt, true); mAnswer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mAnswer.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED); // needed to make long readonly text scroll mAnswer.setHorizontallyScrolling(false); mAnswer.setSingleLine(false); mAnswer.setKeyListener(new DigitsKeyListener() { @Override protected char[] getAcceptedChars() { char[] accepted = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '-', '+', ' ', ',' }; return accepted; } }); if (prompt.isReadOnly()) { setBackgroundDrawable(null); setFocusable(false); setClickable(false); } String s = null; if (prompt.getAnswerValue() != null) s = (String) prompt.getAnswerValue().getValue(); if (s != null) { mAnswer.setText(s); } setupChangeListener(); }
public IntegerWidget(Context context, FormEntryPrompt prompt) { super(context, prompt, true); mAnswer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mAnswer.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED); // needed to make long readonly text scroll mAnswer.setHorizontallyScrolling(false); mAnswer.setSingleLine(false); // only allows numbers and no periods mAnswer.setKeyListener(new DigitsKeyListener(true, false)); // ints can only hold 2,147,483,648. we allow 999,999,999 InputFilter[] fa = new InputFilter[1]; fa[0] = new InputFilter.LengthFilter(9); mAnswer.setFilters(fa); if (prompt.isReadOnly()) { setBackgroundDrawable(null); setFocusable(false); setClickable(false); } Integer i = getIntegerAnswerValue(); if (i != null) { mAnswer.setText(i.toString()); } setupChangeListener(); }
public NumberPicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); setOrientation(VERTICAL); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.number_picker, this, true); mHandler = new Handler(); mIncrementButton = (NumberPickerButton) findViewById(R.id.increment); mIncrementButton.setOnClickListener(this); mIncrementButton.setOnLongClickListener(this); mIncrementButton.setNumberPicker(this); mDecrementButton = (NumberPickerButton) findViewById(R.id.decrement); mDecrementButton.setOnClickListener(this); mDecrementButton.setOnLongClickListener(this); mDecrementButton.setNumberPicker(this); mText = (EditText) findViewById(R.id.timepicker_input); mText.setOnFocusChangeListener(this); DigitsKeyListener keyListener = DigitsKeyListener.getInstance(false, true); mText.setFilters(new InputFilter[] { keyListener }); mText.setRawInputType(keyListener.getInputType()); if (!isEnabled()) { setEnabled(false); } }