From 1642f7173f71699fc2699e3fc20b0f37b47cddad Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Tue, 18 Sep 2018 11:40:35 -0700 Subject: [PATCH] Removing ViewScrim and cutom drawing code Bug: 109828640 Change-Id: I2cab0215a32c2ca6bc331d48083fcc00ada05c3b --- res/values/config.xml | 3 - .../launcher3/InsettableFrameLayout.java | 2 +- .../launcher3/dragndrop/DragLayer.java | 10 --- .../launcher3/graphics/ColorScrim.java | 65 ---------------- .../android/launcher3/graphics/ViewScrim.java | 77 ------------------- .../launcher3/widget/BaseWidgetSheet.java | 34 +++++++- .../launcher3/widget/WidgetsBottomSheet.java | 3 +- .../launcher3/widget/WidgetsFullSheet.java | 2 +- 8 files changed, 33 insertions(+), 163 deletions(-) delete mode 100644 src/com/android/launcher3/graphics/ColorScrim.java delete mode 100644 src/com/android/launcher3/graphics/ViewScrim.java diff --git a/res/values/config.xml b/res/values/config.xml index 9f9747834d..0efaccf194 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -101,9 +101,6 @@ - - - diff --git a/src/com/android/launcher3/InsettableFrameLayout.java b/src/com/android/launcher3/InsettableFrameLayout.java index 1db1fc0004..faa18b8050 100644 --- a/src/com/android/launcher3/InsettableFrameLayout.java +++ b/src/com/android/launcher3/InsettableFrameLayout.java @@ -68,7 +68,7 @@ public class InsettableFrameLayout extends FrameLayout implements Insettable { } public static class LayoutParams extends FrameLayout.LayoutParams { - boolean ignoreInsets = false; + public boolean ignoreInsets = false; public LayoutParams(Context c, AttributeSet attrs) { super(c, attrs); diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java index 6d2d3cb442..f005ce7bf7 100644 --- a/src/com/android/launcher3/dragndrop/DragLayer.java +++ b/src/com/android/launcher3/dragndrop/DragLayer.java @@ -47,7 +47,6 @@ import com.android.launcher3.Workspace; import com.android.launcher3.anim.Interpolators; import com.android.launcher3.folder.Folder; import com.android.launcher3.folder.FolderIcon; -import com.android.launcher3.graphics.ViewScrim; import com.android.launcher3.graphics.WorkspaceAndHotseatScrim; import com.android.launcher3.keyboard.ViewGroupFocusHelper; import com.android.launcher3.uioverrides.UiFactory; @@ -124,15 +123,6 @@ public class DragLayer extends BaseDragLayer { return mDragController.dispatchKeyEvent(event) || super.dispatchKeyEvent(event); } - @Override - protected boolean drawChild(Canvas canvas, View child, long drawingTime) { - ViewScrim scrim = ViewScrim.get(child); - if (scrim != null) { - scrim.draw(canvas, getWidth(), getHeight()); - } - return super.drawChild(canvas, child, drawingTime); - } - @Override protected boolean findActiveController(MotionEvent ev) { if (mActivity.getStateManager().getState().disableInteraction) { diff --git a/src/com/android/launcher3/graphics/ColorScrim.java b/src/com/android/launcher3/graphics/ColorScrim.java deleted file mode 100644 index 5c1081ac3f..0000000000 --- a/src/com/android/launcher3/graphics/ColorScrim.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.graphics; - -import android.graphics.Canvas; -import android.graphics.Color; -import android.view.View; -import android.view.animation.Interpolator; - -import com.android.launcher3.R; -import com.android.launcher3.anim.Interpolators; -import com.android.launcher3.uioverrides.WallpaperColorInfo; - -import androidx.core.graphics.ColorUtils; - -/** - * Simple scrim which draws a color - */ -public class ColorScrim extends ViewScrim { - - private final int mColor; - private final Interpolator mInterpolator; - private int mCurrentColor; - - public ColorScrim(View view, int color, Interpolator interpolator) { - super(view); - mColor = color; - mInterpolator = interpolator; - } - - @Override - protected void onProgressChanged() { - mCurrentColor = ColorUtils.setAlphaComponent(mColor, - Math.round(mInterpolator.getInterpolation(mProgress) * Color.alpha(mColor))); - } - - @Override - public void draw(Canvas canvas, int width, int height) { - if (mProgress > 0) { - canvas.drawColor(mCurrentColor); - } - } - - public static ColorScrim createExtractedColorScrim(View view) { - WallpaperColorInfo colors = WallpaperColorInfo.getInstance(view.getContext()); - int alpha = view.getResources().getInteger(R.integer.extracted_color_gradient_alpha); - ColorScrim scrim = new ColorScrim(view, ColorUtils.setAlphaComponent( - colors.getSecondaryColor(), alpha), Interpolators.LINEAR); - scrim.attach(); - return scrim; - } -} diff --git a/src/com/android/launcher3/graphics/ViewScrim.java b/src/com/android/launcher3/graphics/ViewScrim.java deleted file mode 100644 index e1727e0e5b..0000000000 --- a/src/com/android/launcher3/graphics/ViewScrim.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.graphics; - -import android.graphics.Canvas; -import android.util.Property; -import android.view.View; -import android.view.ViewParent; - -import com.android.launcher3.R; - -/** - * A utility class that can be used to draw a scrim behind a view - */ -public abstract class ViewScrim { - - public static Property PROGRESS = - new Property(Float.TYPE, "progress") { - @Override - public Float get(ViewScrim viewScrim) { - return viewScrim.mProgress; - } - - @Override - public void set(ViewScrim object, Float value) { - object.setProgress(value); - } - }; - - protected final T mView; - protected float mProgress = 0; - - public ViewScrim(T view) { - mView = view; - } - - public void attach() { - mView.setTag(R.id.view_scrim, this); - } - - public void setProgress(float progress) { - if (mProgress != progress) { - mProgress = progress; - onProgressChanged(); - invalidate(); - } - } - - public abstract void draw(Canvas canvas, int width, int height); - - protected void onProgressChanged() { } - - public void invalidate() { - ViewParent parent = mView.getParent(); - if (parent != null) { - ((View) parent).invalidate(); - } - } - - public static ViewScrim get(View view) { - return (ViewScrim) view.getTag(R.id.view_scrim); - } -} diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java index 20c8876d29..48c18f8538 100644 --- a/src/com/android/launcher3/widget/BaseWidgetSheet.java +++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java @@ -15,6 +15,8 @@ */ package com.android.launcher3.widget; +import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; + import static com.android.launcher3.logging.LoggerUtils.newContainerTarget; import android.content.Context; @@ -31,13 +33,16 @@ import com.android.launcher3.ItemInfo; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.dragndrop.DragOptions; -import com.android.launcher3.graphics.ColorScrim; import com.android.launcher3.touch.ItemLongClickListener; +import com.android.launcher3.uioverrides.WallpaperColorInfo; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; import com.android.launcher3.userevent.nano.LauncherLogProto.Target; import com.android.launcher3.util.SystemUiController; import com.android.launcher3.util.Themes; import com.android.launcher3.views.AbstractSlideInView; +import com.android.launcher3.views.BaseDragLayer; + +import androidx.core.graphics.ColorUtils; /** * Base class for various widgets popup @@ -49,11 +54,11 @@ abstract class BaseWidgetSheet extends AbstractSlideInView /* Touch handling related member variables. */ private Toast mWidgetInstructionToast; - protected final ColorScrim mColorScrim; + protected final View mColorScrim; public BaseWidgetSheet(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - mColorScrim = ColorScrim.createExtractedColorScrim(this); + mColorScrim = createColorScrim(context); } @Override @@ -80,9 +85,14 @@ abstract class BaseWidgetSheet extends AbstractSlideInView return true; } + protected void attachToContainer() { + getPopupContainer().addView(mColorScrim); + getPopupContainer().addView(this); + } + protected void setTranslationShift(float translationShift) { super.setTranslationShift(translationShift); - mColorScrim.setProgress(1 - mTranslationShift); + mColorScrim.setAlpha(1 - mTranslationShift); } private boolean beginDraggingWidget(WidgetCell v) { @@ -115,6 +125,7 @@ abstract class BaseWidgetSheet extends AbstractSlideInView protected void onCloseComplete() { super.onCloseComplete(); + getPopupContainer().removeView(mColorScrim); clearNavBarColor(); } @@ -148,4 +159,19 @@ abstract class BaseWidgetSheet extends AbstractSlideInView protected SystemUiController getSystemUiController() { return mLauncher.getSystemUiController(); } + + private static View createColorScrim(Context context) { + View view = new View(context); + view.forceHasOverlappingRendering(false); + + WallpaperColorInfo colors = WallpaperColorInfo.getInstance(context); + int alpha = context.getResources().getInteger(R.integer.extracted_color_gradient_alpha); + view.setBackgroundColor(ColorUtils.setAlphaComponent(colors.getSecondaryColor(), alpha)); + + BaseDragLayer.LayoutParams lp = new BaseDragLayer.LayoutParams(MATCH_PARENT, MATCH_PARENT); + lp.ignoreInsets = true; + view.setLayoutParams(lp); + + return view; + } } diff --git a/src/com/android/launcher3/widget/WidgetsBottomSheet.java b/src/com/android/launcher3/widget/WidgetsBottomSheet.java index 4ba6b5b123..4bd6234bcd 100644 --- a/src/com/android/launcher3/widget/WidgetsBottomSheet.java +++ b/src/com/android/launcher3/widget/WidgetsBottomSheet.java @@ -70,8 +70,7 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { R.string.widgets_bottom_sheet_title, mOriginalItemInfo.title)); onWidgetsBound(); - - getPopupContainer().addView(this); + attachToContainer(); mIsOpen = false; animateOpen(); } diff --git a/src/com/android/launcher3/widget/WidgetsFullSheet.java b/src/com/android/launcher3/widget/WidgetsFullSheet.java index f7ff69abe3..11126861f8 100644 --- a/src/com/android/launcher3/widget/WidgetsFullSheet.java +++ b/src/com/android/launcher3/widget/WidgetsFullSheet.java @@ -220,8 +220,8 @@ public class WidgetsFullSheet extends BaseWidgetSheet public static WidgetsFullSheet show(Launcher launcher, boolean animate) { WidgetsFullSheet sheet = (WidgetsFullSheet) launcher.getLayoutInflater() .inflate(R.layout.widgets_full_sheet, launcher.getDragLayer(), false); + sheet.attachToContainer(); sheet.mIsOpen = true; - sheet.getPopupContainer().addView(sheet); sheet.open(animate); return sheet; }