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

The following examples show how to use android.widget.EditText#setFocusableInTouchMode() . 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: AbstractEditComponent.java    From weex-uikit with MIT License 6 votes vote down vote up
@WXComponentProp(name = Constants.Name.AUTOFOCUS)
public void setAutofocus(boolean autofocus) {
  if (getHostView() == null) {
    return;
  }
  mAutoFocus = autofocus;
  EditText inputView = getHostView();
  if (mAutoFocus) {
    inputView.setFocusable(true);
    inputView.requestFocus();
    inputView.setFocusableInTouchMode(true);
    showSoftKeyboard();
  } else {
    hideSoftKeyboard();
  }
}
 
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: KeyboardHelper.java    From belvedere with Apache License 2.0 6 votes vote down vote up
private KeyboardHelper(@NonNull Activity activity) {
    super(activity);
    this.statusBarHeight = getStatusBarHeight();
    int sizeForDummyView = activity.getResources()
            .getDimensionPixelSize(zendesk.belvedere.ui.R.dimen.belvedere_dummy_edit_text_size);
    setLayoutParams(new ViewGroup.LayoutParams(sizeForDummyView, sizeForDummyView));

    inputTrap = new EditText(activity);
    inputTrap.setFocusable(true);
    inputTrap.setFocusableInTouchMode(true);
    inputTrap.setVisibility(View.VISIBLE);
    inputTrap.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    inputTrap.setInputType(EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES);

    addView(inputTrap);

    final View rootView = activity.getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(new KeyboardTreeObserver(activity));
}
 
Example 4
Source File: RxKeyboardTool.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
/**
 * 切换键盘显示与否状态
 *
 * @param context 上下文
 * @param edit    输入框
 */
public static void toggleSoftInput(Context context, EditText edit) {
    edit.setFocusable(true);
    edit.setFocusableInTouchMode(true);
    edit.requestFocus();
    InputMethodManager inputManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
 
Example 5
Source File: KeyboardUtils.java    From android-mvp-architecture with Apache License 2.0 5 votes vote down vote up
public static void showSoftInput(EditText edit, Context context) {
    edit.setFocusable(true);
    edit.setFocusableInTouchMode(true);
    edit.requestFocus();
    InputMethodManager imm = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(edit, 0);
}
 
Example 6
Source File: EmoticonsKeyboardUtils.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 开启软键盘
 * @param et
 */
public static void openSoftKeyboard(EditText et) {
    if (et != null) {
        et.setFocusable(true);
        et.setFocusableInTouchMode(true);
        et.requestFocus();
        InputMethodManager inputManager = (InputMethodManager) et.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.showSoftInput(et, 0);
    }
}
 
Example 7
Source File: KeyBoardUtils.java    From Android_UE with Apache License 2.0 5 votes vote down vote up
/**
 * EditText获取焦点并显示软键盘
 */
public static void showSoftInputFromWindow(EditText editText, Activity activity) {
    editText.setFocusable(true);
    editText.setFocusableInTouchMode(true);
    editText.requestFocus();
    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
 
Example 8
Source File: KeyboardUtils.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * 动态显示软键盘
 */
public static void showSoftInput(Context context, EditText edit) {
    edit.setFocusable(true);
    edit.setFocusableInTouchMode(true);
    edit.requestFocus();
    InputMethodManager inputManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.showSoftInput(edit, 0);
}
 
Example 9
Source File: ViewAdapter.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * EditText重新获取焦点的事件绑定
 */
@BindingAdapter(value = {"requestFocus"}, requireAll = false)
public static void requestFocusCommand(EditText editText, final Boolean needRequestFocus) {
    if (needRequestFocus) {
        editText.setSelection(editText.getText().length());
        editText.requestFocus();
        InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    }
    editText.setFocusableInTouchMode(needRequestFocus);
}
 
Example 10
Source File: RxKeyboardTool.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
/**
 * 动态显示软键盘
 *
 * @param context 上下文
 * @param edit    输入框
 */
public static void showSoftInput(Context context, EditText edit) {
    edit.setFocusable(true);
    edit.setFocusableInTouchMode(true);
    edit.requestFocus();
    InputMethodManager inputManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.showSoftInput(edit, 0);
}
 
Example 11
Source File: KeyboardUtils.java    From Android-UtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * 动态显示软键盘
 *
 * @param edit 输入框
 */
public static void showSoftInput(EditText edit) {
    edit.setFocusable(true);
    edit.setFocusableInTouchMode(true);
    edit.requestFocus();
    InputMethodManager imm = (InputMethodManager) Utils.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null) return;
    imm.showSoftInput(edit, 0);
}
 
Example 12
Source File: UIHelp.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
public static void showSoftInputFromWindow(EditText editText)
{
    editText.setFocusable(true);
    editText.setFocusableInTouchMode(true);
    editText.requestFocus();
    InputMethodManager inputManager = (InputMethodManager) editText.getContext().getSystemService(
            Context.INPUT_METHOD_SERVICE);
    inputManager.showSoftInput(editText, 0);
}
 
Example 13
Source File: UtilsActivity.java    From AndroidDemo with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void showSoftInput(Context context, EditText edit) {
	edit.setFocusable(true);
	edit.setFocusableInTouchMode(true);
	edit.requestFocus();
	InputMethodManager inputManager = (InputMethodManager) context
			.getSystemService(Context.INPUT_METHOD_SERVICE);
	inputManager.showSoftInput(edit, 0);
}
 
Example 14
Source File: FormAdapter.java    From SSForms with GNU General Public License v3.0 5 votes vote down vote up
private void setDatePickerInputLayout(final EditText editText, final int position, final LinearLayout layoutRow) {
    editText.setFocusableInTouchMode(false);

    editText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editText.requestFocus();
            InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
        }
    });

    layoutRow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            clickedPosition = position;
            DatePickerDialog datePickerDialog = new DatePickerDialog(mContext,
                    date,
                    mCalendarCurrentDate.get(Calendar.YEAR),
                    mCalendarCurrentDate.get(Calendar.MONTH),
                    mCalendarCurrentDate.get(Calendar.DAY_OF_MONTH));

            // this could be used to set a minimum date
            // datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);

            // display the picker
            datePickerDialog.show();
        }
    });

}
 
Example 15
Source File: KeyboardUtil.java    From timecat with Apache License 2.0 5 votes vote down vote up
/**
 * 针对于EditText 获得焦点,显示软键盘
 *
 * @param edit EditText
 */
public void showKeyboard(EditText edit) {
    edit.setFocusable(true);
    edit.setFocusableInTouchMode(true);
    edit.requestFocus();
    imm.showSoftInput(edit, 0);
}
 
Example 16
Source File: EmoticonsKeyboardUtils.java    From aurora-imui with MIT License 5 votes vote down vote up
/**
 * 开启软键盘
 * @param et
 */
public static void openSoftKeyboard(EditText et) {
    if (et != null) {
        et.setFocusable(true);
        et.setFocusableInTouchMode(true);
        et.requestFocus();
        InputMethodManager inputManager = (InputMethodManager) et.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.showSoftInput(et, 0);
    }
}
 
Example 17
Source File: ScriptEditorActivity.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
public void resetView(){
	this.source = (ScriptSourceConfig)MainActivity.script;
	
	TextView title = (TextView)findViewById(R.id.title);
	title.setText(Utils.stripTags(this.instance.name));
	
	String script = source.source;
	
	EditText editScript = (EditText)findViewById(R.id.scriptSource);
	Button saveButton = (Button)findViewById(R.id.saveScriptButton);
	
	if (script != null && !script.equals("")) {
		editScript.setText(script);
	}
	else {
		editScript.setText("");
	}
	
	boolean isAdmin = (MainActivity.user != null) && instance.isAdmin;
	if (!isAdmin || instance.isExternal) {
		editScript.setFocusable(false);
		saveButton.setEnabled(false);
		saveButton.setVisibility(View.GONE);
	} else {
		editScript.setFocusableInTouchMode(true);
		saveButton.setEnabled(true);
	}
}
 
Example 18
Source File: MaterialDialog.java    From pius1 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setView(View view)
{
           LinearLayout l = (LinearLayout) mAlertDialogWindow.findViewById(R.id.contentView);
           l.removeAllViews();
           ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
	ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
           view.setLayoutParams(layoutParams);

           view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
	    @Override public void onFocusChange(View v, boolean hasFocus)
	    {
		mAlertDialogWindow.setSoftInputMode(
                           WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
		// show imm
		InputMethodManager imm = (InputMethodManager) mContext.getSystemService(
                           Context.INPUT_METHOD_SERVICE);
		imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
				    InputMethodManager.HIDE_IMPLICIT_ONLY);
	    }
	});

           l.addView(view);

           if (view instanceof ViewGroup)
    {

               ViewGroup viewGroup = (ViewGroup) view;

               for (int i = 0; i < viewGroup.getChildCount(); i++)
	{
                   if (viewGroup.getChildAt(i) instanceof EditText)
	    {
                       EditText editText = (EditText) viewGroup.getChildAt(i);
                       editText.setFocusable(true);
                       editText.requestFocus();
                       editText.setFocusableInTouchMode(true);
                   }
               }
               for (int i = 0; i < viewGroup.getChildCount(); i++)
	{
                   if (viewGroup.getChildAt(i) instanceof AutoCompleteTextView)
	    {
                       AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) viewGroup
		    .getChildAt(i);
                       autoCompleteTextView.setFocusable(true);
                       autoCompleteTextView.requestFocus();
                       autoCompleteTextView.setFocusableInTouchMode(true);
                   }
               }
           }
       }
 
Example 19
Source File: IpcamActivity.java    From openwebnet-android with MIT License 4 votes vote down vote up
private void enableEditText(EditText editText) {
    editText.setEnabled(true);
    editText.setFocusableInTouchMode(true);
}
 
Example 20
Source File: RichAdapter.java    From RichEditor with Apache License 2.0 4 votes vote down vote up
/**
 * 文本编辑器
 */
private void bindEditComponent(RecyclerView.ViewHolder holder, final int pos, final
RichModel item) {
    if (holder instanceof EditHolder) {
        final EditText mEdit = ((EditHolder) holder).mEt;
        mEtHolder.add(mEdit);
        if (index == pos) {
            mCurEdit = ((EditHolder) holder).mEt;
            mEdit.setFocusable(true);
            mEdit.setFocusableInTouchMode(true);
            mEdit.requestFocus();
        } else {
            mEdit.setFocusable(false);
        }
        ((EditHolder) holder).textWatcher.updatePosition(pos);
        ((EditHolder) holder).filter.updatePosition(pos);
        mEdit.setTextSize(Const.DEFAULT_TEXT_SIZE);
        if (item.isParagraphStyle) {
            SpannableStringBuilder spannableString = new SpannableStringBuilder(item.source);
            for (Object obj : item.paragraphSpan.mSpans) {
                if (obj instanceof AbsoluteSizeSpan) {
                    AbsoluteSizeSpan sizeSpan = (AbsoluteSizeSpan) obj;
                    mEdit.setTextSize(sizeSpan.getSize());
                    continue;
                }
                spannableString.setSpan(obj, 0, item.source.length(), Spanned
                        .SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            mEdit.setText(spannableString);
            paragraphHelper.handleTextStyle(mEdit, item.paragraphSpan.paragraphType);
        } else {
            mSpanString.clear();
            mSpanString.clearSpans();
            mSpanString.append(item.source);
            if (isEnter) {
                for (SpanModel span : item.getSpanList()) {
                    mSpanString.setMultiSpans(span.mSpans, span.start, span.end, Spanned
                            .SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
            mEdit.setText(mSpanString);
            paragraphHelper.handleTextStyle(mEdit, -1);
        }
        mEdit.setSelection(item.curIndex);
        //mEdit.setSelection(item.source.length());
        mEdit.setHint(item.hint);
        mEdit.setTag(pos);
        //只存在一个EditText的时候,点击区域太小,所以只有一个的时候,将MinHeight设为500
        if (index == pos && index < 2 && index == mData.size() - 1) {
            mEdit.setMinHeight(DensityUtil.dp2px(mContext, 500));
        } else {
            mEdit.setMinHeight(DensityUtil.dp2px(mContext, 0));
        }
    }

}