Update SoftKeyboard sample to use InputMethodSubtype
Bug: 5475117 Change-Id: I94c70800e272e28c080edd5102adceabf06d7aff
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2009 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Copyright (C) 2008-2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.softkeyboard;
|
||||
@@ -19,8 +19,8 @@ package com.example.android.softkeyboard;
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
import android.inputmethodservice.Keyboard;
|
||||
import android.inputmethodservice.KeyboardView;
|
||||
import android.text.InputType;
|
||||
import android.text.method.MetaKeyKeyListener;
|
||||
import android.util.Log;
|
||||
import android.view.KeyCharacterMap;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
@@ -28,6 +28,7 @@ import android.view.inputmethod.CompletionInfo;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -52,8 +53,10 @@ public class SoftKeyboard extends InputMethodService
|
||||
* that are primarily intended to be used for on-screen text entry.
|
||||
*/
|
||||
static final boolean PROCESS_HARD_KEYS = true;
|
||||
|
||||
private KeyboardView mInputView;
|
||||
|
||||
private InputMethodManager mInputMethodManager;
|
||||
|
||||
private LatinKeyboardView mInputView;
|
||||
private CandidateView mCandidateView;
|
||||
private CompletionInfo[] mCompletions;
|
||||
|
||||
@@ -79,6 +82,7 @@ public class SoftKeyboard extends InputMethodService
|
||||
*/
|
||||
@Override public void onCreate() {
|
||||
super.onCreate();
|
||||
mInputMethodManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
|
||||
mWordSeparators = getResources().getString(R.string.word_separators);
|
||||
}
|
||||
|
||||
@@ -107,7 +111,7 @@ public class SoftKeyboard extends InputMethodService
|
||||
* a configuration change.
|
||||
*/
|
||||
@Override public View onCreateInputView() {
|
||||
mInputView = (KeyboardView) getLayoutInflater().inflate(
|
||||
mInputView = (LatinKeyboardView) getLayoutInflater().inflate(
|
||||
R.layout.input, null);
|
||||
mInputView.setOnKeyboardActionListener(this);
|
||||
mInputView.setKeyboard(mQwertyKeyboard);
|
||||
@@ -149,21 +153,21 @@ public class SoftKeyboard extends InputMethodService
|
||||
|
||||
// We are now going to initialize our state based on the type of
|
||||
// text being edited.
|
||||
switch (attribute.inputType&EditorInfo.TYPE_MASK_CLASS) {
|
||||
case EditorInfo.TYPE_CLASS_NUMBER:
|
||||
case EditorInfo.TYPE_CLASS_DATETIME:
|
||||
switch (attribute.inputType & InputType.TYPE_MASK_CLASS) {
|
||||
case InputType.TYPE_CLASS_NUMBER:
|
||||
case InputType.TYPE_CLASS_DATETIME:
|
||||
// Numbers and dates default to the symbols keyboard, with
|
||||
// no extra features.
|
||||
mCurKeyboard = mSymbolsKeyboard;
|
||||
break;
|
||||
|
||||
case EditorInfo.TYPE_CLASS_PHONE:
|
||||
case InputType.TYPE_CLASS_PHONE:
|
||||
// Phones will also default to the symbols keyboard, though
|
||||
// often you will want to have a dedicated phone keyboard.
|
||||
mCurKeyboard = mSymbolsKeyboard;
|
||||
break;
|
||||
|
||||
case EditorInfo.TYPE_CLASS_TEXT:
|
||||
case InputType.TYPE_CLASS_TEXT:
|
||||
// This is general text editing. We will default to the
|
||||
// normal alphabetic keyboard, and assume that we should
|
||||
// be doing predictive text (showing candidates as the
|
||||
@@ -173,23 +177,23 @@ public class SoftKeyboard extends InputMethodService
|
||||
|
||||
// We now look for a few special variations of text that will
|
||||
// modify our behavior.
|
||||
int variation = attribute.inputType & EditorInfo.TYPE_MASK_VARIATION;
|
||||
if (variation == EditorInfo.TYPE_TEXT_VARIATION_PASSWORD ||
|
||||
variation == EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
|
||||
int variation = attribute.inputType & InputType.TYPE_MASK_VARIATION;
|
||||
if (variation == InputType.TYPE_TEXT_VARIATION_PASSWORD ||
|
||||
variation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
|
||||
// Do not display predictions / what the user is typing
|
||||
// when they are entering a password.
|
||||
mPredictionOn = false;
|
||||
}
|
||||
|
||||
if (variation == EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|
||||
|| variation == EditorInfo.TYPE_TEXT_VARIATION_URI
|
||||
|| variation == EditorInfo.TYPE_TEXT_VARIATION_FILTER) {
|
||||
if (variation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|
||||
|| variation == InputType.TYPE_TEXT_VARIATION_URI
|
||||
|| variation == InputType.TYPE_TEXT_VARIATION_FILTER) {
|
||||
// Our predictions are not useful for e-mail addresses
|
||||
// or URIs.
|
||||
mPredictionOn = false;
|
||||
}
|
||||
|
||||
if ((attribute.inputType&EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) {
|
||||
if ((attribute.inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) {
|
||||
// If this is an auto-complete text view, then our predictions
|
||||
// will not be shown and instead we will allow the editor
|
||||
// to supply their own. We only show the editor's
|
||||
@@ -245,8 +249,15 @@ public class SoftKeyboard extends InputMethodService
|
||||
// Apply the selected keyboard to the input view.
|
||||
mInputView.setKeyboard(mCurKeyboard);
|
||||
mInputView.closing();
|
||||
final InputMethodSubtype subtype = mInputMethodManager.getCurrentInputMethodSubtype();
|
||||
mInputView.setSubtypeOnSpaceKey(subtype);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
|
||||
mInputView.setSubtypeOnSpaceKey(subtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal with the editor reporting movement of its cursor.
|
||||
*/
|
||||
@@ -284,7 +295,7 @@ public class SoftKeyboard extends InputMethodService
|
||||
}
|
||||
|
||||
List<String> stringList = new ArrayList<String>();
|
||||
for (int i=0; i<(completions != null ? completions.length : 0); i++) {
|
||||
for (int i = 0; i < completions.length; i++) {
|
||||
CompletionInfo ci = completions[i];
|
||||
if (ci != null) stringList.add(ci.getText().toString());
|
||||
}
|
||||
@@ -435,7 +446,7 @@ public class SoftKeyboard extends InputMethodService
|
||||
&& mInputView != null && mQwertyKeyboard == mInputView.getKeyboard()) {
|
||||
int caps = 0;
|
||||
EditorInfo ei = getCurrentInputEditorInfo();
|
||||
if (ei != null && ei.inputType != EditorInfo.TYPE_NULL) {
|
||||
if (ei != null && ei.inputType != InputType.TYPE_NULL) {
|
||||
caps = getCurrentInputConnection().getCursorCapsMode(attr.inputType);
|
||||
}
|
||||
mInputView.setShifted(mCapsLock || caps != 0);
|
||||
|
||||
Reference in New Issue
Block a user