[SuwLib] Tint navigation button icons

- Remove the dark variant of button icons, since it is now tinted
  to the desired color
- Use DrawableCompat.setTintList to tint the drawables to the same
  color used as text
- Use textColorPrimary as the navigation text color, since the spec
  now matches the default textColorPrimary implementation of material
  theme (This changes the disabled color from 20% alpha to 26% alpha)
- Configured the build to take two different implementations of
  NavigationBarButton. The platform build is the same as Button,
  since drawable tinting is natively supported. The comapt build
  uses DrawableCompat in the support library to tint any compound
  drawables
- Removed all xxxhdpi assets since that was introduced in L, but
  vector assets are used in L instead.
- For the vector drawables, use tint instead of fillColor so that the
  state in the ColorStateList will be taken into account.

Bug: 22129308
Change-Id: Id0c7b40ad3e71c2c66a0e89df4522865a61e923e
This commit is contained in:
Maurice Lam 2015-08-06 15:38:55 -07:00
parent 3fa6e08ea0
commit 91051468db
56 changed files with 187 additions and 200 deletions

View file

@ -8,6 +8,6 @@ LOCAL_RESOURCE_DIR := \
$(LOCAL_PATH)/main/res \
$(LOCAL_PATH)/platform/res
LOCAL_SDK_VERSION := current
LOCAL_SRC_FILES := $(call all-java-files-under, main/src)
LOCAL_SRC_FILES := $(call all-java-files-under, main/src platform/src)
include $(BUILD_STATIC_JAVA_LIBRARY)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 308 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 312 B

View file

@ -16,4 +16,4 @@
-->
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/suw_navbar_ic_left_arrow_dark" />
android:src="@drawable/suw_navbar_ic_right_arrow" />

View file

@ -1,19 +0,0 @@
<?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.
-->
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/suw_navbar_ic_right_arrow_light" />

View file

@ -16,4 +16,4 @@
-->
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/suw_navbar_ic_left_arrow_dark" />
android:src="@drawable/suw_navbar_ic_left_arrow" />

View file

@ -1,19 +0,0 @@
<?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.
-->
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/suw_navbar_ic_left_arrow_light" />

Binary file not shown.

Before

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 280 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 325 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 502 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 507 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 303 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 523 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 541 B

View file

@ -16,4 +16,4 @@
-->
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/suw_navbar_ic_down_arrow_dark" />
android:src="@drawable/suw_navbar_ic_left_arrow" />

View file

@ -1,19 +0,0 @@
<?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.
-->
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/suw_navbar_ic_left_arrow_light" />

View file

@ -16,4 +16,4 @@
-->
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/suw_navbar_ic_right_arrow_dark" />
android:src="@drawable/suw_navbar_ic_down_arrow" />

View file

@ -1,19 +0,0 @@
<?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.
-->
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/suw_navbar_ic_down_arrow_light" />

View file

@ -0,0 +1,19 @@
<?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.
-->
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/suw_navbar_ic_right_arrow" />

View file

@ -1,19 +0,0 @@
<?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.
-->
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/suw_navbar_ic_right_arrow_dark" />

View file

@ -1,19 +0,0 @@
<?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.
-->
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/suw_navbar_ic_right_arrow_light" />

View file

@ -75,21 +75,13 @@
</style>
<style name="SuwNavBarThemeDark" parent="SuwNavBarTheme">
<item name="suwNavBarBackButton">@drawable/suw_navbar_ic_back_dark</item>
<item name="suwNavBarBackgroundColor">@color/suw_navbar_bg_dark</item>
<item name="suwNavBarButtonBackground">@drawable/suw_navbar_btn_bg_dark</item>
<item name="suwNavBarMoreButton">@drawable/suw_navbar_ic_more_dark</item>
<item name="suwNavBarNextButton">@drawable/suw_navbar_ic_next_dark</item>
<item name="suwNavBarTextColor">@color/suw_navbar_text_dark</item>
</style>
<style name="SuwNavBarThemeLight" parent="SuwNavBarTheme">
<item name="suwNavBarBackButton">@drawable/suw_navbar_ic_back_light</item>
<item name="suwNavBarBackgroundColor">@color/suw_navbar_bg_light</item>
<item name="suwNavBarButtonBackground">@drawable/suw_navbar_btn_bg_light</item>
<item name="suwNavBarMoreButton">@drawable/suw_navbar_ic_more_light</item>
<item name="suwNavBarNextButton">@drawable/suw_navbar_ic_next_light</item>
<item name="suwNavBarTextColor">@color/suw_navbar_text_light</item>
</style>
</resources>

View file

@ -0,0 +1,107 @@
/*
* 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.
*/
package com.android.setupwizardlib.view;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.util.AttributeSet;
import android.widget.Button;
public class NavigationBarButton extends Button {
public NavigationBarButton(Context context) {
super(context);
init();
}
public NavigationBarButton(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
// Unfortunately, drawableStart and drawableEnd set through XML does not call the setter,
// so manually getting it and wrapping it in the compat drawable.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Drawable[] drawables = getCompoundDrawablesRelative();
for (int i = 0; i < drawables.length; i++) {
if (drawables[i] != null) {
drawables[i] = DrawableCompat.wrap(drawables[i].mutate());
}
}
setCompoundDrawablesRelativeWithIntrinsicBounds(drawables[0], drawables[1],
drawables[2], drawables[3]);
}
}
@Override
public void setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom) {
if (left != null) left = DrawableCompat.wrap(left.mutate());
if (top != null) top = DrawableCompat.wrap(top.mutate());
if (right != null) right = DrawableCompat.wrap(right.mutate());
if (bottom != null) bottom = DrawableCompat.wrap(bottom.mutate());
super.setCompoundDrawables(left, top, right, bottom);
tintDrawables();
}
@Override
public void setCompoundDrawablesRelative(Drawable start, Drawable top, Drawable end,
Drawable bottom) {
if (start != null) start = DrawableCompat.wrap(start.mutate());
if (top != null) top = DrawableCompat.wrap(top.mutate());
if (end != null) end = DrawableCompat.wrap(end.mutate());
if (bottom != null) bottom = DrawableCompat.wrap(bottom.mutate());
super.setCompoundDrawablesRelative(start, top, end, bottom);
tintDrawables();
}
@Override
public void setTextColor(ColorStateList colors) {
super.setTextColor(colors);
tintDrawables();
}
private void tintDrawables() {
final ColorStateList textColors = getTextColors();
if (textColors != null) {
for (Drawable drawable : getAllCompoundDrawables()) {
if (drawable != null) {
DrawableCompat.setTintList(drawable, textColors);
}
}
invalidate();
}
}
private Drawable[] getAllCompoundDrawables() {
Drawable[] drawables = new Drawable[6];
Drawable[] compoundDrawables = getCompoundDrawables();
drawables[0] = compoundDrawables[0]; // left
drawables[1] = compoundDrawables[1]; // top
drawables[2] = compoundDrawables[2]; // right
drawables[3] = compoundDrawables[3]; // bottom
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Drawable[] compoundDrawablesRelative = getCompoundDrawablesRelative();
drawables[4] = compoundDrawablesRelative[0]; // start
drawables[5] = compoundDrawablesRelative[2]; // end
}
return drawables;
}
}

View file

@ -19,11 +19,13 @@
android:autoMirrored="true"
android:width="@dimen/suw_navbar_ic_intrinsic_size"
android:height="@dimen/suw_navbar_ic_intrinsic_size"
android:tint="?attr/suwNavBarTextColor"
android:viewportWidth="24"
android:viewportHeight="24">
<!-- Fill with solid black as the actual button color will be tinted on the entire drawable -->
<path
android:fillColor="?attr/suwNavBarTextColor"
android:fillColor="@android:color/black"
android:pathData="M15.4,7.4l-1.4,-1.4 -6,6 6,6 1.4,-1.4 -4.6,-4.6z" />
</vector>

View file

@ -18,11 +18,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="@dimen/suw_navbar_ic_intrinsic_size"
android:height="@dimen/suw_navbar_ic_intrinsic_size"
android:tint="?attr/suwNavBarTextColor"
android:viewportWidth="24"
android:viewportHeight="24">
<!-- Fill with solid black as the actual button color will be tinted on the entire drawable -->
<path
android:fillColor="?attr/suwNavBarTextColor"
android:fillColor="@android:color/black"
android:pathData="M16.6,8.6l-4.6,4.6 -4.6,-4.6 -1.4,1.4 6,6 6,-6z"/>
</vector>

View file

@ -19,11 +19,13 @@
android:autoMirrored="true"
android:width="@dimen/suw_navbar_ic_intrinsic_size"
android:height="@dimen/suw_navbar_ic_intrinsic_size"
android:tint="?attr/suwNavBarTextColor"
android:viewportWidth="24"
android:viewportHeight="24">
<!-- Fill with solid black as the actual button color will be tinted on the entire drawable -->
<path
android:fillColor="?attr/suwNavBarTextColor"
android:fillColor="@android:color/black"
android:pathData="M10,6 l-1.4,1.4 4.6,4.6 -4.6,4.6 1.4,1.4 6,-6z" />
</vector>

View file

@ -17,14 +17,14 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<view class="com.android.setupwizardlib.view.NavigationBar$NavButton"
<com.android.setupwizardlib.view.NavigationBarButton
android:id="@+id/suw_navbar_back"
style="@style/SuwNavBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:contentDescription="@string/suw_back_button_label"
android:drawableLeft="?attr/suwNavBarBackButton"
android:drawableStart="?attr/suwNavBarBackButton" />
android:drawableLeft="@drawable/suw_navbar_ic_back"
android:drawableStart="@drawable/suw_navbar_ic_back" />
<View
android:layout_width="0dp"
@ -32,24 +32,24 @@
android:layout_weight="1"
android:visibility="invisible" />
<view class="com.android.setupwizardlib.view.NavigationBar$NavButton"
<com.android.setupwizardlib.view.NavigationBarButton
android:id="@+id/suw_navbar_more"
style="@style/SuwNavBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:contentDescription="@string/suw_more_button_label"
android:drawableEnd="?attr/suwNavBarMoreButton"
android:drawableRight="?attr/suwNavBarMoreButton"
android:drawableEnd="@drawable/suw_navbar_ic_more"
android:drawableRight="@drawable/suw_navbar_ic_more"
android:gravity="end|center_vertical"
android:visibility="gone" />
<view class="com.android.setupwizardlib.view.NavigationBar$NavButton"
<com.android.setupwizardlib.view.NavigationBarButton
android:id="@+id/suw_navbar_next"
style="@style/SuwNavBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:drawableEnd="?attr/suwNavBarNextButton"
android:drawableRight="?attr/suwNavBarNextButton"
android:drawableEnd="@drawable/suw_navbar_ic_next"
android:drawableRight="@drawable/suw_navbar_ic_next"
android:gravity="end|center_vertical"
android:text="@string/suw_next_button_label" />

View file

@ -44,21 +44,13 @@
</style>
<style name="SuwNavBarThemeDark" parent="SuwNavBarTheme">
<item name="suwNavBarBackButton">@drawable/suw_navbar_ic_back</item>
<item name="suwNavBarBackgroundColor">@color/suw_navbar_bg_dark</item>
<item name="suwNavBarButtonBackground">@drawable/suw_navbar_btn_bg</item>
<item name="suwNavBarMoreButton">@drawable/suw_navbar_ic_more</item>
<item name="suwNavBarNextButton">@drawable/suw_navbar_ic_next</item>
<item name="suwNavBarTextColor">@color/suw_navbar_text_dark</item>
</style>
<style name="SuwNavBarThemeLight" parent="SuwNavBarTheme">
<item name="suwNavBarBackButton">@drawable/suw_navbar_ic_back</item>
<item name="suwNavBarBackgroundColor">@color/suw_navbar_bg_light</item>
<item name="suwNavBarButtonBackground">@drawable/suw_navbar_btn_bg</item>
<item name="suwNavBarMoreButton">@drawable/suw_navbar_ic_more</item>
<item name="suwNavBarNextButton">@drawable/suw_navbar_ic_next</item>
<item name="suwNavBarTextColor">@color/suw_navbar_text_light</item>
</style>
</resources>

View file

@ -20,11 +20,8 @@
<attr name="suwLayoutTheme" format="reference" />
<attr name="suwCardBackground" format="color|reference" />
<attr name="suwNavBarBackButton" format="reference" />
<attr name="suwNavBarBackgroundColor" format="color" />
<attr name="suwNavBarButtonBackground" format="color|reference" />
<attr name="suwNavBarMoreButton" format="reference" />
<attr name="suwNavBarNextButton" format="reference" />
<attr name="suwNavBarTextColor" format="color" />
<attr name="suwNavBarTheme" format="reference" />

View file

@ -32,7 +32,5 @@
<color name="suw_navbar_bg_dark">#ff21272b</color>
<color name="suw_navbar_bg_light">#ffe4e7e9</color>
<color name="suw_navbar_text_dark">#deffffff</color>
<color name="suw_navbar_text_light">#de000000</color>
</resources>

View file

@ -116,6 +116,7 @@
<item name="android:background">?attr/suwNavBarBackgroundColor</item>
<item name="android:paddingLeft">@dimen/suw_navbar_padding_sides</item>
<item name="android:paddingRight">@dimen/suw_navbar_padding_sides</item>
<item name="suwNavBarTextColor">?android:attr/textColorPrimary</item>
</style>
</resources>

View file

@ -20,10 +20,7 @@ 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.VERSION;
import android.os.Build.VERSION_CODES;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.ContextThemeWrapper;
import android.view.View;
@ -127,47 +124,4 @@ public class NavigationBar extends LinearLayout implements View.OnClickListener
}
}
}
public static class NavButton extends Button {
public NavButton(Context context) {
super(context);
}
public NavButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
// The color of the button is #de000000 / #deffffff when enabled. When disabled, the
// alpha value = 0x3b/0xff * 0xde/0xff = 20%.
final int alpha = enabled ? 0xff : 0x3b;
setTextColor(getTextColors().withAlpha(alpha));
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
final Drawable[] relativeDrawables = getCompoundDrawablesRelative();
for (Drawable d : relativeDrawables) {
if (d != null) {
d.mutate().setAlpha(alpha);
}
}
}
final Drawable[] compoundDrawables = getCompoundDrawables();
for (Drawable d : compoundDrawables) {
if (d != null) {
d.mutate().setAlpha(alpha);
}
}
}
@Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore,
int lengthAfter) {
super.onTextChanged(text, start, lengthBefore, lengthAfter);
setCompoundDrawablePadding(TextUtils.isEmpty(text) ? 0 : getResources()
.getDimensionPixelSize(R.dimen.suw_navbar_button_drawable_padding));
}
}
}

View file

@ -0,0 +1,32 @@
/*
* 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.
*/
package com.android.setupwizardlib.view;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Button;
public class NavigationBarButton extends Button {
public NavigationBarButton(Context context) {
super(context);
}
public NavigationBarButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
}

View file

@ -61,14 +61,17 @@ android {
}
platform {
java.srcDirs = ['platform/src']
res.srcDirs = ['platform/res']
}
icsCompat {
java.srcDirs = ['eclair-mr1/src']
res.srcDirs = ['eclair-mr1/res']
}
eclairMr1Compat {
java.srcDirs = ['eclair-mr1/src']
res.srcDirs = ['eclair-mr1/res']
}

View file

@ -102,9 +102,9 @@ public class PartnerTest extends InstrumentationTestCase {
);
ResourceEntry entry =
Partner.getResourceEntry(mTestContext, R.color.suw_navbar_text_dark);
Partner.getResourceEntry(mTestContext, R.color.suw_color_accent_dark);
int partnerValue = entry.resources.getColor(entry.id);
assertEquals("Partner value should default to 0xdeffffff", 0xdeffffff, partnerValue);
assertEquals("Partner value should default to 0xff448aff", 0xff448aff, partnerValue);
assertFalse("Partner value should come from fallback", entry.isOverlay);
}