mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 15:26:58 +00:00
Using the system color extraction logic instead of inbuild logic
> Moving the inbuild color extraction logic to the aosp flavor Bug: 79111591 Change-Id: I766b0397da7224b424cd5f309cedf635d60a5e0f
This commit is contained in:
@@ -81,7 +81,7 @@
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name="com.android.launcher3.compat.WallpaperManagerCompatVL$ColorExtractionService"
|
||||
android:name="com.android.launcher3.uioverrides.dynamicui.WallpaperManagerCompatVL$ColorExtractionService"
|
||||
android:exported="false"
|
||||
android:process=":wallpaper_chooser"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE" />
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
-->
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.android.launcher3" >
|
||||
|
||||
<uses-sdk android:targetSdkVersion="28" android:minSdkVersion="28"/>
|
||||
@@ -70,6 +71,12 @@
|
||||
<action android:name="android.content.action.SEARCH_INDEXABLES_PROVIDER" />
|
||||
</intent-filter>
|
||||
</provider>
|
||||
|
||||
|
||||
<service
|
||||
android:name="com.android.launcher3.uioverrides.dynamicui.WallpaperManagerCompatVL$ColorExtractionService"
|
||||
tools:node="remove" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.launcher3.uioverrides;
|
||||
|
||||
import static android.app.WallpaperManager.FLAG_SYSTEM;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.WallpaperColors;
|
||||
import android.app.WallpaperManager;
|
||||
import android.app.WallpaperManager.OnColorsChangedListener;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.android.systemui.shared.system.TonalCompat;
|
||||
import com.android.systemui.shared.system.TonalCompat.ExtractionInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.P)
|
||||
public class WallpaperColorInfo implements OnColorsChangedListener {
|
||||
|
||||
private static final Object sInstanceLock = new Object();
|
||||
private static WallpaperColorInfo sInstance;
|
||||
|
||||
public static WallpaperColorInfo getInstance(Context context) {
|
||||
synchronized (sInstanceLock) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new WallpaperColorInfo(context.getApplicationContext());
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
}
|
||||
|
||||
private final ArrayList<OnChangeListener> mListeners = new ArrayList<>();
|
||||
private final WallpaperManager mWallpaperManager;
|
||||
private final TonalCompat mTonalCompat;
|
||||
|
||||
private ExtractionInfo mExtractionInfo;
|
||||
|
||||
private OnChangeListener[] mTempListeners = new OnChangeListener[0];
|
||||
|
||||
private WallpaperColorInfo(Context context) {
|
||||
mWallpaperManager = context.getSystemService(WallpaperManager.class);
|
||||
mTonalCompat = new TonalCompat(context);
|
||||
|
||||
mWallpaperManager.addOnColorsChangedListener(this, new Handler(Looper.getMainLooper()));
|
||||
update(mWallpaperManager.getWallpaperColors(FLAG_SYSTEM));
|
||||
}
|
||||
|
||||
public int getMainColor() {
|
||||
return mExtractionInfo.mainColor;
|
||||
}
|
||||
|
||||
public int getSecondaryColor() {
|
||||
return mExtractionInfo.secondaryColor;
|
||||
}
|
||||
|
||||
public boolean isDark() {
|
||||
return mExtractionInfo.supportsDarkTheme;
|
||||
}
|
||||
|
||||
public boolean supportsDarkText() {
|
||||
return mExtractionInfo.supportsDarkText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorsChanged(WallpaperColors colors, int which) {
|
||||
if ((which & FLAG_SYSTEM) != 0) {
|
||||
update(colors);
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
private void update(WallpaperColors wallpaperColors) {
|
||||
mExtractionInfo = mTonalCompat.extractDarkColors(wallpaperColors);
|
||||
}
|
||||
|
||||
public void addOnChangeListener(OnChangeListener listener) {
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeOnChangeListener(OnChangeListener listener) {
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
|
||||
private void notifyChange() {
|
||||
// Create a new array to avoid concurrent modification when the activity destroys itself.
|
||||
mTempListeners = mListeners.toArray(mTempListeners);
|
||||
for (OnChangeListener listener : mTempListeners) {
|
||||
if (listener != null) {
|
||||
listener.onExtractedColorsChanged(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnChangeListener {
|
||||
void onExtractedColorsChanged(WallpaperColorInfo wallpaperColorInfo);
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ import android.widget.Toast;
|
||||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
import com.android.launcher3.badge.BadgeInfo;
|
||||
import com.android.launcher3.compat.LauncherAppsCompat;
|
||||
import com.android.launcher3.dynamicui.WallpaperColorInfo;
|
||||
import com.android.launcher3.uioverrides.WallpaperColorInfo;
|
||||
import com.android.launcher3.shortcuts.DeepShortcutManager;
|
||||
import com.android.launcher3.views.BaseDragLayer;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.view.animation.Interpolator;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.anim.Interpolators;
|
||||
import com.android.launcher3.dynamicui.WallpaperColorInfo;
|
||||
import com.android.launcher3.uioverrides.WallpaperColorInfo;
|
||||
|
||||
/**
|
||||
* Simple scrim which draws a color
|
||||
|
||||
@@ -34,7 +34,7 @@ import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.dynamicui.WallpaperColorInfo;
|
||||
import com.android.launcher3.uioverrides.WallpaperColorInfo;
|
||||
|
||||
/**
|
||||
* View scrim which draws behind hotseat and workspace
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.android.launcher3.Insettable;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.dynamicui.WallpaperColorInfo;
|
||||
import com.android.launcher3.uioverrides.WallpaperColorInfo;
|
||||
|
||||
/**
|
||||
* A PageIndicator that briefly shows a fraction of a line when moving between pages
|
||||
|
||||
@@ -1,11 +1,28 @@
|
||||
package com.android.launcher3.dynamicui;
|
||||
/*
|
||||
* Copyright (C) 2018 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.launcher3.uioverrides;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.launcher3.compat.WallpaperColorsCompat;
|
||||
import com.android.launcher3.compat.WallpaperManagerCompat;
|
||||
import com.android.launcher3.uioverrides.dynamicui.WallpaperColorsCompat;
|
||||
import com.android.launcher3.uioverrides.dynamicui.WallpaperManagerCompat;
|
||||
import com.android.launcher3.uioverrides.dynamicui.ColorExtractionAlgorithm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -78,10 +95,10 @@ public class WallpaperColorInfo implements WallpaperManagerCompat.OnColorsChange
|
||||
}
|
||||
mSupportsDarkText = wallpaperColors != null
|
||||
? (wallpaperColors.getColorHints()
|
||||
& WallpaperColorsCompat.HINT_SUPPORTS_DARK_TEXT) > 0 : false;
|
||||
& WallpaperColorsCompat.HINT_SUPPORTS_DARK_TEXT) > 0 : false;
|
||||
mIsDark = wallpaperColors != null
|
||||
? (wallpaperColors.getColorHints()
|
||||
& WallpaperColorsCompat.HINT_SUPPORTS_DARK_THEME) > 0 : false;
|
||||
& WallpaperColorsCompat.HINT_SUPPORTS_DARK_THEME) > 0 : false;
|
||||
}
|
||||
|
||||
public void addOnChangeListener(OnChangeListener listener) {
|
||||
@@ -107,4 +124,4 @@ public class WallpaperColorInfo implements WallpaperManagerCompat.OnColorsChange
|
||||
public interface OnChangeListener {
|
||||
void onExtractedColorsChanged(WallpaperColorInfo wallpaperColorInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.dynamicui;
|
||||
package com.android.launcher3.uioverrides.dynamicui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
@@ -27,7 +27,6 @@ import android.util.Range;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.compat.WallpaperColorsCompat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.launcher3.compat;
|
||||
package com.android.launcher3.uioverrides.dynamicui;
|
||||
|
||||
/**
|
||||
* A compatibility layer around platform implementation of WallpaperColors
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.compat;
|
||||
package com.android.launcher3.uioverrides.dynamicui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.launcher3.compat;
|
||||
package com.android.launcher3.uioverrides.dynamicui;
|
||||
|
||||
import static android.app.WallpaperManager.FLAG_SYSTEM;
|
||||
|
||||
@@ -58,7 +58,7 @@ public class WallpaperManagerCompatVL extends WallpaperManagerCompat {
|
||||
private static final String VERSION_PREFIX = "1,";
|
||||
private static final String KEY_COLORS = "wallpaper_parsed_colors";
|
||||
private static final String ACTION_EXTRACTION_COMPLETE =
|
||||
"com.android.launcher3.compat.WallpaperManagerCompatVL.EXTRACTION_COMPLETE";
|
||||
"com.android.launcher3.uioverrides.dynamicui.WallpaperManagerCompatVL.EXTRACTION_COMPLETE";
|
||||
|
||||
private final ArrayList<OnColorsChangedListenerCompat> mListeners = new ArrayList<>();
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.launcher3.compat;
|
||||
package com.android.launcher3.uioverrides.dynamicui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.WallpaperColors;
|
||||
@@ -26,7 +26,6 @@ import android.util.Log;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
@TargetApi(27)
|
||||
public class WallpaperManagerCompatVOMR1 extends WallpaperManagerCompat {
|
||||
|
||||
Reference in New Issue
Block a user