Example usage for android.view KeyEvent KEYCODE_DEL

List of usage examples for android.view KeyEvent KEYCODE_DEL

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_DEL.

Prototype

int KEYCODE_DEL

To view the source code for android.view KeyEvent KEYCODE_DEL.

Click Source Link

Document

Key code constant: Backspace key.

Usage

From source file:com.android.deskclock.timer.TimerSetupView.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_0:
        return clickButton(mNumbers[0]);
    case KeyEvent.KEYCODE_1:
        return clickButton(mNumbers[1]);
    case KeyEvent.KEYCODE_2:
        return clickButton(mNumbers[2]);
    case KeyEvent.KEYCODE_3:
        return clickButton(mNumbers[3]);
    case KeyEvent.KEYCODE_4:
        return clickButton(mNumbers[4]);
    case KeyEvent.KEYCODE_5:
        return clickButton(mNumbers[5]);
    case KeyEvent.KEYCODE_6:
        return clickButton(mNumbers[6]);
    case KeyEvent.KEYCODE_7:
        return clickButton(mNumbers[7]);
    case KeyEvent.KEYCODE_8:
        return clickButton(mNumbers[8]);
    case KeyEvent.KEYCODE_9:
        return clickButton(mNumbers[9]);
    case KeyEvent.KEYCODE_DEL:
        return clickButton(mDelete);
    default:/*from   w  w  w  . j  a  va 2 s . co m*/
        return false;
    }
}

From source file:com.andinrajesh.emojicon.EmojiPopup.java

public static void backspace(EditText editText) {
    KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
    editText.dispatchKeyEvent(event);//w  ww .  j  a v a2  s .  com
}

From source file:com.androidinspain.deskclock.timer.TimerSetupView.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    View view = null;/*from w w  w  . j  a va2s. c om*/
    if (keyCode == KeyEvent.KEYCODE_DEL) {
        view = mDeleteView;
    } else if (keyCode >= KeyEvent.KEYCODE_0 && keyCode <= KeyEvent.KEYCODE_9) {
        view = mDigitViews[keyCode - KeyEvent.KEYCODE_0];
    }

    if (view != null) {
        final boolean result = view.performClick();
        if (result && hasValidInput()) {
            mFabContainer.updateFab(FabContainer.FAB_REQUEST_FOCUS);
        }
        return result;
    }

    return false;
}

From source file:cn.apputest.ctria.section2.Lucha2Activity.java

void inti() {

    if (manager == null) {
        try {//from  www  .  j av  a2 s  .  c o m
            manager = Manager.getInstance();
        } catch (Exception e) {
            e.printStackTrace();
            // finish();
        }
    }
    openInterface();

    context = this.getParent();
    toast = new Toast(context);
    preferences = context.getSharedPreferences(Login.FILE_USER, MODE_PRIVATE);
    String DBName = preferences.getString(Login.KEY_NAME, "1");
    helper = new DBHelper(context, DBName + "_DB");
    mgr = new DBManager(helper);

    isNetworkConnected(context);
    qualificationsID = (EditText) findViewById(R.id.IDcardnum);
    driverlicenseID = (EditText) findViewById(R.id.DriverCardID);
    qualificationsID.addTextChangedListener(mTextWatcherjob);
    driverlicenseID.addTextChangedListener(mTextWatcherdriver);

    error1 = (TextView) findViewById(R.id.warning_P1);

    zheng1 = (TextView) findViewById(R.id.zheng_P1);
    zheng2 = (TextView) findViewById(R.id.zheng_P2);

    zheng1.setOnClickListener(this);
    zheng2.setOnClickListener(this);

    uploadrecordlucha = (RelativeLayout) findViewById(R.id.uploadrecordlucha);
    chancel1 = (RelativeLayout) findViewById(R.id.chancel1);

    uploadrecordlucha.setOnClickListener(this);
    chancel1.setOnClickListener(this);

    qualificationsID.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if (keyCode == KeyEvent.KEYCODE_DEL) {
                error1.setText("");
                zheng2.setTextColor(getResources().getColor(R.color.black));
            }
            return false;
        }
    });
    driverlicenseID.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if (keyCode == KeyEvent.KEYCODE_DEL) {

                error1.setText("");
                zheng1.setTextColor(getResources().getColor(R.color.black));

            }
            return false;
        }
    });
}

From source file:com.googlecode.eyesfree.brailleback.IMENavigationMode.java

@Override
public boolean onMappedInputEvent(BrailleInputEvent event, DisplayManager.Content content) {
    BrailleIME ime = getIME();/*from   w w w  .  j a  v a  2s .c  om*/

    // These commands are handled by the IME whenever it is accepting
    // input, even if it has not taken control of the display.
    if (ime != null && mState.acceptsText()) {
        switch (event.getCommand()) {
        case BrailleInputEvent.CMD_KEY_DEL:
            return ime.sendAndroidKey(KeyEvent.KEYCODE_DEL);
        case BrailleInputEvent.CMD_KEY_ENTER:
            return ime.sendAndroidKey(KeyEvent.KEYCODE_ENTER);
        case BrailleInputEvent.CMD_KEY_FORWARD_DEL:
            return ime.sendAndroidKey(KeyEvent.KEYCODE_FORWARD_DEL);
        case BrailleInputEvent.CMD_BRAILLE_KEY:
            return ime.handleBrailleKey(event.getArgument());
        }
    }

    // If navigation commands are handled by the IME in this state, then
    // move the cursor by the appropriate granularity.
    if (ime != null && mState.navigatesViaIME()) {
        switch (event.getCommand()) {
        case BrailleInputEvent.CMD_NAV_ITEM_PREVIOUS:
            return ime.moveCursor(BrailleIME.DIRECTION_BACKWARD,
                    AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER);
        case BrailleInputEvent.CMD_NAV_ITEM_NEXT:
            return ime.moveCursor(BrailleIME.DIRECTION_FORWARD,
                    AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER);
        case BrailleInputEvent.CMD_NAV_LINE_PREVIOUS:
            // Line navigation moves by paragraph since there's no way
            // of knowing the line extents in the edit text.
            return ime.moveCursor(BrailleIME.DIRECTION_BACKWARD,
                    AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_PARAGRAPH);
        case BrailleInputEvent.CMD_NAV_LINE_NEXT:
            return ime.moveCursor(BrailleIME.DIRECTION_FORWARD,
                    AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_PARAGRAPH);
        }
    }

    // Alternatively, we may handle these navigation commands by sending
    // "move by granularity" through the accessibility system.
    if (ime != null && mState.navigatesByTextGranularity()) {
        AccessibilityNodeInfoCompat focusedNode = getFocusedNode();
        switch (event.getCommand()) {
        case BrailleInputEvent.CMD_NAV_ITEM_PREVIOUS:
            return previousAtMovementGranularity(AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER);
        case BrailleInputEvent.CMD_NAV_ITEM_NEXT:
            return nextAtMovementGranularity(AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER);
        case BrailleInputEvent.CMD_NAV_LINE_PREVIOUS:
            return previousAtMovementGranularity(AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_LINE);
        case BrailleInputEvent.CMD_NAV_LINE_NEXT:
            return nextAtMovementGranularity(AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_LINE);
        }
    }

    // These commands are handled by the IME only when it has taken
    // control of the display. Otherwise, they are delegated.
    if (ime != null && mState.controlsDisplay()) {
        switch (event.getCommand()) {
        case BrailleInputEvent.CMD_ACTIVATE_CURRENT:
            return ime.sendDefaultAction();
        case BrailleInputEvent.CMD_ROUTE:
            return ime.route(event.getArgument(), content);
        }
    }

    // If all else fails, delegate the event.
    return mNext.onMappedInputEvent(event, content);
}

From source file:de.elanev.studip.android.app.frontend.messages.MessageComposeFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // initialize CursorLoader
    getLoaderManager().initLoader(0, mArgs, this);
    // initializing OptionsMenu and Actionbar
    setHasOptionsMenu(true);//from www.j a va2 s.  c om

    // fill the views with message details from the arguments if existing
    if (mUserItem != null && mMessageFlag != MESSAGE_FORWARD) {
        mAutoCompleteTextView.setText(mUserItem.getFullname());
        mAutoCompleteTextView.setTag(mUserItem);
        mAutoCompleteTextView.setEnabled(false);
    }

    // set message subject and fragment title according to the messageFlag
    if (mSubject != null) {
        switch (mMessageFlag) {
        case MESSAGE_FORWARD:
            mSubject = String.format("%s: %s", getString(R.string.message_forward_string), mSubject);
            getActivity().setTitle(TextTools.capitalizeFirstLetter(getString(R.string.forward_message)));
            break;
        case MESSAGE_REPLY:
            mSubject = String.format("%s: %s", getString(R.string.message_reply_string), mSubject);
            getActivity().setTitle(TextTools.capitalizeFirstLetter(getString(R.string.reply_message)));
            break;
        }

        mSubjectEditTextView.setText(mSubject);
    }

    if (mMessage != null)
        mMessageEditTextView.setText(String.format("\n%s %s:\n%s", getString(R.string.original_message),
                TextTools.getLocalizedAuthorAndDateString(mUserItem.getFullname(), mDate, mContext),
                Html.fromHtml(mMessage)));

    mAutoCompleteTextView.setOnItemClickListener(new OnItemClickListener() {

        // set the selected item
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            UserItem item = (UserItem) parent.getItemAtPosition(position);
            mAutoCompleteTextView.setTag(item);
            mAutoCompleteTextView.setEnabled(false);
        }
    });

    mAutoCompleteTextView.setOnKeyListener(new OnKeyListener() {

        // Check if there is a valid receiver set an delete it completely
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_DEL) {
                if (mAutoCompleteTextView.getTag() != null) {
                    mAutoCompleteTextView.setTag(null);
                    mAutoCompleteTextView.setText("");
                }
            }
            return false;
        }
    });

    if (TextUtils.isEmpty(mAutoCompleteTextView.getText())) {
        mAutoCompleteTextView.requestFocus();
    } else if (TextUtils.isEmpty(mSubjectEditTextView.getText())) {
        mSubjectEditTextView.requestFocus();
    } else {
        mMessageEditTextView.requestFocus();
        mMessageEditTextView.setSelection(0);
    }

}

From source file:com.googlecode.eyesfree.brailleback.IMENavigationModeTest.java

/**
 * Tests the behaviour of the "text only" mode.
 * Used when there's an input connection, but input is not started.
 *//* ww w .j a va 2 s .com*/
public void testTextOnlyMode() {
    mIMENavMode.onActivate();
    mIMENavMode.onCreateIME();
    verify(mNext).onActivate();
    mIMENavMode.onBindInput();

    assertEquals(mBrailleTranslator, mIMENavMode.getBrailleTranslator());
    assertNull(mIMENavMode.getDisplayManager());
    assertEquals(mFeedbackManager, mIMENavMode.getFeedbackManager());

    AccessibilityEvent accessibilityEvent = AccessibilityEvent.obtain();
    try {
        mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent);
        verify(mNext).onObserveAccessibilityEvent(accessibilityEvent);
    } finally {
        accessibilityEvent.recycle();
    }

    accessibilityEvent = AccessibilityEvent.obtain();
    try {
        mIMENavMode.onAccessibilityEvent(accessibilityEvent);
        verify(mNext).onAccessibilityEvent(accessibilityEvent);
    } finally {
        accessibilityEvent.recycle();
    }

    AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain();
    try {
        mIMENavMode.onInvalidateAccessibilityNode(node);
        verify(mNext).onInvalidateAccessibilityNode(node);
    } finally {
        node.recycle();
    }

    DisplayManager.Content content = new DisplayManager.Content("");
    mIMENavMode.onPanLeftOverflow(content);
    verify(mNext).onPanLeftOverflow(content);
    mIMENavMode.onPanRightOverflow(content);
    verify(mNext).onPanRightOverflow(content);

    BrailleInputEvent inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_ENTER, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext, never()).onMappedInputEvent(inputEvent, content);
    verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_ENTER);

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_DEL, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext, never()).onMappedInputEvent(inputEvent, content);
    verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_DEL);

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_BRAILLE_KEY, 0x1b, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext, never()).onMappedInputEvent(inputEvent, content);
    verify(mIME).handleBrailleKey(0x1b);

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_NAV_ITEM_NEXT, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext).onMappedInputEvent(inputEvent, content);
    verify(mIME, never()).moveCursor(anyInt(), anyInt());

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ACTIVATE_CURRENT, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext).onMappedInputEvent(inputEvent, content);
    verify(mIME, never()).sendDefaultAction();

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ROUTE, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext).onMappedInputEvent(inputEvent, content);
    verify(mIME, never()).route(anyInt(), any(DisplayManager.Content.class));

    mIMENavMode.onUnbindInput();
    mIMENavMode.onDestroyIME();
    verify(mSelfBrailleManager, atLeastOnce()).setImeOpen(false);
    verify(mSelfBrailleManager, never()).setImeOpen(true);

    // Deactivate, but make sure it didn't happen too early.
    verify(mNext, never()).onDeactivate();
    mIMENavMode.onDeactivate();
    verify(mNext).onDeactivate();
}

From source file:android.support.text.emoji.EmojiProcessor.java

/**
 * Handles onKeyDown commands from a {@link KeyListener} and if {@code keyCode} is one of
 * {@link KeyEvent#KEYCODE_DEL} or {@link KeyEvent#KEYCODE_FORWARD_DEL} it tries to delete an
 * {@link EmojiSpan} from an {@link Editable}. Returns {@code true} if an {@link EmojiSpan} is
 * deleted with the characters it covers.
 * <p/>//from   w  w w.j a  va  2 s . c o  m
 * If there is a selection where selection start is not equal to selection end, does not
 * delete.
 *
 * @param editable Editable instance passed to {@link KeyListener#onKeyDown(android.view.View,
 *                 Editable, int, KeyEvent)}
 * @param keyCode keyCode passed to {@link KeyListener#onKeyDown(android.view.View, Editable,
 *                int, KeyEvent)}
 * @param event KeyEvent passed to {@link KeyListener#onKeyDown(android.view.View, Editable,
 *              int, KeyEvent)}
 *
 * @return {@code true} if an {@link EmojiSpan} is deleted
 */
static boolean handleOnKeyDown(@NonNull final Editable editable, final int keyCode, final KeyEvent event) {
    final boolean handled;
    switch (keyCode) {
    case KeyEvent.KEYCODE_DEL:
        handled = delete(editable, event, false /*forwardDelete*/);
        break;
    case KeyEvent.KEYCODE_FORWARD_DEL:
        handled = delete(editable, event, true /*forwardDelete*/);
        break;
    default:
        handled = false;
        break;
    }

    if (handled) {
        MetaKeyKeyListener.adjustMetaAfterKeypress(editable);
        return true;
    }

    return false;
}

From source file:cn.zhangls.android.weibo.ui.edit.EditActivity.java

/**
 * ?//from  w  ww  . j  a v a2 s.co  m
 */
private void setText(String text, boolean isComment) {
    if (isComment) {
        mBinding.acEditText.setText(TextUtil.convertText(this, text,
                ContextCompat.getColor(this, R.color.colorAccent), (int) mBinding.acEditText.getTextSize()));
        return;
    }

    if (mStatus.getRetweeted_status() != null) // ?
        mBinding.acEditText.setText(TextUtil.convertText(this, text,
                ContextCompat.getColor(this, R.color.colorAccent), (int) mBinding.acEditText.getTextSize()));
    // ???????
    mTopicList = TextUtil.findRegexString(mBinding.acEditText.getText().toString(),
            Constants.RegularExpression.TopicRegex);
    mNameList = TextUtil.findRegexString(mBinding.acEditText.getText().toString(),
            Constants.RegularExpression.NameRegex);

    // ? UserName  Topic 
    mBinding.acEditText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // 
            return keyCode == KeyEvent.KEYCODE_DEL && event.getAction() == KeyEvent.ACTION_DOWN
                    && (setSelection(mBinding.acEditText, mTopicList, true)
                            || setSelection(mBinding.acEditText, mNameList, true));
        }
    });
    // EditText ? UserName  Topic ? UserName  Topic ?
    mBinding.acEditText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // ? Topic Name 
            boolean topic = setSelection(mBinding.acEditText, mTopicList, false);
            if (!topic) {
                setSelection(mBinding.acEditText, mNameList, false);
            }
        }
    });
}

From source file:org.connectbot.TerminalView.java

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_ENTER_ACTION
            | EditorInfo.IME_ACTION_NONE;
    outAttrs.inputType = EditorInfo.TYPE_NULL;
    return new BaseInputConnection(this, false) {
        @Override//from  www .  j a  va  2 s.co  m
        public boolean deleteSurroundingText(int leftLength, int rightLength) {
            if (rightLength == 0 && leftLength == 0) {
                return this.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            }
            for (int i = 0; i < leftLength; i++) {
                this.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            }
            // TODO: forward delete
            return true;
        }
    };
}