Note that shouldPreinflate param should be set to {@code false} for taskbar, because this - * method is too late to preinflate all apps, as user will open all apps in the same frame. + *
Note that shouldPreinflate param should be set to {@code false} for taskbar, because + * this method is too late to preinflate all apps, as user will open all apps in the frame + * + *
Param: apps are required to be sorted using the comparator COMPONENT_KEY_COMPARATOR
+ * in order to enable binary search on the mApps store
*/
public void setApps(@Nullable AppInfo[] apps, int flags, Map
+ * This can cause the Private Space container items to not load/respond correctly sometimes,
+ * when the All Apps Container loads for the first time (device restarts, new profiles
+ * added/removed, etc.), as the properties are being set in non-ui thread whereas the container
+ * loads in the ui thread.
+ * This case should still be ok, as locking the Private Space container and unlocking it,
+ * reloads the values, fixing the incorrect UI.
+ */
+ private void initializeInBackgroundThread() {
+ Preconditions.assertNonUiThread();
+ setPreInstalledSystemPackages();
+ setAppInstallerIntent();
+ initializePrivateSpaceSettingsState();
+ }
+
+ private void initializePrivateSpaceSettingsState() {
Preconditions.assertNonUiThread();
- Intent psSettingsIntent = new Intent(SAFETY_CENTER_INTENT);
- psSettingsIntent.putExtra(PS_SETTINGS_FRAGMENT_KEY, PS_SETTINGS_FRAGMENT_VALUE);
ResolveInfo resolveInfo = mAllApps.getContext().getPackageManager()
- .resolveActivity(psSettingsIntent, PackageManager.MATCH_SYSTEM_ONLY);
- mPrivateSpaceSettingsAvailable = resolveInfo != null;
+ .resolveActivity(PRIVATE_SPACE_INTENT, PackageManager.MATCH_SYSTEM_ONLY);
+ setPrivateSpaceSettingsAvailable(resolveInfo != null);
+ }
+
+ private void setPreInstalledSystemPackages() {
+ Preconditions.assertNonUiThread();
+ if (getProfileUser() != null) {
+ mPreInstalledSystemPackages = new HashSet<>(ApiWrapper
+ .getPreInstalledSystemPackages(mAllApps.getContext(), getProfileUser()));
+ }
+ }
+
+ private void setAppInstallerIntent() {
+ Preconditions.assertNonUiThread();
+ if (getProfileUser() != null) {
+ mAppInstallerIntent = ApiWrapper.getAppMarketActivityIntent(mAllApps.getContext(),
+ BuildConfig.APPLICATION_ID, getProfileUser());
+ }
}
@VisibleForTesting
@@ -138,13 +233,6 @@ public class PrivateProfileManager extends UserProfileManager {
}
// Add Private Space Decorator to the Recycler view.
mainAdapterHolder.mRecyclerView.addItemDecoration(mPrivateAppsSectionDecorator);
- if (Flags.privateSpaceAnimation() && mAllApps.getActiveRecyclerView()
- == mainAdapterHolder.mRecyclerView) {
- RecyclerViewAnimationController recyclerViewAnimationController =
- new RecyclerViewAnimationController(mAllApps);
- recyclerViewAnimationController.animateToState(true /* expand */,
- ANIMATION_DURATION, () -> {});
- }
} else {
// Remove Private Space Decorator from the Recycler view.
if (mPrivateAppsSectionDecorator != null) {
@@ -158,8 +246,30 @@ public class PrivateProfileManager extends UserProfileManager {
setQuietMode(enable);
}
+ void applyUnlockRunnable() {
+ if (mUnlockRunnable != null) {
+ // reset the runnable to prevent re-execution.
+ MAIN_EXECUTOR.post(mUnlockRunnable);
+ mUnlockRunnable = null;
+ }
+ }
+
+ private boolean transitioningFromLockedToUnlocked(int previousState, int updatedState) {
+ return previousState == STATE_DISABLED && updatedState == STATE_ENABLED;
+ }
+
@Override
public Predicate
+ * Different from {@link #addFloat}, this method use animator provided by
+ * {@link AnimatedFloat#animateToValue}, which tracks the animator inside the AnimatedFloat,
+ * allowing the animation to be canceled and animate again from AnimatedFloat side.
+ */
+ public void addAnimatedFloat(AnimatedFloat target, float from, float to,
+ TimeInterpolator interpolator) {
+ Animator anim = target.animateToValue(from, to);
+ anim.setInterpolator(interpolator);
+ add(anim);
+ }
+
/** If trace is enabled, add counter to trace animation progress. */
public void logAnimationProgressToTrace(String counterName) {
- if (Utilities.ATLEAST_Q && Trace.isEnabled()) {
+ if (Trace.isEnabled()) {
super.addOnFrameListener(
animation -> Trace.setCounter(
counterName, (long) (animation.getAnimatedFraction() * 100)));
diff --git a/src/com/android/launcher3/apppairs/AppPairIcon.java b/src/com/android/launcher3/apppairs/AppPairIcon.java
index 1d73441b71e6e66ffc1e0e4036d06d66f19f9108..48d0fbd48551c54eadbcea8d4ee3e8597415f42e 100644
--- a/src/com/android/launcher3/apppairs/AppPairIcon.java
+++ b/src/com/android/launcher3/apppairs/AppPairIcon.java
@@ -17,8 +17,10 @@
package com.android.launcher3.apppairs;
import android.content.Context;
+import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -32,11 +34,13 @@ import com.android.launcher3.R;
import com.android.launcher3.Reorderable;
import com.android.launcher3.dragndrop.DraggableView;
import com.android.launcher3.model.data.FolderInfo;
+import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.util.MultiTranslateDelegate;
import com.android.launcher3.views.ActivityContext;
import java.util.Collections;
import java.util.Comparator;
+import java.util.function.Predicate;
/**
* A {@link android.widget.FrameLayout} used to represent an app pair icon on the workspace.
@@ -45,6 +49,13 @@ import java.util.Comparator;
* member apps are set into these rectangles.
*/
public class AppPairIcon extends FrameLayout implements DraggableView, Reorderable {
+ private static final String TAG = "AppPairIcon";
+
+ /**
+ * Indicates that the app pair is currently launchable on the current screen.
+ */
+ private boolean mIsLaunchableAtScreenSize = true;
+
// A view that holds the app pair icon graphic.
private AppPairIconGraphic mIconGraphic;
// A view that holds the app pair's title.
@@ -83,6 +94,13 @@ public class AppPairIcon extends FrameLayout implements DraggableView, Reorderab
icon.setOnClickListener(activity.getItemOnClickListener());
icon.mInfo = appPairInfo;
+ if (icon.mInfo.contents.size() != 2) {
+ Log.wtf(TAG, "AppPair contents not 2, size: " + icon.mInfo.contents.size());
+ return icon;
+ }
+
+ icon.checkScreenSize();
+
// Set up icon drawable area
icon.mIconGraphic = icon.findViewById(R.id.app_pair_icon_graphic);
icon.mIconGraphic.init(activity.getDeviceProfile(), icon);
@@ -96,8 +114,7 @@ public class AppPairIcon extends FrameLayout implements DraggableView, Reorderab
icon.mAppPairName.setText(appPairInfo.title);
// Set up accessibility
- icon.setContentDescription(icon.getAccessibilityTitle(
- appPairInfo.contents.get(0).title, appPairInfo.contents.get(1).title));
+ icon.setContentDescription(icon.getAccessibilityTitle(appPairInfo));
icon.setAccessibilityDelegate(activity.getAccessibilityDelegate());
return icon;
@@ -106,7 +123,9 @@ public class AppPairIcon extends FrameLayout implements DraggableView, Reorderab
/**
* Returns a formatted accessibility title for app pairs.
*/
- public String getAccessibilityTitle(CharSequence app1, CharSequence app2) {
+ public String getAccessibilityTitle(FolderInfo appPairInfo) {
+ CharSequence app1 = appPairInfo.contents.get(0).title;
+ CharSequence app2 = appPairInfo.contents.get(1).title;
return getContext().getString(R.string.app_pair_name_format, app1, app2);
}
@@ -158,4 +177,40 @@ public class AppPairIcon extends FrameLayout implements DraggableView, Reorderab
public View getIconDrawableArea() {
return mIconGraphic;
}
+
+ public boolean isLaunchableAtScreenSize() {
+ return mIsLaunchableAtScreenSize;
+ }
+
+ /**
+ * Checks if the app pair is launchable in the current device configuration.
+ *
+ * App pairs can be "disabled" in two ways:
+ * 1) One of the member WorkspaceItemInfos is disabled (i.e. the app software itself is paused
+ * by the user or can't be launched).
+ * 2) This specific instance of an app pair can't be launched due to screen size requirements.
+ *
+ * This method checks and updates #2. Both #1 and #2 are checked when app pairs are drawn
+ * {@link AppPairIconGraphic#dispatchDraw(Canvas)} or clicked on
+ * {@link com.android.launcher3.touch.ItemClickHandler#onClickAppPairIcon(View)}
+ */
+ public void checkScreenSize() {
+ DeviceProfile dp = ActivityContext.lookupContext(getContext()).getDeviceProfile();
+ // If user is on a small screen, we can't launch if either of the apps is non-resizeable
+ mIsLaunchableAtScreenSize =
+ dp.isTablet || getInfo().contents.stream().noneMatch(
+ wii -> wii.hasStatusFlag(WorkspaceItemInfo.FLAG_NON_RESIZEABLE));
+ }
+
+ /**
+ * Called when WorkspaceItemInfos get updated, and the app pair icon may need to be redrawn.
+ */
+ public void maybeRedrawForWorkspaceUpdate(Predicate
+ * When changing the size of the widget this method will try first subtracting -1 in the x
+ * dimension and then subtracting -1 in the y dimension until finding a possible solution or
+ * until it no longer can reduce the span.
+ * @param direction Direction to attempt to push items if needed
+ * @param decX whether it will decrease the horizontal or vertical span if it can't find a
+ * solution for the current span.
+ * @return the same solution variable
+ */
+ public ItemConfiguration findReorderSolution(ReorderParameters reorderParameters,
+ int[] direction, boolean decX) {
return findReorderSolutionRecursive(reorderParameters.getPixelX(),
reorderParameters.getPixelY(), reorderParameters.getMinSpanX(),
reorderParameters.getMinSpanY(), reorderParameters.getSpanX(),
- reorderParameters.getSpanY(), mCellLayout.mDirectionVector,
+ reorderParameters.getSpanY(), direction,
reorderParameters.getDragView(), decX, reorderParameters.getSolution());
}
-
private ItemConfiguration findReorderSolutionRecursive(int pixelX, int pixelY, int minSpanX,
int minSpanY, int spanX, int spanY, int[] direction, View dragView, boolean decX,
ItemConfiguration solution) {
diff --git a/src/com/android/launcher3/celllayout/ReorderPreviewAnimation.kt b/src/com/android/launcher3/celllayout/ReorderPreviewAnimation.kt
new file mode 100644
index 0000000000000000000000000000000000000000..62b19d4d04472994caebc66baecdf224fa887cfa
--- /dev/null
+++ b/src/com/android/launcher3/celllayout/ReorderPreviewAnimation.kt
@@ -0,0 +1,166 @@
+/*
+ * Copyright (C) 2024 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.celllayout
+
+import android.animation.ObjectAnimator
+import android.animation.ValueAnimator
+import android.animation.ValueAnimator.areAnimatorsEnabled
+import android.util.ArrayMap
+import android.view.View
+import com.android.app.animation.Interpolators.DECELERATE_1_5
+import com.android.launcher3.CellLayout
+import com.android.launcher3.CellLayout.REORDER_ANIMATION_DURATION
+import com.android.launcher3.Reorderable
+import com.android.launcher3.Workspace
+import com.android.launcher3.util.MultiTranslateDelegate.INDEX_REORDER_BOUNCE_OFFSET
+import com.android.launcher3.util.Thunk
+import kotlin.math.abs
+import kotlin.math.atan
+import kotlin.math.cos
+import kotlin.math.sign
+import kotlin.math.sin
+
+/**
+ * Class which represents the reorder preview animations. These animations show that an item is in a
+ * temporary state, and hint at where the item will return to.
+ */
+class ReorderPreviewAnimation Should be set to {@code true} while the screen is binding or new data is being applied,
+ * and to {@code false} once done. This prevents animation conflicts due to scrolling during
+ * those periods.