Java Code Examples for android.widget.EditText#setClickable()

The following examples show how to use android.widget.EditText#setClickable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongolInputMethodManager.java    From mongol-library with MIT License 6 votes vote down vote up
private void setAllowSystemKeyboardOnEditText(EditText editText, boolean allowSystemKeyboard) {
    // TODO this needs to be tested on lower versions!
    // https://stackoverflow.com/a/45229457

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // api 21+
        editText.setShowSoftInputOnFocus(allowSystemKeyboard);
    } else { // api 11+
        if (allowSystemKeyboard) {
            // re-enable keyboard (see https://stackoverflow.com/a/45228867)
            // FIXME this does not necessarily always work
            editText.setTextIsSelectable(false);
            editText.setFocusable(true);
            editText.setFocusableInTouchMode(true);
            editText.setClickable(true);
            editText.setLongClickable(true);
            editText.setMovementMethod(ArrowKeyMovementMethod.getInstance());
            editText.setText(editText.getText(), TextView.BufferType.SPANNABLE);
        } else {
            // disable keyboard
            editText.setTextIsSelectable(true);
        }
    }
}
 
Example 2
Source File: AlertBuilder.java    From biermacht with Apache License 2.0 6 votes vote down vote up
public AlertDialog.Builder editTextDisabled(final TextView text, final TextView title, String message) {
  LayoutInflater factory = LayoutInflater.from(context);
  final LinearLayout alertView = (LinearLayout) factory.inflate(R.layout.alert_view_edit_text_float_2_4, null);
  final EditText editText = (EditText) alertView.findViewById(R.id.edit_text);
  final TextView messageView = new TextView(this.context);
  messageView.setText(message);
  messageView.setGravity(Gravity.CENTER);
  alertView.addView(messageView);

  // Set text
  editText.setText(text.getText().toString());

  // Set disabled.
  editText.setEnabled(false);
  editText.setClickable(false);
  editText.setFocusable(false);
  editText.setFocusableInTouchMode(false);

  return new AlertDialog.Builder(context)
          .setTitle(title.getText().toString())
          .setView(alertView)
          .setPositiveButton(R.string.ok, null);
}
 
Example 3
Source File: DialpadView.java    From call_manage with MIT License 5 votes vote down vote up
/**
 * Whether or not the digits above the dialer can be edited.
 *
 * @param canBeEdited If true, the backspace button will be shown and the digits EditText
 *                    will be configured to allow text manipulation.
 */
public void setDigitsCanBeEdited(boolean canBeEdited) {
    View deleteButton = findViewById(R.id.button_delete);
    deleteButton.setVisibility(canBeEdited ? View.VISIBLE : View.GONE);
    View callButton = findViewById(R.id.button_call);
    callButton.setVisibility(canBeEdited ? View.VISIBLE : View.GONE);
    EditText digits = (DigitsEditText) findViewById(R.id.digits_edit_text);
    digits.setClickable(canBeEdited);
    digits.setLongClickable(canBeEdited);
    digits.setFocusableInTouchMode(canBeEdited);
    digits.setCursorVisible(canBeEdited);
}
 
Example 4
Source File: Pinview.java    From Pinview with MIT License 5 votes vote down vote up
/**
 * Takes care of styling the editText passed in the param.
 * tag is the index of the editText.
 *
 * @param styleEditText
 * @param tag
 */
private void generateOneEditText(EditText styleEditText, String tag) {
    params.setMargins(mSplitWidth / 2, mSplitWidth / 2, mSplitWidth / 2, mSplitWidth / 2);
    filters[0] = new InputFilter.LengthFilter(1);
    styleEditText.setFilters(filters);
    styleEditText.setLayoutParams(params);
    styleEditText.setGravity(Gravity.CENTER);
    styleEditText.setCursorVisible(mCursorVisible);

    if (!mCursorVisible) {
        styleEditText.setClickable(false);
        styleEditText.setHint(mHint);

        styleEditText.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                // When back space is pressed it goes to delete mode and when u click on an edit Text it should get out of the delete mode
                mDelPressed = false;
                return false;
            }
        });
    }
    styleEditText.setBackgroundResource(mPinBackground);
    styleEditText.setPadding(0, 0, 0, 0);
    styleEditText.setTag(tag);
    styleEditText.setInputType(getKeyboardInputType());
    styleEditText.addTextChangedListener(this);
    styleEditText.setOnFocusChangeListener(this);
    styleEditText.setOnKeyListener(this);
}
 
Example 5
Source File: JieEditTextDel.java    From AndJie with GNU General Public License v2.0 5 votes vote down vote up
protected void initLayout() {
	context = getContext();
	view = LayoutInflater.from(context).inflate(R.layout.item_editext_del,
			null);
	lefText = (TextView) view.findViewById(R.id.leftText);
	middleText = (EditText) view.findViewById(R.id.middleText);
	rightText = (TextView) view.findViewById(R.id.rightText);
	rightImg = (ImageView) view.findViewById(R.id.right_img);
	middleText.setSingleLine(true);
	middleText.setEllipsize(TruncateAt.END);
	middleText.setClickable(true);
	addListener();
	addView(view);
}
 
Example 6
Source File: CreateOrEditActivity.java    From android-sqlite-sample with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    personID = getIntent().getIntExtra(MainActivity.KEY_EXTRA_CONTACT_ID, 0);

    setContentView(R.layout.activity_edit);
    nameEditText = (EditText) findViewById(R.id.editTextName);
    genderEditText = (EditText) findViewById(R.id.editTextGender);
    ageEditText = (EditText) findViewById(R.id.editTextAge);

    saveButton = (Button) findViewById(R.id.saveButton);
    saveButton.setOnClickListener(this);
    buttonLayout = (LinearLayout) findViewById(R.id.buttonLayout);
    editButton = (Button) findViewById(R.id.editButton);
    editButton.setOnClickListener(this);
    deleteButton = (Button) findViewById(R.id.deleteButton);
    deleteButton.setOnClickListener(this);

    dbHelper = new ExampleDBHelper(this);

    if(personID > 0) {
        saveButton.setVisibility(View.GONE);
        buttonLayout.setVisibility(View.VISIBLE);

        Cursor rs = dbHelper.getPerson(personID);
        rs.moveToFirst();
        String personName = rs.getString(rs.getColumnIndex(ExampleDBHelper.PERSON_COLUMN_NAME));
        String personGender = rs.getString(rs.getColumnIndex(ExampleDBHelper.PERSON_COLUMN_GENDER));
        int personAge = rs.getInt(rs.getColumnIndex(ExampleDBHelper.PERSON_COLUMN_AGE));
        if (!rs.isClosed()) {
            rs.close();
        }

        nameEditText.setText(personName);
        nameEditText.setFocusable(false);
        nameEditText.setClickable(false);

        genderEditText.setText((CharSequence) personGender);
        genderEditText.setFocusable(false);
        genderEditText.setClickable(false);

        ageEditText.setText((CharSequence) (personAge + ""));
        ageEditText.setFocusable(false);
        ageEditText.setClickable(false);
    }
}
 
Example 7
Source File: AlertBuilder.java    From biermacht with Apache License 2.0 4 votes vote down vote up
public AlertDialog.Builder editTextFloatCheckBoxAlert(final TextView text, final TextView title, boolean checked, final BooleanCallback cb) {
  LayoutInflater factory = LayoutInflater.from(context);
  final LinearLayout alertView = (LinearLayout) factory.inflate(R.layout.alert_view_edit_text_float_with_check_box, null);
  final EditText editText = (EditText) alertView.findViewById(R.id.edit_text);
  final CheckBox checkBox = (CheckBox) alertView.findViewById(R.id.check_box);

  // Set text
  editText.setText(text.getText().toString());

  checkBox.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      cb.call(checkBox.isChecked());
      if (checkBox.isChecked()) {
        editText.setEnabled(false);
        editText.setClickable(false);
        editText.setFocusable(false);
        editText.setFocusableInTouchMode(false);
        editText.setText(text.getText().toString());
      }
      else {
        editText.setEnabled(true);
        editText.setClickable(true);
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
      }
    }
  });

  // Set the box to be checked or not.
  checkBox.setChecked(checked);

  // If checked initially, grey out edit text
  if (checked) {
    editText.setEnabled(false);
    editText.setClickable(false);
    editText.setFocusable(false);
    editText.setFocusableInTouchMode(false);
  }

  return new AlertDialog.Builder(context)
          .setTitle(title.getText().toString())
          .setView(alertView)
          .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
              text.setText(editText.getText().toString());
              callback.call();
              cb.call(checkBox.isChecked());
            }

          })

          .setNegativeButton(R.string.cancel, null);
}
 
Example 8
Source File: StringWidget.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
public StringWidget(Context context, FormEntryPrompt prompt, boolean secret, boolean inCompactGroup) {
    super(context, prompt, inCompactGroup);
    mAnswer = (EditText)LayoutInflater.from(getContext()).inflate(getAnswerLayout(), this, false);
    mAnswer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontSize);
    mAnswer.setOnClickListener(this);

    mAnswer.addTextChangedListener(this);

    //Let's see if we can figure out a constraint for this string
    try {
        addAnswerFilter(new InputFilter.LengthFilter(guessMaxStringLength(prompt)));
    } catch (UnpivotableExpressionException e) {
        //expected if there isn't a constraint that does this
    }

    this.secret = secret;

    if (!secret) {
        // capitalize the first letter of the sentence
        mAnswer.setKeyListener(new TextKeyListener(Capitalize.SENTENCES, false));
    }
    setTextInputType(mAnswer);

    if (!secret) {
        mAnswer.setSingleLine(false);
    }

    if (prompt != null) {
        mReadOnly = prompt.isReadOnly();
        IAnswerData value = prompt.getAnswerValue();
        if (value != null) {
            mAnswer.setText(value.getDisplayText());
        }

        if (mReadOnly) {
            if (value == null) {
                mAnswer.setText("---");
            }
            mAnswer.setBackgroundDrawable(null);
            mAnswer.setFocusable(false);
            mAnswer.setClickable(false);
        }
    }

    if (isInCompactMode()) {
        addToCompactLayout(mAnswer);
    } else {
        addView(mAnswer);
    }
}