Merge branch 'aosp-13' into 13-wip
This commit is contained in:
commit
19bf26dd5a
1558 files changed
+103731
-36693
No files matched your search
@@ -30,7 +30,6 @@ import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
@@ -43,6 +42,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.Alarm;
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
@@ -57,9 +57,9 @@ import com.android.launcher3.R;
|
||||
import com.android.launcher3.Reorderable;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.allapps.AllAppsContainerView;
|
||||
import com.android.launcher3.allapps.ActivityAllAppsContainerView;
|
||||
import com.android.launcher3.anim.Interpolators;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.celllayout.CellLayoutLayoutParams;
|
||||
import com.android.launcher3.dot.FolderDotInfo;
|
||||
import com.android.launcher3.dragndrop.BaseItemDragListener;
|
||||
import com.android.launcher3.dragndrop.DragLayer;
|
||||
@@ -70,14 +70,15 @@ import com.android.launcher3.logger.LauncherAtom.FromState;
|
||||
import com.android.launcher3.logger.LauncherAtom.ToState;
|
||||
import com.android.launcher3.logging.InstanceId;
|
||||
import com.android.launcher3.logging.StatsLogManager;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.model.data.FolderInfo;
|
||||
import com.android.launcher3.model.data.FolderInfo.FolderListener;
|
||||
import com.android.launcher3.model.data.FolderInfo.LabelState;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.WorkspaceItemFactory;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
import com.android.launcher3.touch.ItemClickHandler;
|
||||
import com.android.launcher3.util.Executors;
|
||||
import com.android.launcher3.util.MultiTranslateDelegate;
|
||||
import com.android.launcher3.util.Thunk;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
import com.android.launcher3.views.IconLabelDotView;
|
||||
@@ -87,28 +88,32 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
|
||||
/**
|
||||
* An icon that can appear on in the workspace representing an {@link Folder}.
|
||||
*/
|
||||
public class FolderIcon extends FrameLayout implements FolderListener, IconLabelDotView,
|
||||
DraggableView, Reorderable {
|
||||
|
||||
@Thunk ActivityContext mActivity;
|
||||
@Thunk Folder mFolder;
|
||||
private final MultiTranslateDelegate mTranslateDelegate = new MultiTranslateDelegate(this);
|
||||
@Thunk
|
||||
ActivityContext mActivity;
|
||||
@Thunk
|
||||
Folder mFolder;
|
||||
public FolderInfo mInfo;
|
||||
|
||||
private CheckLongPressHelper mLongPressHelper;
|
||||
|
||||
static final int DROP_IN_ANIMATION_DURATION = 400;
|
||||
|
||||
// Flag whether the folder should open itself when an item is dragged over is enabled.
|
||||
// Flag whether the folder should open itself when an item is dragged over is
|
||||
// enabled.
|
||||
public static final boolean SPRING_LOADING_ENABLED = true;
|
||||
|
||||
// Delay when drag enters until the folder opens, in miliseconds.
|
||||
private static final int ON_OPEN_DELAY = 800;
|
||||
|
||||
@Thunk BubbleTextView mFolderName;
|
||||
@Thunk
|
||||
BubbleTextView mFolderName;
|
||||
|
||||
PreviewBackground mBackground = new PreviewBackground();
|
||||
private boolean mBackgroundIsVisible = true;
|
||||
@@ -134,15 +139,10 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
|
||||
private Rect mTouchArea = new Rect();
|
||||
|
||||
private final PointF mTranslationForMoveFromCenterAnimation = new PointF(0, 0);
|
||||
private float mTranslationXForTaskbarAlignmentAnimation = 0f;
|
||||
|
||||
private final PointF mTranslationForReorderBounce = new PointF(0, 0);
|
||||
private final PointF mTranslationForReorderPreview = new PointF(0, 0);
|
||||
private float mScaleForReorderBounce = 1f;
|
||||
|
||||
private static final Property<FolderIcon, Float> DOT_SCALE_PROPERTY
|
||||
= new Property<FolderIcon, Float>(Float.TYPE, "dotScale") {
|
||||
private static final Property<FolderIcon, Float> DOT_SCALE_PROPERTY = new Property<FolderIcon, Float>(Float.TYPE,
|
||||
"dotScale") {
|
||||
@Override
|
||||
public Float get(FolderIcon folderIcon) {
|
||||
return folderIcon.mDotScale;
|
||||
@@ -183,8 +183,11 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
return icon;
|
||||
}
|
||||
|
||||
public static FolderIcon inflateIcon(int resId, ActivityContext activity, ViewGroup group,
|
||||
FolderInfo folderInfo) {
|
||||
/**
|
||||
* Builds a FolderIcon to be added to the Launcher
|
||||
*/
|
||||
public static FolderIcon inflateIcon(int resId, ActivityContext activity,
|
||||
@Nullable ViewGroup group, FolderInfo folderInfo) {
|
||||
@SuppressWarnings("all") // suppress dead code warning
|
||||
final boolean error = INITIAL_ITEM_ANIMATION_DURATION >= DROP_IN_ANIMATION_DURATION;
|
||||
if (error) {
|
||||
@@ -194,8 +197,10 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
}
|
||||
|
||||
DeviceProfile grid = activity.getDeviceProfile();
|
||||
FolderIcon icon = (FolderIcon) LayoutInflater.from(group.getContext())
|
||||
.inflate(resId, group, false);
|
||||
LayoutInflater inflater = (group != null)
|
||||
? LayoutInflater.from(group.getContext())
|
||||
: activity.getLayoutInflater();
|
||||
FolderIcon icon = (FolderIcon) inflater.inflate(resId, group, false);
|
||||
|
||||
icon.setClipToPadding(false);
|
||||
icon.mFolderName = icon.findViewById(R.id.folder_icon_name);
|
||||
@@ -279,14 +284,15 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
}
|
||||
|
||||
public void onDragEnter(ItemInfo dragInfo) {
|
||||
if (mFolder.isDestroyed() || !willAcceptItem(dragInfo)) return;
|
||||
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams();
|
||||
if (mFolder.isDestroyed() || !willAcceptItem(dragInfo))
|
||||
return;
|
||||
CellLayoutLayoutParams lp = (CellLayoutLayoutParams) getLayoutParams();
|
||||
CellLayout cl = (CellLayout) getParent().getParent();
|
||||
|
||||
mBackground.animateToAccept(cl, lp.cellX, lp.cellY);
|
||||
mBackground.animateToAccept(cl, lp.getCellX(), lp.getCellY());
|
||||
mOpenAlarm.setOnAlarmListener(mOnOpenListener);
|
||||
if (SPRING_LOADING_ENABLED &&
|
||||
((dragInfo instanceof AppInfo)
|
||||
((dragInfo instanceof WorkspaceItemFactory)
|
||||
|| (dragInfo instanceof WorkspaceItemInfo)
|
||||
|| (dragInfo instanceof PendingAddShortcutInfo))) {
|
||||
mOpenAlarm.setAlarm(ON_OPEN_DELAY);
|
||||
@@ -335,8 +341,10 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
item.cellX = -1;
|
||||
item.cellY = -1;
|
||||
DragView animateView = d.dragView;
|
||||
// Typically, the animateView corresponds to the DragView; however, if this is being done
|
||||
// after a configuration activity (ie. for a Shortcut being dragged from AllApps) we
|
||||
// Typically, the animateView corresponds to the DragView; however, if this is
|
||||
// being done
|
||||
// after a configuration activity (ie. for a Shortcut being dragged from
|
||||
// AllApps) we
|
||||
// will not have a view to animate
|
||||
if (animateView != null && mActivity instanceof Launcher) {
|
||||
final Launcher launcher = (Launcher) mActivity;
|
||||
@@ -344,8 +352,9 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
Rect to = finalRect;
|
||||
if (to == null) {
|
||||
to = new Rect();
|
||||
Workspace workspace = launcher.getWorkspace();
|
||||
// Set cellLayout and this to it's final state to compute final animation locations
|
||||
Workspace<?> workspace = launcher.getWorkspace();
|
||||
// Set cellLayout and this to it's final state to compute final animation
|
||||
// locations
|
||||
workspace.setFinalTransitionTransform();
|
||||
float scaleX = getScaleX();
|
||||
float scaleY = getScaleY();
|
||||
@@ -399,7 +408,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
float finalScale = scale * scaleRelativeToDragLayer;
|
||||
|
||||
// Account for potentially different icon sizes with non-default grid settings
|
||||
if (d.dragSource instanceof AllAppsContainerView) {
|
||||
if (d.dragSource instanceof ActivityAllAppsContainerView) {
|
||||
DeviceProfile grid = mActivity.getDeviceProfile();
|
||||
float containerScale = (1f * grid.iconSizePx / grid.allAppsIconSizePx);
|
||||
finalScale *= containerScale;
|
||||
@@ -412,43 +421,32 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
() -> {
|
||||
mPreviewItemManager.hidePreviewItem(finalIndex, false);
|
||||
mFolder.showItem(item);
|
||||
},
|
||||
},
|
||||
DragLayer.ANIMATION_END_DISAPPEAR, null);
|
||||
|
||||
mFolder.hideItem(item);
|
||||
|
||||
if (!itemAdded) mPreviewItemManager.hidePreviewItem(index, true);
|
||||
if (!itemAdded)
|
||||
mPreviewItemManager.hidePreviewItem(index, true);
|
||||
|
||||
FolderNameInfos nameInfos = new FolderNameInfos();
|
||||
if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
|
||||
Executors.MODEL_EXECUTOR.post(() -> {
|
||||
d.folderNameProvider.getSuggestedFolderName(
|
||||
getContext(), mInfo.contents, nameInfos);
|
||||
showFinalView(finalIndex, item, nameInfos, d.logInstanceId);
|
||||
});
|
||||
} else {
|
||||
showFinalView(finalIndex, item, nameInfos, d.logInstanceId);
|
||||
}
|
||||
Executors.MODEL_EXECUTOR.post(() -> {
|
||||
d.folderNameProvider.getSuggestedFolderName(
|
||||
getContext(), mInfo.contents, nameInfos);
|
||||
postDelayed(() -> {
|
||||
setLabelSuggestion(nameInfos, d.logInstanceId);
|
||||
invalidate();
|
||||
}, DROP_IN_ANIMATION_DURATION);
|
||||
});
|
||||
} else {
|
||||
addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void showFinalView(int finalIndex, final WorkspaceItemInfo item,
|
||||
FolderNameInfos nameInfos, InstanceId instanceId) {
|
||||
postDelayed(() -> {
|
||||
setLabelSuggestion(nameInfos, instanceId);
|
||||
invalidate();
|
||||
}, DROP_IN_ANIMATION_DURATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the suggested folder name.
|
||||
*/
|
||||
public void setLabelSuggestion(FolderNameInfos nameInfos, InstanceId instanceId) {
|
||||
if (!FeatureFlags.FOLDER_NAME_SUGGEST.get()) {
|
||||
return;
|
||||
}
|
||||
if (!mInfo.getLabelState().equals(LabelState.UNLABELED)) {
|
||||
return;
|
||||
}
|
||||
@@ -485,13 +483,12 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
.log(LAUNCHER_FOLDER_AUTO_LABELED);
|
||||
}
|
||||
|
||||
|
||||
public void onDrop(DragObject d, boolean itemReturnedOnFailedDrop) {
|
||||
WorkspaceItemInfo item;
|
||||
if (d.dragInfo instanceof AppInfo) {
|
||||
if (d.dragInfo instanceof WorkspaceItemFactory) {
|
||||
// Came from all apps -- make a copy
|
||||
item = ((AppInfo) d.dragInfo).makeWorkspaceItem();
|
||||
} else if (d.dragSource instanceof BaseItemDragListener){
|
||||
item = ((WorkspaceItemFactory) d.dragInfo).makeWorkspaceItem(getContext());
|
||||
} else if (d.dragSource instanceof BaseItemDragListener) {
|
||||
// Came from a different window -- make a copy
|
||||
item = new WorkspaceItemInfo((WorkspaceItemInfo) d.dragInfo);
|
||||
} else {
|
||||
@@ -500,8 +497,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
mFolder.notifyDrop();
|
||||
onDrop(item, d, null, 1.0f,
|
||||
itemReturnedOnFailedDrop ? item.rank : mInfo.contents.size(),
|
||||
itemReturnedOnFailedDrop
|
||||
);
|
||||
itemReturnedOnFailedDrop);
|
||||
}
|
||||
|
||||
public void setDotInfo(FolderDotInfo dotInfo) {
|
||||
@@ -608,7 +604,8 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
super.dispatchDraw(canvas);
|
||||
|
||||
if (!mBackgroundIsVisible) return;
|
||||
if (!mBackgroundIsVisible)
|
||||
return;
|
||||
|
||||
mPreviewItemManager.recomputePreviewDrawingParams();
|
||||
|
||||
@@ -616,7 +613,8 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
mBackground.drawBackground(canvas);
|
||||
}
|
||||
|
||||
if (mCurrentPreviewItems.isEmpty() && !mAnimating) return;
|
||||
if (mCurrentPreviewItems.isEmpty() && !mAnimating)
|
||||
return;
|
||||
|
||||
mPreviewItemManager.draw(canvas);
|
||||
|
||||
@@ -630,11 +628,15 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
public void drawDot(Canvas canvas) {
|
||||
if (!mForceHideDot && ((mDotInfo != null && mDotInfo.hasDot()) || mDotScale > 0)) {
|
||||
Rect iconBounds = mDotParams.iconBounds;
|
||||
// FolderIcon draws the icon to be top-aligned (with padding) &
|
||||
// horizontally-centered
|
||||
int iconSize = mActivity.getDeviceProfile().iconSizePx;
|
||||
iconBounds.left = (getWidth() - iconSize) / 2;
|
||||
iconBounds.right = iconBounds.left + iconSize;
|
||||
iconBounds.top = getPaddingTop();
|
||||
iconBounds.bottom = iconBounds.top + iconSize;
|
||||
|
||||
Utilities.setRectToViewCenter(this, mActivity.getDeviceProfile().iconSizePx,
|
||||
iconBounds);
|
||||
iconBounds.offsetTo(iconBounds.left, getPaddingTop());
|
||||
float iconScale = (float) mBackground.previewSize / iconBounds.width();
|
||||
float iconScale = (float) mBackground.previewSize / iconSize;
|
||||
Utilities.scaleRectAboutCenter(iconBounds, iconScale);
|
||||
|
||||
// If we are animating to the accepting state, animate the dot out.
|
||||
@@ -724,7 +726,8 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
return false;
|
||||
}
|
||||
|
||||
// Call the superclass onTouchEvent first, because sometimes it changes the state to
|
||||
// Call the superclass onTouchEvent first, because sometimes it changes the
|
||||
// state to
|
||||
// isPressed() on an ACTION_UP
|
||||
super.onTouchEvent(event);
|
||||
mLongPressHelper.onTouchEvent(event);
|
||||
@@ -772,71 +775,23 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
mPreviewItemManager.onFolderClose(currentPage);
|
||||
}
|
||||
|
||||
private void updateTranslation() {
|
||||
super.setTranslationX(mTranslationForReorderBounce.x + mTranslationForReorderPreview.x
|
||||
+ mTranslationForMoveFromCenterAnimation.x
|
||||
+ mTranslationXForTaskbarAlignmentAnimation);
|
||||
super.setTranslationY(mTranslationForReorderBounce.y + mTranslationForReorderPreview.y
|
||||
+ mTranslationForMoveFromCenterAnimation.y);
|
||||
}
|
||||
|
||||
public void setReorderBounceOffset(float x, float y) {
|
||||
mTranslationForReorderBounce.set(x, y);
|
||||
updateTranslation();
|
||||
}
|
||||
|
||||
public void getReorderBounceOffset(PointF offset) {
|
||||
offset.set(mTranslationForReorderBounce);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets translationX value for taskbar to launcher alignment animation
|
||||
*/
|
||||
public void setTranslationForTaskbarAlignmentAnimation(float translationX) {
|
||||
mTranslationXForTaskbarAlignmentAnimation = translationX;
|
||||
updateTranslation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns translation values for taskbar to launcher alignment animation
|
||||
*/
|
||||
public float getTranslationXForTaskbarAlignmentAnimation() {
|
||||
return mTranslationXForTaskbarAlignmentAnimation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets translation values for move from center animation
|
||||
*/
|
||||
public void setTranslationForMoveFromCenterAnimation(float x, float y) {
|
||||
mTranslationForMoveFromCenterAnimation.set(x, y);
|
||||
updateTranslation();
|
||||
@Override
|
||||
public MultiTranslateDelegate getTranslateDelegate() {
|
||||
return mTranslateDelegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReorderPreviewOffset(float x, float y) {
|
||||
mTranslationForReorderPreview.set(x, y);
|
||||
updateTranslation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getReorderPreviewOffset(PointF offset) {
|
||||
offset.set(mTranslationForReorderPreview);
|
||||
}
|
||||
|
||||
public void setReorderBounceScale(float scale) {
|
||||
mScaleForReorderBounce = scale;
|
||||
super.setScaleX(scale);
|
||||
super.setScaleY(scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getReorderBounceScale() {
|
||||
return mScaleForReorderBounce;
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewType() {
|
||||
return DRAGGABLE_ICON;
|
||||
@@ -861,16 +816,20 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface that provides callbacks to a parent ViewGroup that hosts this FolderIcon.
|
||||
* Interface that provides callbacks to a parent ViewGroup that hosts this
|
||||
* FolderIcon.
|
||||
*/
|
||||
public interface FolderIconParent {
|
||||
/**
|
||||
* Tells the FolderIconParent to draw a "leave-behind" when the Folder is open and leaving a
|
||||
* Tells the FolderIconParent to draw a "leave-behind" when the Folder is open
|
||||
* and leaving a
|
||||
* gap where the FolderIcon would be when the Folder is closed.
|
||||
*/
|
||||
void drawFolderLeaveBehindForIcon(FolderIcon child);
|
||||
|
||||
/**
|
||||
* Tells the FolderIconParent to stop drawing the "leave-behind" as the Folder is closed.
|
||||
* Tells the FolderIconParent to stop drawing the "leave-behind" as the Folder
|
||||
* is closed.
|
||||
*/
|
||||
void clearFolderLeaveBehind(FolderIcon child);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user