blob: 1ed5f565117fa400f86b38656dde4d7654bc598d [file] [log] [blame]
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.systemui.colorextraction;
18
19import static org.junit.Assert.assertEquals;
20
Lucas Dupin1cd133a2017-06-13 10:47:15 -070021import android.app.WallpaperColors;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -070022import android.app.WallpaperManager;
23import android.graphics.Color;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -070024import android.support.test.filters.SmallTest;
25import android.support.test.runner.AndroidJUnit4;
Lucas Dupin1cd133a2017-06-13 10:47:15 -070026import android.util.Pair;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -070027
28import com.android.systemui.SysuiTestCase;
29
30import com.google.android.colorextraction.ColorExtractor;
31import com.google.android.colorextraction.types.Tonal;
32
33import org.junit.Test;
34import org.junit.runner.RunWith;
35
Lucas Dupin1cd133a2017-06-13 10:47:15 -070036import java.util.ArrayList;
37import java.util.List;
38
Lucas Dupin1ead7fc2017-05-24 14:14:44 -070039/**
40 * Tests color extraction generation.
41 */
42@SmallTest
43@RunWith(AndroidJUnit4.class)
44public class SysuiColorExtractorTests extends SysuiTestCase {
45
Lucas Dupin1cd133a2017-06-13 10:47:15 -070046 private static int[] sWhich = new int[]{
Lucas Dupin1ead7fc2017-05-24 14:14:44 -070047 WallpaperManager.FLAG_SYSTEM,
48 WallpaperManager.FLAG_LOCK};
Lucas Dupin1cd133a2017-06-13 10:47:15 -070049 private static int[] sTypes = new int[]{
Lucas Dupin1ead7fc2017-05-24 14:14:44 -070050 ColorExtractor.TYPE_NORMAL,
51 ColorExtractor.TYPE_DARK,
52 ColorExtractor.TYPE_EXTRA_DARK};
53
Lucas Dupin1ead7fc2017-05-24 14:14:44 -070054 @Test
55 public void getColors_usesGreyIfWallpaperNotVisible() {
56 ColorExtractor.GradientColors fallbackColors = new ColorExtractor.GradientColors();
57 fallbackColors.setMainColor(ColorExtractor.FALLBACK_COLOR);
58 fallbackColors.setSecondaryColor(ColorExtractor.FALLBACK_COLOR);
59
60 SysuiColorExtractor extractor = new SysuiColorExtractor(getContext(), new Tonal(), false);
Lucas Dupin1cd133a2017-06-13 10:47:15 -070061 simulateEvent(extractor);
Lucas Dupin1ead7fc2017-05-24 14:14:44 -070062 extractor.setWallpaperVisible(false);
63
64 for (int which : sWhich) {
65 for (int type : sTypes) {
66 assertEquals("Not using fallback!", extractor.getColors(which, type),
67 fallbackColors);
68 }
69 }
70 }
71
Lucas Dupin1ead7fc2017-05-24 14:14:44 -070072 @Test
73 public void getColors_doesntUseFallbackIfVisible() {
74 ColorExtractor.GradientColors colors = new ColorExtractor.GradientColors();
75 colors.setMainColor(Color.RED);
76 colors.setSecondaryColor(Color.RED);
77
78 SysuiColorExtractor extractor = new SysuiColorExtractor(getContext(),
79 (inWallpaperColors, outGradientColorsNormal, outGradientColorsDark,
80 outGradientColorsExtraDark) -> {
81 outGradientColorsNormal.set(colors);
82 outGradientColorsDark.set(colors);
83 outGradientColorsExtraDark.set(colors);
84 return true;
85 }, false);
Lucas Dupin1cd133a2017-06-13 10:47:15 -070086 simulateEvent(extractor);
Lucas Dupin1ead7fc2017-05-24 14:14:44 -070087 extractor.setWallpaperVisible(true);
88
89 for (int which : sWhich) {
90 for (int type : sTypes) {
91 assertEquals("Not using extracted colors!",
92 extractor.getColors(which, type), colors);
93 }
94 }
95 }
Lucas Dupin1cd133a2017-06-13 10:47:15 -070096
97 private void simulateEvent(SysuiColorExtractor extractor) {
98 // Let's fake a color event
Lucas Dupin84b89d92017-05-09 12:16:19 -070099 extractor.onColorsChanged(new WallpaperColors(Color.valueOf(Color.BLACK), null, null, 0),
Lucas Dupin1cd133a2017-06-13 10:47:15 -0700100 WallpaperManager.FLAG_SYSTEM | WallpaperManager.FLAG_LOCK);
101 }
102}