Moving color extraction classes

Fixes: 62220212
Test: make
Test: runtest -x tests/Internal/src/com/android/internal/colorextraction/ColorExtractorTest.java
Test: runtest -x tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java
Test: runtest systemui
Change-Id: I7c4cf5c40a88555e81fbad9bec2b32c55c927468
Merged-In: I7c4cf5c40a88555e81fbad9bec2b32c55c927468
This commit is contained in:
Lucas Dupin
2017-07-06 14:35:30 -07:00
parent d7aa26f33b
commit e2292a94bb
23 changed files with 60 additions and 233 deletions

View File

@@ -14,24 +14,22 @@
* limitations under the License
*/
package com.google.android.colorextraction;
package com.android.internal.colorextraction;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.WallpaperColors;
import android.app.WallpaperManager;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Trace;
import android.support.annotation.VisibleForTesting;
import android.util.Log;
import android.util.SparseArray;
import com.google.android.colorextraction.types.ExtractionType;
import com.google.android.colorextraction.types.Tonal;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.colorextraction.types.ExtractionType;
import com.android.internal.colorextraction.types.Tonal;
import java.util.ArrayList;
import java.util.List;
/**
* Class to process wallpaper colors and generate a tonal palette based on them.

View File

@@ -14,11 +14,13 @@
* limitations under the License
*/
package com.google.android.colorextraction.drawable;
package com.android.internal.colorextraction.drawable;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
@@ -29,13 +31,11 @@ import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.Xfermode;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.support.v4.graphics.ColorUtils;
import android.view.animation.DecelerateInterpolator;
import com.google.android.colorextraction.ColorExtractor;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.colorextraction.ColorExtractor;
import com.android.internal.graphics.ColorUtils;
/**
* Draws a gradient based on a Palette

View File

@@ -14,11 +14,11 @@
* limitations under the License
*/
package com.google.android.colorextraction.types;
package com.android.internal.colorextraction.types;
import android.app.WallpaperColors;
import com.google.android.colorextraction.ColorExtractor;
import com.android.internal.colorextraction.ColorExtractor;
/**
* Interface to allow various color extraction implementations.

View File

@@ -14,20 +14,19 @@
* limitations under the License
*/
package com.google.android.colorextraction.types;
package com.android.internal.colorextraction.types;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.WallpaperColors;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.support.v4.graphics.ColorUtils;
import android.util.Log;
import android.util.MathUtils;
import android.util.Pair;
import android.util.Range;
import com.google.android.colorextraction.ColorExtractor.GradientColors;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.colorextraction.ColorExtractor.GradientColors;
import com.android.internal.graphics.ColorUtils;
import java.util.Arrays;
import java.util.List;
@@ -616,7 +615,7 @@ public class Tonal implements ExtractionType {
@SuppressWarnings("WeakerAccess")
@VisibleForTesting
static final ColorRange[] BLACKLISTED_COLORS = new ColorRange[] {
public static final ColorRange[] BLACKLISTED_COLORS = new ColorRange[] {
// Red
new ColorRange(
@@ -768,18 +767,18 @@ public class Tonal implements ExtractionType {
* </ul>
*/
@VisibleForTesting
static class ColorRange {
public static class ColorRange {
private Range<Float> mHue;
private Range<Float> mSaturation;
private Range<Float> mLightness;
ColorRange(Range<Float> hue, Range<Float> saturation, Range<Float> lightness) {
public ColorRange(Range<Float> hue, Range<Float> saturation, Range<Float> lightness) {
mHue = hue;
mSaturation = saturation;
mLightness = lightness;
}
boolean containsColor(float h, float s, float l) {
public boolean containsColor(float h, float s, float l) {
if (!mHue.contains(h)) {
return false;
} else if (!mSaturation.contains(s)) {
@@ -790,8 +789,7 @@ public class Tonal implements ExtractionType {
return true;
}
@VisibleForTesting
float[] getCenter() {
public float[] getCenter() {
return new float[] {
mHue.getLower() + (mHue.getUpper() - mHue.getLower()) / 2f,
mSaturation.getLower() + (mSaturation.getUpper() - mSaturation.getLower()) / 2f,

View File

@@ -38,8 +38,7 @@ LOCAL_STATIC_ANDROID_LIBRARIES := \
android-support-v7-mediarouter \
android-support-v7-palette \
android-support-v14-preference \
android-support-v17-leanback \
colorextraction
android-support-v17-leanback
LOCAL_STATIC_JAVA_LIBRARIES := \
SystemUI-tags \

View File

@@ -1,26 +0,0 @@
# 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.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_USE_AAPT2 := true
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_STATIC_ANDROID_LIBRARIES := android-support-annotations \
android-support-v7-palette \
android-support-v4
LOCAL_MODULE := colorextraction
include $(BUILD_STATIC_JAVA_LIBRARY)

View File

@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.colorextraction">
</manifest>

View File

@@ -1,41 +0,0 @@
# 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.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
$(call all-java-files-under, ../src)
LOCAL_JAVA_LIBRARIES := android.test.runner
LOCAL_PACKAGE_NAME := ColorExtractorTests
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_TAGS := tests
LOCAL_JAVA_LIBRARIES := android-support-test
LOCAL_STATIC_JAVA_LIBRARIES := \
android-support-test \
mockito-target-minus-junit4 \
espresso-core \
truth-prebuilt \
legacy-android-test \
android-support-annotations \
android-support-v7-palette \
android-support-v4
LOCAL_COMPATIBILITY_SUITE := device-tests
include $(BUILD_PACKAGE)

View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.systemui.colorextraction.tests">
<application>
<uses-library android:name="android.test.runner" />
</application>
<instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
android:targetPackage="com.android.systemui.colorextraction.tests"
android:label="Tests for ColorExtractor">
</instrumentation>
</manifest>

View File

@@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<configuration description="Runs Tests for ColorExtractor.">
<target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">
<option name="test-file-name" value="ColorExtractorTests.apk" />
</target_preparer>
<option name="test-suite-tag" value="apct" />
<option name="test-tag" value="SystemUITests" />
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
<option name="package" value="com.android.systemui.tests" />
<option name="runner" value="android.support.test.runner.AndroidJUnitRunner" />
</test>
</configuration>

View File

@@ -27,10 +27,9 @@ import android.view.IWindowManager;
import android.view.WindowManagerGlobal;
import com.android.internal.annotations.VisibleForTesting;
import com.google.android.colorextraction.ColorExtractor;
import com.google.android.colorextraction.types.ExtractionType;
import com.google.android.colorextraction.types.Tonal;
import com.android.internal.colorextraction.ColorExtractor;
import com.android.internal.colorextraction.types.ExtractionType;
import com.android.internal.colorextraction.types.Tonal;
/**
* ColorExtractor aware of wallpaper visibility

View File

@@ -14,9 +14,9 @@
package com.android.systemui.globalactions;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import com.android.internal.R;
import com.android.internal.colorextraction.ColorExtractor;
import com.android.internal.colorextraction.ColorExtractor.GradientColors;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.util.EmergencyAffordanceManager;
@@ -28,7 +28,6 @@ import com.android.systemui.HardwareUiLayout;
import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
import com.android.systemui.statusbar.phone.ScrimController;
import com.android.systemui.volume.VolumeDialogImpl;
import com.android.systemui.volume.VolumeDialogMotion.LogAccelerateInterpolator;
import com.android.systemui.volume.VolumeDialogMotion.LogDecelerateInterpolator;
@@ -42,11 +41,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.database.DataSetObserver;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.net.ConnectivityManager;
@@ -68,11 +63,9 @@ import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
@@ -85,9 +78,7 @@ import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.colorextraction.ColorExtractor;
import com.google.android.colorextraction.ColorExtractor.GradientColors;
import com.google.android.colorextraction.drawable.GradientDrawable;
import com.android.internal.colorextraction.drawable.GradientDrawable;
import java.util.ArrayList;
import java.util.List;

View File

@@ -42,6 +42,7 @@ import android.view.WindowInsets;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.android.internal.colorextraction.ColorExtractor;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.Dependency;
@@ -82,8 +83,7 @@ import com.android.systemui.stackdivider.WindowManagerProxy;
import com.android.systemui.statusbar.FlingAnimationUtils;
import com.android.systemui.statusbar.phone.ScrimController;
import com.google.android.colorextraction.ColorExtractor;
import com.google.android.colorextraction.drawable.GradientDrawable;
import com.android.internal.colorextraction.drawable.GradientDrawable;
import java.io.PrintWriter;
import java.util.ArrayList;

View File

@@ -39,12 +39,11 @@ import android.view.WindowManager;
import android.view.animation.Interpolator;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.colorextraction.ColorExtractor;
import com.android.internal.colorextraction.drawable.GradientDrawable;
import com.android.systemui.Dependency;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.google.android.colorextraction.ColorExtractor;
import com.google.android.colorextraction.drawable.GradientDrawable;
/**
* A view which can draw a scrim
*/

View File

@@ -33,6 +33,9 @@ import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.PathInterpolator;
import com.android.internal.colorextraction.ColorExtractor;
import com.android.internal.colorextraction.ColorExtractor.GradientColors;
import com.android.internal.colorextraction.ColorExtractor.OnColorsChangedListener;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.Dependency;
import com.android.systemui.R;
@@ -43,9 +46,6 @@ import com.android.systemui.statusbar.ScrimView;
import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener;
import com.android.systemui.statusbar.stack.ViewState;
import com.google.android.colorextraction.ColorExtractor;
import com.google.android.colorextraction.ColorExtractor.OnColorsChangedListener;
/**
* Controls both the scrim behind the notifications and in front of the notifications (when a
* security method gets shown).
@@ -80,8 +80,8 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private final SysuiColorExtractor mColorExtractor;
private ColorExtractor.GradientColors mLockColors;
private ColorExtractor.GradientColors mSystemColors;
private GradientColors mLockColors;
private GradientColors mSystemColors;
private boolean mNeedsDrawableColorUpdate;
protected float mScrimBehindAlpha;

View File

@@ -139,6 +139,7 @@ import android.widget.RemoteViews;
import android.widget.TextView;
import android.widget.Toast;
import com.android.internal.colorextraction.ColorExtractor;
import com.android.internal.graphics.ColorUtils;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -243,8 +244,6 @@ import com.android.systemui.util.NotificationChannels;
import com.android.systemui.util.leak.LeakDetector;
import com.android.systemui.volume.VolumeComponent;
import com.google.android.colorextraction.ColorExtractor;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.StringWriter;

View File

@@ -81,14 +81,10 @@ import com.android.systemui.plugins.VolumeDialogController;
import com.android.systemui.plugins.VolumeDialogController.State;
import com.android.systemui.plugins.VolumeDialogController.StreamState;
import com.android.systemui.plugins.VolumeDialog;
import com.android.systemui.statusbar.phone.ScrimController;
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerZenModePanel;
import com.google.android.colorextraction.ColorExtractor;
import com.google.android.colorextraction.drawable.GradientDrawable;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

View File

@@ -45,8 +45,7 @@ LOCAL_STATIC_ANDROID_LIBRARIES := \
android-support-v7-mediarouter \
android-support-v7-palette \
android-support-v14-preference \
android-support-v17-leanback \
colorextraction
android-support-v17-leanback
LOCAL_STATIC_JAVA_LIBRARIES := \
metrics-helper-lib \

View File

@@ -23,19 +23,14 @@ import android.app.WallpaperManager;
import android.graphics.Color;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.util.Pair;
import com.android.internal.colorextraction.ColorExtractor;
import com.android.internal.colorextraction.types.Tonal;
import com.android.systemui.SysuiTestCase;
import com.google.android.colorextraction.ColorExtractor;
import com.google.android.colorextraction.types.Tonal;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.List;
/**
* Tests color extraction generation.
*/

View File

@@ -35,12 +35,11 @@ import android.testing.TestableLooper.RunWithLooper;
import android.testing.ViewUtils;
import android.view.View;
import com.android.internal.colorextraction.ColorExtractor;
import com.android.internal.colorextraction.drawable.GradientDrawable;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.utils.leaks.LeakCheckedTest;
import com.google.android.colorextraction.ColorExtractor;
import com.google.android.colorextraction.drawable.GradientDrawable;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@@ -10,7 +10,10 @@ LOCAL_PROTOC_OPTIMIZE_TYPE := nano
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_JAVA_LIBRARIES := android.test.runner
LOCAL_STATIC_JAVA_LIBRARIES := junit legacy-android-test android-support-test
LOCAL_STATIC_JAVA_LIBRARIES := junit \
legacy-android-test \
android-support-test \
mockito-target-minus-junit4
LOCAL_CERTIFICATE := platform

View File

@@ -13,16 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.google.android.colorextraction;
package com.android.internal.colorextraction;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import android.app.WallpaperColors;
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Color;
@@ -30,9 +29,10 @@ import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import com.google.android.colorextraction.ColorExtractor.GradientColors;
import com.google.android.colorextraction.types.ExtractionType;
import com.google.android.colorextraction.types.Tonal;
import com.android.internal.colorextraction.ColorExtractor;
import com.android.internal.colorextraction.ColorExtractor.GradientColors;
import com.android.internal.colorextraction.types.ExtractionType;
import com.android.internal.colorextraction.types.Tonal;
import org.junit.Before;
import org.junit.Test;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.google.android.colorextraction.types;
package com.android.internal.colorextraction.types;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -22,19 +22,15 @@ import android.app.WallpaperColors;
import android.graphics.Color;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.v4.graphics.ColorUtils;
import android.util.Pair;
import android.util.Range;
import com.google.android.colorextraction.ColorExtractor;
import com.google.android.colorextraction.ColorExtractor.GradientColors;
import com.android.internal.colorextraction.ColorExtractor.GradientColors;
import com.android.internal.graphics.ColorUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Tests tonal palette generation.
@@ -71,9 +67,8 @@ public class TonalTest {
public void colorRange_excludeBlacklistedColor() {
// Creating a WallpaperColors object that contains *only* blacklisted colors
float[] hsl = Tonal.BLACKLISTED_COLORS[0].getCenter();
ArrayList<Pair<Color, Integer>> blacklistedColorList = new ArrayList<>();
blacklistedColorList.add(new Pair<>(Color.valueOf(ColorUtils.HSLToColor(hsl)), 1));
WallpaperColors colors = new WallpaperColors(blacklistedColorList);
WallpaperColors colors = new WallpaperColors(Color.valueOf(ColorUtils.HSLToColor(hsl)),
null, null, 0);
// Make sure that palette generation will fail
Tonal tonal = new Tonal();