Example usage for android.text InputType TYPE_CLASS_PHONE

List of usage examples for android.text InputType TYPE_CLASS_PHONE

Introduction

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

Prototype

int TYPE_CLASS_PHONE

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

Click Source Link

Document

Class for a phone number.

Usage

From source file:com.fb.android.remindmap.parselogin.ParseLoginActivity.java

private void updatePhoneNumber(final ParseUser user) {
    AlertDialog.Builder phoneNumberDialog = new AlertDialog.Builder(this);
    phoneNumberDialog.setTitle("Phone Number").setMessage("Please enter a 10 digit phone number");

    final EditText phoneNumberInput = new EditText(this);
    if (user.get("phoneNumber") != null) {
        phoneNumberInput.setText(user.get("phoneNumber").toString());
    }//from   w  ww  . j a v a  2  s  .c  om
    phoneNumberInput.setInputType(InputType.TYPE_CLASS_PHONE);
    phoneNumberInput.setPadding(100, 0, 100, 25);
    phoneNumberDialog.setView(phoneNumberInput);

    phoneNumberDialog.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            user.put("phoneNumber", phoneNumberInput.getText().toString());
            user.pinInBackground("phoneNumber", new SaveCallback() {
                @Override
                public void done(ParseException e) {
                    if (e == null) {
                        user.saveEventually();
                    } else {
                        Toast.makeText(getApplicationContext(), "Error saving: " + e.getMessage(),
                                Toast.LENGTH_LONG).show();
                    }
                }
            });

            if (user.get("phoneNumber") == null) {
                Toast.makeText(getApplicationContext(), "Please enter a valid 10-digit phone number",
                        Toast.LENGTH_LONG).show();
                updatePhoneNumber(user);
            }
            if (user.get("phoneNumber") != null) {
                if (user.get("phoneNumber").toString().length() != 10) {
                    Toast.makeText(getApplicationContext(), "Please enter a valid 10-digit phone number",
                            Toast.LENGTH_LONG).show();
                    updatePhoneNumber(user);
                }
                if (user.get("phoneNumber").toString().length() == 10) {
                    finish();
                }
            }
        }
    })

            .setIcon(android.R.drawable.ic_menu_call).show();
}

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:/*  w  w  w.  j av a 2s.c  o  m*/
        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;/*w  w  w  .jav 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;
        }
    });
}

From source file:com.emobc.android.activities.generators.FormActivityGenerator.java

private EditText insertPhoneField(Activity activity, FormDataItem dataItem) {
    EditText txt = insertTextField(activity, dataItem);
    txt.setInputType(InputType.TYPE_CLASS_PHONE);
    return txt;
}

From source file:com.android.mms.rcs.FavoriteDetailActivity.java

private void inputNumberForwarMessage() {
    final EditText editText = new EditText(FavoriteDetailActivity.this);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    editText.setLayoutParams(lp);/*from   w  w w .  j  av a 2s.  c o m*/
    editText.setInputType(InputType.TYPE_CLASS_PHONE);
    editText.setHint(R.string.forward_input_number_hint);
    new AlertDialog.Builder(FavoriteDetailActivity.this).setTitle(R.string.forward_input_number_title)
            .setView(editText).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    String input = editText.getText().toString();
                    if (TextUtils.isEmpty(input)) {
                        Toast.makeText(FavoriteDetailActivity.this, R.string.forward_input_number_title,
                                Toast.LENGTH_SHORT).show();
                    } else {
                        String[] numbers = input.split(";");
                        if (numbers != null && numbers.length > 0) {
                            ArrayList<String> numberList = new ArrayList<String>();
                            for (int i = 0; i < numbers.length; i++) {
                                numberList.add(numbers[i]);
                            }
                            forwardRcsMessage(numberList);
                        }
                    }
                }
            }).setNegativeButton(android.R.string.cancel, null).show();
}

From source file:com.auth0.android.lock.views.ValidatedInputView.java

private void setupInputValidation() {
    String hint = "";
    String error = "";
    input.setTransformationMethod(null);
    Log.v(TAG, "Setting up validation for field of type " + dataType);
    switch (dataType) {
    case EMAIL://ww  w.j  av a  2  s .  c o m
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
        inputIcon = R.drawable.com_auth0_lock_ic_email;
        hint = getResources().getString(R.string.com_auth0_lock_hint_email);
        error = getResources().getString(R.string.com_auth0_lock_input_error_email);
        break;
    case PASSWORD:
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        input.setTransformationMethod(PasswordTransformationMethod.getInstance());
        input.setTypeface(Typeface.DEFAULT);
        inputIcon = R.drawable.com_auth0_lock_ic_password;
        hint = getResources().getString(R.string.com_auth0_lock_hint_password);
        error = getResources().getString(R.string.com_auth0_lock_input_error_password);
        break;
    case USERNAME_OR_EMAIL:
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
        inputIcon = R.drawable.com_auth0_lock_ic_username;
        hint = getResources().getString(R.string.com_auth0_lock_hint_username_or_email);
        error = getResources().getString(R.string.com_auth0_lock_input_error_username_email);
        break;
    case TEXT_NAME:
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
        inputIcon = R.drawable.com_auth0_lock_ic_username;
        hint = getResources().getString(R.string.com_auth0_lock_hint_username);
        error = getResources().getString(R.string.com_auth0_lock_input_error_empty);
        break;
    case NON_EMPTY_USERNAME:
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
        inputIcon = R.drawable.com_auth0_lock_ic_username;
        hint = getResources().getString(R.string.com_auth0_lock_hint_username);
        error = getResources().getString(R.string.com_auth0_lock_input_error_username_empty);
        break;
    case USERNAME:
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
        inputIcon = R.drawable.com_auth0_lock_ic_username;
        hint = getResources().getString(R.string.com_auth0_lock_hint_username);
        error = String.format(getResources().getString(R.string.com_auth0_lock_input_error_username),
                MIN_USERNAME_LENGTH, MAX_USERNAME_LENGTH);
        break;
    case NUMBER:
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        inputIcon = R.drawable.com_auth0_lock_ic_password;
        hint = getResources().getString(R.string.com_auth0_lock_hint_code);
        error = getResources().getString(R.string.com_auth0_lock_input_error_empty);
        break;
    case MFA_CODE:
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        inputIcon = R.drawable.com_auth0_lock_ic_password;
        hint = getResources().getString(R.string.com_auth0_lock_hint_code);
        error = getResources().getString(R.string.com_auth0_lock_input_error_code);
        break;
    case MOBILE_PHONE:
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        inputIcon = R.drawable.com_auth0_lock_ic_mobile;
        hint = getResources().getString(R.string.com_auth0_lock_hint_phone_number);
        error = getResources().getString(R.string.com_auth0_lock_input_error_phone_number);
        break;
    case PHONE_NUMBER:
        input.setInputType(InputType.TYPE_CLASS_PHONE);
        inputIcon = R.drawable.com_auth0_lock_ic_phone;
        hint = getResources().getString(R.string.com_auth0_lock_hint_phone_number);
        error = getResources().getString(R.string.com_auth0_lock_input_error_phone_number);
        break;
    }
    input.setHint(hint);
    errorDescription.setText(error);
    icon.setImageResource(inputIcon);
}

From source file:edu.cens.loci.ui.widget.GenericEditorView.java

/**
 * Prepare this editor using the given {@link DataKind} for defining
 * structure and {@link ValuesDelta} describing the content to edit.
 *///from   ww w.  j  ava 2 s .  c o  m
public void setValues(DataKind kind, ValuesDelta entry, EntityDelta state, boolean readOnly,
        ViewIdGenerator vig) {
    mKind = kind;
    mEntry = entry;
    mState = state;
    mReadOnly = readOnly;
    mViewIdGenerator = vig;

    setId(vig.getId(state, kind, entry, ViewIdGenerator.NO_VIEW_INDEX));

    final boolean enabled = !readOnly;

    //Log.d(TAG, "setValues: kind=" + mKind.mimeType);

    if (!entry.isVisible()) {
        // Hide ourselves entirely if deleted
        setVisibility(View.GONE);
        return;
    } else {
        setVisibility(View.VISIBLE);
    }

    // Display label selector if multiple types available
    final boolean hasTypes = EntityModifier.hasEditTypes(kind);
    mLabel.setVisibility(hasTypes ? View.VISIBLE : View.GONE);
    mLabel.setEnabled(enabled);
    if (hasTypes) {
        mType = EntityModifier.getCurrentType(entry, kind);
        rebuildLabel();
    }

    // Build out set of fields
    mFields.removeAllViews();
    boolean hidePossible = false;
    int n = 0;

    if (mKind.mimeType.equals(WifiFingerprint.CONTENT_ITEM_TYPE)) {

        //Log.d(TAG, "setValues: Wifi");

        for (EditField field : kind.fieldList) {
            Button fieldView = (Button) mInflater.inflate(RES_WIFI_FIELD, mFields, false);

            mWifiFieldButtonId = vig.getId(state, kind, entry, n++);

            fieldView.setId(mWifiFieldButtonId);

            final String column = field.column;
            final String value = entry.getAsString(column);
            fieldView.setText("Fingerprint on " + MyDateUtils.getAbrv_MMM_d_h_m(new Long(value)));

            final String extra1column = field.extra1;
            final String extra1value = entry.getAsString(extra1column);
            try {
                mWifiFingerprint = new LociWifiFingerprint(extra1value);
                mWifiFingerprintTimeStamp = MyDateUtils.getDateFormatLong(new Long(value));
            } catch (JSONException e) {
                MyLog.e(LociConfig.D.JSON, TAG, "LociWifiFingerprint parsing failed");
                e.printStackTrace();
            }

            // Hide field when empty and optional value
            final boolean couldHide = (field.optional);
            final boolean willHide = (mHideOptional && couldHide);
            fieldView.setVisibility(willHide ? View.GONE : View.VISIBLE);
            fieldView.setEnabled(enabled);
            hidePossible = hidePossible || couldHide;

            fieldView.setOnClickListener(this);

            mFields.addView(fieldView);
        }
    } else if (mKind.mimeType.equals(Keyword.CONTENT_ITEM_TYPE)) {

        //Log.d(TAG, "setValues: Keywords");

        for (EditField field : kind.fieldList) {

            AutoCompleteTextView fieldView = (AutoCompleteTextView) mInflater.inflate(RES_AUTOCOMPLETE_FIELD,
                    mFields, false);
            fieldView.setId(vig.getId(state, kind, entry, n++));
            if (field.titleRes > 0) {
                fieldView.setHint(field.titleRes);
            }
            int inputType = field.inputType;
            fieldView.setInputType(inputType);
            fieldView.setMinLines(field.minLines);

            // Read current value from state
            final String column = field.column;
            final String value = entry.getAsString(column);
            fieldView.setText(value);

            // Prepare listener for writing changes
            fieldView.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    // Trigger event for newly changed value
                    onFieldChanged(column, s.toString());
                }

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

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
            });

            // Hide field when empty and optional value
            final boolean couldHide = (field.optional);
            final boolean willHide = (mHideOptional && couldHide);
            fieldView.setVisibility(willHide ? View.GONE : View.VISIBLE);
            fieldView.setEnabled(enabled);
            hidePossible = hidePossible || couldHide;

            String[] usedKeywords = getResources().getStringArray(R.array.keyword_default);

            LociDbUtils myDb = new LociDbUtils(getContext());
            ArrayList<String> suggestedKeywords = myDb.getSavedKeywords();
            HashSet<String> suggestedKeywordsSet = new HashSet<String>();

            for (String keyword : suggestedKeywords) {
                suggestedKeywordsSet.add(keyword);
            }

            //Log.d(TAG, "size of usedKeywords : " + usedKeywords.length);
            //Log.d(TAG, "size of suggestedKeywords : " + suggestedKeywords.size());

            for (String usedKeyword : usedKeywords) {
                if (!suggestedKeywordsSet.contains(usedKeyword))
                    suggestedKeywords.add(usedKeyword);
            }

            //Log.d(TAG, "size of suggestedKeywords : " + suggestedKeywords.size());

            Collections.sort(suggestedKeywords);

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getContext(),
                    R.layout.item_suggestion_list, suggestedKeywords);
            fieldView.setAdapter(adapter);
            fieldView.setThreshold(0);

            mFields.addView(fieldView);
        }

    } else {

        //Log.d(TAG, "General Types...");

        for (EditField field : kind.fieldList) {
            // Inflate field from definition
            EditText fieldView = (EditText) mInflater.inflate(RES_FIELD, mFields, false);
            fieldView.setId(vig.getId(state, kind, entry, n++));
            if (field.titleRes > 0) {
                fieldView.setHint(field.titleRes);
            }
            int inputType = field.inputType;
            fieldView.setInputType(inputType);
            if (inputType == InputType.TYPE_CLASS_PHONE) {
                fieldView.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
            }
            fieldView.setMinLines(field.minLines);

            // Read current value from state
            final String column = field.column;
            final String value = entry.getAsString(column);
            fieldView.setText(value);

            //Log.d(TAG, "setValues: column=" + column);
            //Log.d(TAG, "setValues: value=" + value);

            // Prepare listener for writing changes
            fieldView.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    // Trigger event for newly changed value
                    onFieldChanged(column, s.toString());
                }

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

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
            });

            // Hide field when empty and optional value
            final boolean couldHide = (field.optional);
            final boolean willHide = (mHideOptional && couldHide);
            fieldView.setVisibility(willHide ? View.GONE : View.VISIBLE);
            fieldView.setEnabled(enabled);
            hidePossible = hidePossible || couldHide;

            mFields.addView(fieldView);
        }
    }

    // When hiding fields, place expandable
    if (hidePossible) {
        mMore.setVisibility(mHideOptional ? View.VISIBLE : View.GONE);
        mLess.setVisibility(mHideOptional ? View.GONE : View.VISIBLE);
    } else {
        mMore.setVisibility(View.GONE);
        mLess.setVisibility(View.GONE);
    }
    mMore.setEnabled(enabled);
    mLess.setEnabled(enabled);
}

From source file:com.mobicage.rogerthat.SendMessageButtonActivity.java

private void addButton() {
    final View dialog = getLayoutInflater().inflate(R.layout.new_button_dialog, null);
    final TextInputLayout captionViewLayout = (TextInputLayout) dialog.findViewById(R.id.button_caption);
    mCaptionView = captionViewLayout.getEditText();
    mActionView = (EditText) dialog.findViewById(R.id.button_action);
    final ImageButton actionHelpButton = (ImageButton) dialog.findViewById(R.id.action_help_button);
    final RadioButton noneRadio = (RadioButton) dialog.findViewById(R.id.action_none);
    final RadioButton telRadio = (RadioButton) dialog.findViewById(R.id.action_tel);
    final RadioButton geoRadio = (RadioButton) dialog.findViewById(R.id.action_geo);
    final RadioButton wwwRadio = (RadioButton) dialog.findViewById(R.id.action_www);
    final int iconColor = LookAndFeelConstants.getPrimaryIconColor(SendMessageButtonActivity.this);
    noneRadio.setChecked(true);//from  w ww .j ava  2s  .  c  o m
    mActionView.setVisibility(View.GONE);
    actionHelpButton.setVisibility(View.GONE);
    noneRadio.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            mActionView.setVisibility(View.GONE);
            actionHelpButton.setVisibility(View.GONE);
        }
    });
    telRadio.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            mActionView.setText("");
            mActionView.setVisibility(View.VISIBLE);
            mActionView.setInputType(InputType.TYPE_CLASS_PHONE);
            actionHelpButton.setVisibility(View.VISIBLE);
            actionHelpButton.setImageDrawable(new IconicsDrawable(mService, FontAwesome.Icon.faw_address_book_o)
                    .color(iconColor).sizeDp(24));
        }
    });
    geoRadio.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            mActionView.setText("");
            mActionView.setVisibility(View.VISIBLE);
            mActionView.setInputType(InputType.TYPE_CLASS_TEXT);
            actionHelpButton.setVisibility(View.VISIBLE);
            actionHelpButton.setImageDrawable(
                    new IconicsDrawable(mService, FontAwesome.Icon.faw_map_marker).color(iconColor).sizeDp(24));
        }
    });
    wwwRadio.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            mActionView.setText("http://");
            mActionView.setVisibility(View.VISIBLE);
            mActionView.setInputType(InputType.TYPE_CLASS_TEXT);
            actionHelpButton.setVisibility(View.GONE);
        }
    });
    actionHelpButton.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            if (telRadio.isChecked()) {
                Intent intent = new Intent(Intent.ACTION_PICK,
                        ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
                startActivityForResult(intent, PICK_CONTACT);
            } else if (geoRadio.isChecked()) {
                Intent intent = new Intent(SendMessageButtonActivity.this, GetLocationActivity.class);
                startActivityForResult(intent, GET_LOCATION);
            }
        }
    });
    String message = getString(R.string.create_button_title);
    String positiveCaption = getString(R.string.ok);
    String negativeCaption = getString(R.string.cancel);
    SafeDialogClick positiveClick = new SafeDialogClick() {
        @Override
        public void safeOnClick(DialogInterface di, int id) {
            String caption = mCaptionView.getText().toString();
            if ("".equals(caption.trim())) {
                UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.caption_required));
                return;
            }

            CannedButton cannedButton;
            if (!noneRadio.isChecked()) {
                String actionText = mActionView.getText().toString();
                if ("".equals(caption.trim())) {
                    UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.action_not_valid));
                    return;
                }
                if (telRadio.isChecked()) {
                    actionText = "tel://" + actionText;
                } else if (geoRadio.isChecked()) {
                    actionText = "geo://" + actionText;
                }

                Matcher action = actionPattern.matcher(actionText);
                if (!action.matches()) {
                    UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.action_not_valid));
                    return;
                }
                cannedButton = new CannedButton(caption, "".equals(action.group(2)) ? null : action.group());

            } else {
                cannedButton = new CannedButton(caption, null);
            }

            mCannedButtons.add(cannedButton);
            cannedButton.setSelected(true);
            mCannedButtonAdapter.notifyDataSetChanged();
            mButtons.add(cannedButton.getId());
            di.dismiss();
        }
    };
    AlertDialog alertDialog = UIUtils.showDialog(SendMessageButtonActivity.this, null, message, positiveCaption,
            positiveClick, negativeCaption, null, dialog);
    alertDialog.setCanceledOnTouchOutside(true);
}

From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.java

/**
 * This is the main point where we do our initialization of the input method
 * to begin operating on an application.  At this point we have been
 * bound to the client, and are now receiving all of the detailed information
 * about the target of our edits.//  w  ww . j a  v  a2 s. c  o  m
 */
@Override
public void onStartInput(EditorInfo attribute, boolean restarting) {
    super.onStartInput(attribute, restarting);

    // Reset our state.  We want to do this even if restarting, because
    // the underlying state of the text editor could have changed in any way.
    mComposing.setLength(0);
    updateCandidates();

    if (!restarting) {
        // Clear shift states.
        mMetaState = 0;
    }

    mPredictionOn = false;
    mCompletionOn = false;
    mCompletions = null;

    // We are now going to initialize our state based on the type of
    // text being edited.
    switch (attribute.inputType & InputType.TYPE_MASK_CLASS) {
    case InputType.TYPE_CLASS_NUMBER:
    case InputType.TYPE_CLASS_DATETIME:
        // Numbers and dates default to the symbols keyboard, with
        // no extra features.
        mCurKeyboard = mSymbolsKeyboard;
        break;

    case InputType.TYPE_CLASS_PHONE:
        // Phones will also default to the symbols keyboard, though
        // often you will want to have a dedicated phone keyboard.
        mCurKeyboard = mSymbolsKeyboard;
        break;

    case InputType.TYPE_CLASS_TEXT:
        // This is general text editing.  We will default to the
        // normal alphabetic keyboard, and assume that we should
        // be doing predictive text (showing candidates as the
        // user types).
        mCurKeyboard = mQwertyKeyboard;
        mPredictionOn = true;
        //mPredictionOn = false;

        // We now look for a few special variations of text that will
        // modify our behavior.
        int variation = attribute.inputType & InputType.TYPE_MASK_VARIATION;
        if (variation == InputType.TYPE_TEXT_VARIATION_PASSWORD
                || variation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
            // Do not display predictions / what the user is typing
            // when they are entering a password.
            mPredictionOn = false;
        }

        if (variation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
                || variation == InputType.TYPE_TEXT_VARIATION_URI
                || variation == InputType.TYPE_TEXT_VARIATION_FILTER) {
            // Our predictions are not useful for e-mail addresses
            // or URIs.
            mPredictionOn = false;
        }

        if ((attribute.inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) {
            // If this is an auto-complete text view, then our predictions
            // will not be shown and instead we will allow the editor
            // to supply their own.  We only show the editor's
            // candidates when in fullscreen mode, otherwise relying
            // own it displaying its own UI.
            mPredictionOn = false;
            mCompletionOn = isFullscreenMode();
        }

        // We also want to look at the current state of the editor
        // to decide whether our alphabetic keyboard should start out
        // shifted.
        updateShiftKeyState(attribute);
        break;

    default:
        // For all unknown input types, default to the alphabetic
        // keyboard with no special features.
        mCurKeyboard = mQwertyKeyboard;
        updateShiftKeyState(attribute);
    }

    // Update the label on the enter key, depending on what the application
    // says it will do.
    mCurKeyboard.setImeOptions(getResources(), attribute.imeOptions);
}

From source file:com.grass.caishi.cc.activity.SettingUserActivity.java

/**
 * /*from  w  ww  .j av a2  s .  c  o m*/
 */
public void change_age(String age) {

    final EditText texta = new EditText(this);
    texta.setText(age);
    // EditText
    texta.setKeyListener(new NumberKeyListener() {
        public int getInputType() {
            return InputType.TYPE_CLASS_PHONE;
        }

        @Override
        protected char[] getAcceptedChars() {
            // TODO Auto-generated method stub
            char[] numbers = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
            return numbers;
        }
    });
    new AlertDialog.Builder(this).setTitle("").setIcon(android.R.drawable.ic_dialog_info)
            .setView(texta).setPositiveButton("", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogg, int which) {
                    String age = texta.getEditableText().toString();
                    RequestParams params = new RequestParams();
                    params.add("age", age);
                    params.add("type", "age");
                    HttpRestClient.get(Constant.UPDATE_USER_INFO_DO, params, responseHandler);
                    dialog.show();
                    dialogg.dismiss();
                    // ?
                }
            }).setNegativeButton("?", null).show();
    // return true;
}