Java Code Examples for android.view.inputmethod.EditorInfo#IME_ACTION_DONE

The following examples show how to use android.view.inputmethod.EditorInfo#IME_ACTION_DONE . 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: BatteryServiceFragment.java    From ble-test-peripheral-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
  if (actionId == EditorInfo.IME_ACTION_DONE) {
    String newBatteryLevelString = textView.getText().toString();
    // Need to check if the string is empty since isDigitsOnly returns
    // true for empty strings.
    if (!newBatteryLevelString.isEmpty()
        && android.text.TextUtils.isDigitsOnly(newBatteryLevelString)) {
      int newBatteryLevel = Integer.parseInt(newBatteryLevelString);
      if (newBatteryLevel <= BATTERY_LEVEL_MAX) {
        setBatteryLevel(newBatteryLevel, textView);
      } else {
        Toast.makeText(getActivity(), R.string.batteryLevelTooHigh, Toast.LENGTH_SHORT)
            .show();
      }
    } else {
      Toast.makeText(getActivity(), R.string.batteryLevelIncorrect, Toast.LENGTH_SHORT)
          .show();
    }
  }
  return false;
}
 
Example 2
Source File: PassphrasePromptActivity.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent keyEvent) {
  if ((keyEvent == null && actionId == EditorInfo.IME_ACTION_DONE) ||
      (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN &&
          (actionId == EditorInfo.IME_NULL)))
  {
    handlePassphrase();
    return true;
  } else if (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_UP &&
             actionId == EditorInfo.IME_NULL)
  {
    return true;
  }

  return false;
}
 
Example 3
Source File: InputMethodService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Return text that can be used as a button label for the given
 * {@link EditorInfo#imeOptions EditorInfo.imeOptions}.  Returns null
 * if there is no action requested.  Note that there is no guarantee that
 * the returned text will be relatively short, so you probably do not
 * want to use it as text on a soft keyboard key label.
 *
 * @param imeOptions The value from {@link EditorInfo#imeOptions EditorInfo.imeOptions}.
 *
 * @return Returns a label to use, or null if there is no action.
 */
public CharSequence getTextForImeAction(int imeOptions) {
    switch (imeOptions&EditorInfo.IME_MASK_ACTION) {
        case EditorInfo.IME_ACTION_NONE:
            return null;
        case EditorInfo.IME_ACTION_GO:
            return getText(com.android.internal.R.string.ime_action_go);
        case EditorInfo.IME_ACTION_SEARCH:
            return getText(com.android.internal.R.string.ime_action_search);
        case EditorInfo.IME_ACTION_SEND:
            return getText(com.android.internal.R.string.ime_action_send);
        case EditorInfo.IME_ACTION_NEXT:
            return getText(com.android.internal.R.string.ime_action_next);
        case EditorInfo.IME_ACTION_DONE:
            return getText(com.android.internal.R.string.ime_action_done);
        case EditorInfo.IME_ACTION_PREVIOUS:
            return getText(com.android.internal.R.string.ime_action_previous);
        default:
            return getText(com.android.internal.R.string.ime_action_default);
    }
}
 
Example 4
Source File: AuthenticatorActivity.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  Called when the 'action' button in an IME is pressed ('enter' in software keyboard).
 * 
 *  Used to trigger the authentication check when the user presses 'enter' after writing the 
 *  password, or to throw the server test when the only field on screen is the URL input field.
 */
@Override
public boolean onEditorAction(TextView inputField, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE && inputField != null && 
            inputField.equals(mPasswordInput)) {
        if (mOkButton.isEnabled()) {
            mOkButton.performClick();
        }

    } else if (actionId == EditorInfo.IME_ACTION_NEXT && inputField != null && 
            inputField.equals(mHostUrlInput)) {
        if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).
                equals(mAuthTokenType)) {
            checkOcServer();
        }
    }
    return false;   // always return false to grant that the software keyboard is hidden anyway
}
 
Example 5
Source File: TextInputQuizView.java    From android-topeka with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (TextUtils.isEmpty(v.getText())) {
        return false;
    }
    allowAnswer();
    if (actionId == EditorInfo.IME_ACTION_DONE) {
        submitAnswer();
        hideKeyboard(v);
        return true;
    }
    return false;
}
 
Example 6
Source File: KeyCodeDescriptionMapper.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a context-sensitive description of the "Enter" action key.
 *
 * @param context The package's context.
 * @param keyboard The keyboard on which the key resides.
 * @param key The key to describe.
 * @return Returns a context-sensitive description of the "Enter" action key.
 */
private static String getDescriptionForActionKey(final Context context, final Keyboard keyboard,
        final Key key) {
    final KeyboardId keyboardId = keyboard.mId;
    final int actionId = keyboardId.imeAction();
    final int resId;

    // Always use the label, if available.
    if (!TextUtils.isEmpty(key.getLabel())) {
        return key.getLabel().trim();
    }

    // Otherwise, use the action ID.
    switch (actionId) {
    case EditorInfo.IME_ACTION_SEARCH:
        resId = R.string.spoken_description_search;
        break;
    case EditorInfo.IME_ACTION_GO:
        resId = R.string.label_go_key;
        break;
    case EditorInfo.IME_ACTION_SEND:
        resId = R.string.label_send_key;
        break;
    case EditorInfo.IME_ACTION_NEXT:
        resId = R.string.label_next_key;
        break;
    case EditorInfo.IME_ACTION_DONE:
        resId = R.string.label_done_key;
        break;
    case EditorInfo.IME_ACTION_PREVIOUS:
        resId = R.string.label_previous_key;
        break;
    default:
        resId = R.string.spoken_description_return;
    }
    return context.getString(resId);
}
 
Example 7
Source File: AssignmentsFragment.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE) {
        hideInputLayout();
        createAssignment();
        return true;
    }
    return false;
}
 
Example 8
Source File: AdbShell.java    From RemoteAdbShell with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
	/* We always return false because we want to dismiss the keyboard */
	
	if (commandBox.getText().length() == 0 || connection == null)
		return false;
	
	if (actionId == EditorInfo.IME_ACTION_DONE)
	{
		String text = commandBox.getText().toString();
		
		/* Append the command to our command buffer (which is empty) */
		commandBuffer.append(text);
		
		/* Add the command to the previous command list */
		commandHistory.add(text);
		
		/* Append a newline since it's not included in the command itself */
		commandBuffer.append('\n');
		
		/* Send it to the device */
		connection.queueCommand(commandBuffer.toString());
		
		/* Clear the textbox and command buffer */
		commandBuffer.setLength(0);
		commandBox.setText("");
		
		/* Force scroll to the bottom */
		scrollViewAtBottom = true;
		doAsyncGuiUpdate();
		return true;
	}
	
	return false;
}
 
Example 9
Source File: NeighborsFragment.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if ((actionId == EditorInfo.IME_ACTION_DONE)
            || ((event.getKeyCode() == KeyEvent.KEYCODE_ENTER) && (event.getAction() == KeyEvent.ACTION_DOWN))) {
        if (editTextNewAddress.getText().toString().isEmpty()) {
            Snackbar.make(getActivity().findViewById(R.id.drawer_layout), getString(R.string.messages_enter_neighbor_address), Snackbar.LENGTH_LONG)
                    .setAction(null, null).show();
            return false;
        }
        addNeighbor();
    }
    return true;
}
 
Example 10
Source File: BlacklistDialog.java    From UpdogFarmer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE) {
        // Submit
        addItem();
        return true;
    }
    return false;
}
 
Example 11
Source File: ChangeSeedPasswordDialog.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
@OnEditorAction(R.id.password_new_confirm)
public boolean onPasswordNewConfirmEditorAction(int actionId, KeyEvent event) {
    if ((actionId == EditorInfo.IME_ACTION_DONE)
            || ((event.getKeyCode() == KeyEvent.KEYCODE_ENTER) && (event.getAction() == KeyEvent.ACTION_DOWN))) {
        changeSeedPassword();
    }

    return true;
}
 
Example 12
Source File: DatePicker.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the IME options for a spinner based on its ordering.
 *
 * @param spinner The spinner.
 * @param spinnerCount The total spinner count.
 * @param spinnerIndex The index of the given spinner.
 */
private void setImeOptions(NumberPicker spinner, int spinnerCount, int spinnerIndex) {
    final int imeOptions;
    if (spinnerIndex < spinnerCount - 1) {
        imeOptions = EditorInfo.IME_ACTION_NEXT;
    } else {
        imeOptions = EditorInfo.IME_ACTION_DONE;
    }
    TextView input = (TextView) spinner.findViewById(R.id.numberpicker_input);
    input.setImeOptions(imeOptions);
}
 
Example 13
Source File: AddPrinterActivity.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE) {
        onAddPrinterButtonClicked();
    }
    return false;
}
 
Example 14
Source File: SplitBCCSendActivity.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE) {
        if (btnSend.isEnabled()) {
            sendClick.onClick(btnSend);
        }
        return true;
    }
    return false;
}
 
Example 15
Source File: NumberPicker.java    From zen4android with MIT License 5 votes vote down vote up
@Override
public void onEditorAction(int actionCode) {
    super.onEditorAction(actionCode);
    if (actionCode == EditorInfo.IME_ACTION_DONE) {
        clearFocus();
    }
}
 
Example 16
Source File: CommandDialogFragment.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE && getDialog() != null) {
        Button ok = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
        if (ok != null) ok.performClick();
    }
    return false;
}
 
Example 17
Source File: AuthenticateActivity.java    From andOTP with MIT License 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE) {
        checkPassword(v.getText().toString());
        return true;
    }

    return false;
}
 
Example 18
Source File: PassphrasePromptActivity.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent keyEvent) {
  if ((keyEvent == null && actionId == EditorInfo.IME_ACTION_DONE) ||
      (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN &&
       (actionId == EditorInfo.IME_NULL))) {
    if (okButton.isClickable()) {
      okButton.performClick();
    }
    return true;
  }
  return keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_UP
          && actionId == EditorInfo.IME_NULL;
}
 
Example 19
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 20
Source File: InPlaceEditView.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Finish the in-place editing of the given text area, release the edit lock, and allow the synchronous call
 * to 'edit' to return.
 */
private synchronized void endEditing(int reason, boolean forceVKBOpen, boolean forceVKBClose, int actionCode) {
    //if (cursorTimer != null) {
    //    cursorTimer.cancel();
    //}
    System.out.println("-------In endEditing");
    if (!mIsEditing || mEditText == null) {
        return;
    }
    // SJH: Setting visibility GONE causes a size change event to be fired even when the
    // input mode is adjustPan.  This causes problems and glitches with the layout because we
    // have to guess if a resize even is accurate or not.
    //setVisibility(GONE);
    mLastEndEditReason = reason;

    // If the IME action is set to NEXT, do not hide the virtual keyboard
    boolean isNextActionFlagSet = ((mEditText.getImeOptions() & 0xf) == EditorInfo.IME_ACTION_NEXT);



    boolean leaveKeyboardShowing = impl.isAsyncEditMode();
    System.out.println("Next flag: "+isNextActionFlagSet);
    System.out.println("Next cmp: "+getNextComponent(mEditText.mTextArea));
    System.out.println("Reason : "+reason+" IME Action: "+REASON_IME_ACTION);
    if (reason == REASON_IME_ACTION && isNextActionFlagSet) {
        if (getNextComponent(mEditText.mTextArea) instanceof TextArea) {
            leaveKeyboardShowing = true;
        } else {
            leaveKeyboardShowing = false;
        }

    }
    if (forceVKBOpen) {
        leaveKeyboardShowing = true;
    }
    if (forceVKBClose) {
        leaveKeyboardShowing = false;
    }
    System.out.println("-----LEAVE KEYBOARD SHOWING: "+leaveKeyboardShowing);
    if (!leaveKeyboardShowing || actionCode == EditorInfo.IME_ACTION_DONE || actionCode == EditorInfo.IME_ACTION_SEARCH || actionCode == EditorInfo.IME_ACTION_SEND || actionCode == EditorInfo.IME_ACTION_GO) {
        System.out.println("Hiding virtual keyboard");
        showVirtualKeyboard(false);
    }
    int imo = mEditText.getImeOptions() & 0xf; // Get rid of flags
    if (reason == REASON_IME_ACTION
            && ((TextArea) mEditText.mTextArea).getDoneListener() != null
            && (actionCode == EditorInfo.IME_ACTION_DONE)|| actionCode == EditorInfo.IME_ACTION_SEARCH || actionCode == EditorInfo.IME_ACTION_SEND || actionCode == EditorInfo.IME_ACTION_GO) {
        ((TextArea) mEditText.mTextArea).fireDoneEvent();

    }
    

    // Call this in onComplete instead
    //mIsEditing = false;
    mLastEditText = mEditText;
    removeView(mEditText);
    Component editingComponent = mEditText.mTextArea;
    mEditText.removeTextChangedListener(mEditText.mTextWatcher);
    mEditText = null;

    if (impl.isAsyncEditMode()) {
        Runnable onComplete = (Runnable)editingComponent.getClientProperty("android.onAsyncEditingComplete");
        editingComponent.putClientProperty("android.onAsyncEditingComplete", null);
        if (onComplete != null) {
            Display.getInstance().callSerially(onComplete);
        }
    }

    waitingForSynchronousEditingCompletion = false;
}