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

Commit 51344781 authored by Alan Viverette's avatar Alan Viverette
Browse files

Add public attributes for TimePicker styling

BUG: 11218747
Change-Id: Ifdf981280ebe20a9066f219c9a4505d0d7486b2e
parent d10b2f17
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -299,6 +299,9 @@ package android {
    field public static final int alphabeticShortcut = 16843235; // 0x10101e3
    field public static final int alwaysDrawnWithCache = 16842991; // 0x10100ef
    field public static final int alwaysRetainTaskState = 16843267; // 0x1010203
    field public static final int amPmSelectedBackgroundColor = 16843946; // 0x10104aa
    field public static final int amPmTextColor = 16843944; // 0x10104a8
    field public static final int amPmUnselectedBackgroundColor = 16843945; // 0x10104a9
    field public static final int angle = 16843168; // 0x10101a0
    field public static final int animateFirstView = 16843477; // 0x10102d5
    field public static final int animateLayoutChanges = 16843506; // 0x10102f2
@@ -626,8 +629,12 @@ package android {
    field public static final int hapticFeedbackEnabled = 16843358; // 0x101025e
    field public static final int hardwareAccelerated = 16843475; // 0x10102d3
    field public static final int hasCode = 16842764; // 0x101000c
    field public static final int headerAmPmTextAppearance = 16843938; // 0x10104a2
    field public static final int headerBackground = 16843055; // 0x101012f
    field public static final int headerBackgroundColor = 16843940; // 0x10104a4
    field public static final int headerDividersEnabled = 16843310; // 0x101022e
    field public static final int headerSelectedTextColor = 16843939; // 0x10104a3
    field public static final int headerTimeTextAppearance = 16843937; // 0x10104a1
    field public static final int height = 16843093; // 0x1010155
    field public static final int hideOnContentScroll = 16843845; // 0x1010445
    field public static final int hint = 16843088; // 0x1010150
@@ -882,6 +889,9 @@ package android {
    field public static final int notificationTimeout = 16843651; // 0x1010383
    field public static final int numColumns = 16843032; // 0x1010118
    field public static final int numStars = 16843076; // 0x1010144
    field public static final int numbersBackgroundColor = 16843942; // 0x10104a6
    field public static final int numbersSelectorColor = 16843943; // 0x10104a7
    field public static final int numbersTextColor = 16843941; // 0x10104a5
    field public static final deprecated int numeric = 16843109; // 0x1010165
    field public static final int numericShortcut = 16843236; // 0x10101e4
    field public static final int onClick = 16843375; // 0x101026f
@@ -1275,6 +1285,8 @@ package android {
    field public static final int tileMode = 16843265; // 0x1010201
    field public static final int tileModeX = 16843897; // 0x1010479
    field public static final int tileModeY = 16843898; // 0x101047a
    field public static final int timePickerDialogTheme = 16843936; // 0x10104a0
    field public static final int timePickerStyle = 16843935; // 0x101049f
    field public static final int timeZone = 16843724; // 0x10103cc
    field public static final int tint = 16843041; // 0x1010121
    field public static final int tintMode = 16843797; // 0x1010415
+8 −9
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.app;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
@@ -28,8 +29,6 @@ import android.widget.TimePicker.OnTimeChangedListener;

import com.android.internal.R;

import static android.os.Build.VERSION_CODES.L;

/**
 * A dialog that prompts the user for the time of day using a {@link TimePicker}.
 *
@@ -102,26 +101,26 @@ public class TimePickerDialog extends AlertDialog
            OnTimeSetListener callBack,
            int hourOfDay, int minute, boolean is24HourView) {
        super(context, resolveDialogTheme(context, theme));

        mTimeSetCallback = callBack;
        mInitialHourOfDay = hourOfDay;
        mInitialMinute = minute;
        mIs24HourView = is24HourView;

        Context themeContext = getContext();
        final Context themeContext = getContext();

        final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion;
        if (targetSdkVersion < L) {
        final int targetSdkVersion = themeContext.getApplicationInfo().targetSdkVersion;
        if (targetSdkVersion < Build.VERSION_CODES.L) {
            setIcon(0);
            setTitle(R.string.time_picker_dialog_title);
            setButton(BUTTON_POSITIVE, themeContext.getText(R.string.date_time_done), this);
        }

        LayoutInflater inflater =
                (LayoutInflater) themeContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.time_picker_dialog, null);
        final LayoutInflater inflater = LayoutInflater.from(themeContext);
        final View view = inflater.inflate(R.layout.time_picker_dialog, null);
        setView(view);
        mTimePicker = (TimePicker) view.findViewById(R.id.timePicker);

        mTimePicker = (TimePicker) view.findViewById(R.id.timePicker);
        mTimePicker.setShowDoneButton(true);
        mTimePicker.setDismissCallback(new TimePicker.TimePickerDismissCallback() {
            @Override
+5 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.widget;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.format.DateFormat;
@@ -104,14 +105,13 @@ class LegacyTimePickerDelegate extends TimePicker.AbstractTimePickerDelegate {
        super(delegator, context);

        // process style attributes
        final TypedArray attributesArray = mContext.obtainStyledAttributes(
        final TypedArray a = mContext.obtainStyledAttributes(
                attrs, R.styleable.TimePicker, defStyleAttr, defStyleRes);
        final int layoutResourceId = attributesArray.getResourceId(
        final int layoutResourceId = a.getResourceId(
                R.styleable.TimePicker_legacyLayout, R.layout.time_picker_legacy);
        attributesArray.recycle();
        a.recycle();

        final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        final LayoutInflater inflater = LayoutInflater.from(mContext);
        inflater.inflate(layoutResourceId, mDelegator, true);

        // hour
+14 −14
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.text.format.DateUtils;
import android.text.format.Time;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.View;
@@ -190,6 +191,8 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
    private int mAmOrPm;
    private int mAmOrPmPressed;

    private int mDisabledAlpha;

    private RectF mRectF = new RectF();
    private boolean mInputEnabled = true;
    private OnValueSelectedListener mListener;
@@ -310,15 +313,18 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
    public RadialTimePickerView(Context context, AttributeSet attrs, int defStyle)  {
        super(context, attrs);

        // Pull disabled alpha from theme.
        final TypedValue outValue = new TypedValue();
        context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true);
        mDisabledAlpha = (int) (outValue.getFloat() * 255 + 0.5f);

        // process style attributes
        final Resources res = getResources();
        final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.TimePicker,
                defStyle, 0);

        final Resources res = getResources();

        mAmPmUnselectedColor = a.getColor(R.styleable.TimePicker_amPmUnselectedBackgroundColor,
                res.getColor(R.color.timepicker_default_ampm_unselected_background_color_material));

        mAmPmSelectedColor = a.getColor(R.styleable.TimePicker_amPmSelectedBackgroundColor,
                res.getColor(R.color.timepicker_default_ampm_selected_background_color_material));

@@ -406,10 +412,6 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
                res.getColor(R.color.timepicker_default_numbers_background_color_material)));
        mPaintBackground.setAntiAlias(true);

        mPaintDisabled.setColor(a.getColor(R.styleable.TimePicker_disabledColor,
                res.getColor(R.color.timepicker_default_disabled_color_material)));
        mPaintDisabled.setAntiAlias(true);

        if (DEBUG) {
            mPaintDebug.setColor(DEBUG_COLOR);
            mPaintDebug.setAntiAlias(true);
@@ -722,7 +724,11 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {

    @Override
    public void onDraw(Canvas canvas) {
        if (!mInputEnabled) {
            canvas.saveLayerAlpha(0, 0, getWidth(), getHeight(), mDisabledAlpha);
        } else {
            canvas.save();
        }

        calculateGridSizesHours();
        calculateGridSizesMinutes();
@@ -749,12 +755,6 @@ public class RadialTimePickerView extends View implements View.OnTouchListener {
            drawAmPm(canvas);
        }

        if(!mInputEnabled) {
            // Draw outer view rectangle
            mRectF.set(0, 0, getWidth(), getHeight());
            canvas.drawRect(mRectF, mPaintDisabled);
        }

        if (DEBUG) {
            drawDebug(canvas);
        }
+11 −55
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.widget;

import android.annotation.Widget;
import android.app.UiModeManager;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
@@ -30,8 +29,6 @@ import com.android.internal.R;

import java.util.Locale;

import static android.os.Build.VERSION_CODES.L;

/**
 * A view for selecting the time of day, in either 24 hour or AM/PM mode. The
 * hour, each minute digit, and AM/PM (if applicable) can be conrolled by
@@ -48,13 +45,7 @@ import static android.os.Build.VERSION_CODES.L;
 */
@Widget
public class TimePicker extends FrameLayout {

    private TimePickerDelegate mDelegate;

    private AttributeSet mAttrs;
    private int mDefStyleAttr;
    private int mDefStyleRes;
    private Context mContext;
    private final TimePickerDelegate mDelegate;

    /**
     * The callback interface used to indicate the time has been adjusted.
@@ -84,50 +75,18 @@ public class TimePicker extends FrameLayout {
    public TimePicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);

        mContext = context;
        mAttrs = attrs;
        mDefStyleAttr = defStyleAttr;
        mDefStyleRes = defStyleRes;

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TimePicker,
                mDefStyleAttr, mDefStyleRes);

        // Create the correct UI delegate. Legacy mode is used when API Levels is below L
        // release or when it is a TV UI
        final boolean isLegacyMode =  a.getBoolean(
                R.styleable.TimePicker_legacyMode, isLegacyMode());

        final TypedArray a = context.obtainStyledAttributes(
                attrs, R.styleable.TimePicker, defStyleAttr, defStyleRes);
        final boolean legacyMode = a.getBoolean(R.styleable.TimePicker_legacyMode, true);
        a.recycle();

        setLegacyMode(isLegacyMode);
    }

    private boolean isLegacyMode() {
        UiModeManager uiModeManager =
                (UiModeManager) mContext.getSystemService(Context.UI_MODE_SERVICE);
        if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
            return true;
        if (legacyMode) {
            mDelegate = new LegacyTimePickerDelegate(
                    this, context, attrs, defStyleAttr, defStyleRes);
        } else {
            mDelegate = new android.widget.TimePickerDelegate(
                    this, context, attrs, defStyleAttr, defStyleRes);
        }
        final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion;
        return targetSdkVersion < L;
    }

    private TimePickerDelegate createLegacyUIDelegate(Context context, AttributeSet attrs,
            int defStyleAttr, int defStyleRes) {
        return new LegacyTimePickerDelegate(this, context, attrs, defStyleAttr, defStyleRes);
    }

    private TimePickerDelegate createNewUIDelegate(Context context, AttributeSet attrs,
            int defStyleAttr, int defStyleRes) {
        return new android.widget.TimePickerDelegate(this, context, attrs, defStyleAttr,
                defStyleRes);
    }

    private void setLegacyMode(boolean isLegacyMode) {
        removeAllViewsInLayout();
        mDelegate = isLegacyMode ?
                createLegacyUIDelegate(mContext, mAttrs, mDefStyleAttr, mDefStyleRes) :
                createNewUIDelegate(mContext, mAttrs, mDefStyleAttr, mDefStyleRes);
    }

    /**
@@ -185,9 +144,6 @@ public class TimePicker extends FrameLayout {

    @Override
    public void setEnabled(boolean enabled) {
        if (mDelegate.isEnabled() == enabled) {
            return;
        }
        super.setEnabled(enabled);
        mDelegate.setEnabled(enabled);
    }
Loading