Move more keys divider to MoreKeysKeyboardView
Bug: 15681452 Change-Id: I1b32719cc927a24db4c41fdeb812b39f7e98a85cmain
parent
6888ec0099
commit
727e818e95
|
@ -27,5 +27,6 @@
|
||||||
<com.android.inputmethod.keyboard.MoreKeysKeyboardView
|
<com.android.inputmethod.keyboard.MoreKeysKeyboardView
|
||||||
android:id="@+id/more_keys_keyboard_view"
|
android:id="@+id/more_keys_keyboard_view"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content"
|
||||||
|
style="?attr/moreKeysKeyboardViewStyle" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -173,6 +173,10 @@
|
||||||
<attr name="suppressKeyPreviewAfterBatchInputDuration" format="integer" />
|
<attr name="suppressKeyPreviewAfterBatchInputDuration" format="integer" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
|
<declare-styleable name="MoreKeysKeyboardView">
|
||||||
|
<attr name="divider" format="reference" />
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="EmojiPalettesView">
|
<declare-styleable name="EmojiPalettesView">
|
||||||
<attr name="categoryIndicatorEnabled" format="boolean" />
|
<attr name="categoryIndicatorEnabled" format="boolean" />
|
||||||
<attr name="categoryIndicatorDrawable" format="reference" />
|
<attr name="categoryIndicatorDrawable" format="reference" />
|
||||||
|
|
|
@ -115,10 +115,7 @@
|
||||||
for instance delete button, need themed {@link KeyboardView} attributes. -->
|
for instance delete button, need themed {@link KeyboardView} attributes. -->
|
||||||
<style name="EmojiPalettesView" />
|
<style name="EmojiPalettesView" />
|
||||||
<style name="MoreKeysKeyboard" />
|
<style name="MoreKeysKeyboard" />
|
||||||
<style
|
<style name="MoreKeysKeyboardView" />
|
||||||
name="MoreKeysKeyboardView"
|
|
||||||
parent="KeyboardView" />
|
|
||||||
<style name="MoreKeysKeyboardContainer" />
|
|
||||||
<style name="SuggestionStripView" />
|
<style name="SuggestionStripView" />
|
||||||
<style name="SuggestionWord">
|
<style name="SuggestionWord">
|
||||||
<item name="android:minWidth">@dimen/config_suggestion_min_width</item>
|
<item name="android:minWidth">@dimen/config_suggestion_min_width</item>
|
||||||
|
|
|
@ -103,6 +103,7 @@
|
||||||
>
|
>
|
||||||
<item name="android:background">@drawable/keyboard_popup_panel_background_ics</item>
|
<item name="android:background">@drawable/keyboard_popup_panel_background_ics</item>
|
||||||
<item name="keyBackground">@drawable/btn_keyboard_key_popup_ics</item>
|
<item name="keyBackground">@drawable/btn_keyboard_key_popup_ics</item>
|
||||||
|
<item name="divider">@drawable/more_keys_divider</item>
|
||||||
<item name="keyTypeface">normal</item>
|
<item name="keyTypeface">normal</item>
|
||||||
<item name="verticalCorrection">@dimen/config_more_keys_keyboard_vertical_correction_holo</item>
|
<item name="verticalCorrection">@dimen/config_more_keys_keyboard_vertical_correction_holo</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -103,6 +103,7 @@
|
||||||
>
|
>
|
||||||
<item name="android:background">@drawable/keyboard_popup_panel_background_klp</item>
|
<item name="android:background">@drawable/keyboard_popup_panel_background_klp</item>
|
||||||
<item name="keyBackground">@drawable/btn_keyboard_key_popup_klp</item>
|
<item name="keyBackground">@drawable/btn_keyboard_key_popup_klp</item>
|
||||||
|
<item name="divider">@drawable/more_keys_divider</item>
|
||||||
<item name="keyTypeface">normal</item>
|
<item name="keyTypeface">normal</item>
|
||||||
<item name="verticalCorrection">@dimen/config_more_keys_keyboard_vertical_correction_holo</item>
|
<item name="verticalCorrection">@dimen/config_more_keys_keyboard_vertical_correction_holo</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -101,6 +101,7 @@
|
||||||
>
|
>
|
||||||
<item name="android:background">@drawable/keyboard_popup_panel_background_lxx_dark</item>
|
<item name="android:background">@drawable/keyboard_popup_panel_background_lxx_dark</item>
|
||||||
<item name="keyBackground">@drawable/btn_keyboard_key_popup_lxx_dark</item>
|
<item name="keyBackground">@drawable/btn_keyboard_key_popup_lxx_dark</item>
|
||||||
|
<item name="divider">@drawable/more_keys_divider</item>
|
||||||
<item name="keyTypeface">normal</item>
|
<item name="keyTypeface">normal</item>
|
||||||
<item name="verticalCorrection">@dimen/config_more_keys_keyboard_vertical_correction_holo</item>
|
<item name="verticalCorrection">@dimen/config_more_keys_keyboard_vertical_correction_holo</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -101,6 +101,7 @@
|
||||||
>
|
>
|
||||||
<item name="android:background">@drawable/keyboard_popup_panel_background_lxx_light</item>
|
<item name="android:background">@drawable/keyboard_popup_panel_background_lxx_light</item>
|
||||||
<item name="keyBackground">@drawable/btn_keyboard_key_popup_lxx_light</item>
|
<item name="keyBackground">@drawable/btn_keyboard_key_popup_lxx_light</item>
|
||||||
|
<item name="divider">@drawable/more_keys_divider</item>
|
||||||
<item name="keyTypeface">normal</item>
|
<item name="keyTypeface">normal</item>
|
||||||
<item name="verticalCorrection">@dimen/config_more_keys_keyboard_vertical_correction_holo</item>
|
<item name="verticalCorrection">@dimen/config_more_keys_keyboard_vertical_correction_holo</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -18,11 +18,9 @@ package com.android.inputmethod.keyboard;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
|
|
||||||
import com.android.inputmethod.annotations.UsedForTesting;
|
import com.android.inputmethod.annotations.UsedForTesting;
|
||||||
import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
|
import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
|
||||||
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
|
|
||||||
import com.android.inputmethod.keyboard.internal.KeyboardParams;
|
import com.android.inputmethod.keyboard.internal.KeyboardParams;
|
||||||
import com.android.inputmethod.keyboard.internal.MoreKeySpec;
|
import com.android.inputmethod.keyboard.internal.MoreKeySpec;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
|
@ -257,7 +255,6 @@ public final class MoreKeysKeyboard extends Keyboard {
|
||||||
|
|
||||||
public static class Builder extends KeyboardBuilder<MoreKeysKeyboardParams> {
|
public static class Builder extends KeyboardBuilder<MoreKeysKeyboardParams> {
|
||||||
private final Key mParentKey;
|
private final Key mParentKey;
|
||||||
private final Drawable mDivider;
|
|
||||||
|
|
||||||
private static final float LABEL_PADDING_RATIO = 0.2f;
|
private static final float LABEL_PADDING_RATIO = 0.2f;
|
||||||
private static final float DIVIDER_RATIO = 0.2f;
|
private static final float DIVIDER_RATIO = 0.2f;
|
||||||
|
@ -306,10 +303,8 @@ public final class MoreKeysKeyboard extends Keyboard {
|
||||||
}
|
}
|
||||||
final int dividerWidth;
|
final int dividerWidth;
|
||||||
if (key.needsDividersInMoreKeys()) {
|
if (key.needsDividersInMoreKeys()) {
|
||||||
mDivider = mResources.getDrawable(R.drawable.more_keys_divider);
|
|
||||||
dividerWidth = (int)(keyWidth * DIVIDER_RATIO);
|
dividerWidth = (int)(keyWidth * DIVIDER_RATIO);
|
||||||
} else {
|
} else {
|
||||||
mDivider = null;
|
|
||||||
dividerWidth = 0;
|
dividerWidth = 0;
|
||||||
}
|
}
|
||||||
final MoreKeySpec[] moreKeys = key.getMoreKeys();
|
final MoreKeySpec[] moreKeys = key.getMoreKeys();
|
||||||
|
@ -352,7 +347,8 @@ public final class MoreKeysKeyboard extends Keyboard {
|
||||||
if (params.mDividerWidth > 0 && pos != 0) {
|
if (params.mDividerWidth > 0 && pos != 0) {
|
||||||
final int dividerX = (pos > 0) ? x - params.mDividerWidth
|
final int dividerX = (pos > 0) ? x - params.mDividerWidth
|
||||||
: x + params.mDefaultKeyWidth;
|
: x + params.mDefaultKeyWidth;
|
||||||
final Key divider = new MoreKeyDivider(params, mDivider, dividerX, y);
|
final Key divider = new MoreKeyDivider(
|
||||||
|
params, dividerX, y, params.mDividerWidth, params.mDefaultRowHeight);
|
||||||
params.onAddKey(divider);
|
params.onAddKey(divider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -360,22 +356,11 @@ public final class MoreKeysKeyboard extends Keyboard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MoreKeyDivider extends Key.Spacer {
|
// Used as a divider maker. A divider is drawn by {@link MoreKeysKeyboardView}.
|
||||||
private final Drawable mIcon;
|
public static class MoreKeyDivider extends Key.Spacer {
|
||||||
|
public MoreKeyDivider(final KeyboardParams params, final int x, final int y,
|
||||||
public MoreKeyDivider(final MoreKeysKeyboardParams params, final Drawable icon,
|
final int width, final int height) {
|
||||||
final int x, final int y) {
|
super(params, x, y, width, height);
|
||||||
super(params, x, y, params.mDividerWidth, params.mDefaultRowHeight);
|
|
||||||
mIcon = icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Drawable getIcon(final KeyboardIconsSet iconSet, final int alpha) {
|
|
||||||
// KeyboardIconsSet and alpha are unused. Use the icon that has been passed to the
|
|
||||||
// constructor.
|
|
||||||
// TODO: Drawable itself should have an alpha value.
|
|
||||||
mIcon.setAlpha(128);
|
|
||||||
return mIcon;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,10 @@
|
||||||
package com.android.inputmethod.keyboard;
|
package com.android.inputmethod.keyboard;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -24,6 +28,7 @@ import android.view.ViewGroup;
|
||||||
|
|
||||||
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
||||||
import com.android.inputmethod.accessibility.MoreKeysKeyboardAccessibilityDelegate;
|
import com.android.inputmethod.accessibility.MoreKeysKeyboardAccessibilityDelegate;
|
||||||
|
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
|
||||||
import com.android.inputmethod.latin.Constants;
|
import com.android.inputmethod.latin.Constants;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.utils.CoordinateUtils;
|
import com.android.inputmethod.latin.utils.CoordinateUtils;
|
||||||
|
@ -35,6 +40,7 @@ import com.android.inputmethod.latin.utils.CoordinateUtils;
|
||||||
public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel {
|
public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel {
|
||||||
private final int[] mCoordinates = CoordinateUtils.newInstance();
|
private final int[] mCoordinates = CoordinateUtils.newInstance();
|
||||||
|
|
||||||
|
private final Drawable mDivider;
|
||||||
protected final KeyDetector mKeyDetector;
|
protected final KeyDetector mKeyDetector;
|
||||||
private Controller mController = EMPTY_CONTROLLER;
|
private Controller mController = EMPTY_CONTROLLER;
|
||||||
protected KeyboardActionListener mListener;
|
protected KeyboardActionListener mListener;
|
||||||
|
@ -53,6 +59,14 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
|
||||||
public MoreKeysKeyboardView(final Context context, final AttributeSet attrs,
|
public MoreKeysKeyboardView(final Context context, final AttributeSet attrs,
|
||||||
final int defStyle) {
|
final int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
|
final TypedArray moreKeysKeyboardViewAttr = context.obtainStyledAttributes(attrs,
|
||||||
|
R.styleable.MoreKeysKeyboardView, defStyle, R.style.MoreKeysKeyboardView);
|
||||||
|
mDivider = moreKeysKeyboardViewAttr.getDrawable(R.styleable.MoreKeysKeyboardView_divider);
|
||||||
|
if (mDivider != null) {
|
||||||
|
// TODO: Drawable itself should have an alpha value.
|
||||||
|
mDivider.setAlpha(128);
|
||||||
|
}
|
||||||
|
moreKeysKeyboardViewAttr.recycle();
|
||||||
mKeyDetector = new MoreKeysDetector(getResources().getDimension(
|
mKeyDetector = new MoreKeysDetector(getResources().getDimension(
|
||||||
R.dimen.config_more_keys_keyboard_slide_allowance));
|
R.dimen.config_more_keys_keyboard_slide_allowance));
|
||||||
}
|
}
|
||||||
|
@ -69,6 +83,23 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint,
|
||||||
|
final KeyDrawParams params) {
|
||||||
|
if (!key.isSpacer() || !(key instanceof MoreKeysKeyboard.MoreKeyDivider)
|
||||||
|
|| mDivider == null) {
|
||||||
|
super.onDrawKeyTopVisuals(key, canvas, paint, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final int keyWidth = key.getDrawWidth();
|
||||||
|
final int keyHeight = key.getHeight();
|
||||||
|
final int iconWidth = Math.min(mDivider.getIntrinsicWidth(), keyWidth);
|
||||||
|
final int iconHeight = mDivider.getIntrinsicHeight();
|
||||||
|
final int iconX = (keyWidth - iconWidth) / 2; // Align horizontally center
|
||||||
|
final int iconY = (keyHeight - iconHeight) / 2; // Align vertically center
|
||||||
|
drawIcon(canvas, mDivider, iconX, iconY, iconWidth, iconHeight);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setKeyboard(final Keyboard keyboard) {
|
public void setKeyboard(final Keyboard keyboard) {
|
||||||
super.setKeyboard(keyboard);
|
super.setKeyboard(keyboard);
|
||||||
|
|
Loading…
Reference in New Issue