Merge "Make status bar white on GLIF pixel theme"
This commit is contained in:
commit
d86822922f
|
@ -69,6 +69,8 @@
|
||||||
|
|
||||||
<declare-styleable name="SuwGlifLayout">
|
<declare-styleable name="SuwGlifLayout">
|
||||||
<attr name="suwColorPrimary" />
|
<attr name="suwColorPrimary" />
|
||||||
|
<attr name="suwBackgroundPatterned" format="boolean" />
|
||||||
|
<attr name="suwBackgroundBaseColor" format="color" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="SuwStatusBarBackgroundLayout">
|
<declare-styleable name="SuwStatusBarBackgroundLayout">
|
||||||
|
|
|
@ -20,10 +20,18 @@
|
||||||
<!-- General styles -->
|
<!-- General styles -->
|
||||||
|
|
||||||
<style name="SuwThemeGlifPixel" parent="SuwThemeGlif">
|
<style name="SuwThemeGlifPixel" parent="SuwThemeGlif">
|
||||||
|
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
|
||||||
|
|
||||||
|
<item name="suwBackgroundBaseColor">?android:attr/colorBackground</item>
|
||||||
|
<item name="suwBackgroundPatterned">false</item>
|
||||||
<item name="suwGlifHeaderGravity">center_horizontal</item>
|
<item name="suwGlifHeaderGravity">center_horizontal</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="SuwThemeGlifPixel.Light" parent="SuwThemeGlif.Light">
|
<style name="SuwThemeGlifPixel.Light" parent="SuwThemeGlif.Light">
|
||||||
|
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
|
||||||
|
|
||||||
|
<item name="suwBackgroundBaseColor">?android:attr/colorBackground</item>
|
||||||
|
<item name="suwBackgroundPatterned">false</item>
|
||||||
<item name="suwGlifHeaderGravity">center_horizontal</item>
|
<item name="suwGlifHeaderGravity">center_horizontal</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,13 @@ import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Build.VERSION_CODES;
|
import android.os.Build.VERSION_CODES;
|
||||||
import android.support.annotation.LayoutRes;
|
import android.support.annotation.LayoutRes;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -64,6 +66,14 @@ public class GlifLayout extends TemplateLayout {
|
||||||
|
|
||||||
private ColorStateList mPrimaryColor;
|
private ColorStateList mPrimaryColor;
|
||||||
|
|
||||||
|
private boolean mBackgroundPatterned = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The color of the background. If null, the color will inherit from mPrimaryColor.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
private ColorStateList mBackgroundBaseColor;
|
||||||
|
|
||||||
public GlifLayout(Context context) {
|
public GlifLayout(Context context) {
|
||||||
this(context, 0, 0);
|
this(context, 0, 0);
|
||||||
}
|
}
|
||||||
|
@ -105,6 +115,14 @@ public class GlifLayout extends TemplateLayout {
|
||||||
setPrimaryColor(primaryColor);
|
setPrimaryColor(primaryColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ColorStateList backgroundColor =
|
||||||
|
a.getColorStateList(R.styleable.SuwGlifLayout_suwBackgroundBaseColor);
|
||||||
|
setBackgroundBaseColor(backgroundColor);
|
||||||
|
|
||||||
|
boolean backgroundPatterned =
|
||||||
|
a.getBoolean(R.styleable.SuwGlifLayout_suwBackgroundPatterned, true);
|
||||||
|
setBackgroundPatterned(backgroundPatterned);
|
||||||
|
|
||||||
a.recycle();
|
a.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +187,7 @@ public class GlifLayout extends TemplateLayout {
|
||||||
*/
|
*/
|
||||||
public void setPrimaryColor(@NonNull ColorStateList color) {
|
public void setPrimaryColor(@NonNull ColorStateList color) {
|
||||||
mPrimaryColor = color;
|
mPrimaryColor = color;
|
||||||
setGlifPatternColor(color);
|
updateBackground();
|
||||||
getMixin(ProgressBarMixin.class).setColor(color);
|
getMixin(ProgressBarMixin.class).setColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,11 +195,56 @@ public class GlifLayout extends TemplateLayout {
|
||||||
return mPrimaryColor;
|
return mPrimaryColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setGlifPatternColor(@NonNull ColorStateList color) {
|
/**
|
||||||
|
* Sets the base color of the background view, which is the status bar for phones and the full-
|
||||||
|
* screen background for tablets. If {@link #isBackgroundPatterned()} is true, the pattern will
|
||||||
|
* be drawn with this color.
|
||||||
|
*
|
||||||
|
* @param color The color to use as the base color of the background. If {@code null},
|
||||||
|
* {@link #getPrimaryColor()} will be used.
|
||||||
|
*/
|
||||||
|
public void setBackgroundBaseColor(@Nullable ColorStateList color) {
|
||||||
|
mBackgroundBaseColor = color;
|
||||||
|
updateBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The base color of the background. {@code null} indicates the background will be drawn
|
||||||
|
* with {@link #getPrimaryColor()}.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public ColorStateList getBackgroundBaseColor() {
|
||||||
|
return mBackgroundBaseColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the background should be {@link GlifPatternDrawable}. If {@code false}, the
|
||||||
|
* background will be a solid color.
|
||||||
|
*/
|
||||||
|
public void setBackgroundPatterned(boolean patterned) {
|
||||||
|
mBackgroundPatterned = patterned;
|
||||||
|
updateBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return True if this view uses {@link GlifPatternDrawable} as background.
|
||||||
|
*/
|
||||||
|
public boolean isBackgroundPatterned() {
|
||||||
|
return mBackgroundPatterned;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBackground() {
|
||||||
final View patternBg = findManagedViewById(R.id.suw_pattern_bg);
|
final View patternBg = findManagedViewById(R.id.suw_pattern_bg);
|
||||||
if (patternBg != null) {
|
if (patternBg != null) {
|
||||||
final GlifPatternDrawable background =
|
int backgroundColor = 0;
|
||||||
new GlifPatternDrawable(color.getDefaultColor());
|
if (mBackgroundBaseColor != null) {
|
||||||
|
backgroundColor = mBackgroundBaseColor.getDefaultColor();
|
||||||
|
} else if (mPrimaryColor != null) {
|
||||||
|
backgroundColor = mPrimaryColor.getDefaultColor();
|
||||||
|
}
|
||||||
|
Drawable background = mBackgroundPatterned
|
||||||
|
? new GlifPatternDrawable(backgroundColor)
|
||||||
|
: new ColorDrawable(backgroundColor);
|
||||||
if (patternBg instanceof StatusBarBackgroundLayout) {
|
if (patternBg instanceof StatusBarBackgroundLayout) {
|
||||||
((StatusBarBackgroundLayout) patternBg).setStatusBarBackground(background);
|
((StatusBarBackgroundLayout) patternBg).setStatusBarBackground(background);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package com.android.setupwizardlib.test;
|
package com.android.setupwizardlib.test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@ -99,6 +100,12 @@ public class GlifLayoutTest {
|
||||||
assertEquals("Icon should be center aligned on GLIF Pixel theme",
|
assertEquals("Icon should be center aligned on GLIF Pixel theme",
|
||||||
Gravity.CENTER_HORIZONTAL, parent.getGravity() & Gravity.CENTER_HORIZONTAL);
|
Gravity.CENTER_HORIZONTAL, parent.getGravity() & Gravity.CENTER_HORIZONTAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertEquals("Status bar color should be white in GLIF Pixel theme",
|
||||||
|
"fffafafa",
|
||||||
|
Integer.toHexString(glifLayout.getBackgroundBaseColor().getDefaultColor()));
|
||||||
|
assertFalse("GLIF Pixel theme shuold not have patterned background",
|
||||||
|
glifLayout.isBackgroundPatterned());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertDefaultTemplateInflated(GlifLayout layout) {
|
private void assertDefaultTemplateInflated(GlifLayout layout) {
|
||||||
|
|
|
@ -16,16 +16,21 @@
|
||||||
|
|
||||||
package com.android.setupwizardlib;
|
package com.android.setupwizardlib;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.robolectric.RuntimeEnvironment.application;
|
import static org.robolectric.RuntimeEnvironment.application;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.annotation.IdRes;
|
import android.support.annotation.IdRes;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
|
@ -39,6 +44,7 @@ import com.android.setupwizardlib.template.ColoredHeaderMixin;
|
||||||
import com.android.setupwizardlib.template.HeaderMixin;
|
import com.android.setupwizardlib.template.HeaderMixin;
|
||||||
import com.android.setupwizardlib.template.IconMixin;
|
import com.android.setupwizardlib.template.IconMixin;
|
||||||
import com.android.setupwizardlib.template.ProgressBarMixin;
|
import com.android.setupwizardlib.template.ProgressBarMixin;
|
||||||
|
import com.android.setupwizardlib.view.StatusBarBackgroundLayout;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -123,9 +129,66 @@ public class GlifLayoutTest {
|
||||||
ColorStateList.valueOf(Color.RED), progressBar.getProgressBackgroundTintList());
|
ColorStateList.valueOf(Color.RED), progressBar.getProgressBackgroundTintList());
|
||||||
}
|
}
|
||||||
|
|
||||||
final View patternBg = layout.findManagedViewById(R.id.suw_pattern_bg);
|
assertEquals(Color.RED, ((GlifPatternDrawable) getTabletBackground(layout)).getColor());
|
||||||
final GlifPatternDrawable background = (GlifPatternDrawable) patternBg.getBackground();
|
}
|
||||||
assertEquals(Color.RED, background.getColor());
|
|
||||||
|
@Test
|
||||||
|
public void testSetBackgroundBaseColor() {
|
||||||
|
GlifLayout layout = new GlifLayout(mContext);
|
||||||
|
layout.setPrimaryColor(ColorStateList.valueOf(Color.BLUE));
|
||||||
|
layout.setBackgroundBaseColor(ColorStateList.valueOf(Color.RED));
|
||||||
|
|
||||||
|
assertEquals(Color.RED, ((GlifPatternDrawable) getPhoneBackground(layout)).getColor());
|
||||||
|
assertEquals(Color.RED, layout.getBackgroundBaseColor().getDefaultColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Config(qualifiers = "sw600dp")
|
||||||
|
@Test
|
||||||
|
public void testSetBackgroundBaseColorTablet() {
|
||||||
|
GlifLayout layout = new GlifLayout(mContext);
|
||||||
|
layout.setPrimaryColor(ColorStateList.valueOf(Color.BLUE));
|
||||||
|
layout.setBackgroundBaseColor(ColorStateList.valueOf(Color.RED));
|
||||||
|
|
||||||
|
assertEquals(Color.RED, ((GlifPatternDrawable) getTabletBackground(layout)).getColor());
|
||||||
|
assertEquals(Color.RED, layout.getBackgroundBaseColor().getDefaultColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetBackgroundPatternedTrue() {
|
||||||
|
GlifLayout layout = new GlifLayout(mContext);
|
||||||
|
layout.setBackgroundPatterned(true);
|
||||||
|
|
||||||
|
assertThat(getPhoneBackground(layout), instanceOf(GlifPatternDrawable.class));
|
||||||
|
assertTrue("Background should be patterned", layout.isBackgroundPatterned());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetBackgroundPatternedFalse() {
|
||||||
|
GlifLayout layout = new GlifLayout(mContext);
|
||||||
|
layout.setBackgroundPatterned(false);
|
||||||
|
|
||||||
|
assertThat(getPhoneBackground(layout), instanceOf(ColorDrawable.class));
|
||||||
|
assertFalse("Background should not be patterned", layout.isBackgroundPatterned());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Config(qualifiers = "sw600dp")
|
||||||
|
@Test
|
||||||
|
public void testSetBackgroundPatternedTrueTablet() {
|
||||||
|
GlifLayout layout = new GlifLayout(mContext);
|
||||||
|
layout.setBackgroundPatterned(true);
|
||||||
|
|
||||||
|
assertThat(getTabletBackground(layout), instanceOf(GlifPatternDrawable.class));
|
||||||
|
assertTrue("Background should be patterned", layout.isBackgroundPatterned());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Config(qualifiers = "sw600dp")
|
||||||
|
@Test
|
||||||
|
public void testSetBackgroundPatternedFalseTablet() {
|
||||||
|
GlifLayout layout = new GlifLayout(mContext);
|
||||||
|
layout.setBackgroundPatterned(false);
|
||||||
|
|
||||||
|
assertThat(getTabletBackground(layout), instanceOf(ColorDrawable.class));
|
||||||
|
assertFalse("Background should not be patterned", layout.isBackgroundPatterned());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -161,6 +224,17 @@ public class GlifLayoutTest {
|
||||||
layout.getMixin(ProgressBarMixin.class));
|
layout.getMixin(ProgressBarMixin.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Drawable getPhoneBackground(GlifLayout layout) {
|
||||||
|
final StatusBarBackgroundLayout patternBg =
|
||||||
|
(StatusBarBackgroundLayout) layout.findManagedViewById(R.id.suw_pattern_bg);
|
||||||
|
return patternBg.getStatusBarBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Drawable getTabletBackground(GlifLayout layout) {
|
||||||
|
final View patternBg = layout.findManagedViewById(R.id.suw_pattern_bg);
|
||||||
|
return patternBg.getBackground();
|
||||||
|
}
|
||||||
|
|
||||||
private void assertDefaultTemplateInflated(GlifLayout layout) {
|
private void assertDefaultTemplateInflated(GlifLayout layout) {
|
||||||
View title = layout.findViewById(R.id.suw_layout_title);
|
View title = layout.findViewById(R.id.suw_layout_title);
|
||||||
assertNotNull("@id/suw_layout_title should not be null", title);
|
assertNotNull("@id/suw_layout_title should not be null", title);
|
||||||
|
|
Loading…
Reference in a new issue