From 277ef4868cbef1f1608dad8553bf6819ed420868 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Fri, 26 Apr 2024 15:45:02 -0700 Subject: [PATCH] Removing disabled color extractor from Widgets Bug: 266941872 Flag: None Test: Presubmit (removed dead code) Change-Id: Ie45cf08c694652266af6c95dab0eac5b9dd138f6 --- src/com/android/launcher3/CellLayout.java | 23 ------ src/com/android/launcher3/Workspace.java | 4 - .../widget/LauncherAppWidgetHostView.java | 74 ++----------------- .../launcher3/widget/LocalColorExtractor.java | 29 -------- .../widget/PendingItemDragHelper.java | 3 - .../AppWidgetHostViewDragListener.java | 48 ------------ 6 files changed, 6 insertions(+), 175 deletions(-) delete mode 100644 src/com/android/launcher3/widget/dragndrop/AppWidgetHostViewDragListener.java diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 98dade5d52..7e9e8645e6 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -33,7 +33,6 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Point; -import android.graphics.PointF; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.Drawable; @@ -115,7 +114,6 @@ public class CellLayout extends ViewGroup { @Thunk final int[] mTempLocation = new int[2]; @Thunk final Rect mTempOnDrawCellToRect = new Rect(); - final PointF mTmpPointF = new PointF(); protected GridOccupancy mOccupied; public GridOccupancy mTmpOccupied; @@ -197,16 +195,11 @@ public class CellLayout extends ViewGroup { public static final int REORDER_ANIMATION_DURATION = 150; @Thunk final float mReorderPreviewAnimationMagnitude; - private final ArrayList mIntersectingViews = new ArrayList<>(); - private final Rect mOccupiedRect = new Rect(); public final int[] mDirectionVector = new int[2]; ItemConfiguration mPreviousSolution = null; - private static final int INVALID_DIRECTION = -100; private final Rect mTempRect = new Rect(); - private final RectF mTempRectF = new RectF(); - private final float[] mTmpFloatArray = new float[4]; private static final Paint sPaint = new Paint(); @@ -1163,9 +1156,6 @@ public class CellLayout extends ViewGroup { mDragCellSpan[0] = spanX; mDragCellSpan[1] = spanY; - // Apply color extraction on a widget when dragging. - applyColorExtractionOnWidget(dragObject, mDragCell, spanX, spanY); - final int oldIndex = mDragOutlineCurrent; mDragOutlineAnims[oldIndex].animateOut(); mDragOutlineCurrent = (oldIndex + 1) % mDragOutlines.length; @@ -1186,19 +1176,6 @@ public class CellLayout extends ViewGroup { } } - /** Applies the local color extraction to a dragging widget object. */ - private void applyColorExtractionOnWidget(DropTarget.DragObject dragObject, int[] targetCell, - int spanX, int spanY) { - // Apply local extracted color if the DragView is an AppWidgetHostViewDrawable. - View view = dragObject.dragView.getContentView(); - if (view instanceof LauncherAppWidgetHostView) { - int screenId = mCellLayoutContainer.getCellLayoutId(this); - cellToRect(targetCell[0], targetCell[1], spanX, spanY, mTempRect); - - ((LauncherAppWidgetHostView) view).handleDrag(mTempRect, this, screenId); - } - } - @SuppressLint("StringFormatMatches") public String getItemMoveDescription(int cellX, int cellY) { if (mContainerType == HOTSEAT) { diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index f03dcab2f7..5927e6a6b9 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -126,7 +126,6 @@ import com.android.launcher3.widget.PendingAddShortcutInfo; import com.android.launcher3.widget.PendingAddWidgetInfo; import com.android.launcher3.widget.PendingAppWidgetHostView; import com.android.launcher3.widget.WidgetManagerHelper; -import com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener; import com.android.launcher3.widget.util.WidgetSizes; import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayCallbacks; import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlayTouchProxy; @@ -1744,9 +1743,6 @@ public class Workspace extends PagedView final DragView dv; if (contentView instanceof View) { - if (contentView instanceof LauncherAppWidgetHostView) { - mDragController.addDragListener(new AppWidgetHostViewDragListener(mLauncher)); - } dv = mDragController.startDrag( contentView, draggableView, diff --git a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java index c3e9ad6f9c..44ab966472 100644 --- a/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java +++ b/src/com/android/launcher3/widget/LauncherAppWidgetHostView.java @@ -42,7 +42,6 @@ import com.android.launcher3.CheckLongPressHelper; import com.android.launcher3.Flags; import com.android.launcher3.R; import com.android.launcher3.model.data.ItemInfo; -import com.android.launcher3.model.data.LauncherAppWidgetInfo; import com.android.launcher3.util.Themes; import com.android.launcher3.views.ActivityContext; import com.android.launcher3.views.BaseDragLayer; @@ -52,8 +51,7 @@ import com.android.launcher3.views.BaseDragLayer.TouchCompleteListener; * {@inheritDoc} */ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView - implements TouchCompleteListener, View.OnLongClickListener, - LocalColorExtractor.Listener { + implements TouchCompleteListener, View.OnLongClickListener { private static final String TAG = "LauncherAppWidgetHostView"; @@ -70,13 +68,9 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView private static final String TRACE_METHOD_NAME = "appwidget load-widget "; - private final Rect mTempRect = new Rect(); private final CheckLongPressHelper mLongPressHelper; protected final ActivityContext mActivityContext; - // Maintain the color manager. - private final LocalColorExtractor mColorExtractor; - private boolean mIsScrollable; private boolean mIsAttachedToWindow; private boolean mIsAutoAdvanceRegistered; @@ -84,11 +78,6 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView private long mDeferUpdatesUntilMillis = 0; RemoteViews mLastRemoteViews; - private boolean mHasDeferredColorChange = false; - private @Nullable SparseIntArray mDeferredColorChange = null; - - // The following member variables are only used during drag-n-drop. - private boolean mIsInDragMode = false; private boolean mTrackingWidgetUpdate = false; @@ -109,7 +98,6 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView if (Themes.getAttrBoolean(context, R.attr.isWorkspaceDarkText)) { setOnLightBackground(true); } - mColorExtractor = new LocalColorExtractor(); // no-op } @Override @@ -177,8 +165,8 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView } /** - * Returns true if the application of {@link RemoteViews} through {@link #updateAppWidget} and - * colors through {@link #onColorsChanged} are currently being deferred. + * Returns true if the application of {@link RemoteViews} through {@link #updateAppWidget} are + * currently being deferred. * @see #beginDeferringUpdates() */ private boolean isDeferringUpdates() { @@ -187,9 +175,8 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView /** * Begin deferring the application of any {@link RemoteViews} updates made through - * {@link #updateAppWidget} and color changes through {@link #onColorsChanged} until - * {@link #endDeferringUpdates()} has been called or the next {@link #updateAppWidget} or - * {@link #onColorsChanged} call after {@link #UPDATE_LOCK_TIMEOUT_MILLIS} have elapsed. + * {@link #updateAppWidget} until {@link #endDeferringUpdates()} has been called or the next + * {@link #updateAppWidget} call after {@link #UPDATE_LOCK_TIMEOUT_MILLIS} have elapsed. */ public void beginDeferringUpdates() { mDeferUpdatesUntilMillis = SystemClock.uptimeMillis() + UPDATE_LOCK_TIMEOUT_MILLIS; @@ -197,26 +184,16 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView /** * Stop deferring the application of {@link RemoteViews} updates made through - * {@link #updateAppWidget} and color changes made through {@link #onColorsChanged} and apply - * any deferred updates. + * {@link #updateAppWidget} and apply any deferred updates. */ public void endDeferringUpdates() { RemoteViews remoteViews; - SparseIntArray deferredColors; - boolean hasDeferredColors; mDeferUpdatesUntilMillis = 0; remoteViews = mLastRemoteViews; - deferredColors = mDeferredColorChange; - hasDeferredColors = mHasDeferredColorChange; - mDeferredColorChange = null; - mHasDeferredColorChange = false; if (remoteViews != null) { updateAppWidget(remoteViews); } - if (hasDeferredColors) { - onColorsChanged(deferredColors); - } } public boolean onInterceptTouchEvent(MotionEvent ev) { @@ -242,7 +219,6 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView super.onAttachedToWindow(); mIsAttachedToWindow = true; checkIfAutoAdvance(); - mColorExtractor.setListener(this); } @Override @@ -253,7 +229,6 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView // state is updated. So isAttachedToWindow() will return true until next frame. mIsAttachedToWindow = false; checkIfAutoAdvance(); - mColorExtractor.setListener(null); } @Override @@ -292,29 +267,6 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); mIsScrollable = checkScrollableRecursively(this); - - if (!mIsInDragMode && getTag() instanceof LauncherAppWidgetInfo info) { - mTempRect.set(left, top, right, bottom); - mColorExtractor.setWorkspaceLocation(mTempRect, (View) getParent(), info.screenId); - } - } - - /** Starts the drag mode. */ - public void startDrag() { - mIsInDragMode = true; - } - - /** Handles a drag event occurred on a workspace page corresponding to the {@code screenId}. */ - public void handleDrag(Rect rectInView, View view, int screenId) { - if (mIsInDragMode) { - mColorExtractor.setWorkspaceLocation(rectInView, view, screenId); - } - } - - /** Ends the drag mode. */ - public void endDrag() { - mIsInDragMode = false; - requestLayout(); } /** @@ -337,20 +289,6 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView mCellChildViewPreLayoutListener = null; } - @Override - public void onColorsChanged(SparseIntArray colors) { - if (isDeferringUpdates()) { - mDeferredColorChange = colors; - mHasDeferredColorChange = true; - return; - } - mDeferredColorChange = null; - mHasDeferredColorChange = false; - - // setColorResources will reapply the view, which must happen in the UI thread. - post(() -> setColorResources(colors)); - } - @Override public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { super.onInitializeAccessibilityNodeInfo(info); diff --git a/src/com/android/launcher3/widget/LocalColorExtractor.java b/src/com/android/launcher3/widget/LocalColorExtractor.java index 96e75311c8..7b500c72c4 100644 --- a/src/com/android/launcher3/widget/LocalColorExtractor.java +++ b/src/com/android/launcher3/widget/LocalColorExtractor.java @@ -17,11 +17,8 @@ package com.android.launcher3.widget; import android.app.WallpaperColors; -import android.appwidget.AppWidgetHostView; import android.content.Context; -import android.graphics.Rect; import android.util.SparseIntArray; -import android.view.View; import androidx.annotation.Nullable; @@ -31,18 +28,6 @@ import com.android.launcher3.util.ResourceBasedOverride; /** Extracts the colors we need from the wallpaper at given locations. */ public class LocalColorExtractor implements ResourceBasedOverride { - /** Listener for color changes on a screen location. */ - public interface Listener { - /** - * Method called when the colors on a registered location has changed. - * - * {@code extractedColors} maps the color resources {@code android.R.colors.system_*} to - * their value, in a format that can be passed directly to - * {@link AppWidgetHostView#setColorResources(SparseIntArray)}. - */ - void onColorsChanged(SparseIntArray extractedColors); - } - /** * Creates a new instance of LocalColorExtractor */ @@ -51,19 +36,6 @@ public class LocalColorExtractor implements ResourceBasedOverride { R.string.local_colors_extraction_class); } - /** Sets the object that will receive the color changes. */ - public void setListener(@Nullable Listener listener) { - // no-op - } - - /** - * Sets the location used for color extraction - * @param pos position to use for color extraction - * @param child view whose coordinate space is used for {@code pos} - * @param screenId the workspace screenId - */ - public void setWorkspaceLocation(Rect pos, View child, int screenId) { } - /** * Updates the base context to contain the colors override */ @@ -76,5 +48,4 @@ public class LocalColorExtractor implements ResourceBasedOverride { public SparseIntArray generateColorsOverride(WallpaperColors colors) { return null; } - } diff --git a/src/com/android/launcher3/widget/PendingItemDragHelper.java b/src/com/android/launcher3/widget/PendingItemDragHelper.java index faad307b35..8857774922 100644 --- a/src/com/android/launcher3/widget/PendingItemDragHelper.java +++ b/src/com/android/launcher3/widget/PendingItemDragHelper.java @@ -44,7 +44,6 @@ import com.android.launcher3.icons.BaseIconFactory; import com.android.launcher3.icons.FastBitmapDrawable; import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.icons.RoundDrawableWrapper; -import com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener; /** * Extension of {@link DragPreviewProvider} with logic specific to pending widgets/shortcuts @@ -132,8 +131,6 @@ public class PendingItemDragHelper extends DragPreviewProvider { } if (mAppWidgetHostViewPreview != null) { previewSizeBeforeScale[0] = mAppWidgetHostViewPreview.getMeasuredWidth(); - launcher.getDragController() - .addDragListener(new AppWidgetHostViewDragListener(launcher)); } if (preview == null && mAppWidgetHostViewPreview == null) { Drawable p = new FastBitmapDrawable(new DatabaseWidgetPreviewLoader(launcher) diff --git a/src/com/android/launcher3/widget/dragndrop/AppWidgetHostViewDragListener.java b/src/com/android/launcher3/widget/dragndrop/AppWidgetHostViewDragListener.java deleted file mode 100644 index 3e54b33068..0000000000 --- a/src/com/android/launcher3/widget/dragndrop/AppWidgetHostViewDragListener.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2021 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.widget.dragndrop; - -import com.android.launcher3.DropTarget; -import com.android.launcher3.Launcher; -import com.android.launcher3.dragndrop.DragController; -import com.android.launcher3.dragndrop.DragOptions; -import com.android.launcher3.widget.LauncherAppWidgetHostView; - -/** A drag listener of {@link LauncherAppWidgetHostView}. */ -public final class AppWidgetHostViewDragListener implements DragController.DragListener { - private final Launcher mLauncher; - private LauncherAppWidgetHostView mAppWidgetHostView; - - public AppWidgetHostViewDragListener(Launcher launcher) { - mLauncher = launcher; - } - - @Override - public void onDragStart(DropTarget.DragObject dragObject, DragOptions unused) { - if (dragObject.dragView.getContentView() instanceof LauncherAppWidgetHostView) { - mAppWidgetHostView = (LauncherAppWidgetHostView) dragObject.dragView.getContentView(); - mAppWidgetHostView.startDrag(); - } else { - mLauncher.getDragController().removeDragListener(this); - } - } - - @Override - public void onDragEnd() { - mAppWidgetHostView.endDrag(); - mLauncher.getDragController().removeDragListener(this); - } -}