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

Commit f16888f1 authored by Adam Powell's avatar Adam Powell
Browse files

Holo fixes

* Fix up ButtonGroup to behave better.
* Fix bad states with holo list selectors.
* Clean up action mode UI components.
* Change action mode UI to use a text button instead of 'X' to dismiss.
* Fixed spinner dropdowns for Holo.Light

Change-Id: Ifc092bd549ffb539d6a3b2ddd95ebd4b114a441f
parent 425c305a
Loading
Loading
Loading
Loading
+68 −0
Original line number Diff line number Diff line
@@ -228812,6 +228812,74 @@
<parameter name="defStyleRes" type="int">
</parameter>
</constructor>
<method name="getShowDividers"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="setShowDividers"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="showDividers" type="int">
</parameter>
</method>
<field name="SHOW_DIVIDER_BEGINNING"
 type="int"
 transient="false"
 volatile="false"
 value="1"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="SHOW_DIVIDER_END"
 type="int"
 transient="false"
 volatile="false"
 value="4"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="SHOW_DIVIDER_MIDDLE"
 type="int"
 transient="false"
 volatile="false"
 value="2"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="SHOW_DIVIDER_NONE"
 type="int"
 transient="false"
 volatile="false"
 value="0"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<class name="CheckBox"
 extends="android.widget.CompoundButton"
+84 −11
Original line number Diff line number Diff line
@@ -26,6 +26,24 @@ import android.view.ViewGroup;
public class ButtonGroup extends LinearLayout {
    private Drawable mDivider;
    private Drawable mButtonBackground;
    private int mShowDividers;

    /**
     * Don't show any dividers.
     */
    public static final int SHOW_DIVIDER_NONE = 0;
    /**
     * Show a divider at the beginning of the group.
     */
    public static final int SHOW_DIVIDER_BEGINNING = 1;
    /**
     * Show dividers between each item in the group.
     */
    public static final int SHOW_DIVIDER_MIDDLE = 2;
    /**
     * Show a divider at the end of the group.
     */
    public static final int SHOW_DIVIDER_END = 4;

    public ButtonGroup(Context context) {
        this(context, null);
@@ -39,34 +57,89 @@ public class ButtonGroup extends LinearLayout {
        super(context, attrs, defStyleRes);
        
        TypedArray a = context.obtainStyledAttributes(attrs,
                com.android.internal.R.styleable.ButtonGroup);
                com.android.internal.R.styleable.ButtonGroup, defStyleRes, 0);
        
        mDivider = a.getDrawable(com.android.internal.R.styleable.ButtonGroup_divider);
        mButtonBackground = a.getDrawable(
                com.android.internal.R.styleable.ButtonGroup_buttonBackground);
        mShowDividers = a.getInt(com.android.internal.R.styleable.ButtonGroup_showDividers,
                SHOW_DIVIDER_MIDDLE);
        a.recycle();
    }

    /**
     * Set how dividers should be shown between items in this button group.
     *
     * @param showDividers One or more of {@link #SHOW_DIVIDER_BEGINNING},
     *                     {@link #SHOW_DIVIDER_MIDDLE}, or {@link #SHOW_DIVIDER_END},
     *                     or {@link #SHOW_DIVIDER_NONE} to show no dividers.
     */
    public void setShowDividers(int showDividers) {
        mShowDividers = showDividers;
    }

    /**
     * @return A flag set indicating how dividers should be shown around items.
     * @see #setShowDividers(int)
     */
    public int getShowDividers() {
        return mShowDividers;
    }

    @Override
    public void addView(View child, int index, ViewGroup.LayoutParams params) {
        if (getChildCount() > 0) {
            super.addView(makeDividerView(), index, makeDividerLayoutParams());
        if (!hasDividerBefore(index)) {
            if (((getChildCount() > 0
                    && (mShowDividers & SHOW_DIVIDER_MIDDLE) == SHOW_DIVIDER_MIDDLE)
                    || (mShowDividers & SHOW_DIVIDER_BEGINNING) == SHOW_DIVIDER_BEGINNING)) {
                super.addView(new DividerView(mContext), index, makeDividerLayoutParams());
                if (index >= 0) {
                    index++;
                }
            }
        }

        // Preserve original padding as we change the background
        final int paddingLeft = child.getPaddingLeft();
        final int paddingRight = child.getPaddingRight();
        final int paddingTop = child.getPaddingTop();
        final int paddingBottom = child.getPaddingBottom();
        child.setBackgroundDrawable(mButtonBackground);
        child.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);

        final boolean isLast = index < 0 || index == getChildCount();
        super.addView(child, index, params);

        if (index >= 0) {
            index++;
        }
        if ((isLast && (mShowDividers & SHOW_DIVIDER_END) == SHOW_DIVIDER_END) ||
                ((mShowDividers & SHOW_DIVIDER_MIDDLE) == SHOW_DIVIDER_MIDDLE &&
                        !(getChildAt(index) instanceof DividerView))) {
            super.addView(new DividerView(mContext), index, makeDividerLayoutParams());
        }
    }
    
    private ImageView makeDividerView() {
        ImageView result = new ImageView(mContext);
        result.setImageDrawable(mDivider);
        result.setScaleType(ImageView.ScaleType.FIT_XY);
        return result;
    private boolean hasDividerBefore(int index) {
        if (index == -1) {
            index = getChildCount();
        }
        index--;
        if (index < 0) {
            return false;
        }
        return getChildAt(index) instanceof DividerView;
    }

    private LayoutParams makeDividerLayoutParams() {
        return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    }

    private class DividerView extends ImageView {
        public DividerView(Context context) {
            super(context);
            setImageDrawable(mDivider);
            setScaleType(ImageView.ScaleType.FIT_XY);
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -94,6 +94,8 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
        a.recycle();
        
        mDividerPadding = DIVIDER_PADDING * res.getDisplayMetrics().density;

        setBaselineAligned(false);
    }

    @Override
+20 −16
Original line number Diff line number Diff line
@@ -21,13 +21,13 @@ import com.android.internal.view.menu.MenuBuilder;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.MeasureSpec;
import android.widget.Button;
import android.widget.ButtonGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -41,7 +41,7 @@ public class ActionBarContextView extends ViewGroup {
    private CharSequence mTitle;
    private CharSequence mSubtitle;

    private ImageButton mCloseButton;
    private View mClose;
    private View mCustomView;
    private LinearLayout mTitleLayout;
    private TextView mTitleView;
@@ -120,7 +120,8 @@ public class ActionBarContextView extends ViewGroup {
    private void initTitle() {
        if (mTitleLayout == null) {
            LayoutInflater inflater = LayoutInflater.from(getContext());
            mTitleLayout = (LinearLayout) inflater.inflate(R.layout.action_bar_title_item, null);
            inflater.inflate(R.layout.action_bar_title_item, this);
            mTitleLayout = (LinearLayout) getChildAt(getChildCount() - 1);
            mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title);
            mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle);
            if (mTitle != null) {
@@ -136,7 +137,6 @@ public class ActionBarContextView extends ViewGroup {
                }
                mSubtitleView.setVisibility(VISIBLE);
            }
            addView(mTitleLayout);
        } else {
            mTitleView.setText(mTitle);
            mSubtitleView.setText(mSubtitle);
@@ -148,16 +148,20 @@ public class ActionBarContextView extends ViewGroup {
    }

    public void initForMode(final ActionMode mode) {
        if (mCloseButton == null) {
            mCloseButton = new ImageButton(getContext(), null,
                    com.android.internal.R.attr.actionModeCloseButtonStyle);
        if (mClose == null) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            inflater.inflate(R.layout.action_mode_close_item, this);
            mClose = getChildAt(getChildCount() - 1);
        } else {
            addView(mClose);
        }
        mCloseButton.setOnClickListener(new OnClickListener() {

        View closeButton = mClose.findViewById(R.id.action_mode_close_button);
        closeButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                mode.finish();
            }
        });
        addView(mCloseButton);

        final MenuBuilder menu = (MenuBuilder) mode.getMenu();
        mMenuView = (ActionMenuView) menu.getMenuView(MenuBuilder.TYPE_ACTION_BUTTON, this);
@@ -224,8 +228,8 @@ public class ActionBarContextView extends ViewGroup {
        final int height = maxHeight - verticalPadding;
        final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
        
        if (mCloseButton != null) {
            availableWidth = measureChildView(mCloseButton, availableWidth, childSpecHeight, 0);
        if (mClose != null) {
            availableWidth = measureChildView(mClose, availableWidth, childSpecHeight, 0);
        }

        if (mTitleLayout != null && mCustomView == null) {
@@ -235,7 +239,7 @@ public class ActionBarContextView extends ViewGroup {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            if (child == mCloseButton || child == mTitleLayout || child == mCustomView) {
            if (child == mClose || child == mTitleLayout || child == mCustomView) {
                continue;
            }
            
@@ -278,8 +282,8 @@ public class ActionBarContextView extends ViewGroup {
        final int y = getPaddingTop();
        final int contentHeight = b - t - getPaddingTop() - getPaddingBottom();
        
        if (mCloseButton != null && mCloseButton.getVisibility() != GONE) {
            x += positionChild(mCloseButton, x, y, contentHeight);
        if (mClose != null && mClose.getVisibility() != GONE) {
            x += positionChild(mClose, x, y, contentHeight);
        }
        
        if (mTitleLayout != null && mCustomView == null) {
+28 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 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.
-->

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_window_focused="false" android:drawable="@color/transparent" />

    <!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
    <item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@color/group_button_background_pressed_holo_dark" />
    <item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@color/group_button_background_focused_holo_dark" />
    <item android:state_focused="true"                                android:state_pressed="true" android:drawable="@color/group_button_background_pressed_holo_dark" />
    <item android:state_focused="false"                               android:state_pressed="true" android:drawable="@color/group_button_background_pressed_holo_dark" />
    <item android:state_focused="true"                                                             android:drawable="@color/group_button_background_focused_holo_dark" />
    <item                                                                                          android:drawable="@color/transparent" />
</selector>
Loading