當前位置: 首頁>>代碼示例>>Java>>正文


Java InputConnection.deleteSurroundingText方法代碼示例

本文整理匯總了Java中android.view.inputmethod.InputConnection.deleteSurroundingText方法的典型用法代碼示例。如果您正苦於以下問題:Java InputConnection.deleteSurroundingText方法的具體用法?Java InputConnection.deleteSurroundingText怎麽用?Java InputConnection.deleteSurroundingText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.inputmethod.InputConnection的用法示例。


在下文中一共展示了InputConnection.deleteSurroundingText方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doubleSpace

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
private void doubleSpace() {
    //if (!mAutoPunctuate) return;
    if (mCorrectionMode == Suggest.CORRECTION_NONE) return;
    final InputConnection ic = getCurrentInputConnection();
    if (ic == null) return;
    CharSequence lastThree = ic.getTextBeforeCursor(3, 0);
    if (lastThree != null && lastThree.length() == 3
            && Character.isLetterOrDigit(lastThree.charAt(0))
            && lastThree.charAt(1) == KEYCODE_SPACE && lastThree.charAt(2) == KEYCODE_SPACE) {
        ic.beginBatchEdit();
        ic.deleteSurroundingText(2, 0);
        ic.commitText(". ", 1);
        ic.endBatchEdit();
        updateShiftKeyState(getCurrentInputEditorInfo());
        mJustAddedAutoSpace = true;
    }
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:18,代碼來源:KP2AKeyboard.java

示例2: revertLastWord

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
public void revertLastWord(boolean deleteChar) {
    final int length = mComposing.length();
    if (!mPredicting && length > 0) {
        final InputConnection ic = getCurrentInputConnection();
        mPredicting = true;
        mJustRevertedSeparator = ic.getTextBeforeCursor(1, 0);
        if (deleteChar) ic.deleteSurroundingText(1, 0);
        int toDelete = mCommittedLength;
        CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0);
        if (toTheLeft != null && toTheLeft.length() > 0
                && isWordSeparator(toTheLeft.charAt(0))) {
            toDelete--;
        }
        ic.deleteSurroundingText(toDelete, 0);
        ic.setComposingText(mComposing, 1);
        TextEntryState.backspace();
        postUpdateSuggestions();
    } else {
        sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
        mJustRevertedSeparator = null;
    }
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:23,代碼來源:KP2AKeyboard.java

示例3: onKey

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
@Override
  public void onKey(int primaryCode, int[] keyCodes) {
      InputConnection ic = getCurrentInputConnection() ;
      playclick(primaryCode);
      switch (primaryCode) {
          case Keyboard.KEYCODE_DELETE:
              ic.deleteSurroundingText(1, 0);
              break;
          case Keyboard.KEYCODE_SHIFT:
              caps = !caps;
              keyboard.setShifted(caps);
              kv.invalidateAllKeys();
              break;
          case Keyboard.KEYCODE_DONE:
              ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
              break;
          default:
              char code = (char) primaryCode;
              if(Character.isLetter(code) && caps) {
                  code = Character.toUpperCase(code);
              }

              ic.commitText(String.valueOf(code), 1);
break;
      }
  }
 
開發者ID:zhaofengli,項目名稱:airboard,代碼行數:27,代碼來源:AirBoard.java

示例4: deleteSurroundingText

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
private boolean deleteSurroundingText(int before, int after) {
    final InputConnection ic = Ime.getCurrentInputConnection();
    if(ic != null) {
        ic.deleteSurroundingText(before, after);
        return true;
    }
    return false;
}
 
開發者ID:Adellica,項目名稱:Thumbkeyboard,代碼行數:9,代碼來源:ThumbkeyboardView.java

示例5: swapPunctuationAndSpace

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
private void swapPunctuationAndSpace() {
    final InputConnection ic = getCurrentInputConnection();
    if (ic == null) return;
    CharSequence lastTwo = ic.getTextBeforeCursor(2, 0);
    if (lastTwo != null && lastTwo.length() == 2
            && lastTwo.charAt(0) == KEYCODE_SPACE && isSentenceSeparator(lastTwo.charAt(1))) {
        ic.beginBatchEdit();
        ic.deleteSurroundingText(2, 0);
        ic.commitText(lastTwo.charAt(1) + " ", 1);
        ic.endBatchEdit();
        updateShiftKeyState(getCurrentInputEditorInfo());
        mJustAddedAutoSpace = true;
    }
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:15,代碼來源:KP2AKeyboard.java

示例6: reswapPeriodAndSpace

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
private void reswapPeriodAndSpace() {
    final InputConnection ic = getCurrentInputConnection();
    if (ic == null) return;
    CharSequence lastThree = ic.getTextBeforeCursor(3, 0);
    if (lastThree != null && lastThree.length() == 3
            && lastThree.charAt(0) == KEYCODE_PERIOD
            && lastThree.charAt(1) == KEYCODE_SPACE
            && lastThree.charAt(2) == KEYCODE_PERIOD) {
        ic.beginBatchEdit();
        ic.deleteSurroundingText(3, 0);
        ic.commitText(" ..", 1);
        ic.endBatchEdit();
        updateShiftKeyState(getCurrentInputEditorInfo());
    }
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:16,代碼來源:KP2AKeyboard.java

示例7: maybeRemovePreviousPeriod

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
private void maybeRemovePreviousPeriod(CharSequence text) {
    final InputConnection ic = getCurrentInputConnection();
    if (ic == null) return;

    // When the text's first character is '.', remove the previous period
    // if there is one.
    CharSequence lastOne = ic.getTextBeforeCursor(1, 0);
    if (lastOne != null && lastOne.length() == 1
            && lastOne.charAt(0) == KEYCODE_PERIOD
            && text.charAt(0) == KEYCODE_PERIOD) {
        ic.deleteSurroundingText(1, 0);
    }
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:14,代碼來源:KP2AKeyboard.java

示例8: removeTrailingSpace

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
private void removeTrailingSpace() {
    final InputConnection ic = getCurrentInputConnection();
    if (ic == null) return;

    CharSequence lastOne = ic.getTextBeforeCursor(1, 0);
    if (lastOne != null && lastOne.length() == 1
            && lastOne.charAt(0) == KEYCODE_SPACE) {
        ic.deleteSurroundingText(1, 0);
    }
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:11,代碼來源:KP2AKeyboard.java

示例9: deleteWordAtCursor

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
/**
 * Removes the word surrounding the cursor. Parameters are identical to
 * getWordAtCursor.
 */
public static void deleteWordAtCursor(
    InputConnection connection, String separators) {

    Range range = getWordRangeAtCursor(connection, separators, null);
    if (range == null) return;

    connection.finishComposingText();
    // Move cursor to beginning of word, to avoid crash when cursor is outside
    // of valid range after deleting text.
    int newCursor = getCursorPosition(connection) - range.charsBefore;
    connection.setSelection(newCursor, newCursor);
    connection.deleteSurroundingText(0, range.charsBefore + range.charsAfter);
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:18,代碼來源:EditingUtil.java

示例10: removeLastCharFromText

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
public static void removeLastCharFromText(InputConnection inputConnection) {
    try {
        String deletedChar = String.valueOf(inputConnection.getTextBeforeCursor(1, 0));
        if (deletedChar != null && deletedChar.length() > 0) {
            switch (deletedChar) {
                case " ":
                    deletedChar = context.getString(R.string.space);
                    break;
                case "\n":
                    deletedChar = context.getString(R.string.new_line);
                    break;
                case "×":
                    deletedChar = context.getString(R.string.multiply_pattern);
                    break;
                case "*":
                    deletedChar = context.getString(R.string.asterisk_pattern);
                    break;
                case ",":
                case "،":
                    deletedChar = context.getString(R.string.comma_pattern);
                    break;
            }

            //Check if really the character removed
            boolean isCharRemoved = inputConnection.deleteSurroundingText(1, 0);
            if (isCharRemoved) {
                if ((playAlwaysStoredVoices && currentSystemLanguage.equals("ar") && getSoundPath("ar_message_backspace") != -1) || (!defaultTextSpeech.isArabicSupported() && currentSystemLanguage.equals("ar") && getSoundPath("ar_message_backspace") != -1)) {
                    runPatternSoundPronounce(getSoundPath("ar_message_backspace"), true);
                } else {
                    defaultTextSpeech.speechText(context.getString(R.string.back_space, deletedChar));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:MohammadAlBanna,項目名稱:Swift-Braille-Soft-keyboard,代碼行數:38,代碼來源:Common.java

示例11: removeFullText

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
public static void removeFullText(InputConnection inputConnection) {
    try {
        String fullTextToDelete = getAllInputText(inputConnection);
        int fullTextLength = fullTextToDelete.length();
        if (fullTextLength == 0) {
            fullTextLength = 1000000;
        }
        boolean textCommitted = inputConnection.deleteSurroundingText(fullTextLength, fullTextLength);
        if (textCommitted) {
            defaultTextSpeech.speechText(context.getString(R.string.full_text_deletion), true);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:MohammadAlBanna,項目名稱:Swift-Braille-Soft-keyboard,代碼行數:16,代碼來源:Common.java

示例12: removeLastWordFromText

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
public static void removeLastWordFromText(InputConnection inputConnection) {
    try {
        String fullWordToDelete = getTheLastWord(inputConnection);
        if (fullWordToDelete != null) {
            boolean textCommitted = inputConnection.deleteSurroundingText(fullWordToDelete.length() + 1, 0);
            if (textCommitted) {
                defaultTextSpeech.speechText(context.getString(R.string.word_deletion, fullWordToDelete), true);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:MohammadAlBanna,項目名稱:Swift-Braille-Soft-keyboard,代碼行數:14,代碼來源:Common.java

示例13: onKey

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
@Override
public void onKey(int primaryCode, int[] ints) {
    Log.d(TAG, "onKey " + primaryCode);
    InputConnection ic = getCurrentInputConnection();
    playClick(primaryCode);

    switch (primaryCode) {
        case Keyboard.KEYCODE_DELETE:
            ic.deleteSurroundingText(1, 0);
            break;
        case Keyboard.KEYCODE_SHIFT:
            handleShift();
            break;
        case Keyboard.KEYCODE_DONE:
            ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
            break;
        case Keyboard.KEYCODE_ALT:
            handleSymbolsSwitch();
            break;
        case Keyboard.KEYCODE_MODE_CHANGE:
            handleLanguageSwitch();
            break;
        default:
            char code = (char) primaryCode;
            if (Character.isLetter(code) && isCapsOn) {
                code = Character.toUpperCase(code);
            }

            ic.commitText(String.valueOf(code), 1);
            break;
    }
}
 
開發者ID:Medeuz,項目名稱:CustomAndroidKeyboard,代碼行數:33,代碼來源:SimpleIME.java

示例14: onKey

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
@Override
public void onKey(int primaryCode, int[] keyCodes) {
    InputConnection ic = getCurrentInputConnection();
    playClick(primaryCode);

    switch (primaryCode) {
        case Keyboard.KEYCODE_DELETE:
            ic.deleteSurroundingText(1, 0);
            break;
        case Keyboard.KEYCODE_SHIFT:
            shift = !shift;
            if (kv.getKeyboard() == qwertyKeyboard) {
                kv.getKeyboard().setShifted(shift);
            } else {
                if (shift) {
                    kv.setKeyboard(symShiftKeyboard);
                } else {
                    kv.setKeyboard(symbolsKeyboard);
                }
            }
            kv.invalidateAllKeys();
            break;
        case Keyboard.KEYCODE_MODE_CHANGE:
            if (kv.getKeyboard() == symbolsKeyboard || kv.getKeyboard() == symShiftKeyboard) {
                kv.setKeyboard(qwertyKeyboard);
            } else {
                kv.setKeyboard(symbolsKeyboard);
                symbolsKeyboard.setShifted(false);
            }
            break;
        case Keyboard.KEYCODE_DONE:
            if (prefs.getBoolean("pref_signature_enable", false)) {
                ic.commitText(prefs.getString("pref_signature_text", ""), 0);
            }
            ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
            break;
        default:
            char code = (char)primaryCode;
            if (Character.isLetter(code) && shift) {
                code = Character.toUpperCase(code);
            }
            if (shift) {
                shift = false;
                kv.getKeyboard().setShifted(false);
                kv.invalidateAllKeys();
            }
            ic.commitText(String.valueOf(code), 1);
    }

    if (prefs.getBoolean("pref_swap_enable", false)) {
        shuffleKeyboard(kv.getKeyboard());
    }
}
 
開發者ID:rollforbugs,項目名稱:lokey,代碼行數:54,代碼來源:IME.java

示例15: handleBackspace

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
private void handleBackspace() {
    boolean deleteChar = false;
    InputConnection ic = getCurrentInputConnection();
    if (ic == null) return;

    ic.beginBatchEdit();
   
    if (mPredicting) {
        final int length = mComposing.length();
        if (length > 0) {
            mComposing.delete(length - 1, length);
            mWord.deleteLast();
            ic.setComposingText(mComposing, 1);
            if (mComposing.length() == 0) {
                mPredicting = false;
            }
            postUpdateSuggestions();
        } else {
            ic.deleteSurroundingText(1, 0);
        }
    } else {
        deleteChar = true;
    }
    postUpdateShiftKeyState();
    TextEntryState.backspace();
    if (TextEntryState.getState() == TextEntryState.State.UNDO_COMMIT) {
        revertLastWord(deleteChar);
        ic.endBatchEdit();
        return;
    } else if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) {
        ic.deleteSurroundingText(mEnteredText.length(), 0);
    } else if (deleteChar) {
        if (mCandidateView != null && mCandidateView.dismissAddToDictionaryHint()) {
            // Go back to the suggestion mode if the user canceled the
            // "Touch again to save".
            // NOTE: In gerenal, we don't revert the word when backspacing
            // from a manual suggestion pick.  We deliberately chose a
            // different behavior only in the case of picking the first
            // suggestion (typed word).  It's intentional to have made this
            // inconsistent with backspacing after selecting other suggestions.
            revertLastWord(deleteChar);
        } else {
            sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
            if (mDeleteCount > DELETE_ACCELERATE_AT) {
                sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
            }
        }
    }
    mJustRevertedSeparator = null;
    ic.endBatchEdit();
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:52,代碼來源:KP2AKeyboard.java


注:本文中的android.view.inputmethod.InputConnection.deleteSurroundingText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。