Example usage for android.text.method DigitsKeyListener getInstance

List of usage examples for android.text.method DigitsKeyListener getInstance

Introduction

In this page you can find the example usage for android.text.method DigitsKeyListener getInstance.

Prototype

@NonNull
public static DigitsKeyListener getInstance(@NonNull String accepted) 

Source Link

Document

Returns a DigitsKeyListener that accepts only the characters that appear in the specified String.

Usage

From source file:Main.java

public static void setDigitsWordIDCard(EditText et) {
    if (et != null) {
        et.setKeyListener(DigitsKeyListener.getInstance(WORK_IDCARD));
    }
}

From source file:Main.java

public static void setDigitsWordAndNum(EditText et) {
    if (et != null) {
        et.setKeyListener(DigitsKeyListener.getInstance(WORD_AND_NUM));
    }
}

From source file:uk.ac.horizon.artcodes.fragment.ActionEditDialogFragment.java

@NonNull
@Override//from  w  w w  .j  av a  2  s  .  c om
public Dialog onCreateDialog(Bundle savedInstanceState) throws NullPointerException {
    binding = ActionEditBinding.inflate(getActivity().getLayoutInflater());
    binding.newMarkerCode.setFilters(new InputFilter[] { new MarkerFormat() });
    String currentKeyboard = Settings.Secure.getString(getContext().getContentResolver(),
            Settings.Secure.DEFAULT_INPUT_METHOD);
    Log.i("Keyboard", currentKeyboard);
    if (currentKeyboard.contains("com.lge.ime")) {
        binding.newMarkerCode.setKeyListener(DigitsKeyListener.getInstance("0123456789:"));
        binding.newMarkerCode.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    }
    binding.newMarkerCode.addTextChangedListener(new SimpleTextWatcher() {
        @Override
        public String getText() {
            return null;
        }

        @Override
        public void onTextChanged(String value) {
            if (!value.isEmpty()) {
                binding.newMarkerCode.setText("");
                Action action = getAction();
                action.getCodes().add(value);

                ActionCodeBinding codeBinding = createCodeBinding(binding, action,
                        action.getCodes().size() - 1);
                codeBinding.editMarkerCode.requestFocus();
            }
        }
    });

    binding.scanButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), ScannerActivity.class);
            intent.putExtra("experience", "{\"name\":\"Scan Code\"}");
            startActivityForResult(intent, SCAN_CODE_REQUEST);
        }
    });

    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(binding.getRoot());
    final Dialog dialog = builder.create();

    binding.deleteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (getArguments().containsKey("action")) {
                dialog.dismiss();
                final int index = getArguments().getInt("action");
                if (getTargetFragment() instanceof ActionEditListFragment) {
                    ((ActionEditListFragment) getTargetFragment()).getAdapter().deleteAction(index);
                } else {
                    getExperience().getActions().remove(index);
                }
            }
        }
    });
    binding.doneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (getArguments().containsKey("action")) {
                updateAction(); // make sure code is sorted
                if (getAction().getCodes().size() == 1) {
                    // Actions with only 1 code can not be a group or sequence!
                    getAction().setMatch(Action.Match.any);
                }
                final int index = getArguments().getInt("action");
                if (getTargetFragment() instanceof ActionEditListFragment) {
                    ((ActionEditListFragment) getTargetFragment()).getAdapter().actionUpdated(index);
                }
            }
            dialog.dismiss();
        }
    });

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this.getContext(),
            R.array.match_type_descriptions, R.layout.match_type_spinner_item);
    binding.matchSpinner.setAdapter(adapter);
    binding.matchSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (getAction() != null) {
                switch (i) {
                case 0:
                    getAction().setMatch(Action.Match.any);
                    break;
                case 1:
                    getAction().setMatch(Action.Match.all);
                    break;
                case 2:
                    getAction().setMatch(Action.Match.sequence);
                    break;
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    if (Feature.get(getContext(), R.bool.feature_combined_markers).isEnabled()) {
        binding.selectLayout.setVisibility(View.GONE);
        binding.matchSpinner.setVisibility(View.VISIBLE);
    }

    // Upload to artcodes.co.uk feature button:
    if (Feature.get(getContext(), R.bool.feature_upload_to_artcodes_co_uk).isEnabled()) {
        binding.uploadToArtcodesCoUkButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UUID uuid = UUID.randomUUID();
                String url = "http://www.artcodes.co.uk/test1234/?file=A" + uuid.toString()
                        + "&source=artcodes-android-app";

                getAction().setUrl(url);
                updateAction();

                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url + "&dontCheckForFiles"));
                startActivity(intent);
            }
        });
        binding.uploadToArtcodesCoUkButton.setVisibility(View.VISIBLE);
    }
    return dialog;
}

From source file:es.uniovi.imovil.fcrtrainer.BinaryExerciseFragment.java

private void changeViews() {
    EditText answer = (EditText) rootView.findViewById(R.id.answer);
    TextView title = (TextView) rootView.findViewById(R.id.exercisetitle);

    if (modeGame == MODE_GAME.BINARY_TO_DECIMAL) {

        title.setText(getResources().getString(R.string.convert_to_dec));

        // User input: 0 to 9
        answer.setKeyListener(DigitsKeyListener
                .getInstance(getResources().getString(R.string.digits_available_decimal_binary)));
        answer.setHint(getResources().getString(R.string.hint_2_binary));

    } else {//from   www  . ja v a2 s.co m

        title.setText(getResources().getString(R.string.convert_to_bin));

        // DECIMAL TO BINARY: User input: only 0 or 1
        answer.setKeyListener(
                DigitsKeyListener.getInstance(getResources().getString(R.string.digits_available_01_binary)));
        answer.setHint(getResources().getString(R.string.hint_binary));
    }

}

From source file:uk.ac.horizon.artcodes.fragment.ActionEditDialogFragment.java

private ActionCodeBinding createCodeBinding(final ActionEditBinding binding, final Action action,
        final int codeIndex) {
    final String code = action.getCodes().get(codeIndex);
    final ActionCodeBinding codeBinding = ActionCodeBinding.inflate(getActivity().getLayoutInflater(),
            binding.markerCodeList, false);
    codeBinding.editMarkerCode.setText(code);
    String currentKeyboard = Settings.Secure.getString(getContext().getContentResolver(),
            Settings.Secure.DEFAULT_INPUT_METHOD);
    if (currentKeyboard.contains("com.lge.ime")) {
        codeBinding.editMarkerCode.setKeyListener(DigitsKeyListener.getInstance("0123456789:"));
        codeBinding.editMarkerCode//from   ww w  . ja v  a 2 s  .  c  om
                .setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    }
    codeBinding.editMarkerCode.setFilters(new InputFilter[] { new MarkerFormat() });
    codeBinding.editMarkerCode.addTextChangedListener(new SimpleTextWatcher() {
        @Override
        public String getText() {
            return null;
        }

        @Override
        public void onTextChanged(String value) {
            if (value.isEmpty()) {
                action.getCodes().remove(codeIndex);
                updateCodes(binding, action);
                binding.newMarkerCode.requestFocus();
            } else {
                action.getCodes().set(codeIndex, value);
            }
        }
    });
    binding.markerCodeList.addView(codeBinding.getRoot());
    return codeBinding;
}

From source file:com.goftagram.telegram.ui.PasscodeActivity.java

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));
        }//from w w w  .ja v  a2s . co m
    }
    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());
}

From source file:kr.wdream.ui.PasscodeActivity.java

private void updateDropDownTextView() {
    if (dropDown != null) {
        if (currentPasswordType == 0) {
            dropDown.setText(//from   w ww.j  a v  a 2s  .c om
                    LocaleController.getString("PasscodePIN", kr.wdream.storyshop.R.string.PasscodePIN));
        } else if (currentPasswordType == 1) {
            dropDown.setText(LocaleController.getString("PasscodePassword",
                    kr.wdream.storyshop.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());
}

From source file:com.b44t.ui.PasscodeActivity.java

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));
        }//www  .ja  v a2 s. c o  m
    }
    if (screen == SCREEN1_ENTER_CODE1 && currentPasswordType == 0
            || screen == SCREEN2_ENTER_CODE2 && 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 (screen == SCREEN1_ENTER_CODE1 && currentPasswordType == 1
            || screen == SCREEN2_ENTER_CODE2 && 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());
}

From source file:ir.besteveryeverapp.ui.PasscodeActivity.java

private void updateDropDownTextView() {
    if (dropDown != null) {
        if (currentPasswordType == 0) {
            dropDown.setText(LocaleController.getString("PasscodePIN",
                    ir.besteveryeverapp.telegram.R.string.PasscodePIN));
        } else if (currentPasswordType == 1) {
            dropDown.setText(LocaleController.getString("PasscodePassword",
                    ir.besteveryeverapp.telegram.R.string.PasscodePassword));
        }/*from   w w w . j  a  v  a  2s.  co  m*/
    }
    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());
}