Add a canSplitKeyboard attribute for specifying split keyboard layouts

Change [1/3]

This'll be used in conjunction with a user preference to split the keyboard when possible.

Bug: 4968173
Change-Id: I7a05948d67b94a55024790115ae261d7fef7941a
main
Sandeep Siddhartha 2014-09-10 10:32:24 +09:00
parent 22bf171113
commit 3939455c1d
4 changed files with 22 additions and 7 deletions

View File

@ -514,6 +514,8 @@
<attr name="elementKeyboard" format="reference"/>
<!-- Enable proximity characters correction. Disabled by default. -->
<attr name="enableProximityCharsCorrection" format="boolean" />
<!-- Indicates if the keyboard layout supports being split or not. false by default -->
<attr name="supportsSplitLayout" format="boolean" />
</declare-styleable>
<declare-styleable name="KeyboardLayoutSet_Feature">

View File

@ -23,7 +23,8 @@
<Element
latin:elementName="alphabet"
latin:elementKeyboard="@xml/kbd_qwerty"
latin:enableProximityCharsCorrection="true" />
latin:enableProximityCharsCorrection="true"
latin:supportsSplitLayout="false" />
<Element
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />

View File

@ -73,10 +73,12 @@ public final class KeyboardId {
public final boolean mLanguageSwitchKeyEnabled;
public final String mCustomActionLabel;
public final boolean mHasShortcutKey;
public final boolean mIsSplitLayout;
private final int mHashCode;
public KeyboardId(final int elementId, final KeyboardLayoutSet.Params params) {
public KeyboardId(final int elementId, final KeyboardLayoutSet.Params params,
boolean isSplitLayout) {
mSubtype = params.mSubtype;
mLocale = SubtypeLocaleUtils.getSubtypeLocale(mSubtype);
mWidth = params.mKeyboardWidth;
@ -89,6 +91,7 @@ public final class KeyboardId {
mCustomActionLabel = (mEditorInfo.actionLabel != null)
? mEditorInfo.actionLabel.toString() : null;
mHasShortcutKey = params.mVoiceInputKeyEnabled;
mIsSplitLayout = isSplitLayout;
mHashCode = computeHashCode(this);
}
@ -108,7 +111,8 @@ public final class KeyboardId {
id.mCustomActionLabel,
id.navigateNext(),
id.navigatePrevious(),
id.mSubtype
id.mSubtype,
id.mIsSplitLayout
});
}
@ -128,7 +132,8 @@ public final class KeyboardId {
&& TextUtils.equals(other.mCustomActionLabel, mCustomActionLabel)
&& other.navigateNext() == navigateNext()
&& other.navigatePrevious() == navigatePrevious()
&& other.mSubtype.equals(mSubtype);
&& other.mSubtype.equals(mSubtype)
&& other.mIsSplitLayout == mIsSplitLayout;
}
private static boolean isAlphabetKeyboard(final int elementId) {
@ -175,7 +180,7 @@ public final class KeyboardId {
@Override
public String toString() {
return String.format(Locale.ROOT, "[%s %s:%s %dx%d %s %s%s%s%s%s%s%s%s]",
return String.format(Locale.ROOT, "[%s %s:%s %dx%d %s %s%s%s%s%s%s%s%s%s]",
elementIdToName(mElementId),
mLocale, mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET),
mWidth, mHeight,
@ -187,7 +192,8 @@ public final class KeyboardId {
(passwordInput() ? " passwordInput" : ""),
(mHasShortcutKey ? " hasShortcutKey" : ""),
(mLanguageSwitchKeyEnabled ? " languageSwitchKeyEnabled" : ""),
(isMultiLine() ? " isMultiLine" : "")
(isMultiLine() ? " isMultiLine" : ""),
(mIsSplitLayout ? " isSplitLayout" : "")
);
}

View File

@ -96,6 +96,7 @@ public final class KeyboardLayoutSet {
private static final class ElementParams {
int mKeyboardXmlId;
boolean mProximityCharsCorrectionEnabled;
boolean mSupportsSplitLayout;
public ElementParams() {}
}
@ -168,7 +169,10 @@ public final class KeyboardLayoutSet {
// attribute in a keyboard_layout_set XML file. Also each keyboard layout XML resource is
// specified as an elementKeyboard attribute in the file.
// The KeyboardId is an internal key for a Keyboard object.
final KeyboardId id = new KeyboardId(keyboardLayoutSetElementId, mParams);
// TODO: AND mSupportsSplitLayout with the user preference that forces a split.
final KeyboardId id = new KeyboardId(keyboardLayoutSetElementId, mParams,
elementParams.mSupportsSplitLayout);
try {
return getKeyboard(elementParams, id);
} catch (final RuntimeException e) {
@ -376,6 +380,8 @@ public final class KeyboardLayoutSet {
elementParams.mProximityCharsCorrectionEnabled = a.getBoolean(
R.styleable.KeyboardLayoutSet_Element_enableProximityCharsCorrection,
false);
elementParams.mSupportsSplitLayout = a.getBoolean(
R.styleable.KeyboardLayoutSet_Element_supportsSplitLayout, false);
mParams.mKeyboardLayoutSetElementIdToParamsMap.put(elementName, elementParams);
} finally {
a.recycle();