Merge "Center drop target button alignment across devices" into tm-dev
diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
index 21728ad..d676f7d 100644
--- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
+++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
@@ -1996,9 +1996,11 @@
* Applies the transform on the recents animation
*/
protected void applyScrollAndTransform() {
- // No need to apply any transform if there is ongoing swipe-pip-to-home animator since
- // that animator handles the leash solely.
- boolean notSwipingPipToHome = mRecentsAnimationTargets != null && !mIsSwipingPipToHome;
+ // No need to apply any transform if there is ongoing swipe-to-home animator
+ // swipe-to-pip handles the leash solely
+ // swipe-to-icon animation is handled by RectFSpringAnim anim
+ boolean notSwipingToHome = mRecentsAnimationTargets != null
+ && mGestureState.getEndTarget() != HOME;
boolean setRecentsScroll = mRecentsViewScrollLinked && mRecentsView != null;
for (RemoteTargetHandle remoteHandle : mRemoteTargetHandles) {
AnimatorControllerWithResistance playbackController =
@@ -2008,7 +2010,7 @@
getScaleProgressDueToScroll()), mDragLengthFactor);
}
- if (notSwipingPipToHome) {
+ if (notSwipingToHome) {
TaskViewSimulator taskViewSimulator = remoteHandle.getTaskViewSimulator();
if (setRecentsScroll) {
taskViewSimulator.setScroll(mRecentsView.getScrollOffset());
diff --git a/res/values/id.xml b/res/values/id.xml
index 7ad1412..af21b27 100644
--- a/res/values/id.xml
+++ b/res/values/id.xml
@@ -37,4 +37,5 @@
<item type="id" name="quick_settings_button" />
<item type="id" name="notifications_button" />
+ <item type="id" name="cache_entry_tag_id" />
</resources>
diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java
index 8da4f05..3b24df2 100644
--- a/src/com/android/launcher3/ButtonDropTarget.java
+++ b/src/com/android/launcher3/ButtonDropTarget.java
@@ -179,7 +179,12 @@
@Override
public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
- mActive = !options.isKeyboardDrag && supportsDrop(dragObject.dragInfo);
+ if (options.isKeyboardDrag) {
+ mActive = false;
+ } else {
+ setupItemInfo(dragObject.dragInfo);
+ mActive = supportsDrop(dragObject.dragInfo);
+ }
setVisibility(mActive ? View.VISIBLE : View.GONE);
mAccessibleDrag = options.isAccessibleDrag;
@@ -191,6 +196,11 @@
return supportsDrop(dragObject.dragInfo);
}
+ /**
+ * Setups button for the specified ItemInfo.
+ */
+ protected abstract void setupItemInfo(ItemInfo info);
+
protected abstract boolean supportsDrop(ItemInfo info);
public abstract boolean supportsAccessibilityDrop(ItemInfo info, View view);
diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java
index 371bb80..95d3ad9 100644
--- a/src/com/android/launcher3/DeleteDropTarget.java
+++ b/src/com/android/launcher3/DeleteDropTarget.java
@@ -85,6 +85,9 @@
}
@Override
+ protected void setupItemInfo(ItemInfo info) {}
+
+ @Override
protected boolean supportsDrop(ItemInfo info) {
return true;
}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 31c1eff..1846383 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -536,6 +536,7 @@
if (Utilities.ATLEAST_R) {
getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
}
+ setTitle(R.string.home_screen);
}
protected LauncherOverlayManager getDefaultOverlay() {
diff --git a/src/com/android/launcher3/SecondaryDropTarget.java b/src/com/android/launcher3/SecondaryDropTarget.java
index 5b037e4..f8bc1f4 100644
--- a/src/com/android/launcher3/SecondaryDropTarget.java
+++ b/src/com/android/launcher3/SecondaryDropTarget.java
@@ -6,6 +6,7 @@
import static com.android.launcher3.Launcher.REQUEST_RECONFIGURE_APPWIDGET;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP;
import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.DISMISS_PREDICTION;
+import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.INVALID;
import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.RECONFIGURE;
import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.UNINSTALL;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_DISMISS_PREDICTION_UNDO;
@@ -69,6 +70,7 @@
private boolean mHadPendingAlarm;
protected int mCurrentAccessibilityAction = -1;
+
public SecondaryDropTarget(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@@ -134,24 +136,33 @@
}
@Override
+ protected void setupItemInfo(ItemInfo info) {
+ int buttonType = getButtonType(info, getViewUnderDrag(info));
+ if (buttonType != INVALID) {
+ setupUi(buttonType);
+ }
+ }
+
+ @Override
protected boolean supportsDrop(ItemInfo info) {
- return supportsAccessibilityDrop(info, getViewUnderDrag(info));
+ return getButtonType(info, getViewUnderDrag(info)) != INVALID;
}
@Override
public boolean supportsAccessibilityDrop(ItemInfo info, View view) {
+ return getButtonType(info, view) != INVALID;
+ }
+
+ private int getButtonType(ItemInfo info, View view) {
if (view instanceof AppWidgetHostView) {
if (getReconfigurableWidgetId(view) != INVALID_APPWIDGET_ID) {
- setupUi(RECONFIGURE);
- return true;
+ return RECONFIGURE;
}
- return false;
+ return INVALID;
} else if (FeatureFlags.ENABLE_PREDICTION_DISMISS.get() && info.isPredictedItem()) {
- setupUi(DISMISS_PREDICTION);
- return true;
+ return DISMISS_PREDICTION;
}
- setupUi(UNINSTALL);
Boolean uninstallDisabled = mUninstallDisabledCache.get(info.user);
if (uninstallDisabled == null) {
UserManager userManager =
@@ -165,16 +176,20 @@
mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT);
mCacheExpireAlarm.setOnAlarmListener(this);
if (uninstallDisabled) {
- return false;
+ return INVALID;
}
if (info instanceof ItemInfoWithIcon) {
ItemInfoWithIcon iconInfo = (ItemInfoWithIcon) info;
- if ((iconInfo.runtimeStatusFlags & FLAG_SYSTEM_MASK) != 0) {
- return (iconInfo.runtimeStatusFlags & FLAG_SYSTEM_NO) != 0;
+ if ((iconInfo.runtimeStatusFlags & FLAG_SYSTEM_MASK) != 0
+ && (iconInfo.runtimeStatusFlags & FLAG_SYSTEM_NO) == 0) {
+ return INVALID;
}
}
- return getUninstallTarget(info) != null;
+ if (getUninstallTarget(info) == null) {
+ return INVALID;
+ }
+ return UNINSTALL;
}
/**
diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
index 44d57d7..79214e8 100644
--- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
+++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
@@ -60,6 +60,7 @@
public static final int DISMISS_PREDICTION = R.id.action_dismiss_prediction;
public static final int PIN_PREDICTION = R.id.action_pin_prediction;
public static final int RECONFIGURE = R.id.action_reconfigure;
+ public static final int INVALID = -1;
protected static final int ADD_TO_WORKSPACE = R.id.action_add_to_workspace;
protected static final int MOVE = R.id.action_move;
protected static final int MOVE_TO_WORKSPACE = R.id.action_move_to_workspace;
diff --git a/src/com/android/launcher3/anim/AnimatedPropertySetter.java b/src/com/android/launcher3/anim/AnimatedPropertySetter.java
new file mode 100644
index 0000000..e5f5e7c
--- /dev/null
+++ b/src/com/android/launcher3/anim/AnimatedPropertySetter.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2022 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.anim;
+
+import static com.android.launcher3.LauncherAnimUtils.VIEW_BACKGROUND_COLOR;
+
+import android.animation.Animator;
+import android.animation.Animator.AnimatorListener;
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
+import android.animation.TimeInterpolator;
+import android.animation.ValueAnimator;
+import android.graphics.drawable.ColorDrawable;
+import android.util.FloatProperty;
+import android.util.IntProperty;
+import android.view.View;
+
+import androidx.annotation.NonNull;
+
+import java.util.function.Consumer;
+
+/**
+ * Extension of {@link PropertySetter} which applies the property through an animation
+ */
+public class AnimatedPropertySetter extends PropertySetter {
+
+ protected final AnimatorSet mAnim = new AnimatorSet();
+ protected ValueAnimator mProgressAnimator;
+
+ @Override
+ public Animator setViewAlpha(View view, float alpha, TimeInterpolator interpolator) {
+ if (view == null || view.getAlpha() == alpha) {
+ return NO_OP;
+ }
+ ObjectAnimator anim = ObjectAnimator.ofFloat(view, View.ALPHA, alpha);
+ anim.addListener(new AlphaUpdateListener(view));
+ anim.setInterpolator(interpolator);
+ add(anim);
+ return anim;
+ }
+
+ @Override
+ public Animator setViewBackgroundColor(View view, int color, TimeInterpolator interpolator) {
+ if (view == null || (view.getBackground() instanceof ColorDrawable
+ && ((ColorDrawable) view.getBackground()).getColor() == color)) {
+ return NO_OP;
+ }
+ ObjectAnimator anim = ObjectAnimator.ofArgb(view, VIEW_BACKGROUND_COLOR, color);
+ anim.setInterpolator(interpolator);
+ add(anim);
+ return anim;
+ }
+
+ @Override
+ public <T> Animator setFloat(T target, FloatProperty<T> property, float value,
+ TimeInterpolator interpolator) {
+ if (property.get(target) == value) {
+ return NO_OP;
+ }
+ Animator anim = ObjectAnimator.ofFloat(target, property, value);
+ anim.setInterpolator(interpolator);
+ add(anim);
+ return anim;
+ }
+
+ @Override
+ public <T> Animator setInt(T target, IntProperty<T> property, int value,
+ TimeInterpolator interpolator) {
+ if (property.get(target) == value) {
+ return NO_OP;
+ }
+ Animator anim = ObjectAnimator.ofInt(target, property, value);
+ anim.setInterpolator(interpolator);
+ add(anim);
+ return anim;
+ }
+
+
+ /**
+ * Adds a callback to be run on every frame of the animation
+ */
+ public void addOnFrameCallback(Runnable runnable) {
+ addOnFrameListener(anim -> runnable.run());
+ }
+
+ /**
+ * Adds a listener to be run on every frame of the animation
+ */
+ public void addOnFrameListener(ValueAnimator.AnimatorUpdateListener listener) {
+ if (mProgressAnimator == null) {
+ mProgressAnimator = ValueAnimator.ofFloat(0, 1);
+ }
+
+ mProgressAnimator.addUpdateListener(listener);
+ }
+
+ @Override
+ public void addEndListener(Consumer<Boolean> listener) {
+ if (mProgressAnimator == null) {
+ mProgressAnimator = ValueAnimator.ofFloat(0, 1);
+ }
+ mProgressAnimator.addListener(AnimatorListeners.forEndCallback(listener));
+ }
+
+ /**
+ * @see AnimatorSet#addListener(AnimatorListener)
+ */
+ public void addListener(Animator.AnimatorListener listener) {
+ mAnim.addListener(listener);
+ }
+
+ @Override
+ public void add(Animator a) {
+ mAnim.play(a);
+ }
+
+ /**
+ * Creates and returns the underlying AnimatorSet
+ */
+ @NonNull
+ public AnimatorSet buildAnim() {
+ // Add progress animation to the end, so that frame callback is called after all the other
+ // animation update.
+ if (mProgressAnimator != null) {
+ add(mProgressAnimator);
+ mProgressAnimator = null;
+ }
+ return mAnim;
+ }
+}
diff --git a/src/com/android/launcher3/anim/PendingAnimation.java b/src/com/android/launcher3/anim/PendingAnimation.java
index 1300ce7..7316420 100644
--- a/src/com/android/launcher3/anim/PendingAnimation.java
+++ b/src/com/android/launcher3/anim/PendingAnimation.java
@@ -15,24 +15,18 @@
*/
package com.android.launcher3.anim;
-import static com.android.launcher3.LauncherAnimUtils.VIEW_BACKGROUND_COLOR;
import static com.android.launcher3.anim.AnimatorPlaybackController.addAnimationHoldersRecur;
import android.animation.Animator;
-import android.animation.Animator.AnimatorListener;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
-import android.graphics.drawable.ColorDrawable;
import android.util.FloatProperty;
-import android.util.IntProperty;
-import android.view.View;
import com.android.launcher3.anim.AnimatorPlaybackController.Holder;
import java.util.ArrayList;
-import java.util.function.Consumer;
/**
* Utility class to keep track of a running animation.
@@ -43,17 +37,13 @@
*
* TODO: Find a better name
*/
-public class PendingAnimation implements PropertySetter {
+public class PendingAnimation extends AnimatedPropertySetter {
private final ArrayList<Holder> mAnimHolders = new ArrayList<>();
- private final AnimatorSet mAnim;
private final long mDuration;
- private ValueAnimator mProgressAnimator;
-
public PendingAnimation(long duration) {
mDuration = duration;
- mAnim = new AnimatorSet();
}
public long getDuration() {
@@ -68,6 +58,7 @@
add(anim, springProperty);
}
+ @Override
public void add(Animator anim) {
add(anim, SpringProperty.DEFAULT);
}
@@ -84,39 +75,6 @@
mAnim.setInterpolator(interpolator);
}
- @Override
- public void setViewAlpha(View view, float alpha, TimeInterpolator interpolator) {
- if (view == null || view.getAlpha() == alpha) {
- return;
- }
- ObjectAnimator anim = ObjectAnimator.ofFloat(view, View.ALPHA, alpha);
- anim.addListener(new AlphaUpdateListener(view));
- anim.setInterpolator(interpolator);
- add(anim);
- }
-
- @Override
- public void setViewBackgroundColor(View view, int color, TimeInterpolator interpolator) {
- if (view == null || (view.getBackground() instanceof ColorDrawable
- && ((ColorDrawable) view.getBackground()).getColor() == color)) {
- return;
- }
- ObjectAnimator anim = ObjectAnimator.ofArgb(view, VIEW_BACKGROUND_COLOR, color);
- anim.setInterpolator(interpolator);
- add(anim);
- }
-
- @Override
- public <T> void setFloat(T target, FloatProperty<T> property, float value,
- TimeInterpolator interpolator) {
- if (property.get(target) == value) {
- return;
- }
- Animator anim = ObjectAnimator.ofFloat(target, property, value);
- anim.setDuration(mDuration).setInterpolator(interpolator);
- add(anim);
- }
-
public <T> void addFloat(T target, FloatProperty<T> property, float from, float to,
TimeInterpolator interpolator) {
Animator anim = ObjectAnimator.ofFloat(target, property, from, to);
@@ -124,57 +82,16 @@
add(anim);
}
- @Override
- public <T> void setInt(T target, IntProperty<T> property, int value,
- TimeInterpolator interpolator) {
- if (property.get(target) == value) {
- return;
- }
- Animator anim = ObjectAnimator.ofInt(target, property, value);
- anim.setInterpolator(interpolator);
- add(anim);
- }
-
- /**
- * Adds a callback to be run on every frame of the animation
- */
- public void addOnFrameCallback(Runnable runnable) {
- addOnFrameListener(anim -> runnable.run());
- }
-
- /**
- * Adds a listener to be run on every frame of the animation
- */
- public void addOnFrameListener(ValueAnimator.AnimatorUpdateListener listener) {
- if (mProgressAnimator == null) {
- mProgressAnimator = ValueAnimator.ofFloat(0, 1);
- }
-
- mProgressAnimator.addUpdateListener(listener);
- }
-
- /**
- * @see AnimatorSet#addListener(AnimatorListener)
- */
- public void addListener(Animator.AnimatorListener listener) {
- mAnim.addListener(listener);
- }
-
/**
* Creates and returns the underlying AnimatorSet
*/
+ @Override
public AnimatorSet buildAnim() {
- // Add progress animation to the end, so that frame callback is called after all the other
- // animation update.
- if (mProgressAnimator != null) {
- add(mProgressAnimator);
- mProgressAnimator = null;
- }
if (mAnimHolders.isEmpty()) {
// Add a placeholder animation to that the duration is respected
add(ValueAnimator.ofFloat(0, 1).setDuration(mDuration));
}
- return mAnim;
+ return super.buildAnim();
}
/**
@@ -183,14 +100,4 @@
public AnimatorPlaybackController createPlaybackController() {
return new AnimatorPlaybackController(buildAnim(), mDuration, mAnimHolders);
}
-
- /**
- * Add a listener of receiving the success/failure callback in the end.
- */
- public void addEndListener(Consumer<Boolean> listener) {
- if (mProgressAnimator == null) {
- mProgressAnimator = ValueAnimator.ofFloat(0, 1);
- }
- mProgressAnimator.addListener(AnimatorListeners.forEndCallback(listener));
- }
}
diff --git a/src/com/android/launcher3/anim/PropertySetter.java b/src/com/android/launcher3/anim/PropertySetter.java
index 8d77b4b..d2207f6 100644
--- a/src/com/android/launcher3/anim/PropertySetter.java
+++ b/src/com/android/launcher3/anim/PropertySetter.java
@@ -17,57 +17,94 @@
package com.android.launcher3.anim;
import android.animation.Animator;
+import android.animation.AnimatorSet;
import android.animation.TimeInterpolator;
import android.util.FloatProperty;
import android.util.IntProperty;
import android.view.View;
+import androidx.annotation.NonNull;
+
+import java.util.function.Consumer;
+
/**
* Utility class for setting a property with or without animation
*/
-public interface PropertySetter {
+public abstract class PropertySetter {
- PropertySetter NO_ANIM_PROPERTY_SETTER = new PropertySetter() { };
+ public static final PropertySetter NO_ANIM_PROPERTY_SETTER = new PropertySetter() {
+
+ @Override
+ public void add(Animator animatorSet) {
+ animatorSet.setDuration(0);
+ animatorSet.start();
+ }
+ };
+
+ protected static final AnimatorSet NO_OP = new AnimatorSet();
/**
* Sets the view alpha using the provided interpolator.
* Unlike {@link #setFloat}, this also updates the visibility of the view as alpha changes
* between zero and non-zero.
*/
- default void setViewAlpha(View view, float alpha, TimeInterpolator interpolator) {
+ @NonNull
+ public Animator setViewAlpha(View view, float alpha, TimeInterpolator interpolator) {
if (view != null) {
view.setAlpha(alpha);
AlphaUpdateListener.updateVisibility(view);
}
+ return NO_OP;
}
/**
* Sets the background color of the provided view using the provided interpolator.
*/
- default void setViewBackgroundColor(View view, int color, TimeInterpolator interpolator) {
+ @NonNull
+ public Animator setViewBackgroundColor(View view, int color, TimeInterpolator interpolator) {
if (view != null) {
view.setBackgroundColor(color);
}
+ return NO_OP;
}
/**
* Updates the float property of the target using the provided interpolator
*/
- default <T> void setFloat(T target, FloatProperty<T> property, float value,
+ @NonNull
+ public <T> Animator setFloat(T target, FloatProperty<T> property, float value,
TimeInterpolator interpolator) {
property.setValue(target, value);
+ return NO_OP;
}
/**
* Updates the int property of the target using the provided interpolator
*/
- default <T> void setInt(T target, IntProperty<T> property, int value,
+ @NonNull
+ public <T> Animator setInt(T target, IntProperty<T> property, int value,
TimeInterpolator interpolator) {
property.setValue(target, value);
+ return NO_OP;
}
- default void add(Animator animatorSet) {
- animatorSet.setDuration(0);
- animatorSet.start();
+ /**
+ * Runs the animation as part of setting the property
+ */
+ public abstract void add(Animator animatorSet);
+
+ /**
+ * Add a listener of receiving the success/failure callback in the end.
+ */
+ public void addEndListener(Consumer<Boolean> listener) {
+ listener.accept(true);
+ }
+
+ /**
+ * Creates and returns the AnimatorSet that can be run to apply the properties
+ */
+ @NonNull
+ public AnimatorSet buildAnim() {
+ return NO_OP;
}
}
diff --git a/src/com/android/launcher3/model/FirstScreenBroadcast.java b/src/com/android/launcher3/model/FirstScreenBroadcast.java
index 5fac7cf..9e91b9d 100644
--- a/src/com/android/launcher3/model/FirstScreenBroadcast.java
+++ b/src/com/android/launcher3/model/FirstScreenBroadcast.java
@@ -20,6 +20,7 @@
import static android.os.Process.myUserHandle;
import static com.android.launcher3.pm.InstallSessionHelper.getUserHandle;
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.mapping;
@@ -31,13 +32,18 @@
import android.os.UserHandle;
import android.util.Log;
+import androidx.annotation.AnyThread;
+import androidx.annotation.WorkerThread;
+
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
+import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.util.PackageUserKey;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -78,6 +84,7 @@
* Sends a broadcast to all package installers that have items with active sessions on the users
* first screen.
*/
+ @WorkerThread
public void sendBroadcasts(Context context, List<ItemInfo> firstScreenItems) {
UserHandle myUser = myUserHandle();
mSessionInfoForPackage
@@ -95,6 +102,7 @@
* @param packages List of packages with active sessions for this package installer.
* @param firstScreenItems List of items on the first screen.
*/
+ @WorkerThread
private void sendBroadcastToInstaller(Context context, String installerPackageName,
Set<String> packages, List<ItemInfo> firstScreenItems) {
Set<String> folderItems = new HashSet<>();
@@ -106,7 +114,7 @@
if (info instanceof FolderInfo) {
FolderInfo folderInfo = (FolderInfo) info;
String folderItemInfoPackage;
- for (ItemInfo folderItemInfo : folderInfo.contents) {
+ for (ItemInfo folderItemInfo : cloneOnMainThread(folderInfo.contents)) {
folderItemInfoPackage = getPackageName(folderItemInfo);
if (folderItemInfoPackage != null
&& packages.contains(folderItemInfoPackage)) {
@@ -170,4 +178,17 @@
Log.d(TAG, packageInstaller + ":" + label + ":" + pkg);
}
}
+
+ /**
+ * Clone the provided list on UI thread. This is used for {@link FolderInfo#contents} which
+ * is always modified on UI thread.
+ */
+ @AnyThread
+ private static List<WorkspaceItemInfo> cloneOnMainThread(ArrayList<WorkspaceItemInfo> list) {
+ try {
+ return MAIN_EXECUTOR.submit(() -> new ArrayList(list)).get();
+ } catch (Exception e) {
+ return Collections.emptyList();
+ }
+ }
}
diff --git a/src/com/android/launcher3/util/OnboardingPrefs.java b/src/com/android/launcher3/util/OnboardingPrefs.java
index c1e4fa8..64aeceb 100644
--- a/src/com/android/launcher3/util/OnboardingPrefs.java
+++ b/src/com/android/launcher3/util/OnboardingPrefs.java
@@ -140,4 +140,19 @@
mSharedPrefs.edit().putInt(eventKey, count).apply();
return hasReachedMaxCount(count, eventKey);
}
+
+ /**
+ * Add "incCountBy" to the given event count, if we haven't already reached the max count.
+ *
+ * @return Whether we have now reached the max count.
+ */
+ public boolean incrementEventCountBy(int incCountBy, @EventCountKey String eventKey) {
+ int count = getCount(eventKey);
+ if (hasReachedMaxCount(count, eventKey)) {
+ return true;
+ }
+ count += incCountBy;
+ mSharedPrefs.edit().putInt(eventKey, count).apply();
+ return hasReachedMaxCount(count, eventKey);
+ }
}
diff --git a/src/com/android/launcher3/util/ViewCache.java b/src/com/android/launcher3/util/ViewCache.java
index 08b8744..98e6822 100644
--- a/src/com/android/launcher3/util/ViewCache.java
+++ b/src/com/android/launcher3/util/ViewCache.java
@@ -21,6 +21,8 @@
import android.view.View;
import android.view.ViewGroup;
+import com.android.launcher3.R;
+
/**
* Utility class to cache views at an activity level
*/
@@ -39,18 +41,26 @@
mCache.put(layoutId, entry);
}
+ T result;
if (entry.mCurrentSize > 0) {
entry.mCurrentSize --;
- T result = (T) entry.mViews[entry.mCurrentSize];
+ result = (T) entry.mViews[entry.mCurrentSize];
entry.mViews[entry.mCurrentSize] = null;
- return result;
+ } else {
+ result = (T) LayoutInflater.from(context).inflate(layoutId, parent, false);
+ result.setTag(R.id.cache_entry_tag_id, entry);
}
-
- return (T) LayoutInflater.from(context).inflate(layoutId, parent, false);
+ return result;
}
public void recycleView(int layoutId, View view) {
CacheEntry entry = mCache.get(layoutId);
+ if (entry != view.getTag(R.id.cache_entry_tag_id)) {
+ // Since this view was created, the cache has been reset. The view should not be
+ // recycled since this means the environment could also have changed, requiring new
+ // view setup.
+ return;
+ }
if (entry != null && entry.mCurrentSize < entry.mMaxSize) {
entry.mViews[entry.mCurrentSize] = view;
entry.mCurrentSize++;
diff --git a/src/com/android/launcher3/views/RecyclerViewFastScroller.java b/src/com/android/launcher3/views/RecyclerViewFastScroller.java
index 7a8e9d5..2d6112f 100644
--- a/src/com/android/launcher3/views/RecyclerViewFastScroller.java
+++ b/src/com/android/launcher3/views/RecyclerViewFastScroller.java
@@ -287,7 +287,6 @@
case MotionEvent.ACTION_UP:
hideKeyboardAsync(ActivityContext.lookupContext(getContext()),
getApplicationWindowToken());
- break;
case MotionEvent.ACTION_CANCEL:
mRv.onFastScrollCompleted();
mTouchOffsetY = 0;
diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java
index 1bcba14..8962c4f 100644
--- a/src/com/android/launcher3/widget/BaseWidgetSheet.java
+++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java
@@ -198,7 +198,9 @@
/** Returns the number of cells that can fit horizontally in a given {@code content}. */
protected int computeMaxHorizontalSpans(View content, int contentHorizontalPaddingPx) {
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
- int availableWidth = content.getMeasuredWidth() - contentHorizontalPaddingPx;
+ int availableWidth = content.getMeasuredWidth()
+ - contentHorizontalPaddingPx
+ - (2 * mContentHorizontalMarginInPx);
Point cellSize = deviceProfile.getCellSize();
if (cellSize.x > 0) {
return availableWidth / cellSize.x;