summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLucas Dupin <dupin@google.com>2017-06-29 12:20:29 -0700
committerLucas Dupin <dupin@google.com>2017-07-07 14:36:45 -0700
commit4bd24f36c5c4845bc9fda9c7211d1be2937a748a (patch)
tree7af638a350351830ea8bc5a5b1d3f60ae7702d23 /tests
parent845a4035ae08032ae5fc097bb8027c87fcc76f0a (diff)
Add theme style flag to WallpaperColors
Theme colors should always be the same in sysui and launcher. We're now sharing a hint HINT_SUPPORTS_DARK_THEME, to make sure we're never out of sync. Test: runtest -x tests/Internal/src/android/app/WallpaperColorsTest.java Fixes: 63140091 Change-Id: Ibd196f540d77269df377804b0f4d4d0d20820067
Diffstat (limited to 'tests')
-rw-r--r--tests/Internal/src/android/app/WallpaperColorsTest.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/Internal/src/android/app/WallpaperColorsTest.java b/tests/Internal/src/android/app/WallpaperColorsTest.java
new file mode 100644
index 000000000000..5bbd82bea3de
--- /dev/null
+++ b/tests/Internal/src/android/app/WallpaperColorsTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2017 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 android.app;
+
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class WallpaperColorsTest {
+
+ @Test
+ public void supportsDarkTextOverrideTest() {
+ final Color color = Color.valueOf(Color.WHITE);
+ // Default should not support dark text!
+ WallpaperColors colors = new WallpaperColors(color, null, null, 0);
+ Assert.assertTrue("Default behavior is not to support dark text",
+ (colors.getColorHints() & WallpaperColors.HINT_SUPPORTS_DARK_TEXT) == 0);
+
+ // Override it
+ colors = new WallpaperColors(color, null, null, WallpaperColors.HINT_SUPPORTS_DARK_TEXT);
+ Assert.assertFalse("Forcing dark text support doesn't work",
+ (colors.getColorHints() & WallpaperColors.HINT_SUPPORTS_DARK_TEXT) == 0);
+ }
+
+ /**
+ * Sanity check to guarantee that white supports dark text and black doesn't
+ */
+ @Test
+ public void colorHintsTest() {
+ Bitmap image = Bitmap.createBitmap(30, 30, Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(image);
+
+ canvas.drawColor(Color.WHITE);
+ int hints = WallpaperColors.fromBitmap(image).getColorHints();
+ boolean supportsDarkText = (hints & WallpaperColors.HINT_SUPPORTS_DARK_TEXT) != 0;
+ boolean supportsDarkTheme = (hints & WallpaperColors.HINT_SUPPORTS_DARK_THEME) != 0;
+ Assert.assertTrue("White surface should support dark text", supportsDarkText);
+ Assert.assertFalse("White surface shouldn't support dark theme", supportsDarkTheme);
+
+ canvas.drawColor(Color.BLACK);
+ hints = WallpaperColors.fromBitmap(image).getColorHints();
+ supportsDarkText = (hints & WallpaperColors.HINT_SUPPORTS_DARK_TEXT) != 0;
+ supportsDarkTheme = (hints & WallpaperColors.HINT_SUPPORTS_DARK_THEME) != 0;
+ Assert.assertFalse("Black surface shouldn't support dark text", supportsDarkText);
+ Assert.assertTrue("Black surface should support dark theme", supportsDarkTheme);
+
+ Paint paint = new Paint();
+ paint.setStyle(Paint.Style.FILL);
+ paint.setColor(Color.BLACK);
+ canvas.drawColor(Color.WHITE);
+ canvas.drawRect(0, 0, 8, 8, paint);
+ supportsDarkText = (WallpaperColors.fromBitmap(image)
+ .getColorHints() & WallpaperColors.HINT_SUPPORTS_DARK_TEXT) != 0;
+ Assert.assertFalse("Light surface shouldn't support dark text "
+ + "when it contains dark pixels", supportsDarkText);
+ }
+}