Example usage for android.text.method DigitsKeyListener DigitsKeyListener

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

Introduction

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

Prototype

@Deprecated
public DigitsKeyListener(boolean sign, boolean decimal) 

Source Link

Document

Allocates a DigitsKeyListener that accepts the ASCII digits 0 through 9, plus the ASCII plus or minus sign (only at the beginning) and/or the ASCII period ('.') as the decimal point (only one per field) if specified.

Usage

From source file:org.blanco.lacuenta.fragments.SplitsFragment.java

/***
 * Initialises the components for the current activity. Visual and non
 * visual members of this context.//w ww  .j  ava2  s. c  o  m
 */
public void initComponents() {
    edtTotal = (EditText) mainLayout.findViewById(R.id.main_activity_edt_bill_total);
    // Set the key listener when the orientation is landscape and the input
    // is done through the softkeyboard
    if (getActivity().getWindowManager().getDefaultDisplay()
            .getOrientation() == Configuration.ORIENTATION_LANDSCAPE) {
        edtTotal.setKeyListener(new DigitsKeyListener(false, true));
    }
    txtResult = (TextView) mainLayout.findViewById(R.id.main_activity_txt_result);
    spnTip = (Spinner) mainLayout.findViewById(R.id.main_activity_spn_tip);
    spnPeople = (Spinner) mainLayout.findViewById(R.id.main_activity_spn_people);
    btnCalculate = (Button) mainLayout.findViewById(R.id.main_activity_btn_calculate);
    clickListener = new CalculateClickListener(edtTotal, spnTip, spnPeople);
    btnCalculate.setOnClickListener(clickListener);
    numPad = (NumPad) mainLayout.findViewById(R.id.main_activity_num_pad);

    if (numPad != null) // Landscape layout will not have numPad
        numPad.setText(edtTotal);
}

From source file:ru.orangesoftware.financisto.widget.AmountInput.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    requestId = EDIT_AMOUNT_REQUEST.incrementAndGet();

    LinearLayout v = new LinearLayout(getActivity());
    v.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams lpWrapWrap = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);//from   w w w  . j a  v  a  2 s .  com
    lpWrapWrap.weight = 1;

    inflater.inflate(R.layout.amount_input, v, true);
    c = new Controls(v);

    c.AmountInput.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), QuickAmountInput.class);
            intent.putExtra(EXTRA_AMOUNT, getAbsAmountString());
            startActivityForResult(intent, requestId);
        }
    });

    c.CalculatorInput.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), CalculatorInput.class);
            intent.putExtra(EXTRA_AMOUNT, getAbsAmountString());
            startActivityForResult(intent, requestId);
        }
    });

    c.primary.setKeyListener(keyListener);
    c.primary.addTextChangedListener(textWatcher);
    c.primary.setOnFocusChangeListener(selectAllOnFocusListener);

    c.secondary.setKeyListener(new DigitsKeyListener(false, false) {

        @Override
        public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_DEL) {
                if (content.length() == 0) {
                    c.primary.requestFocus();
                    int pos = c.primary.getText().length();
                    c.primary.setSelection(pos, pos);
                    return true;
                }
            }
            return super.onKeyDown(view, content, keyCode, event);
        }

        @Override
        public int getInputType() {
            return InputType.TYPE_CLASS_PHONE;
        }

    });
    c.secondary.addTextChangedListener(textWatcher);
    c.secondary.setOnFocusChangeListener(selectAllOnFocusListener);

    return v;
}

From source file:edu.rosehulman.grocerydroid.ItemDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_dialog_item, container, false);

    // EditText nameBox = (EditText) view.findViewById(R.id.item_name_box);
    AutoCompleteTextView nameBox = (AutoCompleteTextView) view.findViewById(R.id.item_name_box);

    nameBox.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);

    //      String[] names = new String[] { "Bob", "Joe", "Caleb", "Jonathan",
    //            "Elise" };

    String[] foodNames = getResources().getStringArray(R.array.food_names);

    //      ArrayAdapter<String> autoAdapter = new ArrayAdapter<String>(
    //            getActivity(), android.R.layout.simple_list_item_1, names);
    ArrayAdapter<String> autoAdapter = new ArrayAdapter<String>(getActivity(), R.layout.dropdown_item,
            foodNames);/*from   w w w  . j  av  a2  s.c om*/

    // android.R.layout.sherlock.* both white/invisible
    // android.R.layout.
    // simple_spinner_item too thin
    // simple list item 2: crash
    // activity_list_item crash
    //simple_spinner_dropdown_item

    nameBox.setAdapter(autoAdapter);

    // mEditIcon.setOnKeyListener(new OnKeyListener() {
    // @Override
    // public boolean onKey(View v, int keyCode, KeyEvent event) {
    // // If the event is a key-down event on the "enter" button
    // if ((event.getAction() == KeyEvent.ACTION_DOWN)
    // && (keyCode == KeyEvent.KEYCODE_ENTER)) {
    // Toast.makeText(StockActivity.this, tv.getText(),
    // Toast.LENGTH_SHORT).show();
    // return true;
    // }
    // return false;
    // }
    // });

    EditText priceBox = (EditText) view.findViewById(R.id.item_price_box);
    priceBox.setInputType(InputType.TYPE_CLASS_PHONE);
    // priceBox.setInputType(InputType.TYPE_CLASS_NUMBER|InputType.TYPE_NUMBER_FLAG_DECIMAL);

    // first true : is signed, second one : is decimal
    priceBox.setKeyListener(new DigitsKeyListener(false, true));

    EditText sizeBox = (EditText) view.findViewById(R.id.item_unit_size_box);
    sizeBox.setText("" + mItem.getUnitSize());

    Spinner unitSpinner = (Spinner) view.findViewById(R.id.item_unit_label_spinner);
    ArrayAdapter<Item.UnitLabel> adapter;
    adapter = new ArrayAdapter<Item.UnitLabel>(this.getActivity(), android.R.layout.simple_spinner_item,
            Item.UnitLabel.values());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    unitSpinner.setAdapter(adapter);

    EditText numStockBox = (EditText) view.findViewById(R.id.item_num_stock);
    numStockBox.setText("" + mItem.getNStock());

    // If this activity was started with the purpose of editing an existing
    // item, then we use the item passed in the intent to populate the
    // spinners and edit text boxes.
    if (!mItem.getName().equals("")) {
        // TODO Make non-focusable, non-touchable so it doesn't kick off the drop down.
        // But it doesn't work!
        nameBox.setFocusable(false);
        nameBox.setFocusableInTouchMode(false);
        nameBox.setText(mItem.getName());
        // Reset the focus & touch
        nameBox.setFocusable(true);
        nameBox.setFocusableInTouchMode(true);

        priceBox.setText(Float.toString(mItem.getPrice()));

        unitSpinner.setSelection(mItem.getUnitLabel().ordinal());
    }

    Button incrementNumStockButton = (Button) view.findViewById(R.id.item_increment_num_stock);
    incrementNumStockButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText et = (EditText) view.findViewById(R.id.item_num_stock);
            int numStock = getIntegerFromEditText(et);
            numStock++;
            et.setText(numStock + "");
        }
    });

    Button decrementNumStockButton = (Button) view.findViewById(R.id.item_decrement_num_stock);
    decrementNumStockButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText et = (EditText) view.findViewById(R.id.item_num_stock);
            int numStock = getIntegerFromEditText(et);
            numStock--;
            et.setText(numStock + "");
        }
    });

    Button saveButton = (Button) view.findViewById(R.id.item_save_button);
    saveButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            EditText et = (EditText) view.findViewById(R.id.item_name_box);
            String name = et.getText().toString();

            et = (EditText) view.findViewById(R.id.item_price_box);
            float price = getFloatFromEditText(et);

            et = (EditText) view.findViewById(R.id.item_unit_size_box);
            float size = getFloatFromEditText(et);

            Spinner spinner = (Spinner) view.findViewById(R.id.item_unit_label_spinner);
            int unitIndex = spinner.getSelectedItemPosition();

            et = (EditText) view.findViewById(R.id.item_num_stock);
            int numStock = getIntegerFromEditText(et);

            mItem = new Item(mItem.getId(), mItem.getListId(), name, numStock, mItem.getNBuy(), price, size,
                    Item.UnitLabel.values()[unitIndex], mItem.isBought(), mItem.getStockIdx(),
                    mItem.getShopIdx());
            if (mMode == Mode.ADD) {
                ((ShoppingListActivity) getActivity()).addItem(mItem);
            } else if (mMode == Mode.EDIT) {
                ((ShoppingListActivity) getActivity()).updateItem(mItem);
            } else {
                // shouldn't get here.
            }
            dismiss();
        }
    });

    Button cancelButton = (Button) view.findViewById(R.id.item_cancel_button);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });

    Button deleteButton = (Button) view.findViewById(R.id.item_delete_button);
    deleteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mMode == Mode.EDIT) {
                ConfirmDeleteItemDialogFragment df = new ConfirmDeleteItemDialogFragment();
                df.setItem(mItem);
                df.show(getActivity().getSupportFragmentManager(), "confirm");
            }
            // Otherwise, we are adding this item, so we don't need to
            // delete it.
            // TODO: Remove modes altogether once autocomplete works, since
            // every item here will exist and be beging added.
            // CONSIDER: at that point, I will need to make sure that items
            // that have a name only (from autocomplete) have been saved in
            // the DB
            // and have a unique ID so they can be deleted.
            dismiss();
        }
    });

    return view;
}