当前位置: 首页>>代码示例>>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;未经允许,请勿转载。