Example usage for android.text InputType TYPE_CLASS_NUMBER

List of usage examples for android.text InputType TYPE_CLASS_NUMBER

Introduction

In this page you can find the example usage for android.text InputType TYPE_CLASS_NUMBER.

Prototype

int TYPE_CLASS_NUMBER

To view the source code for android.text InputType TYPE_CLASS_NUMBER.

Click Source Link

Document

Class for numeric text.

Usage

From source file:co.carlosandresjimenez.android.gotit.AddCheckInFragment.java

public void changeQuestion() {
    if (questionNumber > questionPosition) {
        currentQuestion = getQuestionAt(questionPosition);
        questionPosition++;/*from ww  w.  j  a va  2 s . c o  m*/

        if (currentQuestion == null) {
            return;
        }

        mTvAnswer.setText("");
        mTvAnswer.setFocusableInTouchMode(true);

        if (currentQuestion.getAnswerType().equals("checkbox")) {
            mTvAnswer.setVisibility(View.GONE);
            mCbAnswer.setVisibility(View.VISIBLE);
        } else {
            mTvAnswer.setVisibility(View.VISIBLE);
            mCbAnswer.setVisibility(View.GONE);

            switch (currentQuestion.getAnswerType()) {
            case "time":
                mTvAnswer.setFocusable(false);
                Utility.hideSoftKeyboard(getActivity(), mTvAnswer);
                break;
            case "numeric":
                mTvAnswer.setInputType(InputType.TYPE_CLASS_NUMBER);
                break;
            default:
                mTvAnswer.setInputType(InputType.TYPE_CLASS_TEXT);
            }
        }

        mTvQuestion.setText(currentQuestion.getValue());

        if (questionNumber == questionPosition)
            mBtNextQuestion.setText(getString(R.string.action_save));
    } else {
        saveAnswers();
        showProgressDialog(getString(R.string.progressdialog_saving));
    }
}

From source file:org.openmrs.mobile.activities.fragments.FormPageFragment.java

void addQuestion(Question question, LinearLayout parent) {
    if (question.getQuestionOptions().getRendering().equals("group")) {
        LinearLayout questionLL = new LinearLayout(getActivity());
        questionLL.setOrientation(LinearLayout.VERTICAL);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        questionLL.setGravity(Gravity.CENTER);
        parent.addView(questionLL);// ww w  .  j  a  v a 2  s  .  co  m

        Resources r = getActivity().getResources();
        float pxLeftMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());
        float pxTopMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());
        float pxRightMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());
        float pxBottomMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());

        layoutParams.setMargins(Math.round(pxLeftMargin), Math.round(pxTopMargin), Math.round(pxRightMargin),
                Math.round(pxBottomMargin));

        TextView tv = new TextView(getActivity());
        tv.setText(question.getLabel());
        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tv.setTextColor(ContextCompat.getColor(getActivity(), R.color.primary));
        questionLL.addView(tv, layoutParams);
        for (Question subquestion : question.getQuestions()) {
            addQuestion(subquestion, questionLL);
        }
    }

    if (question.getQuestionOptions().getRendering().equals("number")) {
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

        Resources r = getActivity().getResources();
        float pxLeftMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());
        float pxTopMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());
        float pxRightMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());
        float pxBottomMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());

        layoutParams.setMargins(Math.round(pxLeftMargin), Math.round(pxTopMargin), Math.round(pxRightMargin),
                Math.round(pxBottomMargin));

        RangeEditText ed = new RangeEditText(getActivity());
        ed.setName(question.getLabel());
        if (question.getQuestionOptions().getMax() != null) {
            ed.setHint(question.getLabel() + " [" + question.getQuestionOptions().getMin() + "-"
                    + question.getQuestionOptions().getMax() + "]");
            ed.setUpperlimit(Double.parseDouble(question.getQuestionOptions().getMax()));
            ed.setLowerlimit(Double.parseDouble(question.getQuestionOptions().getMin()));
        } else {
            ed.setHint(question.getLabel());
            ed.setLowerlimit(-1.0);
            ed.setUpperlimit(-1.0);
        }
        ed.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
        ed.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
        int id = InputField.generateViewId();
        InputField field = new InputField();
        ed.setId(id);
        field.setId(id);
        field.setConcept(question.getQuestionOptions().getConcept());
        inputFields.add(field);
        parent.addView(ed, layoutParams);
    }
}

From source file:org.trosnoth.serveradmin.ServerSettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    telnet = ConnectionActivity.telnet;/*  w  w w.  ja  v  a 2  s  . c  o  m*/
    telnet.send("game = getGame()");

    pref = new ServerSettings();
    pref.registerOnSharedPreferenceChangeListener(this);

    addPreferencesFromResource(R.xml.server_settings);

    gameModes = telnet.parseJSON(telnet.readWrite("print json.dumps(getGame().listGameModes())"));
    ListPreference gameModesPref = (ListPreference) this.findPreference("gameMode");

    String[] strArray = new String[gameModes.size()];
    gameModes.toArray(strArray);

    gameModesPref.setEntries(strArray);
    gameModesPref.setEntryValues(strArray);

    EditTextPreference setting;
    EditText settingText;

    setting = (EditTextPreference) findPreference("playersPerTeam");
    settingText = setting.getEditText();
    settingText.setInputType(InputType.TYPE_CLASS_NUMBER);
    settingText.setFilters(InputFilters.integerFilter(255));

    setting = (EditTextPreference) findPreference("playersTotal");
    settingText = setting.getEditText();
    settingText.setInputType(InputType.TYPE_CLASS_NUMBER);
    settingText.setFilters(InputFilters.integerFilter(255));

    setting = (EditTextPreference) findPreference("gameSpeed");
    settingText = setting.getEditText();
    settingText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

    // Update every 5 seconds

    Runnable looper = new Runnable() {
        public void run() {
            update();
            mHandler.postDelayed(this, ConnectionActivity.UPDATE_FREQ);
        }
    };

    if (ConnectionActivity.automaticUpdate) {
        mHandler.removeCallbacks(looper);
        mHandler.post(looper);
    } else {
        update();
    }
}

From source file:com.cypress.cysmart.BLEServiceFragments.CSCService.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.cyclingspeed_n_cadence, container, false);
    mDistanceRan = (TextView) rootView.findViewById(R.id.cycling_distance);
    mCadence = (TextView) rootView.findViewById(R.id.cadence);
    mCaloriesBurnt = (TextView) rootView.findViewById(R.id.calories_burnt);
    mTimer = (Chronometer) rootView.findViewById(R.id.time_counter);
    mWeightEdittext = (EditText) rootView.findViewById(R.id.weight_data);
    mWeightEdittext.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    mWeightEdittext.addTextChangedListener(new DecimalTextWatcher(mWeightEdittext));
    mProgressDialog = new ProgressDialog(getActivity());

    // Setting up chart
    setupChart(rootView);//from   ww  w.j  a va  2s .c om

    // Start/Stop listener
    Button start_stop_btn = (Button) rootView.findViewById(R.id.start_stop_btn);
    start_stop_btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Button btn = (Button) v;
            String buttonText = btn.getText().toString();
            String startText = getResources().getString(R.string.blood_pressure_start_btn);
            String stopText = getResources().getString(R.string.blood_pressure_stop_btn);
            weightString = mWeightEdittext.getText().toString();

            if (weightString.equalsIgnoreCase("")) {
                weightInt = 0;
                if (buttonText.equalsIgnoreCase(startText)) {
                    Toast.makeText(getActivity(), getResources().getString(R.string.csc_weight_toast_empty),
                            Toast.LENGTH_SHORT).show();
                    mCaloriesBurnt.setText("0.00");
                }
            }

            if (weightString.equalsIgnoreCase(".") || weightString.equalsIgnoreCase("0.")
                    || weightString.equalsIgnoreCase("0")) {
                weightInt = 0;
                if (buttonText.equalsIgnoreCase(startText)) {
                    Toast.makeText(getActivity(), getResources().getString(R.string.csc_weight_toast_empty),
                            Toast.LENGTH_SHORT).show();
                }
            }

            if (weightInt <= 1.0 && weightInt != 0) {
                if (buttonText.equalsIgnoreCase(startText)) {
                    Toast.makeText(getActivity(), getResources().getString(R.string.csc_weight_toast_zero),
                            Toast.LENGTH_SHORT).show();
                    mCaloriesBurnt.setText("0.00");
                }
            }

            if (weightInt <= 200) {
                if (buttonText.equalsIgnoreCase(startText)) {
                    btn.setText(stopText);
                    mCaloriesBurnt.setText("0.00");
                    mWeightEdittext.setEnabled(false);
                    if (mNotifyCharacteristic != null) {
                        stopBroadcastDataNotify(mNotifyCharacteristic);

                    }
                    getGattData();
                    mTimer.start();
                    mTimer.setBase(SystemClock.elapsedRealtime());
                    mTimer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
                        @Override
                        public void onChronometerTick(Chronometer chronometer) {
                            showCaloriesBurnt();
                        }
                    });
                } else {
                    mWeightEdittext.setEnabled(true);
                    btn.setText(startText);
                    stopBroadcastDataNotify(mNotifyCharacteristic);
                    mTimer.stop();
                }
            } else {
                if (buttonText.equalsIgnoreCase(startText)) {
                    Toast.makeText(getActivity(), getResources().getString(R.string.csc_weight_toast_greater),
                            Toast.LENGTH_SHORT).show();
                    btn.setText(stopText);
                    mCaloriesBurnt.setText("0.00");
                    mWeightEdittext.setEnabled(false);
                    if (mNotifyCharacteristic != null) {
                        stopBroadcastDataNotify(mNotifyCharacteristic);
                    }
                    getGattData();
                    mTimer.start();
                    mTimer.setBase(SystemClock.elapsedRealtime());
                    mTimer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
                        @Override
                        public void onChronometerTick(Chronometer chronometer) {
                            showCaloriesBurnt();
                        }
                    });
                } else {
                    mWeightEdittext.setEnabled(true);
                    btn.setText(startText);
                    stopBroadcastDataNotify(mNotifyCharacteristic);
                    mCaloriesBurnt.setText("0.00");
                    mTimer.stop();
                }
            }

        }
    });
    setHasOptionsMenu(true);
    return rootView;
}

From source file:com.cypress.cysmart.BLEServiceFragments.RSCService.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.runningspeed_n_cadence, container, false);
    mDistanceRan = (TextView) rootView.findViewById(R.id.running_distance);
    mAverageSpeed = (TextView) rootView.findViewById(R.id.running_speed);
    mCaloriesBurnt = (TextView) rootView.findViewById(R.id.calories_burnt);
    mTimer = (Chronometer) rootView.findViewById(R.id.time_counter);
    mWeightEdittext = (EditText) rootView.findViewById(R.id.weight_data);
    mWeightEdittext.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    mWeightEdittext.addTextChangedListener(new DecimalTextWatcher(mWeightEdittext));
    mProgressDialog = new ProgressDialog(getActivity());

    // Setting up chart
    setupChart(rootView);// w w  w.j a v  a  2  s  .  co m

    // Start/Stop listener
    Button start_stop_btn = (Button) rootView.findViewById(R.id.start_stop_btn);
    start_stop_btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Button btn = (Button) v;
            String buttonText = btn.getText().toString();
            String startText = getResources().getString(R.string.blood_pressure_start_btn);
            String stopText = getResources().getString(R.string.blood_pressure_stop_btn);
            weightString = mWeightEdittext.getText().toString();
            if (weightString.equalsIgnoreCase("")) {
                weightInt = 0;
                if (buttonText.equalsIgnoreCase(startText)) {
                    Toast.makeText(getActivity(), getResources().getString(R.string.csc_weight_toast_empty),
                            Toast.LENGTH_SHORT).show();
                    mCaloriesBurnt.setText("0.00");
                }
            }

            if (weightString.equalsIgnoreCase(".") || weightString.equalsIgnoreCase("0.")
                    || weightString.equalsIgnoreCase("0")) {
                weightInt = 0;
                if (buttonText.equalsIgnoreCase(startText)) {
                    Toast.makeText(getActivity(), getResources().getString(R.string.csc_weight_toast_empty),
                            Toast.LENGTH_SHORT).show();
                }
            }

            if (weightInt <= 1.0 && weightInt != 0) {
                if (buttonText.equalsIgnoreCase(startText)) {
                    Toast.makeText(getActivity(), getResources().getString(R.string.csc_weight_toast_zero),
                            Toast.LENGTH_SHORT).show();
                    mCaloriesBurnt.setText("0.00");
                }
            }

            if (weightInt <= 200) {
                if (buttonText.equalsIgnoreCase(startText)) {
                    btn.setText(stopText);
                    mCaloriesBurnt.setText("0.00");
                    mWeightEdittext.setEnabled(false);
                    if (mNotifyCharacteristic != null) {
                        stopBroadcastDataNotify(mNotifyCharacteristic);
                    }
                    getGattData();
                    mTimer.start();
                    mTimer.setBase(SystemClock.elapsedRealtime());
                    mTimer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
                        @Override
                        public void onChronometerTick(Chronometer chronometer) {
                            showCaloriesBurnt();
                        }
                    });
                } else {
                    mWeightEdittext.setEnabled(true);
                    btn.setText(startText);
                    stopBroadcastDataNotify(mNotifyCharacteristic);
                    mTimer.stop();
                }
            } else {
                if (buttonText.equalsIgnoreCase(startText)) {
                    Toast.makeText(getActivity(), getResources().getString(R.string.csc_weight_toast_greater),
                            Toast.LENGTH_SHORT).show();
                    btn.setText(stopText);
                    mCaloriesBurnt.setText("0.00");
                    mWeightEdittext.setEnabled(false);
                    if (mNotifyCharacteristic != null) {
                        stopBroadcastDataNotify(mNotifyCharacteristic);

                    }
                    getGattData();
                    mTimer.start();
                    mTimer.setBase(SystemClock.elapsedRealtime());
                    mTimer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
                        @Override
                        public void onChronometerTick(Chronometer chronometer) {
                            showCaloriesBurnt();
                        }
                    });
                } else {
                    mWeightEdittext.setEnabled(true);
                    btn.setText(startText);
                    stopBroadcastDataNotify(mNotifyCharacteristic);
                    mCaloriesBurnt.setText("0.00");
                    mTimer.stop();
                }
            }

        }
    });
    setHasOptionsMenu(true);
    return rootView;
}

From source file:com.bt.download.android.gui.util.UIUtils.java

public static EditText buildNumericEditText(Context context, String text) {
    return buildEditTextWithType(context, new NumberKeyListener() {
        @Override/*from ww  w  . j av  a  2  s .  co  m*/
        public int getInputType() {
            return InputType.TYPE_CLASS_NUMBER;
        }

        @Override
        protected char[] getAcceptedChars() {
            return new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
        }
    }, text);
}

From source file:com.mattprecious.smsfix.library.FixOld.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//from  w w  w.  j av a2  s.c  o m
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    switch (id) {
    case DIALOG_ID_START_DATE_PICKER:
        dialog = new DatePickerDialog(this, new OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                startCalendar.set(year, monthOfYear, dayOfMonth);

                updateButtons();
            }
        }, startCalendar.get(Calendar.YEAR), startCalendar.get(Calendar.MONTH),
                startCalendar.get(Calendar.DAY_OF_MONTH));
        break;
    case DIALOG_ID_START_TIME_PICKER:
        dialog = new TimePickerDialog(this, new OnTimeSetListener() {

            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                startCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                startCalendar.set(Calendar.MINUTE, minute);

                updateButtons();
            }
        }, startCalendar.get(Calendar.HOUR_OF_DAY), startCalendar.get(Calendar.MINUTE),
                DateFormat.is24HourFormat(this));
        break;
    case DIALOG_ID_END_DATE_PICKER:
        dialog = new DatePickerDialog(this, new OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                endCalendar.set(year, monthOfYear, dayOfMonth);

                updateButtons();
            }
        }, endCalendar.get(Calendar.YEAR), endCalendar.get(Calendar.MONTH),
                endCalendar.get(Calendar.DAY_OF_MONTH));
        break;
    case DIALOG_ID_END_TIME_PICKER:
        dialog = new TimePickerDialog(this, new OnTimeSetListener() {

            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                endCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                endCalendar.set(Calendar.MINUTE, minute);

                updateButtons();
            }
        }, endCalendar.get(Calendar.HOUR_OF_DAY), endCalendar.get(Calendar.MINUTE),
                DateFormat.is24HourFormat(this));
        break;
    case DIALOG_ID_OFFSET_PICKER:
        builder.setTitle(R.string.offset_hours);

        final EditText editText = new EditText(this);

        DecimalFormat df = new DecimalFormat("#.###");
        editText.setText(df.format(Math.abs(offset) / 3600000f));
        editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED
                | InputType.TYPE_NUMBER_FLAG_DECIMAL);

        builder.setView(editText);

        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                offset = (long) (Double.parseDouble(editText.getText().toString()) * 3600000);
                updateButtons();
            }
        });

        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });

        dialog = builder.create();
        break;
    case DIALOG_ID_CONFIRM:
        builder.setTitle(R.string.fix_old_confirm_title);
        builder.setMessage(R.string.fix_old_confirm_message);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                fixMessages();

            }
        });

        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();

            }
        });

        dialog = builder.create();
        break;
    default:
        dialog = null;
    }

    return dialog;
}

From source file:com.mario22gmail.license.nfc_project.FragmentPinDialog.java

@Nullable
@Override//from  w w w . j a  v  a  2  s  . c o  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_pin_dialog, container);
    getDialog().requestWindowFeature(STYLE_NO_TITLE);
    final EditText pinTextDialog = (EditText) view.findViewById(R.id.editTextPinDialog);
    final NavigationDrawerActivity mainActivity = (NavigationDrawerActivity) getActivity();

    disableSoftInputFromAppearing(pinTextDialog);

    Button buttonEnter = (Button) view.findViewById(R.id.buttonEnterPinDialog);
    buttonEnter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String pinNumberText = pinTextDialog.getText().toString();
            AuthResponse cardResponse = mainActivity.AuthenticateOnDesfire(pinNumberText);
            if (cardResponse.isValid()) {
                Toast.makeText(getContext(), "Autentificat", Toast.LENGTH_SHORT).show();
                getDialog().dismiss();
                Log.i("nfc_debug", "Card is valid");
                Intent goToWebCredentialPage = new Intent("goToWebCredentialPage");
                NavigationDrawerActivity.getAppContext().sendBroadcast(goToWebCredentialPage);
            } else {
                Toast.makeText(getDialog().getContext(), "Pin invalid", Toast.LENGTH_SHORT).show();

            }

        }
    });

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

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

            int position = pinTextDialog.getSelectionStart();
            pinTextDialog.getText().insert(position, "1");
        }
    });

    Button buttonNumarul2 = (Button) view.findViewById(R.id.buttonNumarul2);
    buttonNumarul2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = pinTextDialog.getSelectionStart();
            pinTextDialog.getText().insert(position, "2");
        }
    });

    Button buttonNumarul3 = (Button) view.findViewById(R.id.buttonNumarul3);
    buttonNumarul3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = pinTextDialog.getSelectionStart();
            pinTextDialog.getText().insert(position, "3");
        }
    });

    Button buttonNumarul4 = (Button) view.findViewById(R.id.buttonNumarul4);
    buttonNumarul4.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = pinTextDialog.getSelectionStart();
            pinTextDialog.getText().insert(position, "4");
        }
    });

    Button buttonNumarul5 = (Button) view.findViewById(R.id.buttonNumarul5);
    buttonNumarul5.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = pinTextDialog.getSelectionStart();
            pinTextDialog.getText().insert(position, "5");
        }
    });

    Button buttonNumarul6 = (Button) view.findViewById(R.id.buttonNumarul6);
    buttonNumarul6.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = pinTextDialog.getSelectionStart();
            pinTextDialog.getText().insert(position, "6");
        }
    });

    Button buttonNumarul7 = (Button) view.findViewById(R.id.buttonNumarul7);
    buttonNumarul7.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = pinTextDialog.getSelectionStart();
            pinTextDialog.getText().insert(position, "7");
        }
    });

    Button buttonNumarul8 = (Button) view.findViewById(R.id.buttonNumarul8);
    buttonNumarul8.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = pinTextDialog.getSelectionStart();
            pinTextDialog.getText().insert(position, "8");
        }
    });

    Button buttonNumarul9 = (Button) view.findViewById(R.id.buttonNumarul9);
    buttonNumarul9.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = pinTextDialog.getSelectionStart();
            pinTextDialog.getText().insert(position, "9");
        }
    });

    Button buttonNumarul0 = (Button) view.findViewById(R.id.buttonNumarul0);
    buttonNumarul0.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = pinTextDialog.getSelectionStart();
            pinTextDialog.getText().insert(position, "0");
        }
    });

    ImageButton buttonDeleteLastChar = (ImageButton) view.findViewById(R.id.buttonDeleteLastCharPinDialog);
    buttonDeleteLastChar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = pinTextDialog.getSelectionStart();
            if (position > 0) {
                Log.i("nfc_debug", "pozitia e " + position);
                pinTextDialog.getText().delete(position - 1, position);
            }

        }
    });

    final Button pinVisibility = (Button) view.findViewById(R.id.pinVisibility);
    pinTextDialog.setInputType(InputType.TYPE_CLASS_NUMBER);
    pinVisibility.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isPinVisible) {
                int position = pinTextDialog.getSelectionStart();
                pinVisibility.setBackgroundResource(R.drawable.ic_visibility_black_24dp);
                pinTextDialog
                        .setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
                pinTextDialog.setTypeface(Typeface.DEFAULT);
                pinTextDialog.setSelection(position);
                isPinVisible = false;
            } else {
                int position = pinTextDialog.getSelectionStart();
                pinVisibility.setBackgroundResource(R.drawable.ic_visibility_off_black_24dp);
                pinTextDialog.setInputType(InputType.TYPE_CLASS_NUMBER);
                pinTextDialog.setSelection(position);
                isPinVisible = true;
            }
        }
    });

    return view;
}

From source file:eu.geopaparazzi.core.maptools.FeaturePageAdapter.java

private TextView getEditView(final Feature feature, final String fieldName, EDataType type, String value) {
    final TextView editView;
    switch (type) {
    case DATE:/*from w  w  w.  j a v a  2 s.com*/
        editView = new TextView(context);
        editView.setInputType(InputType.TYPE_CLASS_DATETIME);
        editView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FeaturePageAdapter.this.openDatePicker((EditText) view);
            }
        });
        if (value == null || value.equals("")) {
            value = "____-__-__";
        }
        break;
    default:
        editView = new EditText(context);
        break;
    }
    editView.setText(value);

    switch (type) {
    case DOUBLE:
    case FLOAT:
        editView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
        break;
    case PHONE:
        editView.setInputType(InputType.TYPE_CLASS_PHONE);
        break;
    case DATE:
        editView.setInputType(InputType.TYPE_CLASS_DATETIME);
        editView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FeaturePageAdapter.this.openDatePicker((TextView) view);
            }
        });
        break;
    case INTEGER:
        editView.setInputType(InputType.TYPE_CLASS_NUMBER);
        break;
    default:
        break;
    }
    editView.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // ignore
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // ignore
        }

        public void afterTextChanged(Editable s) {
            String text = editView.getText().toString();
            feature.setAttribute(fieldName, text);
        }
    });

    return editView;
}

From source file:org.cocos2dx.lib.Cocos2dxEditBoxDialog.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    getWindow().setBackgroundDrawable(new ColorDrawable(0x80000000));

    LinearLayout layout = new LinearLayout(mParentActivity);
    layout.setOrientation(LinearLayout.VERTICAL);

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);

    mTextViewTitle = new TextView(mParentActivity);
    LinearLayout.LayoutParams textviewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    textviewParams.leftMargin = textviewParams.rightMargin = convertDipsToPixels(10);
    mTextViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    layout.addView(mTextViewTitle, textviewParams);

    mInputEditText = new EditText(mParentActivity);
    LinearLayout.LayoutParams editTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    editTextParams.leftMargin = editTextParams.rightMargin = convertDipsToPixels(10);

    layout.addView(mInputEditText, editTextParams);

    setContentView(layout, layoutParams);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    mInputMode = mMsg.inputMode;/*from  w  ww .  j a  v  a2  s.c o m*/
    mInputFlag = mMsg.inputFlag;
    mReturnType = mMsg.returnType;
    mMaxLength = mMsg.maxLength;

    mTextViewTitle.setText(mMsg.title);
    mInputEditText.setText(mMsg.content);

    int oldImeOptions = mInputEditText.getImeOptions();
    mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    oldImeOptions = mInputEditText.getImeOptions();

    switch (mInputMode) {
    case kEditBoxInputModeAny:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
        break;
    case kEditBoxInputModeEmailAddr:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
        break;
    case kEditBoxInputModeNumeric:
        mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
        break;
    case kEditBoxInputModePhoneNumber:
        mInputModeContraints = InputType.TYPE_CLASS_PHONE;
        break;
    case kEditBoxInputModeUrl:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
        break;
    case kEditBoxInputModeDecimal:
        mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                | InputType.TYPE_NUMBER_FLAG_SIGNED;
        break;
    case kEditBoxInputModeSingleLine:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT;
        break;
    default:

        break;
    }

    if (mIsMultiline) {
        mInputModeContraints |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
    }

    mInputEditText.setInputType(mInputModeContraints | mInputFlagConstraints);

    switch (mInputFlag) {
    case kEditBoxInputFlagPassword:
        mInputFlagConstraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
        break;
    case kEditBoxInputFlagSensitive:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
        break;
    case kEditBoxInputFlagInitialCapsWord:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_WORDS;
        break;
    case kEditBoxInputFlagInitialCapsSentence:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
        break;
    case kEditBoxInputFlagInitialCapsAllCharacters:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
        break;
    default:
        break;
    }
    mInputEditText.setInputType(mInputFlagConstraints | mInputModeContraints);

    switch (mReturnType) {
    case kKeyboardReturnTypeDefault:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE);
        break;
    case kKeyboardReturnTypeDone:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_DONE);
        break;
    case kKeyboardReturnTypeSend:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEND);
        break;
    case kKeyboardReturnTypeSearch:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEARCH);
        break;
    case kKeyboardReturnTypeGo:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_GO);
        break;
    default:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE);
        break;
    }

    if (mMaxLength > 0) {
        mInputEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mMaxLength) });
    }

    Handler initHandler = new Handler();
    initHandler.postDelayed(new Runnable() {
        public void run() {
            mInputEditText.requestFocus();
            mInputEditText.setSelection(mInputEditText.length());
            openKeyboard();
        }
    }, 200);

    mInputEditText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // if user didn't set keyboard type,
            // this callback will be invoked twice with 'KeyEvent.ACTION_DOWN' and 'KeyEvent.ACTION_UP'
            if (actionId != EditorInfo.IME_NULL || (actionId == EditorInfo.IME_NULL && event != null
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
                //Log.d("EditBox", "actionId: "+actionId +",event: "+event);
                mParentActivity.setEditBoxResult(mInputEditText.getText().toString());
                closeKeyboard();
                dismiss();
                return true;
            }
            return false;
        }
    });
}