summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-05-18 23:05:10 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-05-18 23:05:10 +0000
commitd40d4e40c181391fd87033d9abf0beee675398b5 (patch)
tree6c303d4918358d1d4eda153b4d7fad3004a614f6
parent1c0030325388df7f4d9faa36f5c7528c282c92a6 (diff)
parent9d4c7d79dc8b2dec59b49452d60bc4ab7877d6e5 (diff)
downloaddevelopment-d40d4e40c181391fd87033d9abf0beee675398b5.tar.gz
Snap for 5582428 from 9d4c7d79dc8b2dec59b49452d60bc4ab7877d6e5 to qt-release
Change-Id: Ibd5b53e763f5b91449fec99ef2edbdffce953883
-rwxr-xr-xsamples/MultiClientInputMethod/res/xml/qwerty.xml4
-rwxr-xr-xsamples/MultiClientInputMethod/res/xml/symbols.xml79
-rwxr-xr-xsamples/MultiClientInputMethod/res/xml/symbols_shift.xml79
-rw-r--r--samples/MultiClientInputMethod/src/com/example/android/multiclientinputmethod/SoftInputWindow.java78
4 files changed, 227 insertions, 13 deletions
diff --git a/samples/MultiClientInputMethod/res/xml/qwerty.xml b/samples/MultiClientInputMethod/res/xml/qwerty.xml
index 6ca76fcc4..05164d3d2 100755
--- a/samples/MultiClientInputMethod/res/xml/qwerty.xml
+++ b/samples/MultiClientInputMethod/res/xml/qwerty.xml
@@ -67,12 +67,12 @@
<Row android:rowEdgeFlags="bottom">
<Key android:codes="-3" android:keyIcon="@drawable/sym_keyboard_done"
- android:keyWidth="20%p" android:keyEdgeFlags="left"/>
+ android:keyWidth="15%p" android:keyEdgeFlags="left"/>
<Key android:codes="-2" android:keyLabel="123" android:keyWidth="10%p"/>
<Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
android:keyWidth="40%p" android:isRepeatable="true"/>
<Key android:codes="46,44" android:keyLabel=". ,"
- android:keyWidth="20%p"/>
+ android:keyWidth="15%p"/>
<Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
android:keyWidth="20%p" android:keyEdgeFlags="right"/>
</Row>
diff --git a/samples/MultiClientInputMethod/res/xml/symbols.xml b/samples/MultiClientInputMethod/res/xml/symbols.xml
new file mode 100755
index 000000000..df4692b36
--- /dev/null
+++ b/samples/MultiClientInputMethod/res/xml/symbols.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019 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.
+-->
+
+
+<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
+ android:keyWidth="10%p"
+ android:horizontalGap="0px"
+ android:verticalGap="0px"
+ android:keyHeight="50dip"
+ >
+
+ <Row>
+ <Key android:codes="49" android:keyLabel="1" android:keyEdgeFlags="left"/>
+ <Key android:codes="50" android:keyLabel="2"/>
+ <Key android:codes="51" android:keyLabel="3"/>
+ <Key android:codes="52" android:keyLabel="4"/>
+ <Key android:codes="53" android:keyLabel="5"/>
+ <Key android:codes="54" android:keyLabel="6"/>
+ <Key android:codes="55" android:keyLabel="7"/>
+ <Key android:codes="56" android:keyLabel="8"/>
+ <Key android:codes="57" android:keyLabel="9"/>
+ <Key android:codes="48" android:keyLabel="0" android:keyEdgeFlags="right"/>
+ </Row>
+
+ <Row>
+ <Key android:codes="64" android:keyLabel="\@" android:keyEdgeFlags="left"/>
+ <Key android:codes="35" android:keyLabel="\#"/>
+ <Key android:codes="36" android:keyLabel="$"/>
+ <Key android:codes="37" android:keyLabel="%"/>
+ <Key android:codes="38" android:keyLabel="&amp;"/>
+ <Key android:codes="42" android:keyLabel="*"/>
+ <Key android:codes="45" android:keyLabel="-"/>
+ <Key android:codes="61" android:keyLabel="="/>
+ <Key android:codes="40" android:keyLabel="("/>
+ <Key android:codes="41" android:keyLabel=")" android:keyEdgeFlags="right"/>
+ </Row>
+
+ <Row>
+ <Key android:codes="-1" android:keyIcon="@drawable/sym_keyboard_shift"
+ android:keyWidth="15%p" android:isModifier="true"
+ android:isSticky="true" android:keyEdgeFlags="left"/>
+ <Key android:codes="33" android:keyLabel="!" />
+ <Key android:codes="34" android:keyLabel="&quot;"/>
+ <Key android:codes="39" android:keyLabel="\'"/>
+ <Key android:codes="58" android:keyLabel=":"/>
+ <Key android:codes="59" android:keyLabel=";"/>
+ <Key android:codes="47" android:keyLabel="/" />
+ <Key android:codes="63" android:keyLabel="\?"/>
+ <Key android:codes="-5" android:keyIcon="@drawable/sym_keyboard_delete"
+ android:keyWidth="15%p" android:keyEdgeFlags="right"
+ android:isRepeatable="true"/>
+ </Row>
+
+ <Row android:rowEdgeFlags="bottom">
+ <Key android:codes="-3" android:keyIcon="@drawable/sym_keyboard_done"
+ android:keyWidth="15%p" android:keyEdgeFlags="left"/>
+ <Key android:codes="-2" android:keyLabel="ABC" android:keyWidth="10%p"/>
+ <Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
+ android:keyWidth="40%p" android:isRepeatable="true"/>
+ <Key android:codes="46,44" android:keyLabel=". ,"
+ android:keyWidth="15%p"/>
+ <Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
+ android:keyWidth="20%p" android:keyEdgeFlags="right"/>
+ </Row>
+</Keyboard>
diff --git a/samples/MultiClientInputMethod/res/xml/symbols_shift.xml b/samples/MultiClientInputMethod/res/xml/symbols_shift.xml
new file mode 100755
index 000000000..fe771b408
--- /dev/null
+++ b/samples/MultiClientInputMethod/res/xml/symbols_shift.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2019 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.
+-->
+
+
+<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
+ android:keyWidth="10%p"
+ android:horizontalGap="0px"
+ android:verticalGap="0px"
+ android:keyHeight="50dip"
+ >
+
+ <Row>
+ <Key android:codes="126" android:keyLabel="~" android:keyEdgeFlags="left"/>
+ <Key android:codes="177" android:keyLabel="±"/>
+ <Key android:codes="215" android:keyLabel="×"/>
+ <Key android:codes="247" android:keyLabel="÷"/>
+ <Key android:codes="8226" android:keyLabel="•"/>
+ <Key android:codes="176" android:keyLabel="°"/>
+ <Key android:codes="96" android:keyLabel="`"/>
+ <Key android:codes="180" android:keyLabel="´"/>
+ <Key android:codes="123" android:keyLabel="{"/>
+ <Key android:codes="125" android:keyLabel="}" android:keyEdgeFlags="right"/>
+ </Row>
+
+ <Row>
+ <Key android:codes="169" android:keyLabel="©" android:keyEdgeFlags="left"/>
+ <Key android:codes="163" android:keyLabel="£"/>
+ <Key android:codes="8364" android:keyLabel="€"/>
+ <Key android:codes="94" android:keyLabel="^"/>
+ <Key android:codes="174" android:keyLabel="®"/>
+ <Key android:codes="165" android:keyLabel="¥"/>
+ <Key android:codes="95" android:keyLabel="_"/>
+ <Key android:codes="43" android:keyLabel="+"/>
+ <Key android:codes="91" android:keyLabel="["/>
+ <Key android:codes="93" android:keyLabel="]" android:keyEdgeFlags="right"/>
+ </Row>
+
+ <Row>
+ <Key android:codes="-1" android:keyIcon="@drawable/sym_keyboard_shift"
+ android:keyWidth="15%p" android:isModifier="true"
+ android:isSticky="true" android:keyEdgeFlags="left"/>
+ <Key android:codes="161" android:keyLabel="¡" />
+ <Key android:codes="60" android:keyLabel="&lt;"/>
+ <Key android:codes="62" android:keyLabel="&gt;"/>
+ <Key android:codes="162" android:keyLabel="¢"/>
+ <Key android:codes="124" android:keyLabel="|"/>
+ <Key android:codes="92" android:keyLabel="\\" />
+ <Key android:codes="191" android:keyLabel="¿"/>
+ <Key android:codes="-5" android:keyIcon="@drawable/sym_keyboard_delete"
+ android:keyWidth="15%p" android:keyEdgeFlags="right"
+ android:isRepeatable="true"/>
+ </Row>
+
+ <Row android:rowEdgeFlags="bottom">
+ <Key android:codes="-3" android:keyIcon="@drawable/sym_keyboard_done"
+ android:keyWidth="15%p" android:keyEdgeFlags="left"/>
+ <Key android:codes="-2" android:keyLabel="ABC" android:keyWidth="10%p"/>
+ <Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
+ android:keyWidth="40%p" android:isRepeatable="true"/>
+ <Key android:codes="46,44" android:keyLabel=". ,"
+ android:keyWidth="15%p"/>
+ <Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
+ android:keyWidth="20%p" android:keyEdgeFlags="right"/>
+ </Row>
+</Keyboard>
diff --git a/samples/MultiClientInputMethod/src/com/example/android/multiclientinputmethod/SoftInputWindow.java b/samples/MultiClientInputMethod/src/com/example/android/multiclientinputmethod/SoftInputWindow.java
index 00134fde5..afc66a413 100644
--- a/samples/MultiClientInputMethod/src/com/example/android/multiclientinputmethod/SoftInputWindow.java
+++ b/samples/MultiClientInputMethod/src/com/example/android/multiclientinputmethod/SoftInputWindow.java
@@ -36,7 +36,11 @@ final class SoftInputWindow extends Dialog {
private static final String TAG = "SoftInputWindow";
private static final boolean DEBUG = false;
- private final KeyboardView mQwerty;
+ private final KeyboardView mKeyboardView;
+
+ private final Keyboard mQwertygKeyboard;
+ private final Keyboard mSymbolKeyboard;
+ private final Keyboard mSymbolShiftKeyboard;
private int mClientId = MultiClientInputMethodServiceDelegate.INVALID_CLIENT_ID;
private int mTargetWindowHandle = MultiClientInputMethodServiceDelegate.INVALID_WINDOW_HANDLE;
@@ -68,10 +72,13 @@ final class SoftInputWindow extends Dialog {
final LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
- mQwerty = (KeyboardView) getLayoutInflater().inflate(R.layout.input, null);
- mQwerty.setKeyboard(new Keyboard(context, R.xml.qwerty));
- mQwerty.setOnKeyboardActionListener(sNoopListener);
- layout.addView(mQwerty);
+ mKeyboardView = (KeyboardView) getLayoutInflater().inflate(R.layout.input, null);
+ mQwertygKeyboard = new Keyboard(context, R.xml.qwerty);
+ mSymbolKeyboard = new Keyboard(context, R.xml.symbols);
+ mSymbolShiftKeyboard = new Keyboard(context, R.xml.symbols_shift);
+ mKeyboardView.setKeyboard(mQwertygKeyboard);
+ mKeyboardView.setOnKeyboardActionListener(sNoopListener);
+ layout.addView(mKeyboardView);
setContentView(layout, new ViewGroup.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
@@ -88,8 +95,17 @@ final class SoftInputWindow extends Dialog {
return mTargetWindowHandle;
}
+ boolean isQwertyKeyboard() {
+ return mKeyboardView.getKeyboard() == mQwertygKeyboard;
+ }
+
+ boolean isSymbolKeyboard() {
+ Keyboard keyboard = mKeyboardView.getKeyboard();
+ return keyboard == mSymbolKeyboard || keyboard == mSymbolShiftKeyboard;
+ }
+
void onFinishClient() {
- mQwerty.setOnKeyboardActionListener(sNoopListener);
+ mKeyboardView.setOnKeyboardActionListener(sNoopListener);
mClientId = MultiClientInputMethodServiceDelegate.INVALID_CLIENT_ID;
mTargetWindowHandle = MultiClientInputMethodServiceDelegate.INVALID_WINDOW_HANDLE;
}
@@ -99,7 +115,7 @@ final class SoftInputWindow extends Dialog {
Log.v(TAG, "onDummyStartInput clientId=" + clientId
+ " targetWindowHandle=" + targetWindowHandle);
}
- mQwerty.setOnKeyboardActionListener(sNoopListener);
+ mKeyboardView.setOnKeyboardActionListener(sNoopListener);
mClientId = clientId;
mTargetWindowHandle = targetWindowHandle;
}
@@ -111,13 +127,15 @@ final class SoftInputWindow extends Dialog {
}
mClientId = clientId;
mTargetWindowHandle = targetWindowHandle;
- mQwerty.setOnKeyboardActionListener(new NoopKeyboardActionListener() {
+ mKeyboardView.setOnKeyboardActionListener(new NoopKeyboardActionListener() {
@Override
public void onKey(int primaryCode, int[] keyCodes) {
if (DEBUG) {
Log.v(TAG, "onKey clientId=" + clientId + " primaryCode=" + primaryCode
+ " keyCodes=" + Arrays.toString(keyCodes));
}
+ boolean isShifted = isShifted(); // Store the current state before resetting it.
+ resetShift();
switch (primaryCode) {
case Keyboard.KEYCODE_CANCEL:
hide();
@@ -128,10 +146,14 @@ final class SoftInputWindow extends Dialog {
inputConnection.sendKeyEvent(
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
break;
+ case Keyboard.KEYCODE_MODE_CHANGE:
+ handleSwitchKeyboard();
+ break;
+ case Keyboard.KEYCODE_SHIFT:
+ handleShift(isShifted);
+ break;
default:
- if (Character.isLetter(primaryCode)) {
- inputConnection.commitText(String.valueOf((char) primaryCode), 1);
- }
+ handleCharacter(inputConnection, primaryCode, isShifted);
break;
}
}
@@ -148,4 +170,38 @@ final class SoftInputWindow extends Dialog {
}
});
}
+
+ void handleSwitchKeyboard() {
+ if (isQwertyKeyboard()) {
+ mKeyboardView.setKeyboard(mSymbolKeyboard);
+ } else {
+ mKeyboardView.setKeyboard(mQwertygKeyboard);
+ }
+
+ }
+
+ boolean isShifted() {
+ return mKeyboardView.isShifted();
+ }
+
+ void resetShift() {
+ if (isSymbolKeyboard() && isShifted()) {
+ mKeyboardView.setKeyboard(mSymbolKeyboard);
+ }
+ mKeyboardView.setShifted(false);
+ }
+
+ void handleShift(boolean isShifted) {
+ if (isSymbolKeyboard()) {
+ mKeyboardView.setKeyboard(isShifted ? mSymbolKeyboard : mSymbolShiftKeyboard);
+ }
+ mKeyboardView.setShifted(!isShifted);
+ }
+
+ void handleCharacter(InputConnection inputConnection, int primaryCode, boolean isShifted) {
+ if (isQwertyKeyboard() && isShifted) {
+ primaryCode = Character.toUpperCase(primaryCode);
+ }
+ inputConnection.commitText(String.valueOf((char) primaryCode), 1);
+ }
}