/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.deskclock;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Displays text with no padding at the top.
 */
public class ZeroTopPaddingTextView extends TextView {
    private static final float FONT_TOP_PADDING_RATIO = 0.328f;
    private static final float FONT_BOTTOM_PADDING_RATIO = 0.25f;

    private int mPaddingRight = 0;

    public ZeroTopPaddingTextView(Context context) {
        this(context, null);
    }

    public ZeroTopPaddingTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ZeroTopPaddingTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setIncludeFontPadding(false);
        updatePadding();
    }

    public void updatePadding() {
        // no need to scale by display density because getTextSize() already returns the font
        // height in px
        setPadding(0, (int) (-FONT_TOP_PADDING_RATIO * getTextSize()), mPaddingRight,
                (int) (-FONT_BOTTOM_PADDING_RATIO * getTextSize()));
    }

    public void setPaddingRight(int padding) {
        mPaddingRight = padding;
        updatePadding();
    }
}

@@ -917,24 +917,149 @@
 l float 
+NORMAL_FONT_PADDING_RATIO = 0.328f;%0A    // the bold fontface has less empty space on the top%0A    private static final float BOLD_
 FONT
-_TOP
 _PADDING
@@ -1065,30 +1065,31 @@
 G_RATIO = 0.
-3
 2
+0
 8f;%0A
+%0A
     private 
@@ -1107,16 +1107,23 @@
 l float 
+NORMAL_
 FONT_BOT
@@ -1148,16 +1148,242 @@
 = 0.25f;
+%0A    // the bold fontface has less empty space on the top%0A    private static final float BOLD_FONT_BOTTOM_PADDING_RATIO = 0.208f;%0A%0A    private static final Typeface SAN_SERIF_BOLD = Typeface.create(%22san-serif%22, Typeface.BOLD);
 %0A%0A    pr
@@ -1842,24 +1842,328 @@
 Padding() %7B%0A
+        float paddingRatio = NORMAL_FONT_PADDING_RATIO;%0A        float bottomPaddingRatio = NORMAL_FONT_BOTTOM_PADDING_RATIO;%0A        if (getTypeface().equals(SAN_SERIF_BOLD)) %7B%0A            paddingRatio = BOLD_FONT_PADDING_RATIO;%0A            bottomPaddingRatio = BOLD_FONT_BOTTOM_PADDING_RATIO;%0A        %7D%0A
         // n
@@ -2302,30 +2302,20 @@
 ) (-
-FONT_TOP_PADDING_RATIO
+paddingRatio
  * g
@@ -2372,33 +2372,26 @@
 ) (-
-FONT_BOTTOM_PADDING_RATIO
+bottomPaddingRatio
  * g

Revert "Fix alignment issues caused by font change"