下面列出了android.view.inputmethod.EditorInfo#IME_ACTION_DONE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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);
}
}
/**
* 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
}
@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;
}
@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;
}
@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;
}
@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;
}
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
checkPassword(v.getText().toString());
return true;
}
return false;
}
@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;
}
@Override
public void onEditorAction(int actionCode) {
super.onEditorAction(actionCode);
if (actionCode == EditorInfo.IME_ACTION_DONE) {
clearFocus();
}
}
@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;
}
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
onAddPrinterButtonClicked();
}
return false;
}
/**
* 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);
}
@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;
}
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// Submit
addItem();
return true;
}
return false;
}
@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;
}
@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;
}
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
hideInputLayout();
createAssignment();
return true;
}
return false;
}
/**
* 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);
}
/**
* 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;
}
/**
* 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();
}