Bug 1227325 - Part 4: Remove (now unused) FloatingHintEditText r=mcomella draft
authorAndrzej Hunt <ahunt@mozilla.com>
Tue, 12 Jan 2016 10:59:50 -0800
changeset 325485 115229d46fcc07b8327dbfc33f6ff743c24a440e
parent 325484 4a8ca2558940ad2828695ef07ee2447c83dae6d1
child 513447 fda37e376493dbbdbe9326dde2b66bc8fc50a7cb
push id9978
push userahunt@mozilla.com
push dateMon, 25 Jan 2016 16:58:05 +0000
reviewersmcomella
bugs1227325
milestone46.0a1
Bug 1227325 - Part 4: Remove (now unused) FloatingHintEditText r=mcomella
mobile/android/base/java/org/mozilla/gecko/widget/FloatingHintEditText.java
mobile/android/base/moz.build
mobile/android/base/resources/values/attrs.xml
mobile/android/base/resources/values/styles.xml
mobile/android/base/resources/values/themes.xml
deleted file mode 100644
--- a/mobile/android/base/java/org/mozilla/gecko/widget/FloatingHintEditText.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko.widget;
-
-import android.content.Context;
-import android.content.res.ColorStateList;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Paint.FontMetricsInt;
-import android.text.TextUtils;
-import android.util.AttributeSet;
-import android.widget.EditText;
-
-import org.mozilla.gecko.R;
-
-public class FloatingHintEditText extends EditText {
-    private static enum Animation { NONE, SHRINK, GROW }
-    private static final float HINT_SCALE = 0.6f;
-    private static final int ANIMATION_STEPS = 6;
-
-    private final Paint floatingHintPaint = new Paint();
-    private final ColorStateList floatingHintColors;
-    private final ColorStateList normalHintColors;
-    private final int defaultFloatingHintColor;
-    private final int defaultNormalHintColor;
-
-    private boolean wasEmpty;
-
-    private int animationFrame;
-    private Animation animation = Animation.NONE;
-
-    public FloatingHintEditText(Context context) {
-        this(context, null);
-    }
-
-    public FloatingHintEditText(Context context, AttributeSet attrs) {
-        this(context, attrs, R.attr.floatingHintEditTextStyle);
-    }
-
-    public FloatingHintEditText(Context context, AttributeSet attrs, int defStyle) {
-        super(context, attrs, defStyle);
-
-        floatingHintColors = getResources().getColorStateList(R.color.floating_hint_text);
-        normalHintColors = getHintTextColors();
-        defaultFloatingHintColor = floatingHintColors.getDefaultColor();
-        defaultNormalHintColor = normalHintColors.getDefaultColor();
-        wasEmpty = TextUtils.isEmpty(getText());
-    }
-
-    @Override
-    public int getCompoundPaddingTop() {
-        final FontMetricsInt metrics = getPaint().getFontMetricsInt();
-        final int floatingHintHeight = (int) ((metrics.bottom - metrics.top) * HINT_SCALE);
-        return super.getCompoundPaddingTop() + floatingHintHeight;
-    }
-
-    @Override
-    protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
-        super.onTextChanged(text, start, lengthBefore, lengthAfter);
-
-        final boolean isEmpty = TextUtils.isEmpty(getText());
-
-        // The empty state hasn't changed, so the hint stays the same.
-        if (wasEmpty == isEmpty) {
-            return;
-        }
-
-        wasEmpty = isEmpty;
-
-        // Don't animate if we aren't visible.
-        if (!isShown()) {
-            return;
-        }
-
-        if (isEmpty) {
-            animation = Animation.GROW;
-
-            // The TextView will show a hint since the field is empty, but since we're animating
-            // from the floating hint, we don't want the normal hint to appear yet. We set it to
-            // transparent here, then restore the hint color after the animation has finished.
-            setHintTextColor(Color.TRANSPARENT);
-        } else {
-            animation = Animation.SHRINK;
-        }
-    }
-
-    @Override
-    protected void onDraw(Canvas canvas) {
-        super.onDraw(canvas);
-
-        if (TextUtils.isEmpty(getHint())) {
-            return;
-        }
-
-        final boolean isAnimating = (animation != Animation.NONE);
-
-        // The large hint is drawn by Android, so do nothing.
-        if (!isAnimating && TextUtils.isEmpty(getText())) {
-            return;
-        }
-
-        final Paint paint = getPaint();
-        final float hintPosX = getCompoundPaddingLeft() + getScrollX();
-        final float normalHintPosY = getBaseline();
-        final float floatingHintPosY = normalHintPosY + paint.getFontMetricsInt().top + getScrollY();
-        final float normalHintSize = getTextSize();
-        final float floatingHintSize = normalHintSize * HINT_SCALE;
-        final int[] stateSet = getDrawableState();
-        final int floatingHintColor = floatingHintColors.getColorForState(stateSet, defaultFloatingHintColor);
-
-        floatingHintPaint.set(paint);
-
-        // If we're not animating, we're showing the floating hint, so draw it and bail.
-        if (!isAnimating) {
-            drawHint(canvas, floatingHintSize, floatingHintColor, hintPosX, floatingHintPosY);
-            return;
-        }
-
-        // We are animating, so draw the linearly interpolated frame.
-        final int normalHintColor = normalHintColors.getColorForState(stateSet, defaultNormalHintColor);
-        if (animation == Animation.SHRINK) {
-            drawAnimationFrame(canvas, normalHintSize, floatingHintSize,
-                    hintPosX, normalHintPosY, floatingHintPosY, normalHintColor, floatingHintColor);
-        } else {
-            drawAnimationFrame(canvas, floatingHintSize, normalHintSize,
-                    hintPosX, floatingHintPosY, normalHintPosY, floatingHintColor, normalHintColor);
-        }
-
-        animationFrame++;
-
-        if (animationFrame == ANIMATION_STEPS) {
-            // After the grow animation has finished, restore the normal TextView hint color that we
-            // removed in our onTextChanged listener.
-            if (animation == Animation.GROW) {
-                setHintTextColor(normalHintColors);
-            }
-
-            animation = Animation.NONE;
-            animationFrame = 0;
-        }
-
-        invalidate();
-    }
-
-    private void drawAnimationFrame(Canvas canvas, float fromSize, float toSize,
-                                    float hintPosX, float fromY, float toY, int fromColor, int toColor) {
-        final float textSize = lerp(fromSize, toSize);
-        final float hintPosY = lerp(fromY, toY);
-        final int color = Color.rgb((int) lerp(Color.red(fromColor), Color.red(toColor)),
-                                    (int) lerp(Color.green(fromColor), Color.green(toColor)),
-                                    (int) lerp(Color.blue(fromColor), Color.blue(toColor)));
-        drawHint(canvas, textSize, color, hintPosX, hintPosY);
-    }
-
-    private void drawHint(Canvas canvas, float textSize, int color, float x, float y) {
-        floatingHintPaint.setTextSize(textSize);
-        floatingHintPaint.setColor(color);
-        canvas.drawText(getHint().toString(), x, y, floatingHintPaint);
-    }
-
-    private float lerp(float from, float to) {
-        final float alpha = (float) animationFrame / (ANIMATION_STEPS - 1);
-        return from * (1 - alpha) + to * alpha;
-    }
-}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -597,17 +597,16 @@ gbjar.sources += ['java/org/mozilla/geck
     'widget/DoorHanger.java',
     'widget/DoorhangerConfig.java',
     'widget/EllipsisTextView.java',
     'widget/ExternalIntentDuringPrivateBrowsingPromptFragment.java',
     'widget/FadedMultiColorTextView.java',
     'widget/FadedSingleColorTextView.java',
     'widget/FadedTextView.java',
     'widget/FaviconView.java',
-    'widget/FloatingHintEditText.java',
     'widget/FlowLayout.java',
     'widget/GeckoActionProvider.java',
     'widget/GeckoPopupMenu.java',
     'widget/GeckoViewFlipper.java',
     'widget/IconTabWidget.java',
     'widget/LoginDoorHanger.java',
     'widget/RecyclerViewClickSupport.java',
     'widget/ResizablePathDrawable.java',
--- a/mobile/android/base/resources/values/attrs.xml
+++ b/mobile/android/base/resources/values/attrs.xml
@@ -177,20 +177,16 @@
         <attr name="rightDivider" format="reference"/>
         <attr name="dividerVerticalPadding" format="dimension"/>
     </declare-styleable>
 
     <declare-styleable name="EllipsisTextView">
         <attr name="ellipsizeAtLine" format="integer"/>
     </declare-styleable>
 
-    <declare-styleable name="FloatingHintEditText">
-        <attr name="floatingHintEditTextStyle" format="reference" />
-    </declare-styleable>
-
     <declare-styleable name="FaviconView">
         <attr name="dominantBorderEnabled" format="boolean" />
         <attr name="overrideScaleType" format="boolean" />
     </declare-styleable>
 
     <declare-styleable name="OverlayDialogButton">
         <attr name="drawable" format="reference" />
         <attr name="enabledText" format="string" />
--- a/mobile/android/base/resources/values/styles.xml
+++ b/mobile/android/base/resources/values/styles.xml
@@ -767,20 +767,16 @@
     </style>
 
     <style name="TabInput.Tab">
         <item name="android:background">@drawable/tabs_strip_indicator</item>
         <item name="android:gravity">center</item>
         <item name="android:minHeight">@dimen/menu_item_row_height</item>
     </style>
 
-    <style name="FloatingHintEditText" parent="android:style/Widget.EditText">
-        <item name="android:paddingTop">0dp</item>
-    </style>
-
     <style name="TextAppearance.FirstrunLight"/>
     <style name="TextAppearance.FirstrunRegular"/>
 
     <style name="TextAppearance.FirstrunLight.Main">
         <item name="android:textSize">20sp</item>
         <item name="android:textColor">@color/text_and_tabs_tray_grey</item>
     </style>
 
--- a/mobile/android/base/resources/values/themes.xml
+++ b/mobile/android/base/resources/values/themes.xml
@@ -86,30 +86,28 @@
     </style>
 
     <!-- All customizations that are NOT specific to a particular API-level can go here. -->
     <style name="Gecko.App" parent="GeckoAppBase">
         <item name="android:gridViewStyle">@style/Widget.GridView</item>
         <item name="android:spinnerStyle">@style/Widget.Spinner</item>
         <item name="android:windowBackground">@android:color/white</item>
         <item name="bookmarksListViewStyle">@style/Widget.BookmarksListView</item>
-        <item name="floatingHintEditTextStyle">@style/FloatingHintEditText</item>
         <item name="tabGridLayoutViewStyle">@style/Widget.TabsGridLayout</item>
         <item name="geckoMenuListViewStyle">@style/Widget.GeckoMenuListView</item>
         <item name="homeListViewStyle">@style/Widget.HomeListView</item>
         <item name="menuItemActionBarStyle">@style/Widget.MenuItemActionBar</item>
         <item name="menuItemActionModeStyle">@style/GeckoActionBar.Button</item>
         <item name="menuItemShareActionButtonStyle">@style/Widget.MenuItemSecondaryActionBar</item>
         <item name="topSitesGridItemViewStyle">@style/Widget.TopSitesGridItemView</item>
         <item name="topSitesGridViewStyle">@style/Widget.TopSitesGridView</item>
         <item name="topSitesThumbnailViewStyle">@style/Widget.TopSitesThumbnailView</item>
     </style>
 
     <style name="Gecko.Preferences" parent="GeckoPreferencesBase">
-        <item name="floatingHintEditTextStyle">@style/FloatingHintEditText</item>
         <!-- This fixed bug 1233412 (Crash in GeckoPrefs due to missing colorAccent in JB) -->
         <item name="colorAccent">@color/action_orange</item>
     </style>
 
     <!-- Make an activity appear like an overlay. -->
     <style name="OverlayActivity" parent="Gecko">
         <item name="android:windowBackground">@android:color/transparent</item>
         <item name="android:windowNoTitle">true</item>