Java Code Examples for android.widget.TextView#OnEditorActionListener

The following examples show how to use android.widget.TextView#OnEditorActionListener . 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: SettingsFilter.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Makes an OnEditorActionListener that calls filtersAdd when done is pressed
 *
 * @param filtersAdd called when done is pressed
 * @return The new OnEditorActionListener
 */
private TextView.OnEditorActionListener makeOnEditorActionListener(Consumer<String> filtersAdd) {
    return new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                String text = v.getText().toString().toLowerCase(Locale.ENGLISH).trim();
                if (!text.isEmpty()) {
                    filtersAdd.accept(text);
                    v.setText("");
                    updateFilters();
                }
            }
            return false;
        }
    };
}
 
Example 2
Source File: UI.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
public static TextView.OnEditorActionListener getListenerRunOnEnter(final Runnable r) {
    return new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE ||
                actionId == EditorInfo.IME_ACTION_SEARCH ||
                actionId == EditorInfo.IME_ACTION_SEND ||
                isEnterKeyDown(event)) {
                if (event == null || !event.isShiftPressed()) {
                    r.run(); // The user is done typing.
                    return true; // Consume.
                }
            }
            return false; // Pass on to other listeners.
        }
    };
}
 
Example 3
Source File: AbstractEditComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
protected final void addEditorActionListener(TextView.OnEditorActionListener listener) {
  TextView view;
  if (listener != null && (view = getHostView()) != null) {
    if (mEditorActionListeners == null) {
      mEditorActionListeners = new ArrayList<>();
      view.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        private boolean handled = true;

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
          for (TextView.OnEditorActionListener l : mEditorActionListeners) {
            if (l != null) {
              handled = handled & l.onEditorAction(v, actionId, event);
            }
          }
          return handled;
        }
      });
    }
    mEditorActionListeners.add(listener);
  }
}
 
Example 4
Source File: CustomTextView.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setOnEditorActionListener(TextView.OnEditorActionListener actionListener) {
    editText.setOnEditorActionListener((v, actionId, event) -> {
        if (validate())
            return actionListener.onEditorAction(v, actionId, event);
        return true;
    });
}
 
Example 5
Source File: AbstractViewQuery.java    From COCOQuery with Apache License 2.0 5 votes vote down vote up
/**
 * Change the custom IME action associated with the text view. click the lable will trigger the associateView's onClick method
 * @param listener
 */
public T imeAction(TextView.OnEditorActionListener listener) {
    if (view instanceof EditText) {
        ((EditText)view).setOnEditorActionListener(listener);
    }
    return self();
}
 
Example 6
Source File: EditorView.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the editor view.
 *
 * @param activity        The activity on top of which the UI should be displayed.
 * @param observerForTest Optional event observer for testing.
 */
public EditorView(Activity activity, PaymentRequestObserverForTest observerForTest) {
    super(activity, R.style.FullscreenWhiteDialog);
    mContext = activity;
    mObserverForTest = observerForTest;
    mHandler = new Handler();
    mPhoneFormatterTask = new AsyncTask<Void, Void, PhoneNumberFormattingTextWatcher>() {
        @Override
        protected PhoneNumberFormattingTextWatcher doInBackground(Void... unused) {
            return new PhoneNumberFormattingTextWatcher();
        }
    }.execute();

    mEditorActionListener = new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                mDoneButton.performClick();
                return true;
            } else if (actionId == EditorInfo.IME_ACTION_NEXT) {
                View next = v.focusSearch(View.FOCUS_FORWARD);
                if (next != null && next instanceof AutoCompleteTextView) {
                    focusInputField(next);
                    return true;
                }
            }
            return false;
        }
    };
}
 
Example 7
Source File: DataBindingAdapters.java    From OpenYOLO-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Facilitates binding editor action listeners on EditText fields.
 */
@BindingAdapter("onEditorAction")
public static void setOnEditorActionListener(
        EditText layout,
        TextView.OnEditorActionListener listener) {
    layout.setOnEditorActionListener(listener);
}
 
Example 8
Source File: UI.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public static TextView.OnEditorActionListener getListenerRunOnEnter(final Runnable r) {
    return (v, actionId, event) -> {
               if (actionId == EditorInfo.IME_ACTION_DONE ||
                   actionId == EditorInfo.IME_ACTION_SEARCH ||
                   actionId == EditorInfo.IME_ACTION_SEND ||
                   isEnterKeyDown(event)) {
                   if (event == null || !event.isShiftPressed()) {
                       r.run(); // The user is done typing.
                       return true; // Consume.
                   }
               }
               return false; // Pass on to other listeners.
    };
}
 
Example 9
Source File: DialogUtils.java    From RedReader with GNU General Public License v3.0 5 votes vote down vote up
public static void showSearchDialog (Context context, int titleRes, final OnSearchListener listener) {
	final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
	final EditText editText = (EditText) LayoutInflater.from(context).inflate(R.layout.dialog_editbox, null);

	TextView.OnEditorActionListener onEnter = new TextView.OnEditorActionListener() {
		@Override
		public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
			performSearch(editText, listener);
			return true;
		}
	};
	editText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
	editText.setOnEditorActionListener(onEnter);

	alertBuilder.setView(editText);
	alertBuilder.setTitle(titleRes);

	alertBuilder.setPositiveButton(R.string.action_search, new DialogInterface.OnClickListener() {
		@Override
		public void onClick(DialogInterface dialog, int which) {
			performSearch(editText, listener);
		}
	});

	alertBuilder.setNegativeButton(R.string.dialog_cancel, null);

	final AlertDialog alertDialog = alertBuilder.create();
	alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
	alertDialog.show();
}
 
Example 10
Source File: EditTextSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    final ComponentContext c,
    EditTextWithEventHandlers editText,
    @Prop(optional = true, resType = ResType.STRING) CharSequence text,
    @Prop(optional = true, resType = ResType.STRING) CharSequence initialText,
    @Prop(optional = true, resType = ResType.STRING) CharSequence hint,
    @Prop(optional = true) TextUtils.TruncateAt ellipsize,
    @Prop(optional = true, resType = ResType.INT) int minLines,
    @Prop(optional = true, resType = ResType.INT) int maxLines,
    @Prop(optional = true, resType = ResType.INT) int maxLength,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowRadius,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDx,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDy,
    @Prop(optional = true, resType = ResType.COLOR) int shadowColor,
    @Prop(optional = true, resType = ResType.BOOL) boolean isSingleLine,
    @Prop(optional = true, resType = ResType.COLOR) int textColor,
    @Prop(optional = true) ColorStateList textColorStateList,
    @Prop(optional = true, resType = ResType.COLOR) int hintColor,
    @Prop(optional = true) ColorStateList hintColorStateList,
    @Prop(optional = true, resType = ResType.COLOR) int linkColor,
    @Prop(optional = true, resType = ResType.COLOR) int highlightColor,
    @Prop(optional = true) ColorStateList tintColorStateList,
    @Prop(optional = true, resType = ResType.DIMEN_TEXT) int textSize,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float extraSpacing,
    @Prop(optional = true, resType = ResType.FLOAT) float spacingMultiplier,
    @Prop(optional = true) int textStyle,
    @Prop(optional = true) Typeface typeface,
    @Prop(optional = true) Layout.Alignment textAlignment,
    @Prop(optional = true) int gravity,
    @Prop(optional = true) boolean editable,
    @Prop(optional = true) int selection,
    @Prop(optional = true) int inputType,
    @Prop(optional = true) int rawInputType,
    @Prop(optional = true) int imeOptions,
    @Prop(optional = true) TextView.OnEditorActionListener editorActionListener,
    @Prop(optional = true) boolean isSingleLineWrap,
    @Prop(optional = true) boolean requestFocus,
    @Prop(optional = true) int cursorDrawableRes,
    @Prop(optional = true, varArg = "inputFilter") List<InputFilter> inputFilters,
    @State AtomicReference<EditTextWithEventHandlers> mountedView,
    @State AtomicBoolean configuredInitialText,
    @State(canUpdateLazily = true) CharSequence input) {

  mountedView.set(editText);

  initEditText(
      editText,
      input == null ? text : input,
      // Only set initialText on the EditText during the very first mount.
      configuredInitialText.getAndSet(true) ? null : initialText,
      hint,
      ellipsize,
      inputFilters,
      minLines,
      maxLines,
      maxLength,
      shadowRadius,
      shadowDx,
      shadowDy,
      shadowColor,
      isSingleLine,
      textColor,
      textColorStateList,
      hintColor,
      hintColorStateList,
      linkColor,
      highlightColor,
      tintColorStateList,
      textSize,
      extraSpacing,
      spacingMultiplier,
      textStyle,
      typeface,
      textAlignment,
      gravity,
      editable,
      selection,
      inputType,
      rawInputType,
      imeOptions,
      editorActionListener,
      isSingleLineWrap,
      requestFocus,
      cursorDrawableRes);
}
 
Example 11
Source File: EditorView.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Builds the editor view.
 *
 * @param activity        The activity on top of which the UI should be displayed.
 * @param observerForTest Optional event observer for testing.
 */
public EditorView(Activity activity, PaymentRequestObserverForTest observerForTest) {
    super(activity, R.style.FullscreenWhite);
    mContext = activity;
    mObserverForTest = observerForTest;
    mHandler = new Handler();
    mEditorActionListener = new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                mDoneButton.performClick();
                return true;
            } else if (actionId == EditorInfo.IME_ACTION_NEXT) {
                View next = v.focusSearch(View.FOCUS_FORWARD);
                if (next != null) {
                    next.requestFocus();
                    return true;
                }
            }
            return false;
        }
    };

    mHalfRowMargin = activity.getResources().getDimensionPixelSize(
            R.dimen.payments_section_large_spacing);
    mFieldViews = new ArrayList<>();
    mEditableTextFields = new ArrayList<>();
    mDropdownFields = new ArrayList<>();

    final Pattern cardNumberPattern = Pattern.compile("^[\\d- ]*$");
    mCardNumberInputFilter = new InputFilter() {
        @Override
        public CharSequence filter(
                CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            // Accept deletions.
            if (start == end) return null;

            // Accept digits, "-", and spaces.
            if (cardNumberPattern.matcher(source.subSequence(start, end)).matches()) {
                return null;
            }

            // Reject everything else.
            return "";
        }
    };

    mCardNumberFormatter = new CreditCardNumberFormattingTextWatcher();
    new AsyncTask<Void, Void, PhoneNumberFormattingTextWatcher>() {
        @Override
        protected PhoneNumberFormattingTextWatcher doInBackground(Void... unused) {
            return new PhoneNumberFormattingTextWatcher();
        }

        @Override
        protected void onPostExecute(PhoneNumberFormattingTextWatcher result) {
            mPhoneFormatter = result;
            if (mPhoneInput != null) {
                mPhoneInput.addTextChangedListener(mPhoneFormatter);
            }
        }
    }.execute();
}
 
Example 12
Source File: FocusShowTextView.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
public void setOnEditorActionListener(TextView.OnEditorActionListener l) {
    if (innerEditText != null) {
        innerEditText.setOnEditorActionListener(l);
    }
}
 
Example 13
Source File: SearchToolbar.java    From droidkaigi2016 with Apache License 2.0 4 votes vote down vote up
public void setOnEditorActionListener(TextView.OnEditorActionListener actionListener) {
    binding.editSearch.setOnEditorActionListener(actionListener);
}
 
Example 14
Source File: NumberPicker.java    From NumberPicker with MIT License 4 votes vote down vote up
public void setOnEditorActionListener(TextView.OnEditorActionListener onEditorActionListener) {
    this.displayEditText.setOnEditorActionListener(onEditorActionListener);
}
 
Example 15
Source File: EditorDialog.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Builds the editor dialog.
 *
 * @param activity        The activity on top of which the UI should be displayed.
 * @param observerForTest Optional event observer for testing.
 */
public EditorDialog(Activity activity, PaymentRequestObserverForTest observerForTest) {
    super(activity, R.style.FullscreenWhite);
    // Sets transparent background for animating content view.
    getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    mContext = activity;
    mObserverForTest = observerForTest;
    mHandler = new Handler();
    mEditorActionListener = new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                mDoneButton.performClick();
                return true;
            } else if (actionId == EditorInfo.IME_ACTION_NEXT) {
                View next = v.focusSearch(View.FOCUS_FORWARD);
                if (next != null) {
                    next.requestFocus();
                    return true;
                }
            }
            return false;
        }
    };

    mHalfRowMargin = activity.getResources().getDimensionPixelSize(
            R.dimen.payments_section_large_spacing);
    mDropdownTopPadding = activity.getResources().getDimensionPixelSize(
            R.dimen.payments_section_dropdown_top_padding);
    mFieldViews = new ArrayList<>();
    mEditableTextFields = new ArrayList<>();
    mDropdownFields = new ArrayList<>();

    final Pattern cardNumberPattern = Pattern.compile("^[\\d- ]*$");
    mCardNumberInputFilter = new InputFilter() {
        @Override
        public CharSequence filter(
                CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            // Accept deletions.
            if (start == end) return null;

            // Accept digits, "-", and spaces.
            if (cardNumberPattern.matcher(source.subSequence(start, end)).matches()) {
                return null;
            }

            // Reject everything else.
            return "";
        }
    };

    mCardNumberFormatter = new CreditCardNumberFormattingTextWatcher();
    mPhoneFormatter = new PhoneNumberUtil.FormatTextWatcher();
}
 
Example 16
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void onEditorAction(TextView.OnEditorActionListener arg) {
  return BaseDSL.attr("onEditorAction", arg);
}
 
Example 17
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void onEditorAction(TextView.OnEditorActionListener arg) {
  return BaseDSL.attr("onEditorAction", arg);
}
 
Example 18
Source File: SearchToolbar.java    From droidkaigi2016 with Apache License 2.0 4 votes vote down vote up
public void setOnEditorActionListener(TextView.OnEditorActionListener actionListener) {
    binding.editSearch.setOnEditorActionListener(actionListener);
}
 
Example 19
Source File: WatchOnlyLoginActivity.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setAppNameTitle();
    setContentView(R.layout.activity_watchonly);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    setTitleBackTransparent();
    setAppNameTitle();

    mUsernameText = UI.find(this, R.id.input_user);
    mPasswordText = UI.find(this, R.id.input_password);
    mLoginButton = UI.find(this, R.id.btn_login);
    mRememberSwitch = UI.find(this, R.id.remember_watch_only);

    mLoginButton.setOnClickListener(this);

    final TextView.OnEditorActionListener listener;
    listener = UI.getListenerRunOnEnter(this::onLoginButtonClicked);
    mPasswordText.setOnEditorActionListener(listener);

    final String username = cfg().getString(PrefKeys.WATCH_ONLY_USERNAME, "");
    final String password = cfg().getString(PrefKeys.WATCH_ONLY_PASSWORD, "");
    final boolean hasCredentials = !username.isEmpty();
    mUsernameText.setText(username);
    mPasswordText.setText(password);
    mRememberSwitch.setChecked(hasCredentials);

    mRememberSwitch.setOnCheckedChangeListener((compoundButton, isChecked) -> {
        if (!isChecked) {
            cfg().edit().putString(PrefKeys.WATCH_ONLY_USERNAME, "")
            .putString(PrefKeys.WATCH_ONLY_PASSWORD, "").apply();
            mUsernameText.setText("");
            mPasswordText.setText("");
            return;
        }

        UI.popup(WatchOnlyLoginActivity.this, R.string.id_warning_watchonly_credentials)
        .content(R.string.id_your_watchonly_username_and)
        .canceledOnTouchOutside(false)
        .onNegative((dlg, which) -> mRememberSwitch.setChecked(false))
        .onPositive((dlg, which) -> mRememberSwitch.setChecked(true)).build().show();
    });
}
 
Example 20
Source File: EditTextRow.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setOnEditorActionListener(TextView.OnEditorActionListener onEditorActionListener){
    mOnEditorActionListener = onEditorActionListener;
}