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

Commit 15c302f8 authored by Annie Chin's avatar Annie Chin Committed by Android (Google) Code Review
Browse files

Merge "Adjust dialog accent color in Settings page." into ub-deskclock-business

parents 490ed1ec 1b445897
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -22,7 +22,8 @@
    android:layout_width="wrap_content"
    android:layout_height="match_parent" >

    <NumberPicker android:id="@+id/minutes_picker"
    <com.android.deskclock.NumberPickerCompat
        android:id="@+id/minutes_picker"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:focusable="true"
+10 −0
Original line number Diff line number Diff line
@@ -20,6 +20,16 @@
        <item name="android:elevation">8dip</item>
    </style>

    <style name="SettingsTheme" parent="@style/DeskClockParentTheme">
        <item name="android:alertDialogTheme">@style/AlertDialogTheme</item>
        <item name="android:detailsElementBackground">@null</item>
        <item name="android:dialogTheme">@style/AlertDialogTheme</item>
        <item name="android:dropDownListViewStyle">@style/DeskClockDropDownListView</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
        <item name="actionBarStyle">@style/SettingsActionBarStyle</item>
    </style>

    <!-- Custom notification content styles -->
    <style name="TextAppearance.StatusBar.EventContent">
        <item name="android:textSize">@dimen/notification_text_size</item>
+69 −0
Original line number Diff line number Diff line
package com.android.deskclock;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.NumberPicker;

import java.lang.reflect.Field;

/**
 * Subclass of NumberPicker that allows customizing divider color.
 */
public class NumberPickerCompat extends NumberPicker {

    private static Field sSelectionDivider;
    private static boolean sTrySelectionDivider = true;

    public NumberPickerCompat(Context context) {
        this(context, null /* attrs */);
    }

    public NumberPickerCompat(Context context, AttributeSet attrs) {
        super(context, attrs);
        tintSelectionDivider(context);
    }

    public NumberPickerCompat(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        tintSelectionDivider(context);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private void tintSelectionDivider(Context context) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
                || Build.VERSION.SDK_INT > Build.VERSION_CODES.MNC) {
            // Accent color in KK will stay system blue, so leave divider color matching.
            // The divider is correctly tinted to controlColorNormal in MNC.
            return;
        }

        if (sTrySelectionDivider) {
            final TypedArray a = context.obtainStyledAttributes(
                    new int[] { android.R.attr.colorControlNormal });
             // White is default color if colorControlNormal is not defined.
            final int color = a.getColor(0, Color.WHITE);
            a.recycle();

            try {
                if (sSelectionDivider == null) {
                    sSelectionDivider = NumberPicker.class.getDeclaredField("mSelectionDivider");
                    sSelectionDivider.setAccessible(true);
                }
                final Drawable selectionDivider = (Drawable) sSelectionDivider.get(this);
                if (selectionDivider != null) {
                    // setTint is API21+, but this will only be called in API21
                    selectionDivider.setTint(color);
                }
            } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
                LogUtils.e("Unable to set selection divider", e);
                sTrySelectionDivider = false;
            }
        }
    }

}