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