Removing extraction service and palette api dependency

Change-Id: I30ad1a1462a97b6bc03f8e386ae3058c7fe022e5
This commit is contained in:
Sunny Goyal 2017-09-28 11:31:39 -07:00
parent 9315c9a8cd
commit f2dd4216c1
19 changed files with 17 additions and 764 deletions

View File

@ -26,7 +26,6 @@ LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_JAVA_LIBRARIES := \
android-support-v4 \
android-support-v7-recyclerview \
android-support-v7-palette \
android-support-dynamic-animation
LOCAL_SRC_FILES := \
@ -72,7 +71,6 @@ LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_JAVA_LIBRARIES := \
android-support-v4 \
android-support-v7-recyclerview \
android-support-v7-palette \
android-support-dynamic-animation
LOCAL_SRC_FILES := \

View File

@ -81,12 +81,6 @@
</intent-filter>
</receiver>
<service android:name="com.android.launcher3.dynamicui.ColorExtractionService"
android:exported="false"
android:process=":wallpaper_chooser"
android:permission="android.permission.BIND_JOB_SERVICE">
</service>
<service
android:name="com.android.launcher3.compat.WallpaperManagerCompatVL$ColorExtractionService"
android:exported="false"

View File

@ -13,12 +13,12 @@ apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
compileSdkVersion 27
buildToolsVersion '27.0.0'
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName "1.0"
@ -86,12 +86,11 @@ repositories {
jcenter()
}
final String SUPPORT_LIBS_VERSION = '26.0.0-SNAPSHOT'
final String SUPPORT_LIBS_VERSION = '27.0.0-SNAPSHOT'
dependencies {
compile "com.android.support:support-v4:${SUPPORT_LIBS_VERSION}"
compile "com.android.support:support-dynamic-animation:${SUPPORT_LIBS_VERSION}"
compile "com.android.support:recyclerview-v7:${SUPPORT_LIBS_VERSION}"
compile "com.android.support:palette-v7:${SUPPORT_LIBS_VERSION}"
compile 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-7'
testCompile 'junit:junit:4.12'

View File

@ -232,8 +232,4 @@
<dimen name="horizontal_ellipsis_offset">19dp</dimen>
<dimen name="popup_item_divider_height">0.5dp</dimen>
<dimen name="swipe_helper_falsing_threshold">70dp</dimen>
<!-- Other -->
<!-- Approximates the system status bar height. Not guaranteed to be always be correct. -->
<dimen name="status_bar_height">24dp</dimen>
</resources>

View File

@ -16,16 +16,9 @@
package com.android.launcher3;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.graphics.ColorUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@ -35,11 +28,9 @@ import android.widget.FrameLayout;
import android.widget.TextView;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dynamicui.ExtractedColors;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.Themes;
public class Hotseat extends FrameLayout
implements UserEventDispatcher.LogContainerProvider {
@ -51,12 +42,6 @@ public class Hotseat extends FrameLayout
@ViewDebug.ExportedProperty(category = "launcher")
private final boolean mHasVerticalHotseat;
@ViewDebug.ExportedProperty(category = "launcher")
private int mBackgroundColor;
@ViewDebug.ExportedProperty(category = "launcher")
private ColorDrawable mBackground;
private ValueAnimator mBackgroundColorAnimator;
public Hotseat(Context context) {
this(context, null);
}
@ -69,12 +54,6 @@ public class Hotseat extends FrameLayout
super(context, attrs, defStyle);
mLauncher = Launcher.getLauncher(context);
mHasVerticalHotseat = mLauncher.getDeviceProfile().isVerticalBarLayout();
mBackgroundColor = ColorUtils.setAlphaComponent(
Themes.getAttrColor(context, android.R.attr.colorPrimary), 0);
mBackground = new ColorDrawable(mBackgroundColor);
if (!FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
setBackground(mBackground);
}
}
public CellLayout getLayout() {
@ -177,49 +156,4 @@ public class Hotseat extends FrameLayout
target.gridY = info.cellY;
targetParent.containerType = ContainerType.HOTSEAT;
}
public void updateColor(ExtractedColors extractedColors, boolean animate) {
if (FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
// not hotseat visible
return;
}
if (!mHasVerticalHotseat) {
int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX);
if (mBackgroundColorAnimator != null) {
mBackgroundColorAnimator.cancel();
}
if (!animate) {
setBackgroundColor(color);
} else {
mBackgroundColorAnimator = ValueAnimator.ofInt(mBackgroundColor, color);
mBackgroundColorAnimator.setEvaluator(new ArgbEvaluator());
mBackgroundColorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mBackground.setColor((Integer) animation.getAnimatedValue());
}
});
mBackgroundColorAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mBackgroundColorAnimator = null;
}
});
mBackgroundColorAnimator.start();
}
mBackgroundColor = color;
}
}
public void setBackgroundTransparent(boolean enable) {
if (enable) {
mBackground.setAlpha(0);
} else {
mBackground.setAlpha(255);
}
}
public int getBackgroundDrawableColor() {
return mBackgroundColor;
}
}

View File

@ -16,6 +16,9 @@
package com.android.launcher3;
import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_APPS;
import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_WIDGETS;
import android.Manifest;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@ -97,7 +100,6 @@ import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.dragndrop.PinItemDragListener;
import com.android.launcher3.dynamicui.ExtractedColors;
import com.android.launcher3.dynamicui.WallpaperColorInfo;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
@ -118,7 +120,6 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
import com.android.launcher3.util.ActivityResultInfo;
import com.android.launcher3.util.RunnableWithId;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.ComponentKeyMapper;
import com.android.launcher3.util.ItemInfoMatcher;
@ -126,6 +127,7 @@ import com.android.launcher3.util.MultiHashMap;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.PendingRequestArgs;
import com.android.launcher3.util.RunnableWithId;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.TestingUtils;
import com.android.launcher3.util.Themes;
@ -142,15 +144,11 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;
import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_APPS;
import static com.android.launcher3.util.RunnableWithId.RUNNABLE_ID_BIND_WIDGETS;
/**
* Default launcher application.
*/
@ -223,8 +221,6 @@ public class Launcher extends BaseActivity
private static final int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
@Thunk static final int NEW_APPS_ANIMATION_DELAY = 500;
private final ExtractedColors mExtractedColors = new ExtractedColors();
@Thunk Workspace mWorkspace;
private View mLauncherView;
@Thunk DragLayer mDragLayer;
@ -406,7 +402,6 @@ public class Launcher extends BaseActivity
setupViews();
mDeviceProfile.layout(this, false /* notifyListeners */);
loadExtractedColorsAndColorItems();
mPopupDataProvider = new PopupDataProvider(this);
@ -493,12 +488,6 @@ public class Launcher extends BaseActivity
return mLauncherView.findViewById(id);
}
@Override
public void onExtractedColorsChanged() {
loadExtractedColorsAndColorItems();
mExtractedColors.notifyChange();
}
@Override
public void onAppWidgetHostReset() {
if (mAppWidgetHost != null) {
@ -506,15 +495,6 @@ public class Launcher extends BaseActivity
}
}
private void loadExtractedColorsAndColorItems() {
// TODO: do this in pre-N as well, once the extraction part is complete.
if (Utilities.ATLEAST_NOUGAT) {
mExtractedColors.load(this);
mHotseat.updateColor(mExtractedColors, !mPaused);
mWorkspace.getPageIndicator().updateColor(mExtractedColors);
}
}
private LauncherCallbacks mLauncherCallbacks;
public void onPostCreate(Bundle savedInstanceState) {

View File

@ -28,7 +28,6 @@ import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dynamicui.ExtractionUtils;
import com.android.launcher3.notification.NotificationListener;
import com.android.launcher3.util.ConfigMonitor;
import com.android.launcher3.util.Preconditions;
@ -111,18 +110,11 @@ public class LauncherAppState {
filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNLOCKED);
// For extracting colors from the wallpaper
if (Utilities.ATLEAST_NOUGAT) {
// TODO: add a broadcast entry to the manifest for pre-N.
filter.addAction(Intent.ACTION_WALLPAPER_CHANGED);
}
mContext.registerReceiver(mModel, filter);
UserManagerCompat.getInstance(mContext).enableAndResetCache();
new ConfigMonitor(mContext).register();
ExtractionUtils.startColorExtractionServiceIfNecessary(mContext);
if (!mContext.getResources().getBoolean(R.bool.notification_badging_enabled)) {
mNotificationBadgingObserver = null;
} else {

View File

@ -37,7 +37,6 @@ import android.util.Pair;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.dynamicui.ExtractionUtils;
import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.model.AddWorkspaceItemsTask;
import com.android.launcher3.model.BgDataModel;
@ -406,8 +405,6 @@ public class LauncherModel extends BroadcastReceiver
enqueueModelUpdateTask(new UserLockStateChangedTask(user));
}
}
} else if (Intent.ACTION_WALLPAPER_CHANGED.equals(action)) {
ExtractionUtils.startColorExtractionServiceIfNecessary(context);
}
}

View File

@ -55,7 +55,6 @@ import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.LauncherSettings.WorkspaceScreens;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dynamicui.ExtractionUtils;
import com.android.launcher3.graphics.IconShapeOverride;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.DbDowngradeHelper;
@ -372,19 +371,6 @@ public class LauncherProvider extends ContentProvider {
createDbIfNotExists();
switch (method) {
case LauncherSettings.Settings.METHOD_SET_EXTRACTED_COLORS_AND_WALLPAPER_ID: {
String extractedColors = extras.getString(
LauncherSettings.Settings.EXTRA_EXTRACTED_COLORS);
int wallpaperId = extras.getInt(LauncherSettings.Settings.EXTRA_WALLPAPER_ID);
Utilities.getPrefs(getContext()).edit()
.putString(ExtractionUtils.EXTRACTED_COLORS_PREFERENCE_KEY, extractedColors)
.putInt(ExtractionUtils.WALLPAPER_ID_PREFERENCE_KEY, wallpaperId)
.apply();
mListenerHandler.sendEmptyMessage(ChangeListenerWrapper.MSG_EXTRACTED_COLORS_CHANGED);
Bundle result = new Bundle();
result.putString(LauncherSettings.Settings.EXTRA_VALUE, extractedColors);
return result;
}
case LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG: {
clearFlagEmptyDbCreated();
return null;
@ -1153,8 +1139,7 @@ public class LauncherProvider extends ContentProvider {
private static class ChangeListenerWrapper implements Handler.Callback {
private static final int MSG_LAUNCHER_PROVIDER_CHANGED = 1;
private static final int MSG_EXTRACTED_COLORS_CHANGED = 2;
private static final int MSG_APP_WIDGET_HOST_RESET = 3;
private static final int MSG_APP_WIDGET_HOST_RESET = 2;
private LauncherProviderChangeListener mListener;
@ -1165,9 +1150,6 @@ public class LauncherProvider extends ContentProvider {
case MSG_LAUNCHER_PROVIDER_CHANGED:
mListener.onLauncherProviderChanged();
break;
case MSG_EXTRACTED_COLORS_CHANGED:
mListener.onExtractedColorsChanged();
break;
case MSG_APP_WIDGET_HOST_RESET:
mListener.onAppWidgetHostReset();
break;

View File

@ -9,7 +9,5 @@ public interface LauncherProviderChangeListener {
void onLauncherProviderChanged();
void onExtractedColorsChanged();
void onAppWidgetHostReset();
}

View File

@ -304,11 +304,6 @@ public class LauncherSettings {
public static final String METHOD_LOAD_DEFAULT_FAVORITES = "load_default_favorites";
public static final String METHOD_SET_EXTRACTED_COLORS_AND_WALLPAPER_ID =
"set_extracted_colors_and_wallpaper_id_setting";
public static final String EXTRA_EXTRACTED_COLORS = "extra_extractedColors";
public static final String EXTRA_WALLPAPER_ID = "extra_wallpaperId";
public static final String METHOD_REMOVE_GHOST_WIDGETS = "remove_ghost_widgets";
public static final String EXTRA_VALUE = "value";

View File

@ -6,14 +6,11 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.graphics.Color;
import android.support.animation.SpringAnimation;
import android.support.v4.graphics.ColorUtils;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import com.android.launcher3.AbstractFloatingView;
@ -46,12 +43,8 @@ import com.android.launcher3.util.TouchController;
public class AllAppsTransitionController implements TouchController, SwipeDetector.Listener,
SearchUiManager.OnScrollRangeChangeListener {
private static final String TAG = "AllAppsTrans";
private static final boolean DBG = false;
private final Interpolator mWorkspaceAccelnterpolator = new AccelerateInterpolator(2f);
private final Interpolator mHotseatAccelInterpolator = new AccelerateInterpolator(1.5f);
private final Interpolator mDecelInterpolator = new DecelerateInterpolator(3f);
private final Interpolator mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
private final SwipeDetector.ScrollInterpolator mScrollInterpolator
= new SwipeDetector.ScrollInterpolator();
@ -60,10 +53,8 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect
private static final int SINGLE_FRAME_MS = 16;
private AllAppsContainerView mAppsView;
private int mAllAppsBackgroundColor;
private Workspace mWorkspace;
private Hotseat mHotseat;
private int mHotseatBackgroundColor;
private AllAppsCaretController mCaretController;
@ -112,7 +103,6 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect
mProgress = 1f;
mEvaluator = new ArgbEvaluator();
mAllAppsBackgroundColor = Themes.getAttrColor(l, android.R.attr.colorPrimary);
mIsDarkTheme = Themes.getAttrBoolean(mLauncher, R.attr.isMainColorDark);
}
@ -266,29 +256,16 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect
// Initialize values that should not change until #onDragEnd
mStatusBarHeight = mLauncher.getDragLayer().getInsets().top;
mHotseat.setVisibility(View.VISIBLE);
mHotseatBackgroundColor = mHotseat.getBackgroundDrawableColor();
mHotseat.setBackgroundTransparent(true /* transparent */);
if (!mLauncher.isAllAppsVisible()) {
mLauncher.tryAndUpdatePredictedApps();
mAppsView.setVisibility(View.VISIBLE);
if (!FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
mAppsView.setRevealDrawableColor(mHotseatBackgroundColor);
}
}
}
}
private void updateLightStatusBar(float shift) {
// Do not modify status bar on landscape as all apps is not full bleed.
if (!FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS
&& mLauncher.getDeviceProfile().isVerticalBarLayout()) {
return;
}
// Use a light system UI (dark icons) if all apps is behind at least half of the status bar.
boolean forceChange = FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS ?
shift <= mShiftRange / 4 :
shift <= mStatusBarHeight / 2;
boolean forceChange = shift <= mShiftRange / 4;
if (forceChange) {
mLauncher.getSystemUiController().updateUiState(
SystemUiController.UI_STATE_ALL_APPS, !mIsDarkTheme);
@ -320,17 +297,7 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect
float workspaceAlpha = mWorkspaceAccelnterpolator.getInterpolation(workspaceHotseatAlpha);
float hotseatAlpha = mHotseatAccelInterpolator.getInterpolation(workspaceHotseatAlpha);
int color = (Integer) mEvaluator.evaluate(mDecelInterpolator.getInterpolation(alpha),
mHotseatBackgroundColor, mAllAppsBackgroundColor);
int bgAlpha = Color.alpha((int) mEvaluator.evaluate(alpha,
mHotseatBackgroundColor, mAllAppsBackgroundColor));
if (FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
updateAllAppsBg(alpha);
} else {
mAppsView.setRevealDrawableColor(ColorUtils.setAlphaComponent(color, bgAlpha));
}
updateAllAppsBg(alpha);
mAppsView.getContentView().setAlpha(alpha);
mAppsView.setTranslationY(shiftCurrent);
@ -530,7 +497,6 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect
public void finishPullDown() {
mAppsView.setVisibility(View.INVISIBLE);
mHotseat.setBackgroundTransparent(false /* transparent */);
mHotseat.setVisibility(View.VISIBLE);
mAppsView.reset();
if (hasSpringAnimationHandler()) {

View File

@ -15,6 +15,10 @@
*/
package com.android.launcher3.compat;
import static android.app.WallpaperManager.FLAG_SYSTEM;
import static com.android.launcher3.Utilities.getDevicePrefs;
import android.app.WallpaperInfo;
import android.app.WallpaperManager;
import android.app.job.JobInfo;
@ -38,7 +42,6 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.os.ParcelFileDescriptor;
import android.support.annotation.Nullable;
import android.support.v7.graphics.Palette;
import android.util.Log;
import android.util.Pair;
@ -46,12 +49,6 @@ import com.android.launcher3.Utilities;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static android.app.WallpaperManager.FLAG_SYSTEM;
import static com.android.launcher3.Utilities.getDevicePrefs;
public class WallpaperManagerCompatVL extends WallpaperManagerCompat {
@ -260,27 +257,8 @@ public class WallpaperManagerCompatVL extends WallpaperManagerCompat {
String value = VERSION_PREFIX + wallpaperId;
if (bitmap != null) {
Palette palette = Palette.from(bitmap).generate();
bitmap.recycle();
StringBuilder builder = new StringBuilder(value);
List<Pair<Integer,Integer>> colorsToOccurrences = new ArrayList<>();
for (Palette.Swatch swatch : palette.getSwatches()) {
colorsToOccurrences.add(new Pair(swatch.getRgb(), swatch.getPopulation()));
}
Collections.sort(colorsToOccurrences, new Comparator<Pair<Integer, Integer>>() {
@Override
public int compare(Pair<Integer, Integer> a, Pair<Integer, Integer> b) {
return b.second - a.second;
}
});
for (int i=0; i < Math.min(3, colorsToOccurrences.size()); i++) {
builder.append(',').append(colorsToOccurrences.get(i).first);
}
value = builder.toString();
int color = Utilities.findDominantColorByHue(bitmap, MAX_WALLPAPER_EXTRACTION_AREA);
value += "," + color;
}
// Send the result

View File

@ -39,8 +39,6 @@ abstract class BaseFlags {
public static final boolean LAUNCHER3_UPDATE_SOFT_INPUT_MODE = false;
// When enabled the promise icon is visible in all apps while installation an app.
public static final boolean LAUNCHER3_PROMISE_APPS_IN_ALL_APPS = false;
// When enabled uses the AllAppsRadialGradientAndScrimDrawable for all apps
public static final boolean LAUNCHER3_GRADIENT_ALL_APPS = true;
// When enabled allows use of physics based motions in the Launcher.
public static final boolean LAUNCHER3_PHYSICS = true;
// When enabled allows use of spring motions on the icons.
@ -50,16 +48,12 @@ abstract class BaseFlags {
public static final boolean QSB_ON_FIRST_SCREEN = true;
// When enabled the all-apps icon is not added to the hotseat.
public static final boolean NO_ALL_APPS_ICON = true;
// When enabled the status bar may show dark icons based on the top of the wallpaper.
public static final boolean LIGHT_STATUS_BAR = false;
// When enabled, icons not supporting {@link AdaptiveIconDrawable} will be wrapped in {@link FixedScaleDrawable}.
public static final boolean LEGACY_ICON_TREATMENT = true;
// When enabled, adaptive icons would have shadows baked when being stored to icon cache.
public static final boolean ADAPTIVE_ICON_SHADOW = true;
// When enabled, app discovery will be enabled if service is implemented
public static final boolean DISCOVERY_ENABLED = false;
// When enabled, the qsb will be moved to the hotseat.
public static final boolean QSB_IN_HOTSEAT = true;
// When true, custom widgets are loaded using CustomWidgetParser.
public static final boolean ENABLE_CUSTOM_WIDGETS = false;

View File

@ -1,204 +0,0 @@
/*
* Copyright (C) 2016 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.dynamicui;
import android.annotation.TargetApi;
import android.app.WallpaperManager;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapRegionDecoder;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.ParcelFileDescriptor;
import android.support.v7.graphics.Palette;
import android.util.Log;
import com.android.launcher3.LauncherProvider;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import java.io.IOException;
/**
* Extracts colors from the wallpaper, and saves results to {@link LauncherProvider}.
*/
public class ColorExtractionService extends JobService {
private static final String TAG = "ColorExtractionService";
private static final boolean DEBUG = false;
/** The fraction of the wallpaper to extract colors for use on the hotseat. */
private static final float HOTSEAT_FRACTION = 1f / 4;
private HandlerThread mWorkerThread;
private Handler mWorkerHandler;
@Override
public void onCreate() {
super.onCreate();
mWorkerThread = new HandlerThread("ColorExtractionService");
mWorkerThread.start();
mWorkerHandler = new Handler(mWorkerThread.getLooper());
}
@Override
public void onDestroy() {
super.onDestroy();
mWorkerThread.quit();
}
@Override
public boolean onStartJob(final JobParameters jobParameters) {
if (DEBUG) Log.d(TAG, "onStartJob");
mWorkerHandler.post(new Runnable() {
@Override
public void run() {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(
ColorExtractionService.this);
int wallpaperId = ExtractionUtils.getWallpaperId(wallpaperManager);
ExtractedColors extractedColors = new ExtractedColors();
if (wallpaperManager.getWallpaperInfo() != null) {
// We can't extract colors from live wallpapers; always use the default color.
extractedColors.updateHotseatPalette(null);
if (FeatureFlags.QSB_IN_HOTSEAT || FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
extractedColors.updateWallpaperThemePalette(null);
}
} else {
// We extract colors for the hotseat and status bar separately,
// since they only consider part of the wallpaper.
extractedColors.updateHotseatPalette(getHotseatPalette());
if (FeatureFlags.LIGHT_STATUS_BAR) {
extractedColors.updateStatusBarPalette(getStatusBarPalette());
}
if (FeatureFlags.QSB_IN_HOTSEAT || FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
extractedColors.updateWallpaperThemePalette(getWallpaperPalette());
}
}
// Save the extracted colors and wallpaper id to LauncherProvider.
String colorsString = extractedColors.encodeAsString();
Bundle extras = new Bundle();
extras.putInt(LauncherSettings.Settings.EXTRA_WALLPAPER_ID, wallpaperId);
extras.putString(LauncherSettings.Settings.EXTRA_EXTRACTED_COLORS, colorsString);
getContentResolver().call(
LauncherSettings.Settings.CONTENT_URI,
LauncherSettings.Settings.METHOD_SET_EXTRACTED_COLORS_AND_WALLPAPER_ID,
null, extras);
jobFinished(jobParameters, false /* needsReschedule */);
if (DEBUG) Log.d(TAG, "job finished!");
}
});
return true;
}
@Override
public boolean onStopJob(JobParameters jobParameters) {
if (DEBUG) Log.d(TAG, "onStopJob");
mWorkerHandler.removeCallbacksAndMessages(null);
return true;
}
@TargetApi(Build.VERSION_CODES.N)
private Palette getHotseatPalette() {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
if (Utilities.ATLEAST_NOUGAT) {
try (ParcelFileDescriptor fd = wallpaperManager
.getWallpaperFile(WallpaperManager.FLAG_SYSTEM)) {
BitmapRegionDecoder decoder = BitmapRegionDecoder
.newInstance(fd.getFileDescriptor(), false);
int height = decoder.getHeight();
Rect decodeRegion = new Rect(0, (int) (height * (1f - HOTSEAT_FRACTION)),
decoder.getWidth(), height);
Bitmap bitmap = decoder.decodeRegion(decodeRegion, null);
decoder.recycle();
if (bitmap != null) {
return Palette.from(bitmap).clearFilters().generate();
}
} catch (IOException | NullPointerException e) {
Log.e(TAG, "Fetching partial bitmap failed, trying old method", e);
}
}
Bitmap wallpaper = ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap();
return Palette.from(wallpaper)
.setRegion(0, (int) (wallpaper.getHeight() * (1f - HOTSEAT_FRACTION)),
wallpaper.getWidth(), wallpaper.getHeight())
.clearFilters()
.generate();
}
@TargetApi(Build.VERSION_CODES.N)
private Palette getStatusBarPalette() {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
int statusBarHeight = getResources()
.getDimensionPixelSize(R.dimen.status_bar_height);
if (Utilities.ATLEAST_NOUGAT) {
try (ParcelFileDescriptor fd = wallpaperManager
.getWallpaperFile(WallpaperManager.FLAG_SYSTEM)) {
BitmapRegionDecoder decoder = BitmapRegionDecoder
.newInstance(fd.getFileDescriptor(), false);
Rect decodeRegion = new Rect(0, 0,
decoder.getWidth(), statusBarHeight);
Bitmap bitmap = decoder.decodeRegion(decodeRegion, null);
decoder.recycle();
if (bitmap != null) {
return Palette.from(bitmap).clearFilters().generate();
}
} catch (IOException | NullPointerException e) {
Log.e(TAG, "Fetching partial bitmap failed, trying old method", e);
}
}
Bitmap wallpaper = ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap();
return Palette.from(wallpaper)
.setRegion(0, 0, wallpaper.getWidth(), statusBarHeight)
.clearFilters()
.generate();
}
@TargetApi(Build.VERSION_CODES.N)
private Palette getWallpaperPalette() {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
if (Utilities.ATLEAST_NOUGAT) {
try (ParcelFileDescriptor fd = wallpaperManager
.getWallpaperFile(WallpaperManager.FLAG_SYSTEM)) {
Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
if (bitmap != null) {
return Palette.from(bitmap).clearFilters().generate();
}
} catch (IOException | NullPointerException e) {
Log.e(TAG, "Fetching partial bitmap failed, trying old method", e);
}
}
Bitmap wallpaper = ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap();
return Palette.from(wallpaper).clearFilters().generate();
}
}

View File

@ -1,184 +0,0 @@
/*
* Copyright (C) 2016 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.dynamicui;
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.support.v4.graphics.ColorUtils;
import android.support.v7.graphics.Palette;
import android.util.Log;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import java.util.ArrayList;
import java.util.Arrays;
/**
* Saves and loads colors extracted from the wallpaper, as well as the associated wallpaper id.
*/
public class ExtractedColors {
private static final String TAG = "ExtractedColors";
public static final int DEFAULT_LIGHT = Color.WHITE;
public static final int DEFAULT_DARK = Color.BLACK;
// These color profile indices should NOT be changed, since they are used when saving and
// loading extracted colors. New colors should always be added at the end.
public static final int VERSION_INDEX = 0;
public static final int HOTSEAT_INDEX = 1;
public static final int STATUS_BAR_INDEX = 2;
public static final int WALLPAPER_VIBRANT_INDEX = 3;
public static final int ALLAPPS_GRADIENT_MAIN_INDEX = 4;
public static final int ALLAPPS_GRADIENT_SECONDARY_INDEX = 5;
private static final int VERSION;
private static final int[] DEFAULT_VALUES;
static {
if (FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
VERSION = 3;
DEFAULT_VALUES = new int[] {
VERSION, // VERSION_INDEX
0x40FFFFFF, // HOTSEAT_INDEX: White with 25% alpha
DEFAULT_DARK, // STATUS_BAR_INDEX
0xFFCCCCCC, // WALLPAPER_VIBRANT_INDEX
0xFF000000, // ALLAPPS_GRADIENT_MAIN_INDEX
0xFF000000 // ALLAPPS_GRADIENT_SECONDARY_INDEX
};
} else if (FeatureFlags.QSB_IN_HOTSEAT) {
VERSION = 2;
DEFAULT_VALUES = new int[] {
VERSION, // VERSION_INDEX
0x40FFFFFF, // HOTSEAT_INDEX: White with 25% alpha
DEFAULT_DARK, // STATUS_BAR_INDEX
0xFFCCCCCC, // WALLPAPER_VIBRANT_INDEX
};
} else {
VERSION = 1;
DEFAULT_VALUES = new int[] {
VERSION, // VERSION_INDEX
0x40FFFFFF, // HOTSEAT_INDEX: White with 25% alpha
DEFAULT_DARK, // STATUS_BAR_INDEX
};
}
}
private static final String COLOR_SEPARATOR = ",";
private final ArrayList<OnChangeListener> mListeners = new ArrayList<>();
private final int[] mColors;
public ExtractedColors() {
// The first entry is reserved for the version number.
mColors = Arrays.copyOf(DEFAULT_VALUES, DEFAULT_VALUES.length);
}
public void setColorAtIndex(int index, int color) {
if (index > VERSION_INDEX && index < mColors.length) {
mColors[index] = color;
} else {
Log.e(TAG, "Attempted to set a color at an invalid index " + index);
}
}
/**
* Encodes {@link #mColors} as a comma-separated String.
*/
String encodeAsString() {
StringBuilder colorsStringBuilder = new StringBuilder();
for (int color : mColors) {
colorsStringBuilder.append(color).append(COLOR_SEPARATOR);
}
return colorsStringBuilder.toString();
}
/**
* Loads colors and wallpaper id from {@link Utilities#getPrefs(Context)}.
* These were saved there in {@link ColorExtractionService}.
*/
public void load(Context context) {
String encodedString = Utilities.getPrefs(context).getString(
ExtractionUtils.EXTRACTED_COLORS_PREFERENCE_KEY, VERSION + "");
String[] splitColorsString = encodedString.split(COLOR_SEPARATOR);
if (splitColorsString.length == DEFAULT_VALUES.length &&
Integer.parseInt(splitColorsString[VERSION_INDEX]) == VERSION) {
// Parse and apply the saved values.
for (int i = 0; i < mColors.length; i++) {
mColors[i] = Integer.parseInt(splitColorsString[i]);
}
} else {
// Leave the values as default values as the saved values may not be compatible.
ExtractionUtils.startColorExtractionService(context);
}
}
/** @param index must be one of the index values defined at the top of this class. */
public int getColor(int index) {
return mColors[index];
}
/**
* The hotseat's color is defined as follows:
* - 12% black for super light wallpaper
* - 18% white for super dark
* - 25% white otherwise
*/
public void updateHotseatPalette(Palette hotseatPalette) {
int hotseatColor;
if (hotseatPalette != null && ExtractionUtils.isSuperLight(hotseatPalette)) {
hotseatColor = ColorUtils.setAlphaComponent(Color.BLACK, (int) (0.12f * 255));
} else if (hotseatPalette != null && ExtractionUtils.isSuperDark(hotseatPalette)) {
hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.18f * 255));
} else {
hotseatColor = DEFAULT_VALUES[HOTSEAT_INDEX];
}
setColorAtIndex(HOTSEAT_INDEX, hotseatColor);
}
public void updateStatusBarPalette(Palette statusBarPalette) {
setColorAtIndex(STATUS_BAR_INDEX, ExtractionUtils.isSuperLight(statusBarPalette) ?
DEFAULT_LIGHT : DEFAULT_DARK);
}
public void updateWallpaperThemePalette(@Nullable Palette wallpaperPalette) {
int defaultColor = DEFAULT_VALUES[WALLPAPER_VIBRANT_INDEX];
setColorAtIndex(WALLPAPER_VIBRANT_INDEX, wallpaperPalette == null
? defaultColor : wallpaperPalette.getVibrantColor(defaultColor));
}
public void addOnChangeListener(OnChangeListener listener) {
mListeners.add(listener);
}
public void notifyChange() {
for (OnChangeListener listener : mListeners) {
listener.onExtractedColorsChanged();
}
}
/**
* Interface for listening for extracted color changes
*/
public interface OnChangeListener {
void onExtractedColorsChanged();
}
}

View File

@ -1,125 +0,0 @@
/*
* Copyright (C) 2016 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.dynamicui;
import android.annotation.TargetApi;
import android.app.WallpaperManager;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.support.v4.graphics.ColorUtils;
import android.support.v7.graphics.Palette;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import java.util.List;
/**
* Contains helper fields and methods related to extracting colors from the wallpaper.
*/
public class ExtractionUtils {
public static final String EXTRACTED_COLORS_PREFERENCE_KEY = "pref_extractedColors";
public static final String WALLPAPER_ID_PREFERENCE_KEY = "pref_wallpaperId";
private static final float MIN_CONTRAST_RATIO = 2f;
/**
* Extract colors in the :wallpaper-chooser process, if the wallpaper id has changed.
* When the new colors are saved in the LauncherProvider,
* Launcher will be notified in Launcher#onSettingsChanged(String, String).
*/
public static void startColorExtractionServiceIfNecessary(final Context context) {
if (FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
return;
}
// Run on a background thread, since the service is asynchronous anyway.
Utilities.THREAD_POOL_EXECUTOR.execute(new Runnable() {
@Override
public void run() {
if (hasWallpaperIdChanged(context)) {
startColorExtractionService(context);
}
}
});
}
/** Starts the {@link ColorExtractionService} without checking the wallpaper id */
public static void startColorExtractionService(Context context) {
if (FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
return;
}
JobScheduler jobScheduler = (JobScheduler) context.getSystemService(
Context.JOB_SCHEDULER_SERVICE);
jobScheduler.schedule(new JobInfo.Builder(Utilities.COLOR_EXTRACTION_JOB_ID,
new ComponentName(context, ColorExtractionService.class))
.setMinimumLatency(0).build());
}
private static boolean hasWallpaperIdChanged(Context context) {
if (!Utilities.ATLEAST_NOUGAT) {
// TODO: update an id in sharedprefs in onWallpaperChanged broadcast, and read it here.
return false;
}
final SharedPreferences sharedPrefs = Utilities.getPrefs(context);
int wallpaperId = getWallpaperId(WallpaperManager.getInstance(context));
int savedWallpaperId = sharedPrefs.getInt(ExtractionUtils.WALLPAPER_ID_PREFERENCE_KEY, -1);
return wallpaperId != savedWallpaperId;
}
@TargetApi(Build.VERSION_CODES.N)
public static int getWallpaperId(WallpaperManager wallpaperManager) {
return Utilities.ATLEAST_NOUGAT ?
wallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) : -1;
}
public static boolean isSuperLight(Palette p) {
return !isLegibleOnWallpaper(Color.WHITE, p.getSwatches());
}
public static boolean isSuperDark(Palette p) {
return !isLegibleOnWallpaper(Color.BLACK, p.getSwatches());
}
/**
* Given a color, returns true if that color is legible on
* the given wallpaper color swatches, else returns false.
*/
private static boolean isLegibleOnWallpaper(int color, List<Palette.Swatch> wallpaperSwatches) {
int legiblePopulation = 0;
int illegiblePopulation = 0;
for (Palette.Swatch swatch : wallpaperSwatches) {
if (isLegible(color, swatch.getRgb())) {
legiblePopulation += swatch.getPopulation();
} else {
illegiblePopulation += swatch.getPopulation();
}
}
return legiblePopulation > illegiblePopulation;
}
/** @return Whether the foreground color is legible on the background color. */
private static boolean isLegible(int foreground, int background) {
background = ColorUtils.setAlphaComponent(background, 255);
return ColorUtils.calculateContrast(foreground, background) >= MIN_CONTRAST_RATIO;
}
}

View File

@ -20,8 +20,6 @@ import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import com.android.launcher3.dynamicui.ExtractedColors;
/**
* Base class for a page indicator.
*/
@ -74,8 +72,6 @@ public abstract class PageIndicator extends FrameLayout {
public void setShouldAutoHide(boolean shouldAutoHide) {}
public void updateColor(ExtractedColors extractedColors) {}
@Override
protected boolean verifyDrawable(Drawable who) {
return super.verifyDrawable(who) || who == getCaretDrawable();

View File

@ -11,9 +11,7 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.graphics.ColorUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Property;
import android.view.ViewConfiguration;
import android.widget.ImageView;
@ -21,8 +19,6 @@ import android.widget.ImageView;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dynamicui.ExtractedColors;
import com.android.launcher3.dynamicui.WallpaperColorInfo;
/**
@ -31,9 +27,6 @@ import com.android.launcher3.dynamicui.WallpaperColorInfo;
* The fraction is 1 / number of pages and the position is based on the progress of the page scroll.
*/
public class PageIndicatorLineCaret extends PageIndicator {
private static final String TAG = "PageIndicatorLine";
private static final int[] sTempCoords = new int[2];
private static final int LINE_ANIMATE_DURATION = ViewConfiguration.getScrollBarFadeDuration();
private static final int LINE_FADE_DELAY = ViewConfiguration.getScrollDefaultDelay();
@ -218,32 +211,6 @@ public class PageIndicatorLineCaret extends PageIndicator {
}
}
/**
* The line's color will be:
* - mostly opaque white if the hotseat is white (ignoring alpha)
* - mostly opaque black if the hotseat is black (ignoring alpha)
*/
public void updateColor(ExtractedColors extractedColors) {
if (FeatureFlags.LAUNCHER3_GRADIENT_ALL_APPS) {
return;
}
int originalLineAlpha = mLinePaint.getAlpha();
int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX);
if (color != Color.TRANSPARENT) {
color = ColorUtils.setAlphaComponent(color, 255);
if (color == Color.BLACK) {
mActiveAlpha = BLACK_ALPHA;
} else if (color == Color.WHITE) {
mActiveAlpha = WHITE_ALPHA;
} else {
Log.e(TAG, "Setting workspace page indicators to an unsupported color: #"
+ Integer.toHexString(color));
}
mLinePaint.setColor(color);
mLinePaint.setAlpha(originalLineAlpha);
}
}
private void animateLineToAlpha(int alpha) {
if (alpha == mToAlpha) {
// Ignore the new animation if it is going to the same alpha as the current animation.