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


Java InputConnection.setSelection方法代碼示例

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


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

示例1: 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

示例2: onWindowShown

import android.view.inputmethod.InputConnection; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onWindowShown() {
    try {
        //When the user changes the settings, refresh the view with a new object
        if (Common.areSettingsChanged) {
            keyboardSurface = new KeyboardSurface(this, this);
            setInputView(keyboardSurface);
            readTextAfterCloseKeyboard = Common.readTextAfterCloseKeyboard;
            Common.areSettingsChanged = false;
        }

        //Reset the keyboard every time the user open the keyboard
        Common.setPatternSurfaceLanguage(keyboardSurface, getCurrentInputConnection());

        //Check the rotation of the keyboard
        preventKeyboardRotation = Common.preventKeyboardRotation;

        //Get the user option of rotation
        if (preventKeyboardRotation) {
            //Get the previous state of screen rotation
            rotationState = Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION);
            if (Common.SDK_VERSION >= Build.VERSION_CODES.M) {
                if (Settings.System.canWrite(this)) {
                    Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);
                }
            } else {
                Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);
            }
        }

        //Check engine changes
        Common.defaultTextSpeech.checkEngineDefaultChanged();

        //Set the cursor to the end of the edit text
        InputConnection inputConnection = getCurrentInputConnection();
        if (inputConnection != null) {
            String allText = Common.getAllInputText(inputConnection);
            inputConnection.setSelection(allText.length(), allText.length());
        }

        //Show the toast and speech
        //If the input type is numeric, speech the numbers keyboard
        if (Common.isNumericInputText) {
            if (Common.currentLanguage == Common.ENGLISH_LANGUAGE_INPUT_METHOD) {
                if (!Common.defaultTextSpeech.isArabicSupported() && Common.currentSystemLanguage.equals("ar") && Common.getSoundPath("numbers_keyboard") != -1) {
                    Common.runPatternSoundPronounce(Common.getSoundPath("numbers_keyboard"), true);
                } else {
                    Common.defaultTextSpeech.speechText(getString(R.string.numbers_keyboard), true);
                }
            } else {
                if (!Common.defaultTextSpeech.isArabicSupported() && Common.currentSystemLanguage.equals("ar") && Common.getSoundPath("numbers_keyboard") != -1) {
                    Common.runPatternSoundPronounce(Common.getSoundPath("numbers_keyboard"), true);
                } else {
                    Common.defaultTextSpeech.speechText(getString(R.string.app_shows_ar_keyboard), true);
                }
            }
        } else {
            if (Common.currentLanguage == Common.ENGLISH_LANGUAGE_INPUT_METHOD) {
                if (!Common.defaultTextSpeech.isArabicSupported() && Common.currentSystemLanguage.equals("ar") && Common.getSoundPath("ar_message_en_keyboard") != -1) {
                    Common.runPatternSoundPronounce(Common.getSoundPath("ar_message_en_keyboard"), true);
                } else {
                    Common.defaultTextSpeech.speechText(getString(R.string.app_shows_en_keyboard), true);
                }
            } else if(Common.currentLanguage == Common.ARABIC_LANGUAGE_INPUT_METHOD) {
                if (!Common.defaultTextSpeech.isArabicSupported() && Common.currentSystemLanguage.equals("ar") && Common.getSoundPath("ar_message_ar_keyboard") != -1) {
                    Common.runPatternSoundPronounce(Common.getSoundPath("ar_message_ar_keyboard"), true);
                } else {
                    Common.defaultTextSpeech.speechText(getString(R.string.app_shows_ar_keyboard), true);
                }
            } else if(Common.currentLanguage == Common.SPANISH_LANGUAGE_INPUT_METHOD){
                Common.defaultTextSpeech.speechText(getString(R.string.app_shows_es_keyboard), true);
            } else if(Common.currentLanguage == Common.FRENCH_LANGUAGE_INPUT_METHOD){
                Common.defaultTextSpeech.speechText(getString(R.string.app_shows_fr_keyboard), true);
            }
        }
        super.onWindowShown();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:MohammadAlBanna,項目名稱:Swift-Braille-Soft-keyboard,代碼行數:82,代碼來源:BrailleIME.java


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