From 1f2d0aa6c9b343848ee51e5bc13ccaaadf3ba4fe Mon Sep 17 00:00:00 2001
From: "Tadashi G. Takaoka" <takaoka@google.com>
Date: Wed, 16 May 2012 17:41:56 +0900
Subject: [PATCH] Set divider icon's alpha value on the fly

Bug: 6183494
Change-Id: I61a0c7617648d9c52e5001b3479afa0ab4913adc
---
 java/src/com/android/inputmethod/keyboard/Key.java       | 8 ++++++--
 .../com/android/inputmethod/keyboard/KeyboardView.java   | 5 +----
 .../android/inputmethod/keyboard/LatinKeyboardView.java  | 3 ++-
 .../android/inputmethod/keyboard/MoreKeysKeyboard.java   | 9 +++++----
 .../inputmethod/latin/suggestions/MoreSuggestions.java   | 8 +++++---
 5 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 4d7fe3d8e3..c3f5e7da20 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -571,9 +571,13 @@ public class Key {
         return (mMoreKeysColumnAndFlags & MORE_KEYS_FLAGS_EMBEDDED_MORE_KEY) != 0;
     }
 
-    public Drawable getIcon(KeyboardIconsSet iconSet) {
+    public Drawable getIcon(KeyboardIconsSet iconSet, int alpha) {
         final int iconId = mEnabled ? mIconId : mDisabledIconId;
-        return iconSet.getIconDrawable(iconId);
+        final Drawable icon = iconSet.getIconDrawable(iconId);
+        if (icon != null) {
+            icon.setAlpha(alpha);
+        }
+        return icon;
     }
 
     public Drawable getPreviewIcon(KeyboardIconsSet iconSet) {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 9be193ba73..c0d5b67722 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -560,10 +560,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
         }
 
         // Draw key label.
-        final Drawable icon = key.getIcon(mKeyboard.mIconsSet);
-        if (icon != null) {
-            icon.setAlpha(params.mAnimAlpha);
-        }
+        final Drawable icon = key.getIcon(mKeyboard.mIconsSet, params.mAnimAlpha);
         float positionX = centerX;
         if (key.mLabel != null) {
             final String label = key.mLabel;
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index 337ae9c176..cb37672974 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -459,7 +459,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
         mMoreKeysPanelCache.clear();
 
         mSpaceKey = keyboard.getKey(Keyboard.CODE_SPACE);
-        mSpaceIcon = (mSpaceKey != null) ? mSpaceKey.getIcon(keyboard.mIconsSet) : null;
+        mSpaceIcon = (mSpaceKey != null)
+                ? mSpaceKey.getIcon(keyboard.mIconsSet, ALPHA_OPAQUE) : null;
         final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
         mSpacebarTextSize = keyHeight * mSpacebarTextRatio;
         if (ProductionFlag.IS_EXPERIMENTAL) {
diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java
index b6a06e1360..a3741a2d87 100644
--- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java
@@ -289,8 +289,6 @@ public class MoreKeysKeyboard extends Keyboard {
             final int dividerWidth;
             if (parentKey.needsDividersInMoreKeys()) {
                 mDivider = mResources.getDrawable(R.drawable.more_keys_divider);
-                // TODO: Drawable itself should have an alpha value.
-                mDivider.setAlpha(128);
                 dividerWidth = (int)(width * DIVIDER_RATIO);
             } else {
                 mDivider = null;
@@ -333,8 +331,11 @@ public class MoreKeysKeyboard extends Keyboard {
             }
 
             @Override
-            public Drawable getIcon(KeyboardIconsSet iconSet) {
-                // KeyboardIconsSet is unused. Use the icon that has been passed to the constructor.
+            public Drawable getIcon(KeyboardIconsSet iconSet, 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;
             }
         }
diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
index dd83a0c4ea..c6fe43b697 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
@@ -56,8 +56,6 @@ public class MoreSuggestions extends Keyboard {
                 clearKeys();
                 final Resources res = view.getContext().getResources();
                 mDivider = res.getDrawable(R.drawable.more_suggestions_divider);
-                // TODO: Drawable itself should have an alpha value.
-                mDivider.setAlpha(128);
                 mDividerWidth = mDivider.getIntrinsicWidth();
                 final int padding = (int) res.getDimension(
                         R.dimen.more_suggestions_key_horizontal_padding);
@@ -195,7 +193,11 @@ public class MoreSuggestions extends Keyboard {
             }
 
             @Override
-            public Drawable getIcon(KeyboardIconsSet iconSet) {
+            public Drawable getIcon(KeyboardIconsSet iconSet, 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;
             }
         }
-- 
GitLab