Place language name at center of spacebar if no space icon

This change also leaves the language name as light grayed after fading out.

Bug: 3290290

Change-Id: I71adf80c9a3b77d2fd34bca458845d85d55cbee7
diff --git a/java/res/values/config.xml b/java/res/values/config.xml
index adfec4c..11b92e7 100644
--- a/java/res/values/config.xml
+++ b/java/res/values/config.xml
@@ -35,6 +35,7 @@
     <!-- The language is never displayed if == 0, always displayed if < 0 -->
     <integer name="config_delay_before_fadeout_language_on_spacebar">-1</integer>
     <integer name="config_duration_of_fadeout_language_on_spacebar">50</integer>
+    <integer name="config_final_fadeout_percentage_of_language_on_spacebar">15</integer>
     <integer name="config_delay_before_preview">0</integer>
     <integer name="config_delay_after_preview">10</integer>
     <integer name="config_preview_fadein_anim_time">0</integer>
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
index db89340..888375b 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
@@ -70,7 +70,6 @@
     private static final float SPACEBAR_POPUP_MIN_RATIO = 0.4f;
     // Height in space key the language name will be drawn. (proportional to space key height)
     public static final float SPACEBAR_LANGUAGE_BASELINE = 0.6f;
-    private static final float SPACEBAR_LANGUAGE_BASELINE_WITHOUT_ICON = 0.65f;
     // If the full language name needs to be smaller than this value to be drawn on space key,
     // its short language name will be used instead.
     private static final float MINIMUM_SCALE_OF_LANGUAGE_NAME = 0.8f;
@@ -225,9 +224,12 @@
                     allowVariableTextSize);
 
             // Draw language text with shadow
-            final float baseline = height * (mSpaceIcon != null ? SPACEBAR_LANGUAGE_BASELINE
-                    : SPACEBAR_LANGUAGE_BASELINE_WITHOUT_ICON);
+            // In case there is no space icon, we will place the language text at the center of
+            // spacebar.
             final float descent = paint.descent();
+            final float textHeight = -paint.ascent() + descent;
+            final float baseline = (mSpaceIcon != null) ? height * SPACEBAR_LANGUAGE_BASELINE
+                    : height / 2 + textHeight / 2;
             paint.setColor(getSpacebarTextColor(mSpacebarTextShadowColor, mSpacebarTextFadeFactor));
             canvas.drawText(language, width / 2, baseline - descent - 1, paint);
             paint.setColor(getSpacebarTextColor(mSpacebarTextColor, mSpacebarTextFadeFactor));
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index b93b07f..bea44ee 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -154,6 +154,7 @@
     private boolean mConfigSwipeDownDismissKeyboardEnabled;
     private int mConfigDelayBeforeFadeoutLanguageOnSpacebar;
     private int mConfigDurationOfFadeoutLanguageOnSpacebar;
+    private float mConfigFinalFadeoutFactorOfLanugageOnSpacebar;
 
     private int mCorrectionMode;
     private int mCommittedLength;
@@ -267,13 +268,16 @@
                 break;
             case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR:
                 if (inputView != null)
-                    inputView.setSpacebarTextFadeFactor(0.5f, (LatinKeyboard)msg.obj);
+                    inputView.setSpacebarTextFadeFactor(
+                            (1.0f + mConfigFinalFadeoutFactorOfLanugageOnSpacebar) / 2,
+                            (LatinKeyboard)msg.obj);
                 sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj),
                         mConfigDurationOfFadeoutLanguageOnSpacebar);
                 break;
             case MSG_DISMISS_LANGUAGE_ON_SPACEBAR:
                 if (inputView != null)
-                    inputView.setSpacebarTextFadeFactor(0.0f, (LatinKeyboard)msg.obj);
+                    inputView.setSpacebarTextFadeFactor(
+                            mConfigFinalFadeoutFactorOfLanugageOnSpacebar, (LatinKeyboard)msg.obj);
                 break;
             }
         }
@@ -356,6 +360,8 @@
                 R.integer.config_delay_before_fadeout_language_on_spacebar);
         mConfigDurationOfFadeoutLanguageOnSpacebar = res.getInteger(
                 R.integer.config_duration_of_fadeout_language_on_spacebar);
+        mConfigFinalFadeoutFactorOfLanugageOnSpacebar = res.getInteger(
+                R.integer.config_final_fadeout_percentage_of_language_on_spacebar) / 100.0f;
 
         Utils.GCUtils.getInstance().reset();
         boolean tryGC = true;