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

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

Update number picker styling for Material

Implements several missing drawable maintenance methods (state, etc.)
for NumberPicker's divider.

Bug: 21588885
Change-Id: Ibe37884354864c43fbf84d9eb79d7183af46fcad
parent 54310008
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -17113,6 +17113,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * Also calls {@link StateListAnimator#jumpToCurrentState()} if there is a StateListAnimator
     * attached to this view.
     */
    @CallSuper
    public void jumpDrawablesToCurrentState() {
        if (mBackground != null) {
            mBackground.jumpToCurrentState();
+43 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.widget;

import android.annotation.CallSuper;
import android.annotation.IntDef;
import android.annotation.Widget;
import android.content.Context;
@@ -608,7 +609,16 @@ public class NumberPicker extends LinearLayout {

        mSolidColor = attributesArray.getColor(R.styleable.NumberPicker_solidColor, 0);

        mSelectionDivider = attributesArray.getDrawable(R.styleable.NumberPicker_selectionDivider);
        final Drawable selectionDivider = attributesArray.getDrawable(
                R.styleable.NumberPicker_selectionDivider);
        if (selectionDivider != null) {
            selectionDivider.setCallback(this);
            selectionDivider.setLayoutDirection(getLayoutDirection());
            if (selectionDivider.isStateful()) {
                selectionDivider.setState(getDrawableState());
            }
        }
        mSelectionDivider = selectionDivider;

        final int defSelectionDividerHeight = (int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT,
@@ -1499,6 +1509,38 @@ public class NumberPicker extends LinearLayout {
        removeAllCallbacks();
    }

    @CallSuper
    @Override
    protected void drawableStateChanged() {
        super.drawableStateChanged();

        final int[] state = getDrawableState();

        if (mSelectionDivider != null && mSelectionDivider.isStateful()) {
            mSelectionDivider.setState(state);
        }
    }

    @CallSuper
    @Override
    public void jumpDrawablesToCurrentState() {
        super.jumpDrawablesToCurrentState();

        if (mSelectionDivider != null) {
            mSelectionDivider.jumpToCurrentState();
        }
    }

    /** @hide */
    @Override
    public void onResolveDrawables(@ResolvedLayoutDir int layoutDirection) {
        super.onResolveDrawables(layoutDirection);

        if (mSelectionDivider != null) {
            mSelectionDivider.setLayoutDirection(layoutDirection);
        }
    }

    @Override
    protected void onDraw(Canvas canvas) {
        if (!mHasSelectorWheel) {
+21 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 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.
-->

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:tint="?attr/colorControlNormal"
       android:shape="rectangle">
    <solid android:color="@color/black" />
</shape>
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 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.
-->

<view xmlns:android="http://schemas.android.com/apk/res/android"
      class="android.widget.NumberPicker$CustomEditText"
      android:id="@+id/numberpicker_input"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:singleLine="true"
      android:background="@null"
      android:textAppearance="@style/TextAppearance.Material.Caption" />
+6 −6
Original line number Diff line number Diff line
@@ -630,13 +630,13 @@ please see styles_device_defaults.xml.
    </style>

    <style name="Widget.Material.NumberPicker" parent="Widget.NumberPicker">
        <item name="internalLayout">@layout/number_picker_with_selector_wheel</item>
        <item name="internalLayout">@layout/number_picker_material</item>
        <item name="solidColor">@color/transparent</item>
        <item name="selectionDivider">@drawable/numberpicker_selection_divider</item>
        <item name="selectionDividerHeight">2dip</item>
        <item name="selectionDividersDistance">48dip</item>
        <item name="internalMinWidth">64dip</item>
        <item name="internalMaxHeight">180dip</item>
        <item name="selectionDivider">@drawable/number_picker_divider_material</item>
        <item name="selectionDividerHeight">2dp</item>
        <item name="selectionDividersDistance">48dp</item>
        <item name="internalMinWidth">64dp</item>
        <item name="internalMaxHeight">180dp</item>
        <item name="virtualButtonPressedDrawable">?attr/selectableItemBackground</item>
    </style>