Add a symbol keyboard.

- Add a symbol layout.
- Let it change the layout between qwerty and symbol on KEYCODE_MODE_CHANGE.
- Adjust key-sizes of the last row in the qwerty keyboard to make it 100%

Bug: 132636760
Test: test manually
Change-Id: I33bd70dc47498ad3f6d255641c9edf48113c053d
This commit is contained in:
Yuncheol Heo
2019-05-15 17:58:25 -07:00
parent 146dd7045d
commit 94376a0ffe
3 changed files with 111 additions and 13 deletions

View File

@@ -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>

View File

@@ -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>

View File

@@ -36,7 +36,10 @@ 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 int mClientId = MultiClientInputMethodServiceDelegate.INVALID_CLIENT_ID;
private int mTargetWindowHandle = MultiClientInputMethodServiceDelegate.INVALID_WINDOW_HANDLE;
@@ -68,10 +71,12 @@ 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);
mKeyboardView.setKeyboard(mQwertygKeyboard);
mKeyboardView.setOnKeyboardActionListener(sNoopListener);
layout.addView(mKeyboardView);
setContentView(layout, new ViewGroup.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
@@ -88,8 +93,12 @@ final class SoftInputWindow extends Dialog {
return mTargetWindowHandle;
}
boolean isQwerty() {
return mKeyboardView.getKeyboard() == mQwertygKeyboard;
}
void onFinishClient() {
mQwerty.setOnKeyboardActionListener(sNoopListener);
mKeyboardView.setOnKeyboardActionListener(sNoopListener);
mClientId = MultiClientInputMethodServiceDelegate.INVALID_CLIENT_ID;
mTargetWindowHandle = MultiClientInputMethodServiceDelegate.INVALID_WINDOW_HANDLE;
}
@@ -99,7 +108,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,7 +120,7 @@ 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) {
@@ -128,10 +137,11 @@ final class SoftInputWindow extends Dialog {
inputConnection.sendKeyEvent(
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
break;
case Keyboard.KEYCODE_MODE_CHANGE:
handleSwitchKeyboard();
break;
default:
if (Character.isLetter(primaryCode)) {
inputConnection.commitText(String.valueOf((char) primaryCode), 1);
}
inputConnection.commitText(String.valueOf((char) primaryCode), 1);
break;
}
}
@@ -148,4 +158,13 @@ final class SoftInputWindow extends Dialog {
}
});
}
void handleSwitchKeyboard() {
if (isQwerty()) {
mKeyboardView.setKeyboard(mSymbolKeyboard);
} else {
mKeyboardView.setKeyboard(mQwertygKeyboard);
}
}
}