Java Code Examples for android.widget.TextView#OnEditorActionListener

The following examples show how to use android.widget.TextView#OnEditorActionListener . These examples are extracted from open source projects. 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
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 2
Source Project: GreenBits   File: UI.java    License: 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
/**
 * 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 4
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 5
public void setOnEditorActionListener(TextView.OnEditorActionListener actionListener) {
    editText.setOnEditorActionListener((v, actionId, event) -> {
        if (validate())
            return actionListener.onEditorAction(v, actionId, event);
        return true;
    });
}
 
Example 6
Source Project: green_android   File: UI.java    License: 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 7
/**
 * 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 Project: delion   File: EditorView.java    License: 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 9
Source Project: COCOQuery   File: AbstractViewQuery.java    License: 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 10
@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 11
Source Project: litho   File: EditTextSpec.java    License: 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 12
Source Project: AndroidChromium   File: EditorView.java    License: 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 13
Source Project: BaseProject   File: FocusShowTextView.java    License: Apache License 2.0 4 votes vote down vote up
public void setOnEditorActionListener(TextView.OnEditorActionListener l) {
    if (innerEditText != null) {
        innerEditText.setOnEditorActionListener(l);
    }
}
 
Example 14
Source Project: droidkaigi2016   File: SearchToolbar.java    License: Apache License 2.0 4 votes vote down vote up
public void setOnEditorActionListener(TextView.OnEditorActionListener actionListener) {
    binding.editSearch.setOnEditorActionListener(actionListener);
}
 
Example 15
Source Project: NumberPicker   File: NumberPicker.java    License: MIT License 4 votes vote down vote up
public void setOnEditorActionListener(TextView.OnEditorActionListener onEditorActionListener) {
    this.displayEditText.setOnEditorActionListener(onEditorActionListener);
}
 
Example 16
Source Project: 365browser   File: EditorDialog.java    License: 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 17
Source Project: anvil   File: DSL.java    License: MIT License 4 votes vote down vote up
public static Void onEditorAction(TextView.OnEditorActionListener arg) {
  return BaseDSL.attr("onEditorAction", arg);
}
 
Example 18
Source Project: anvil   File: DSL.java    License: MIT License 4 votes vote down vote up
public static Void onEditorAction(TextView.OnEditorActionListener arg) {
  return BaseDSL.attr("onEditorAction", arg);
}
 
Example 19
Source Project: droidkaigi2016   File: SearchToolbar.java    License: Apache License 2.0 4 votes vote down vote up
public void setOnEditorActionListener(TextView.OnEditorActionListener actionListener) {
    binding.editSearch.setOnEditorActionListener(actionListener);
}
 
Example 20
public void setOnEditorActionListener(TextView.OnEditorActionListener onEditorActionListener){
    mOnEditorActionListener = onEditorActionListener;
}