Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b00e18e4 authored by Robyn Coultas's avatar Robyn Coultas
Browse files

Remove ZeroTopPaddingTextView

Change-Id: Idf8ee52846e90c9fb7f88a7b12a84c8808912ff8
parent dcc49f35
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@
            android:baselineAligned="false"
            android:gravity="top" >

            <com.android.deskclock.ZeroTopPaddingTextView
            <TextView
                android:id="@+id/timeDisplayHours"
                style="@style/big_thin"
                android:layout_width="wrap_content"
@@ -66,7 +66,7 @@
                android:singleLine="true"
                android:textColor="@color/clock_white" />

            <com.android.deskclock.ZeroTopPaddingTextView
            <TextView
                android:id="@+id/timeDisplayMinutes"
                style="@style/big_thin"
                android:layout_width="wrap_content"
@@ -75,7 +75,7 @@
                android:singleLine="true"
                android:textColor="@color/clock_white" />

            <com.android.deskclock.ZeroTopPaddingTextView
            <TextView
                android:id="@+id/am_pm"
                style="@style/label"
                android:layout_width="wrap_content"
+3 −3
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@
            android:paddingBottom="24dp"
            android:baselineAligned="false"
            >
            <com.android.deskclock.ZeroTopPaddingTextView
            <TextView
                android:id="@+id/timeDisplayHours"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
@@ -60,7 +60,7 @@
                android:ellipsize="none"
                style="@style/big_thin"
                android:textColor="@color/clock_white"/>
            <com.android.deskclock.ZeroTopPaddingTextView
            <TextView
                android:id="@+id/timeDisplayMinutes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
@@ -68,7 +68,7 @@
                android:singleLine="true"
                android:ellipsize="none"
                android:textColor="@color/clock_white"/>
            <com.android.deskclock.ZeroTopPaddingTextView
            <TextView
                android:id="@+id/am_pm"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
+0 −74
Original line number Diff line number Diff line
/*
 * 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 NORMAL_FONT_PADDING_RATIO = 0.328f;
    // the bold fontface has less empty space on the top
    private static final float BOLD_FONT_PADDING_RATIO = 0.208f;

    private static final float NORMAL_FONT_BOTTOM_PADDING_RATIO = 0.25f;
    // the bold fontface has less empty space on the top
    private static final float BOLD_FONT_BOTTOM_PADDING_RATIO = 0.208f;

    private static final Typeface SAN_SERIF_BOLD = Typeface.create("san-serif", Typeface.BOLD);
    private static final Typeface SAN_SERIF__CONDENSED_BOLD =
            Typeface.create("sans-serif-condensed", Typeface.BOLD);

    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() {
        float paddingRatio = NORMAL_FONT_PADDING_RATIO;
        float bottomPaddingRatio = NORMAL_FONT_BOTTOM_PADDING_RATIO;
    //    if (getTypeface().equals(SAN_SERIF_BOLD) ||
      //              getTypeface().equals(SAN_SERIF__CONDENSED_BOLD)) {
            paddingRatio = BOLD_FONT_PADDING_RATIO;
            bottomPaddingRatio = BOLD_FONT_BOTTOM_PADDING_RATIO;
      //  }
        // no need to scale by display density because getTextSize() already returns the font
        // height in px
        setPadding(0, (int) (-paddingRatio * getTextSize()), mPaddingRight,
                (int) (-bottomPaddingRatio * getTextSize()));
    }

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