本文整理汇总了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);
}
示例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();
}
}