fix: Conflict incoming changes from 15-dev

This commit is contained in:
Pun Butrach committed 2026-01-10 20:49:12 +07:00
1 parent 14e352c827
commit 2e76c99dad
1726 files changed
+146970 -95027

No files matched your search

+222 -125
View File
@@ -28,6 +28,8 @@ import static com.android.launcher3.folder.FolderGridOrganizer.createFolderGridO
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_LABEL_UPDATED;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED;
import static com.android.launcher3.model.data.FolderInfo.willAcceptItemType;
import static com.android.launcher3.pageindicators.PaginationArrow.DISABLED_ARROW_OPACITY;
import static com.android.launcher3.pageindicators.PaginationArrow.FULLY_OPAQUE;
import static com.android.launcher3.testing.shared.TestProtocol.FOLDER_OPENED_MESSAGE;
import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs;
@@ -42,8 +44,10 @@ import android.graphics.Canvas;
import android.graphics.Insets;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.hardware.input.InputManager;
import android.os.Looper;
import android.text.InputType;
import android.text.Selection;
@@ -53,6 +57,8 @@ import android.util.Log;
import android.util.Pair;
import android.util.TypedValue;
import android.view.FocusFinder;
import android.view.Gravity;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -62,12 +68,14 @@ import android.view.WindowInsets;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.EditorInfo;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.view.WindowInsetsCompat;
@@ -78,6 +86,7 @@ import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget;
import com.android.launcher3.ExtendedEditText;
import com.android.launcher3.Flags;
import com.android.launcher3.Launcher;
import com.android.launcher3.OnAlarmListener;
import com.android.launcher3.R;
@@ -88,9 +97,11 @@ import com.android.launcher3.accessibility.FolderAccessibilityHelper;
import com.android.launcher3.anim.KeyboardInsetAnimationCallback;
import com.android.launcher3.compat.AccessibilityManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dagger.LauncherComponentProvider;
import com.android.launcher3.dragndrop.DragController.DragListener;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.graphics.ShapeDelegate;
import com.android.launcher3.graphics.ThemeManager;
import com.android.launcher3.logger.LauncherAtom.FromState;
import com.android.launcher3.logger.LauncherAtom.ToState;
import com.android.launcher3.logging.StatsLogManager;
@@ -100,6 +111,7 @@ 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.pageindicators.PageIndicatorDots;
import com.android.launcher3.pageindicators.PaginationArrow;
import com.android.launcher3.util.Executors;
import com.android.launcher3.util.LauncherBindableItemsContainer;
import com.android.launcher3.util.Themes;
@@ -133,9 +145,9 @@ import app.lawnchair.util.LawnchairUtilsKt;
* Represents a set of icons chosen by the user or generated by the system.
*/
public class Folder extends AbstractFloatingView implements ClipPathView, DragSource,
View.OnLongClickListener, DropTarget, TextView.OnEditorActionListener,
View.OnFocusChangeListener, DragListener, ExtendedEditText.OnBackKeyListener,
LauncherBindableItemsContainer {
View.OnLongClickListener, DropTarget, TextView.OnEditorActionListener,
View.OnFocusChangeListener, DragListener, ExtendedEditText.OnBackKeyListener,
LauncherBindableItemsContainer {
private static final String TAG = "Launcher.Folder";
private static final boolean DEBUG = false;
@@ -206,7 +218,6 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
protected LauncherDelegate mLauncherDelegate;
protected final ActivityContext mActivityContext;
protected DragController mDragController;
public FolderInfo mInfo;
private CharSequence mFromTitle;
private FromState mFromLabelState;
@@ -218,8 +229,10 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
FolderPagedView mContent;
FolderNameEditText mFolderName;
private PageIndicatorDots mPageIndicator;
private PaginationArrow mLeftArrow;
private PaginationArrow mRightArrow;
protected View mFooter;
protected LinearLayout mFooter;
private int mFooterHeight;
// Cell ranks used for drag and drop
@@ -229,14 +242,14 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
private Path mClipPath;
@ViewDebug.ExportedProperty(category = "launcher",
mapping = {
@ViewDebug.IntToString(from = STATE_CLOSED, to = "STATE_CLOSED"),
@ViewDebug.IntToString(from = STATE_ANIMATING, to = "STATE_ANIMATING"),
@ViewDebug.IntToString(from = STATE_OPEN, to = "STATE_OPEN"),
})
mapping = {
@ViewDebug.IntToString(from = STATE_CLOSED, to = "STATE_CLOSED"),
@ViewDebug.IntToString(from = STATE_ANIMATING, to = "STATE_ANIMATING"),
@ViewDebug.IntToString(from = STATE_OPEN, to = "STATE_OPEN"),
})
private int mState = STATE_CLOSED;
private final List<OnFolderStateChangedListener> mOnFolderStateChangedListeners =
new ArrayList<>();
new ArrayList<>();
private OnFolderStateChangedListener mPriorityOnFolderStateChangedListener;
@ViewDebug.ExportedProperty(category = "launcher")
private boolean mRearrangeOnClose = false;
@@ -293,8 +306,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
setFocusableInTouchMode(true);
mBackground = (GradientDrawable) Objects.requireNonNull(
ResourcesCompat.getDrawable(getResources(),
R.drawable.round_rect_folder, getContext().getTheme()));
ResourcesCompat.getDrawable(getResources(),
R.drawable.round_rect_folder, getContext().getTheme()));
mBackground.setCallback(this);
preferenceManager2 = PreferenceManager2.INSTANCE.get(context);
}
@@ -311,7 +324,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
final int paddingLeftRight = dp.folderContentPaddingLeftRight;
mBackground = DrawableTokens.RoundRectFolder.resolve(getContext());
// TODO-Myself: this is interesting, we can customise this.
// pE-TODO: this is interesting, we can customise this.
var alpha = LawnchairUtilsKt.getFolderBackgroundAlpha(getContext());
mBackground.setAlpha(alpha);
@@ -320,24 +333,20 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
mContent.setFolder(this);
mPageIndicator = findViewById(R.id.folder_page_indicator);
if (enableLauncherVisualRefresh()) {
MarginLayoutParams params = ((MarginLayoutParams) mPageIndicator.getLayoutParams());
int horizontalMargin = getContext().getResources()
.getDimensionPixelSize(R.dimen.folder_footer_horiz_padding);
params.setMarginStart(horizontalMargin);
params.setMarginEnd(horizontalMargin);
}
mFooter = findViewById(R.id.folder_footer);
mFooterHeight = dp.folderFooterHeightPx;
mFolderName = findViewById(R.id.folder_name);
if (Flags.enableLauncherVisualRefresh()) {
mFolderName.setTypeface(Typeface.create("google-sans-flex", Typeface.NORMAL));
}
mFolderName.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp.folderLabelTextSizePx);
mFolderName.setOnBackKeyListener(this);
mFolderName.setOnEditorActionListener(this);
mFolderName.setSelectAllOnFocus(true);
mFolderName.setInputType(mFolderName.getInputType()
& ~InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
| InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
| InputType.TYPE_TEXT_FLAG_CAP_WORDS);
& ~InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
| InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
| InputType.TYPE_TEXT_FLAG_CAP_WORDS);
mFolderName.forceDisableSuggestions(true);
@ColorInt
@@ -353,6 +362,76 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
mKeyboardInsetAnimationCallback = new KeyboardInsetAnimationCallback(this);
setWindowInsetsAnimationCallback(mKeyboardInsetAnimationCallback);
}
if (enableLauncherVisualRefresh()) {
// pE-TODO(QPR1): Investigate
// mLeftArrow = findViewById(R.id.left_indicator_arrow);
// mRightArrow = findViewById(R.id.right_indicator_arrow);
// mRightArrow.setOnClickListener(v -> mContent.snapToPage(
// mContent.getCurrentPage() + 1));
// mLeftArrow.setOnClickListener(v -> mContent.snapToPage(
// mContent.getCurrentPage() - 1));
}
}
/**
* If indicator is visible, set margin between folder title and indicator. Also properly show
* arrows if pointer is enabled and indicator is visible.
*/
public void onIndicatorVisibilityChanged() {
if (mPageIndicator.getVisibility() == View.VISIBLE) {
((MarginLayoutParams) mFolderName.getLayoutParams()).setMarginEnd(
getResources().getDimensionPixelSize(R.dimen.folder_footer_horiz_padding));
Context ctx = getContext(); // done here to avoid getting context on bg thread
Executors.UI_HELPER_EXECUTOR.execute(() -> {
// Only show arrows if a mouse or touchpad is connected to the device
int arrowVisibility = isPointerEnabled(ctx) ? View.VISIBLE : View.GONE;
mLeftArrow.setVisibility(arrowVisibility);
mRightArrow.setVisibility(arrowVisibility);
// If the arrows are visible, then their touch box will slightly overlap with the
// footer's padding by 8dp. Update it for proper alignment. PaddingEnd was always
// equal to paddingRight in both LTR & RTL mode, so isRtl is manually accounted for
int endPadding = getResources().getDimensionPixelSize(
arrowVisibility == View.VISIBLE
? R.dimen.folder_footer_horiz_padding_minus_arrow_overlap
: R.dimen.folder_footer_horiz_padding);
boolean isRtl = Utilities.isRtl(getResources());
mFooter.setPadding(
isRtl ? endPadding : mFooter.getPaddingLeft(),
mFooter.getPaddingTop(),
isRtl ? mFooter.getPaddingRight() : endPadding,
mFooter.getPaddingBottom()
);
});
} else {
((MarginLayoutParams) mFolderName.getLayoutParams()).setMarginEnd(0);
mLeftArrow.setVisibility(View.GONE);
mRightArrow.setVisibility(View.GONE);
}
}
@WorkerThread
private boolean isPointerEnabled(Context context) {
InputManager im = context.getSystemService(InputManager.class);
return Arrays.stream(im.getInputDeviceIds())
.mapToObj(im::getInputDevice)
.anyMatch(device -> device.isEnabled()
&& (device.supportsSource(InputDevice.SOURCE_MOUSE)
|| device.supportsSource(InputDevice.SOURCE_TOUCHPAD)));
}
/**
* Called when the page is switched. Sets arrow UX to a disabled appearance if the page is at
* one end or the other.
*/
public void updateArrowAlphas() {
if (enableLauncherVisualRefresh()) {
mLeftArrow.setAlpha(
0 == mContent.getCurrentPage() ? DISABLED_ARROW_OPACITY : FULLY_OPAQUE);
mRightArrow.setAlpha(mContent.getPageCount() == mContent.getCurrentPage() + 1
? DISABLED_ARROW_OPACITY : FULLY_OPAQUE);
}
}
public boolean onLongClick(View v) {
@@ -388,19 +467,19 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
}
void addDragListener(DragOptions options) {
getDragController().addDragListener(this);
mActivityContext.getDragController().addDragListener(this);
if (!options.isAccessibleDrag) {
return;
}
getDragController().addDragListener(new AccessibleDragListenerAdapter(
mContent, FolderAccessibilityHelper::new) {
mActivityContext.getDragController().addDragListener(new AccessibleDragListenerAdapter(
mContent, FolderAccessibilityHelper::new) {
@Override
protected void enableAccessibleDrag(boolean enable,
@Nullable DragObject dragObject) {
@Nullable DragObject dragObject) {
super.enableAccessibleDrag(enable, dragObject);
mFooter.setImportantForAccessibility(enable
? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
: IMPORTANT_FOR_ACCESSIBILITY_AUTO);
? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
: IMPORTANT_FOR_ACCESSIBILITY_AUTO);
}
});
}
@@ -437,7 +516,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
completeDragExit();
}
mIsDragInProgress = false;
getDragController().removeDragListener(this);
mActivityContext.getDragController().removeDragListener(this);
}
public void startEditingFolderName() {
@@ -454,7 +533,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
if (DEBUG) {
Log.d(TAG, "onBackKey newTitle=" + newTitle);
}
mInfo.setTitle(newTitle, mLauncherDelegate.getModelWriter());
mInfo.setTitle(newTitle, mActivityContext.getModelWriter());
mFolderIcon.onTitleChanged(newTitle);
if (TextUtils.isEmpty(mInfo.title)) {
@@ -465,8 +544,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
}
sendCustomAccessibilityEvent(
this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
getContext().getString(R.string.folder_renamed, newTitle));
this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
getContext().getString(R.string.folder_renamed, newTitle));
// This ensures that focus is gained every time the field is clicked, which selects all
// the text and brings up the soft keyboard if necessary.
@@ -480,7 +559,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (DEBUG) {
Log.d(TAG, "onEditorAction actionId=" + actionId + " key="
+ (event != null ? event.getKeyCode() : "null event"));
+ (event != null ? event.getKeyCode() : "null event"));
}
if (actionId == EditorInfo.IME_ACTION_DONE) {
mFolderName.dispatchBackKey();
@@ -492,6 +571,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
@Override
public WindowInsets onApplyWindowInsets(WindowInsets windowInsets) {
this.setTranslationY(0);
// Lawnchair-TODO: Keyboard too close to Folder name edit?
try {
if (windowInsets.isVisible(WindowInsets.Type.ime())) {
@@ -526,17 +607,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
return mFolderIcon;
}
DragController getDragController() {
return mDragController;
}
void setDragController(DragController dragController) {
mDragController = dragController;
}
public void setFolderIcon(FolderIcon icon) {
mFolderIcon = icon;
mLauncherDelegate.init(this, icon);
}
@Override
@@ -626,12 +698,12 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
}
mFolderName.showKeyboard();
mFolderName.displayCompletions(
Stream.of(mInfo.suggestedFolderNames.getLabels())
.filter(Objects::nonNull)
.map(Object::toString)
.filter(s -> !s.isEmpty())
.filter(s -> !s.equalsIgnoreCase(mFolderName.getText().toString()))
.collect(Collectors.toList()));
Stream.of(mInfo.suggestedFolderNames.getLabels())
.filter(Objects::nonNull)
.map(Object::toString)
.filter(s -> !s.isEmpty())
.filter(s -> !s.equalsIgnoreCase(mFolderName.getText().toString()))
.collect(Collectors.toList()));
}
}
@@ -645,12 +717,12 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
@SuppressLint("InflateParams")
static <T extends Context & ActivityContext> Folder fromXml(T activityContext) {
return (Folder) LayoutInflater.from(activityContext).cloneInContext(activityContext)
.inflate(R.layout.user_folder_icon_normalized, null);
.inflate(R.layout.user_folder_icon_normalized, null);
}
private void addAnimationStartListeners(AnimatorSet a) {
mLauncherDelegate.forEachVisibleWorkspacePage(
visiblePage -> addAnimatorListenerForPage(a, (CellLayout) visiblePage));
visiblePage -> addAnimatorListenerForPage(a, (CellLayout) visiblePage));
a.addListener(new AnimatorListenerAdapter() {
@Override
@@ -709,7 +781,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
// Since this folder opened by another controller, it might not get onDrop or
// onDropComplete. Perform cleanup once drag-n-drop ends.
getDragController().addDragListener(this);
mActivityContext.getDragController().addDragListener(this);
ArrayList<ItemInfo> items = new ArrayList<>(mInfo.getContents());
mEmptyCellRank = items.size();
@@ -752,22 +824,22 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
// There was a one-off crash where the folder had a parent already.
if (getParent() == null) {
dragLayer.addView(this);
getDragController().addDropTarget(this);
mActivityContext.getDragController().addDropTarget(this);
} else {
if (FeatureFlags.IS_STUDIO_BUILD) {
Log.e(TAG, "Opening folder (" + this + ") which already has a parent:"
+ getParent());
+ getParent());
}
}
Log.d("b/383526431", "animateOpen: content child count before: "
+ mContent.getTotalChildCount());
+ mContent.getTotalChildCount());
mContent.completePendingPageChanges();
mContent.setCurrentPage(pageNo);
Log.d("b/383526431", "animateOpen: content child count after pending page"
+ " changes: " + mContent.getTotalChildCount());
+ " changes: " + mContent.getTotalChildCount());
// This is set to true in close(), but isn't reset to false until onDropCompleted(). This
// leads to an inconsistent state if you drag out of the folder and drag back in without
@@ -776,10 +848,12 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
cancelRunningAnimations();
Log.d("b/383526431", "animateOpen: content child count after cancelling"
+ " animation: " + mContent.getTotalChildCount());
FolderAnimationManager fam = new FolderAnimationManager(this, true /* isOpening */);
AnimatorSet anim = fam.getAnimator();
anim.addListener(new AnimatorListenerAdapter() {
+ " animation: " + mContent.getTotalChildCount());
AnimatorSet animatorSet = getFolderAnimationManager()
.createAnimatorSet(/* isOpening */ true);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
mFolderIcon.setIconVisible(false);
@@ -791,7 +865,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
setState(STATE_OPEN);
announceAccessibilityChanges();
AccessibilityManagerCompat.sendTestProtocolEventToTest(getContext(),
FOLDER_OPENED_MESSAGE);
FOLDER_OPENED_MESSAGE);
mContent.setFocusOnFirstChild();
}
@@ -800,7 +874,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
// Footer animation
if (mContent.getPageCount() > 1 && !mInfo.hasOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION)) {
int footerWidth = mContent.getDesiredWidth()
- mFooter.getPaddingLeft() - mFooter.getPaddingRight();
- mFooter.getPaddingLeft() - mFooter.getPaddingRight();
float textWidth = mFolderName.getPaint().measureText(mFolderName.getText().toString());
float translation = (footerWidth - textWidth) / 2;
@@ -810,20 +884,20 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
// Do not update the flag if we are in drag mode. The flag will be updated, when we
// actually drop the icon.
final boolean updateAnimationFlag = !mIsDragInProgress;
anim.addListener(new AnimatorListenerAdapter() {
animatorSet.addListener(new AnimatorListenerAdapter() {
@SuppressLint("InlinedApi")
@Override
public void onAnimationEnd(Animator animation) {
mFolderName.animate().setDuration(FOLDER_NAME_ANIMATION_DURATION)
.translationX(0)
.setInterpolator(AnimationUtils.loadInterpolator(
getContext(), android.R.interpolator.fast_out_slow_in));
.translationX(0)
.setInterpolator(AnimationUtils.loadInterpolator(
getContext(), android.R.interpolator.fast_out_slow_in));
mPageIndicator.playEntryAnimation();
if (updateAnimationFlag) {
mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true,
mLauncherDelegate.getModelWriter());
mActivityContext.getModelWriter());
}
}
});
@@ -836,16 +910,18 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
// b/282158620 because setCurrentPlayTime() below will start animator, we need to register
// {@link AnimatorListener} before it so that {@link AnimatorListener#onAnimationStart} can
// be called to register mCurrentAnimator, which will be used to cancel animator
addAnimationStartListeners(anim);
addAnimationStartListeners(animatorSet);
// Because t=0 has the folder match the folder icon, we can skip the
// first frame and have the same movement one frame earlier.
Log.d("b/311077782", "Folder.animateOpen");
anim.setCurrentPlayTime(Math.min(getSingleFrameMs(getContext()), anim.getTotalDuration()));
anim.start();
animatorSet.setCurrentPlayTime(Math.min(
getSingleFrameMs(getContext()), animatorSet.getTotalDuration()));
animatorSet.start();
// Make sure the folder picks up the last drag move even if the finger doesn't move.
if (getDragController().isDragging()) {
getDragController().forceTouchMove();
if (mActivityContext.getDragController().isDragging()) {
mActivityContext.getDragController().forceTouchMove();
}
mContent.verifyVisibleHighResIcons(mContent.getNextPage());
}
@@ -861,6 +937,20 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
return true;
}
private FolderAnimationCreator getFolderAnimationManager() {
boolean shouldUseSpringMotion = Flags.enableLauncherIconShapes()
&& Flags.enableExpressiveFolderExpansion();
if (shouldUseSpringMotion) {
ShapeDelegate shapeDelegate =
ThemeManager.INSTANCE.get(mActivityContext.asContext()).getFolderShape();
return new FolderAnimationSpringBuilderManager(
this, shapeDelegate, mLauncherDelegate
);
} else {
return new FolderAnimationManager(this);
}
}
/**
* If there's a folder already open, we want to close it before opening another one.
*/
@@ -906,7 +996,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
// Notify the accessibility manager that this folder "window" has disappeared and no
// longer occludes the workspace items
mActivityContext.getDragLayer().sendAccessibilityEvent(
AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
}
private void cancelRunningAnimations() {
@@ -932,8 +1022,10 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
mContent.snapToPageImmediately(mContent.getDestinationPage());
cancelRunningAnimations();
AnimatorSet a = new FolderAnimationManager(this, false /* isOpening */).getAnimator();
a.addListener(new AnimatorListenerAdapter() {
AnimatorSet animatorSet = getFolderAnimationManager()
.createAnimatorSet(/* isOpening */ false);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
if (Utilities.ATLEAST_R) {
@@ -954,14 +1046,14 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
mIsAnimatingClosed = false;
}
});
addAnimationStartListeners(a);
a.start();
addAnimationStartListeners(animatorSet);
animatorSet.start();
}
@Override
protected Pair<View, String> getAccessibilityTarget() {
return Pair.create(mContent, mIsOpen ? mContent.getAccessibilityDescription()
: getContext().getString(R.string.folder_closed));
: getContext().getString(R.string.folder_closed));
}
@Override
@@ -976,7 +1068,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
if (parent != null) {
parent.removeView(this);
}
getDragController().removeDropTarget(this);
mActivityContext.getDragController().removeDropTarget(this);
clearFocus();
if (mFolderIcon != null) {
mFolderIcon.setVisibility(View.VISIBLE);
@@ -1038,7 +1130,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
private int getTargetRank(DragObject d, float[] recycle) {
recycle = d.getVisualCenter(recycle);
return mContent.findNearestArea(
(int) recycle[0] - getPaddingLeft(), (int) recycle[1] - getPaddingTop());
(int) recycle[0] - getPaddingLeft(), (int) recycle[1] - getPaddingTop());
}
@Override
@@ -1057,7 +1149,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
if (d.stateAnnouncer != null) {
d.stateAnnouncer.announce(getContext().getString(R.string.move_to_position,
mTargetRank + 1));
mTargetRank + 1));
}
}
@@ -1065,14 +1157,14 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
int currentPage = mContent.getNextPage();
float cellOverlap = mContent.getCurrentCellLayout().getCellWidth()
* ICON_OVERSCROLL_WIDTH_FACTOR;
* ICON_OVERSCROLL_WIDTH_FACTOR;
boolean isOutsideLeftEdge = x < cellOverlap;
boolean isOutsideRightEdge = x > (getWidth() - cellOverlap);
if (currentPage > 0 && (mContent.mIsRtl ? isOutsideRightEdge : isOutsideLeftEdge)) {
showScrollHint(SCROLL_LEFT, d);
} else if (currentPage < (mContent.getPageCount() - 1)
&& (mContent.mIsRtl ? isOutsideLeftEdge : isOutsideRightEdge)) {
&& (mContent.mIsRtl ? isOutsideLeftEdge : isOutsideRightEdge)) {
showScrollHint(SCROLL_RIGHT, d);
} else {
mOnScrollHintAlarm.cancelAlarm();
@@ -1161,20 +1253,20 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
@Override
public void onDropCompleted(final View target, final DragObject d,
final boolean success) {
final boolean success) {
if (success) {
if (getItemCount() <= 1) {
mDeleteFolderOnDropCompleted = true;
}
if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon
&& target != this) {
&& target != this) {
replaceFolderWithFinalItem();
}
} else {
// The drag failed, we need to return the item to the folder
ItemInfo info = d.dragInfo;
View icon = (mCurrentDragView != null && mCurrentDragView.getTag() == info)
? mCurrentDragView : mContent.createNewView(info);
? mCurrentDragView : mContent.createNewView(info);
ArrayList<View> views = getIconsInReadingOrder();
if (!views.contains(icon)) {
info.rank = Utilities.boundToRange(info.rank, 0, views.size());
@@ -1183,7 +1275,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
mItemsInvalidated = true;
executeWithContentUpdateSuppressed(
() -> mFolderIcon.onDrop(d, true /* itemReturnedOnFailedDrop */));
() -> mFolderIcon.onDrop(d, true /* itemReturnedOnFailedDrop */));
}
}
@@ -1211,13 +1303,14 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
if (getItemCount() <= mContent.itemsPerPage()) {
// Show the animation, next time something is added to the folder.
mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, false,
mLauncherDelegate.getModelWriter());
mActivityContext.getModelWriter());
}
}
private void updateItemLocationsInDatabaseBatch(boolean isBind) {
FolderGridOrganizer verifier = createFolderGridOrganizer(
mActivityContext.getDeviceProfile()).setFolderInfo(mInfo);
mActivityContext.getDeviceProfile()
).setFolderInfo(mInfo);
ArrayList<ItemInfo> items = new ArrayList<>();
int total = mInfo.getContents().size();
@@ -1229,15 +1322,12 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
}
if (!items.isEmpty()) {
mLauncherDelegate.getModelWriter().moveItemsInDatabase(items, mInfo.id, 0);
mActivityContext.getModelWriter().moveItemsInDatabase(items, mInfo.id, 0);
}
if (!isBind && total > 1 /* no need to update if there's one icon */) {
Executors.MODEL_EXECUTOR.post(() -> {
FolderNameInfos nameInfos = new FolderNameInfos();
FolderNameProvider fnp = FolderNameProvider.newInstance(getContext());
fnp.getSuggestedFolderName(getContext(), mInfo.getAppContents(), nameInfos);
mInfo.suggestedFolderNames = nameInfos;
});
LauncherComponentProvider.get(getContext()).getFolderNameSuggestionLoader()
.getSuggestedFolderName(mInfo.getAppContents(),
folderNameInfos -> mInfo.suggestedFolderNames = folderNameInfos);
}
}
@@ -1286,15 +1376,15 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
protected int getContentAreaHeight() {
int height = Math.min(getMaxContentAreaHeight(),
mContent.getDesiredHeight());
mContent.getDesiredHeight());
return Math.max(height, MIN_CONTENT_DIMEN);
}
@VisibleForTesting
int getMaxContentAreaHeight() {
DeviceProfile grid = mActivityContext.getDeviceProfile();
return grid.availableHeightPx - grid.getTotalWorkspacePadding().y
- getFooterHeight();
return grid.getDeviceProperties().getAvailableHeightPx() - grid.getTotalWorkspacePadding().y
- getFooterHeight();
}
@VisibleForTesting
@@ -1333,7 +1423,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
mContent.measure(contentAreaWidthSpec, contentAreaHeightSpec);
mFooter.measure(contentAreaWidthSpec,
MeasureSpec.makeMeasureSpec(mFooterHeight, MeasureSpec.EXACTLY));
MeasureSpec.makeMeasureSpec(mFooterHeight, MeasureSpec.EXACTLY));
int folderWidth = getPaddingLeft() + getPaddingRight() + contentWidth;
int folderHeight = getFolderHeight(contentHeight);
@@ -1353,7 +1443,10 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
super.onSizeChanged(w, h, oldw, oldh);
int minTitleWidth = getResources().getDimensionPixelSize(R.dimen.folder_title_min_width);
if (enableLauncherVisualRefresh() && mFolderName.getMeasuredWidth() < minTitleWidth) {
mFolderName.setVisibility(View.GONE);
((MarginLayoutParams) mFolderName.getLayoutParams()).setMarginEnd(0);
// The post is necessary for margins to be recalculated. RTL UI is shifted otherwise.
mFolderName.post(() -> mFolderName.setVisibility(View.GONE));
mFooter.setGravity(Gravity.END);
}
}
@@ -1404,7 +1497,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
boolean isShiftPlusTab = keyCode == KeyEvent.KEYCODE_TAB &&
event.hasModifiers(KeyEvent.META_SHIFT_ON);
event.hasModifiers(KeyEvent.META_SHIFT_ON);
if (isShiftPlusTab && Folder.this.isFocused()) {
return lastChild.requestFocus();
}
@@ -1437,16 +1530,16 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
}
PendingAddShortcutInfo pasi = d.dragInfo instanceof PendingAddShortcutInfo
? (PendingAddShortcutInfo) d.dragInfo : null;
? (PendingAddShortcutInfo) d.dragInfo : null;
WorkspaceItemInfo pasiSi =
pasi != null ? pasi.getActivityInfo(launcher).createWorkspaceItemInfo() : null;
pasi != null ? pasi.getActivityInfo(launcher).createWorkspaceItemInfo() : null;
if (pasi != null && pasiSi == null) {
// There is no WorkspaceItemInfo, so we have to go through a configuration activity.
pasi.container = mInfo.id;
pasi.rank = mEmptyCellRank;
launcher.addPendingItem(pasi, pasi.container, pasi.screenId, null, pasi.spanX,
pasi.spanY);
pasi.spanY);
d.deferDragViewCleanupPostAnimation = false;
mRearrangeOnClose = true;
} else {
@@ -1467,8 +1560,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
// Actually move the item in the database if it was an external drag. Call this
// before creating the view, so that the ItemInfo is updated appropriately.
mLauncherDelegate.getModelWriter().addOrMoveItemInDatabase(
si, mInfo.id, 0, si.cellX, si.cellY);
mActivityContext.getModelWriter().addOrMoveItemInDatabase(
si, mInfo.id, 0, si.cellX, si.cellY);
mIsExternalDrag = false;
} else {
currentDragView = mCurrentDragView;
@@ -1509,7 +1602,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
if (mContent.getPageCount() > 1) {
// The animation has already been shown while opening the folder.
mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true,
mLauncherDelegate.getModelWriter());
mActivityContext.getModelWriter());
}
if (!launcher.isInState(EDIT_MODE)) {
@@ -1520,7 +1613,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
d.stateAnnouncer.completeAction(R.string.item_moved);
}
mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId)
.log(LAUNCHER_ITEM_DROP_COMPLETED);
.log(LAUNCHER_ITEM_DROP_COMPLETED);
}
// This is used so the item doesn't immediately appear in the folder when added. In one case
@@ -1556,11 +1649,11 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
if (!mSuppressContentUpdate) {
FolderGridOrganizer verifier = createFolderGridOrganizer(
mActivityContext.getDeviceProfile()).setFolderInfo(mInfo);
mActivityContext.getDeviceProfile()).setFolderInfo(mInfo);
verifier.updateRankAndPos(item, rank);
mLauncherDelegate.getModelWriter().addOrMoveItemInDatabase(item, mInfo.id, 0,
item.cellX,
item.cellY);
mActivityContext.getModelWriter().addOrMoveItemInDatabase(item, mInfo.id, 0,
item.cellX,
item.cellY);
updateItemLocationsInDatabaseBatch(false);
if (mContent.areViewsBound()) {
@@ -1570,7 +1663,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
updateTextViewFocus();
}
mLauncherDelegate.getModelWriter().notifyItemModified(mInfo);
mActivityContext.getModelWriter().notifyItemModified(mInfo);
mFolderIcon.onItemsChanged(animate);
}
@@ -1578,7 +1671,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
public void removeFolderContent(boolean animate, ItemInfo... items) {
List<ItemInfo> itemArray = Arrays.asList(items);
if (mInfo.getContents().removeAll(itemArray)) {
mLauncherDelegate.getModelWriter().notifyItemModified(mInfo);
mActivityContext.getModelWriter().notifyItemModified(mInfo);
}
if (!mSuppressContentUpdate) {
@@ -1607,6 +1700,11 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
return mContent.iterateOverItems((info, view) -> info == item);
}
@Override
public boolean isContainerSupported(int container) {
return container == mInfo.id;
}
/**
* Utility methods to iterate over items of the view
*/
@@ -1634,8 +1732,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
int totalItemsInFolder = allItems.size();
int itemsPerPage = mContent.itemsPerPage();
int numItemsOnCurrentPage = page == lastPage
? totalItemsInFolder - (itemsPerPage * page)
: itemsPerPage;
? totalItemsInFolder - (itemsPerPage * page)
: itemsPerPage;
int startIndex = page * itemsPerPage;
int endIndex = Math.min(startIndex + numItemsOnCurrentPage, allItems.size());
@@ -1656,8 +1754,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
post(this::startEditingFolderName);
} else {
StatsLogger statsLogger = mStatsLogManager.logger()
.withItemInfo(mInfo)
.withFromState(mFromLabelState);
.withItemInfo(mInfo)
.withFromState(mFromLabelState);
// If the folder label is suggested, it is logged to improve prediction model.
// When both old and new labels are logged together delimiter is used.
@@ -1722,7 +1820,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
// Pause drag event until the scrolling is finished
mScrollPauseAlarm.setOnAlarmListener(new OnScrollFinishedListener(mDragObject));
int rescrollDelay = getResources().getInteger(
R.integer.config_pageSnapAnimationDuration) + RESCROLL_EXTRA_DELAY;
R.integer.config_pageSnapAnimationDuration) + RESCROLL_EXTRA_DELAY;
mScrollPauseAlarm.setAlarm(rescrollDelay);
}
}
@@ -1801,7 +1899,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
}
return false;
} else if (!dl.isEventOverView(this, ev)
&& mLauncherDelegate.interceptOutsideTouch(ev, dl, this)) {
&& mLauncherDelegate.interceptOutsideTouch(ev, dl, this)) {
return true;
}
}
@@ -1905,7 +2003,6 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
mFolderName = value;
}
@VisibleForTesting
FolderNameEditText getFolderName() {
return mFolderName;
}
@@ -1934,7 +2031,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
private int getHeightFromBottom() {
BaseDragLayer.LayoutParams layoutParams = (BaseDragLayer.LayoutParams) getLayoutParams();
int folderBottomPx = layoutParams.y + layoutParams.height;
int windowBottomPx = mActivityContext.getDeviceProfile().heightPx;
int windowBottomPx = mActivityContext.getDeviceProfile().getDeviceProperties().getHeightPx();
return windowBottomPx - folderBottomPx;
}