diff --git a/quickstep/src/com/android/launcher3/taskbar/BaseTaskbarContext.java b/quickstep/src/com/android/launcher3/taskbar/BaseTaskbarContext.java index 4e1f54c9a2..b4052e3d71 100644 --- a/quickstep/src/com/android/launcher3/taskbar/BaseTaskbarContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/BaseTaskbarContext.java @@ -19,7 +19,6 @@ import android.content.Context; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; -import com.android.launcher3.DeviceProfile; import com.android.launcher3.DeviceProfile.DeviceProfileListenable; import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener; import com.android.launcher3.util.Themes; @@ -36,8 +35,6 @@ public abstract class BaseTaskbarContext extends ContextThemeWrapper implements protected final LayoutInflater mLayoutInflater; private final List mDPChangeListeners = new ArrayList<>(); - protected DeviceProfile mDeviceProfile; - public BaseTaskbarContext(Context windowContext) { super(windowContext, Themes.getActivityThemeRes(windowContext)); mLayoutInflater = LayoutInflater.from(this).cloneInContext(this); @@ -48,19 +45,11 @@ public abstract class BaseTaskbarContext extends ContextThemeWrapper implements return mLayoutInflater; } - @Override - public final DeviceProfile getDeviceProfile() { - return mDeviceProfile; - } - @Override public final List getOnDeviceProfileChangeListeners() { return mDPChangeListeners; } - /** Updates the {@link DeviceProfile} instance to the latest representation of the screen. */ - public abstract void updateDeviceProfile(DeviceProfile dp); - /** Callback invoked when a drag is initiated within this context. */ public abstract void onDragStart(); diff --git a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java index 582a47e805..9f1e8959ed 100644 --- a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java @@ -528,7 +528,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT if (button.getVisibility() == View.VISIBLE) { parent.getDescendantRectRelativeToSelf(button, mTempRect); if (mHitboxExtender.extendedHitboxEnabled()) { - mTempRect.bottom += mContext.mDeviceProfile.getTaskbarOffsetY(); + mTempRect.bottom += mContext.getDeviceProfile().getTaskbarOffsetY(); } outRegion.op(mTempRect, Op.UNION); } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 46d4642c81..a7f71443d6 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -111,6 +111,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { private final WindowManager mWindowManager; private final @Nullable RoundedCorner mLeftCorner, mRightCorner; + private DeviceProfile mDeviceProfile; private WindowManager.LayoutParams mWindowLayoutParams; private boolean mIsFullscreen; // The size we should return to when we call setTaskbarWindowFullscreen(false) @@ -135,7 +136,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { TaskbarNavButtonController buttonController, ScopedUnfoldTransitionProgressProvider unfoldTransitionProgressProvider) { super(windowContext); - mDeviceProfile = dp; + mDeviceProfile = dp.copy(this); final Resources resources = getResources(); @@ -200,7 +201,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { new TaskbarAutohideSuspendController(this), new TaskbarPopupController(this), new TaskbarForceVisibleImmersiveController(this), - new TaskbarAllAppsController(this), + new TaskbarAllAppsController(this, dp), isDesktopMode ? new DesktopTaskbarRecentAppsController(this) : TaskbarRecentAppsController.DEFAULT, @@ -219,8 +220,14 @@ public class TaskbarActivityContext extends BaseTaskbarContext { } @Override + public DeviceProfile getDeviceProfile() { + return mDeviceProfile; + } + + /** Updates {@link DeviceProfile} instances for any Taskbar windows. */ public void updateDeviceProfile(DeviceProfile dp) { - mDeviceProfile = dp; + mControllers.taskbarAllAppsController.updateDeviceProfile(dp); + mDeviceProfile = dp.copy(this); updateIconSize(getResources()); AbstractFloatingView.closeAllOpenViewsExcept(this, false, TYPE_REBIND_SAFE); @@ -235,7 +242,6 @@ public class TaskbarActivityContext extends BaseTaskbarContext { mDeviceProfile.updateIconSize(1, resources); float iconScale = taskbarIconSize / mDeviceProfile.iconSizePx; mDeviceProfile.updateIconSize(iconScale, resources); - mDeviceProfile.updateAllAppsIconSize(1, resources); // Leave all apps unscaled. } @VisibleForTesting diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java index ef7bab9832..06262c0a25 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java @@ -148,7 +148,7 @@ public class TaskbarManager { // Config change might be handled without re-creating the taskbar if (mTaskbarActivityContext != null) { if (dp != null && dp.isTaskbarPresent) { - mTaskbarActivityContext.updateDeviceProfile(dp.copy(mContext)); + mTaskbarActivityContext.updateDeviceProfile(dp); } mTaskbarActivityContext.onConfigurationChanged(configDiff); } @@ -274,8 +274,8 @@ public class TaskbarManager { return; } - mTaskbarActivityContext = new TaskbarActivityContext(mContext, dp.copy(mContext), - mNavButtonController, mUnfoldProgressProvider); + mTaskbarActivityContext = new TaskbarActivityContext(mContext, dp, mNavButtonController, + mUnfoldProgressProvider); mTaskbarActivityContext.init(mSharedState); if (mActivity != null) { diff --git a/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsContext.java b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsContext.java index 1cdbdb228b..e2f752212e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsContext.java @@ -19,7 +19,6 @@ import static android.view.KeyEvent.ACTION_UP; import static android.view.KeyEvent.KEYCODE_BACK; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; -import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE; import static com.android.systemui.shared.system.ViewTreeObserverWrapper.InsetsInfo.TOUCHABLE_INSETS_REGION; import android.content.Context; @@ -78,14 +77,13 @@ class TaskbarAllAppsContext extends BaseTaskbarContext { TaskbarStashController taskbarStashController) { super(taskbarContext.createWindowContext(TYPE_APPLICATION_OVERLAY, null)); mTaskbarContext = taskbarContext; - mDeviceProfile = taskbarContext.getDeviceProfile(); + mWindowController = windowController; mDragController = new TaskbarDragController(this); mOnboardingPrefs = new OnboardingPrefs<>(this, Utilities.getPrefs(this)); mDragLayer = new TaskbarAllAppsDragLayer(this); TaskbarAllAppsSlideInView slideInView = (TaskbarAllAppsSlideInView) mLayoutInflater.inflate( R.layout.taskbar_all_apps, mDragLayer, false); - mWindowController = windowController; mAllAppsViewController = new TaskbarAllAppsViewController( this, slideInView, @@ -101,6 +99,11 @@ class TaskbarAllAppsContext extends BaseTaskbarContext { return mAllAppsViewController; } + @Override + public DeviceProfile getDeviceProfile() { + return mWindowController.getDeviceProfile(); + } + @Override public TaskbarDragController getDragController() { return mDragController; @@ -141,15 +144,6 @@ class TaskbarAllAppsContext extends BaseTaskbarContext { return mTaskbarContext.getDotInfoForItem(info); } - @Override - public void updateDeviceProfile(DeviceProfile dp) { - mDeviceProfile = dp; - - AbstractFloatingView.closeAllOpenViewsExcept(this, false, TYPE_REBIND_SAFE); - - dispatchDeviceProfileChanged(); - } - @Override public void onDragStart() {} diff --git a/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsController.java b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsController.java index eaf93843ac..6fd98db19a 100644 --- a/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsController.java +++ b/quickstep/src/com/android/launcher3/taskbar/allapps/TaskbarAllAppsController.java @@ -19,6 +19,7 @@ import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_M import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; import static com.android.launcher3.AbstractFloatingView.TYPE_ALL; +import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE; import android.content.Context; import android.graphics.PixelFormat; @@ -31,7 +32,6 @@ import androidx.annotation.Nullable; import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.DeviceProfile; -import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener; import com.android.launcher3.appprediction.PredictionRowView; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.model.data.AppInfo; @@ -55,7 +55,7 @@ import java.util.Optional; * Application data may be bound while the window does not exist, so this controller will store * the models for the next all apps session. */ -public final class TaskbarAllAppsController implements OnDeviceProfileChangeListener { +public final class TaskbarAllAppsController { private static final String WINDOW_TITLE = "Taskbar All Apps"; @@ -70,6 +70,7 @@ public final class TaskbarAllAppsController implements OnDeviceProfileChangeList } }; + private DeviceProfile mDeviceProfile; private TaskbarControllers mControllers; /** Window context for all apps if it is open. */ private @Nullable TaskbarAllAppsContext mAllAppsContext; @@ -79,7 +80,8 @@ public final class TaskbarAllAppsController implements OnDeviceProfileChangeList private int mAppsModelFlags; private List mPredictedApps; - public TaskbarAllAppsController(TaskbarActivityContext context) { + public TaskbarAllAppsController(TaskbarActivityContext context, DeviceProfile dp) { + mDeviceProfile = dp; mTaskbarContext = context; mProxyView = new TaskbarAllAppsProxyView(mTaskbarContext); mLayoutParams = createLayoutParams(); @@ -146,7 +148,6 @@ public final class TaskbarAllAppsController implements OnDeviceProfileChangeList this, mControllers.taskbarStashController); mAllAppsContext.getDragController().init(mControllers); - mTaskbarContext.addOnDeviceProfileChangeListener(this); TaskStackChangeListeners.getInstance().registerTaskStackListener(mTaskStackListener); Optional.ofNullable(mAllAppsContext.getSystemService(WindowManager.class)) .ifPresent(m -> m.addView(mAllAppsContext.getDragLayer(), mLayoutParams)); @@ -184,13 +185,25 @@ public final class TaskbarAllAppsController implements OnDeviceProfileChangeList /** Destroys the controller and any All Apps window if present. */ public void onDestroy() { TaskStackChangeListeners.getInstance().unregisterTaskStackListener(mTaskStackListener); - mTaskbarContext.removeOnDeviceProfileChangeListener(this); Optional.ofNullable(mAllAppsContext) .map(c -> c.getSystemService(WindowManager.class)) .ifPresent(m -> m.removeView(mAllAppsContext.getDragLayer())); mAllAppsContext = null; } + /** Updates {@link DeviceProfile} instance for Taskbar's All Apps window. */ + public void updateDeviceProfile(DeviceProfile dp) { + mDeviceProfile = dp; + Optional.ofNullable(mAllAppsContext).ifPresent(c -> { + AbstractFloatingView.closeAllOpenViewsExcept(c, false, TYPE_REBIND_SAFE); + c.dispatchDeviceProfileChanged(); + }); + } + + DeviceProfile getDeviceProfile() { + return mDeviceProfile; + } + private LayoutParams createLayoutParams() { LayoutParams layoutParams = new LayoutParams( TYPE_APPLICATION_OVERLAY, @@ -205,11 +218,6 @@ public final class TaskbarAllAppsController implements OnDeviceProfileChangeList return layoutParams; } - @Override - public void onDeviceProfileChanged(DeviceProfile dp) { - Optional.ofNullable(mAllAppsContext).ifPresent(c -> c.updateDeviceProfile(dp)); - } - /** * Proxy view connecting taskbar drag layer to the all apps window. *

diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index d7ee3cbc9d..76513a4419 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -268,6 +268,16 @@ public class TouchInteractionService extends Service MAIN_EXECUTOR.execute(ProxyScreenStatusProvider.INSTANCE::onScreenTurnedOn); } + /** + * Preloads the Overview activity. + * + * This method should only be used when the All Set page of the SUW is reached to safely + * preload the Launcher for the SUW first reveal. + */ + public void preloadOverviewForSUWAllSet() { + preloadOverview(false, true); + } + @Override public void onRotationProposal(int rotation, boolean isValid) { executeForTaskbarManager(() -> mTaskbarManager.onRotationProposal(rotation, isValid)); @@ -883,6 +893,10 @@ public class TouchInteractionService extends Service } private void preloadOverview(boolean fromInit) { + preloadOverview(fromInit, false); + } + + private void preloadOverview(boolean fromInit, boolean forSUWAllSet) { if (!mDeviceState.isUserUnlocked()) { return; } @@ -892,7 +906,8 @@ public class TouchInteractionService extends Service return; } - if (RestoreDbTask.isPending(this) || !mDeviceState.isUserSetupComplete()) { + if ((RestoreDbTask.isPending(this) && !forSUWAllSet) + || !mDeviceState.isUserSetupComplete()) { // Preloading while a restore is pending may cause launcher to start the restore // too early. return; diff --git a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java index 3dab6162b3..66ed0561fd 100644 --- a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java +++ b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java @@ -149,45 +149,50 @@ public class AllSetActivity extends Activity { } private void startBackgroundAnimation() { - if (Utilities.ATLEAST_S && mVibrator != null && mVibrator.areAllPrimitivesSupported( - VibrationEffect.Composition.PRIMITIVE_THUD)) { - if (mBackgroundAnimatorListener == null) { - mBackgroundAnimatorListener = - new Animator.AnimatorListener() { - @Override - public void onAnimationStart(Animator animation) { - runOnUiHelperThread(() -> mVibrator.vibrate(getVibrationEffect())); - } - - @Override - public void onAnimationRepeat(Animator animation) { - runOnUiHelperThread(() -> mVibrator.vibrate(getVibrationEffect())); - } - - @Override - public void onAnimationEnd(Animator animation) { - runOnUiHelperThread(mVibrator::cancel); - } - - @Override - public void onAnimationCancel(Animator animation) { - runOnUiHelperThread(mVibrator::cancel); - } - }; - } - mAnimatedBackground.addAnimatorListener(mBackgroundAnimatorListener); + if (!Utilities.ATLEAST_S || mVibrator == null) { + return; } - mAnimatedBackground.playAnimation(); - } + boolean supportsThud = mVibrator.areAllPrimitivesSupported( + VibrationEffect.Composition.PRIMITIVE_THUD); - /** - * Sets up the vibration effect for the next round of animation. The parameters vary between - * different illustrations. - */ - private VibrationEffect getVibrationEffect() { - return VibrationEffect.startComposition() - .addPrimitive(VibrationEffect.Composition.PRIMITIVE_THUD, 1.0f, 50) - .compose(); + if (!supportsThud && !mVibrator.areAllPrimitivesSupported( + VibrationEffect.Composition.PRIMITIVE_TICK)) { + return; + } + if (mBackgroundAnimatorListener == null) { + VibrationEffect vibrationEffect = VibrationEffect.startComposition() + .addPrimitive(supportsThud + ? VibrationEffect.Composition.PRIMITIVE_THUD + : VibrationEffect.Composition.PRIMITIVE_TICK, + /* scale= */ 1.0f, + /* delay= */ 50) + .compose(); + + mBackgroundAnimatorListener = + new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animation) { + runOnUiHelperThread(() -> mVibrator.vibrate(vibrationEffect)); + } + + @Override + public void onAnimationRepeat(Animator animation) { + runOnUiHelperThread(() -> mVibrator.vibrate(vibrationEffect)); + } + + @Override + public void onAnimationEnd(Animator animation) { + runOnUiHelperThread(mVibrator::cancel); + } + + @Override + public void onAnimationCancel(Animator animation) { + runOnUiHelperThread(mVibrator::cancel); + } + }; + } + mAnimatedBackground.addAnimatorListener(mBackgroundAnimatorListener); + mAnimatedBackground.playAnimation(); } @Override @@ -203,6 +208,7 @@ public class AllSetActivity extends Activity { mBinder = binder; mBinder.getTaskbarManager().setSetupUIVisible(isResumed()); mBinder.setSwipeUpProxy(isResumed() ? this::createSwipeUpProxy : null); + mBinder.preloadOverviewForSUWAllSet(); } @Override diff --git a/quickstep/src/com/android/quickstep/views/FloatingTaskView.java b/quickstep/src/com/android/quickstep/views/FloatingTaskView.java index c980d1eac2..45fc3afb25 100644 --- a/quickstep/src/com/android/quickstep/views/FloatingTaskView.java +++ b/quickstep/src/com/android/quickstep/views/FloatingTaskView.java @@ -1,5 +1,6 @@ package com.android.quickstep.views; +import static com.android.launcher3.AbstractFloatingView.TYPE_TASK_MENU; import static com.android.launcher3.anim.Interpolators.ACCEL; import static com.android.launcher3.anim.Interpolators.DEACCEL_3; import static com.android.launcher3.anim.Interpolators.LINEAR; @@ -19,6 +20,7 @@ import android.widget.FrameLayout; import androidx.annotation.Nullable; +import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.BaseActivity; import com.android.launcher3.InsettableFrameLayout; import com.android.launcher3.LauncherAnimUtils; @@ -110,13 +112,19 @@ public class FloatingTaskView extends FrameLayout { */ public static FloatingTaskView getFloatingTaskView(StatefulActivity launcher, View originalView, @Nullable Bitmap thumbnail, Drawable icon, RectF positionOut) { - final BaseDragLayer dragLayer = launcher.getDragLayer(); - ViewGroup parent = (ViewGroup) dragLayer.getParent(); + final ViewGroup dragLayer = launcher.getDragLayer(); final FloatingTaskView floatingView = (FloatingTaskView) launcher.getLayoutInflater() - .inflate(R.layout.floating_split_select_view, parent, false); + .inflate(R.layout.floating_split_select_view, dragLayer, false); floatingView.init(launcher, originalView, thumbnail, icon, positionOut); - parent.addView(floatingView); + // Add this animating view underneath the existing open task menu view (if there is one) + View openTaskView = AbstractFloatingView.getOpenView(launcher, TYPE_TASK_MENU); + int openTaskViewIndex = dragLayer.indexOfChild(openTaskView); + if (openTaskViewIndex == -1) { + // Add to top if not + openTaskViewIndex = dragLayer.getChildCount(); + } + dragLayer.addView(floatingView, openTaskViewIndex - 1); return floatingView; } @@ -125,7 +133,7 @@ public class FloatingTaskView extends FrameLayout { Utilities.getBoundsForViewInDragLayer(mActivity.getDragLayer(), originalView, viewBounds, false /* ignoreTransform */, null /* recycle */, mStartingPosition); - final InsettableFrameLayout.LayoutParams lp = new InsettableFrameLayout.LayoutParams( + final BaseDragLayer.LayoutParams lp = new BaseDragLayer.LayoutParams( Math.round(mStartingPosition.width()), Math.round(mStartingPosition.height())); initPosition(mStartingPosition, lp); diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index a2f67929b3..364bd59b34 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -34,6 +34,7 @@ import static com.android.launcher3.Utilities.squaredTouchSlop; import static com.android.launcher3.anim.Interpolators.ACCEL; import static com.android.launcher3.anim.Interpolators.ACCEL_0_75; import static com.android.launcher3.anim.Interpolators.ACCEL_DEACCEL; +import static com.android.launcher3.anim.Interpolators.DEACCEL_2; import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN; import static com.android.launcher3.anim.Interpolators.FINAL_FRAME; import static com.android.launcher3.anim.Interpolators.LINEAR; @@ -4097,6 +4098,10 @@ public abstract class RecentsView24dp 20dp 32dp + 32dp 110dp 48dp diff --git a/res/values/dimens.xml b/res/values/dimens.xml index e7b3375c4b..39f0a2bc00 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -241,6 +241,7 @@ 16dp 8dp 28dp + 0dp 30dp diff --git a/src/com/android/launcher3/AbstractFloatingView.java b/src/com/android/launcher3/AbstractFloatingView.java index 90869c2965..21dbc5f7e0 100644 --- a/src/com/android/launcher3/AbstractFloatingView.java +++ b/src/com/android/launcher3/AbstractFloatingView.java @@ -93,6 +93,7 @@ public abstract class AbstractFloatingView extends LinearLayout implements Touch public static final int TYPE_WIDGETS_EDUCATION_DIALOG = 1 << 15; public static final int TYPE_TASKBAR_EDUCATION_DIALOG = 1 << 16; public static final int TYPE_TASKBAR_ALL_APPS = 1 << 17; + public static final int TYPE_ADD_TO_HOME_CONFIRMATION = 1 << 18; public static final int TYPE_ALL = TYPE_FOLDER | TYPE_ACTION_POPUP | TYPE_WIDGETS_BOTTOM_SHEET | TYPE_WIDGET_RESIZE_FRAME | TYPE_WIDGETS_FULL_SHEET @@ -100,7 +101,7 @@ public abstract class AbstractFloatingView extends LinearLayout implements Touch | TYPE_OPTIONS_POPUP | TYPE_SNACKBAR | TYPE_LISTENER | TYPE_ALL_APPS_EDU | TYPE_ICON_SURFACE | TYPE_DRAG_DROP_POPUP | TYPE_PIN_WIDGET_FROM_EXTERNAL_POPUP | TYPE_WIDGETS_EDUCATION_DIALOG | TYPE_TASKBAR_EDUCATION_DIALOG | TYPE_TASKBAR_ALL_APPS - | TYPE_OPTIONS_POPUP_DIALOG; + | TYPE_OPTIONS_POPUP_DIALOG | TYPE_ADD_TO_HOME_CONFIRMATION; // Type of popups which should be kept open during launcher rebind public static final int TYPE_REBIND_SAFE = TYPE_WIDGETS_FULL_SHEET diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java index 8da4f053df..3b24df2f18 100644 --- a/src/com/android/launcher3/ButtonDropTarget.java +++ b/src/com/android/launcher3/ButtonDropTarget.java @@ -179,7 +179,12 @@ public abstract class ButtonDropTarget extends TextView @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 @@ public abstract class ButtonDropTarget extends TextView 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 371bb80484..95d3ad9dbb 100644 --- a/src/com/android/launcher3/DeleteDropTarget.java +++ b/src/com/android/launcher3/DeleteDropTarget.java @@ -84,6 +84,9 @@ public class DeleteDropTarget extends ButtonDropTarget { return LauncherAccessibilityDelegate.REMOVE; } + @Override + protected void setupItemInfo(ItemInfo info) {} + @Override protected boolean supportsDrop(ItemInfo info) { return true; diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 1cffa2a7f5..8a82aebbf7 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -217,6 +217,7 @@ public class DeviceProfile { public int dropTargetHorizontalPaddingPx; public int dropTargetVerticalPaddingPx; public int dropTargetGapPx; + public int dropTargetButtonWorkspaceEdgeGapPx; // Insets private final Rect mInsets = new Rect(); @@ -348,6 +349,8 @@ public class DeviceProfile { dropTargetVerticalPaddingPx = res.getDimensionPixelSize( R.dimen.drop_target_button_drawable_vertical_padding); dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap); + dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize( + R.dimen.drop_target_button_workspace_edge_gap); workspaceSpringLoadedBottomSpace = res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space); @@ -789,7 +792,7 @@ public class DeviceProfile { /** * Updates the iconSize for allApps* variants. */ - public void updateAllAppsIconSize(float scale, Resources res) { + private void updateAllAppsIconSize(float scale, Resources res) { allAppsBorderSpacePx = new Point( pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale), pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale)); diff --git a/src/com/android/launcher3/DropTargetBar.java b/src/com/android/launcher3/DropTargetBar.java index dbddb26651..d908440bc8 100644 --- a/src/com/android/launcher3/DropTargetBar.java +++ b/src/com/android/launcher3/DropTargetBar.java @@ -186,14 +186,13 @@ public class DropTargetBar extends FrameLayout availableWidth = scaledPanelWidth - halfButtonGap / 2; } else { // Both buttons plus the button gap do not display past the edge of the scaled - // workspace. - availableWidth = (scaledPanelWidth - dp.dropTargetGapPx) / 2; + // workspace, less a pre-defined gap from the edge of the workspace. + availableWidth = scaledPanelWidth - dp.dropTargetGapPx + - 2 * dp.dropTargetButtonWorkspaceEdgeGapPx; } int widthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST); firstButton.measure(widthSpec, heightSpec); - secondButton.measure(widthSpec, heightSpec); - if (!mIsVertical) { // Remove icons and put the button's text on two lines if text is truncated. if (firstButton.isTextTruncated(availableWidth)) { @@ -202,6 +201,14 @@ public class DropTargetBar extends FrameLayout firstButton.setPadding(horizontalPadding, verticalPadding / 2, horizontalPadding, verticalPadding / 2); } + } + + if (!dp.isTwoPanels) { + availableWidth -= firstButton.getMeasuredWidth() + dp.dropTargetGapPx; + widthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST); + } + secondButton.measure(widthSpec, heightSpec); + if (!mIsVertical) { if (secondButton.isTextTruncated(availableWidth)) { secondButton.setIconVisible(false); secondButton.setTextMultiLine(true); @@ -243,13 +250,30 @@ public class DropTargetBar extends FrameLayout int buttonGap = dp.dropTargetGapPx; ButtonDropTarget leftButton = mTempTargets[0]; - leftButton.layout(barCenter - leftButton.getMeasuredWidth() - (buttonGap / 2), 0, - barCenter - (buttonGap / 2), leftButton.getMeasuredHeight()); - ButtonDropTarget rightButton = mTempTargets[1]; - rightButton.layout(barCenter + (buttonGap / 2), 0, - barCenter + (buttonGap / 2) + rightButton.getMeasuredWidth(), - rightButton.getMeasuredHeight()); + if (dp.isTwoPanels) { + leftButton.layout(barCenter - leftButton.getMeasuredWidth() - (buttonGap / 2), 0, + barCenter - (buttonGap / 2), leftButton.getMeasuredHeight()); + rightButton.layout(barCenter + (buttonGap / 2), 0, + barCenter + (buttonGap / 2) + rightButton.getMeasuredWidth(), + rightButton.getMeasuredHeight()); + } else { + int scaledPanelWidth = (int) (dp.getCellLayoutWidth() * scale); + + int leftButtonWidth = leftButton.getMeasuredWidth(); + int rightButtonWidth = rightButton.getMeasuredWidth(); + int extraSpace = scaledPanelWidth - leftButtonWidth - rightButtonWidth - buttonGap; + + int leftButtonStart = barCenter - (scaledPanelWidth / 2) + extraSpace / 2; + int leftButtonEnd = leftButtonStart + leftButtonWidth; + int rightButtonStart = leftButtonEnd + buttonGap; + int rightButtonEnd = rightButtonStart + rightButtonWidth; + + leftButton.layout(leftButtonStart, 0, leftButtonEnd, + leftButton.getMeasuredHeight()); + rightButton.layout(rightButtonStart, 0, rightButtonEnd, + rightButton.getMeasuredHeight()); + } } } @@ -318,7 +342,7 @@ public class DropTargetBar extends FrameLayout } public ButtonDropTarget[] getDropTargets() { - return mDropTargets; + return getVisibility() == View.VISIBLE ? mDropTargets : new ButtonDropTarget[0]; } @Override diff --git a/src/com/android/launcher3/SecondaryDropTarget.java b/src/com/android/launcher3/SecondaryDropTarget.java index 5b037e4db8..f8bc1f4e6e 100644 --- a/src/com/android/launcher3/SecondaryDropTarget.java +++ b/src/com/android/launcher3/SecondaryDropTarget.java @@ -6,6 +6,7 @@ import static android.appwidget.AppWidgetProviderInfo.WIDGET_FEATURE_RECONFIGURA 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 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList private boolean mHadPendingAlarm; protected int mCurrentAccessibilityAction = -1; + public SecondaryDropTarget(Context context, AttributeSet attrs) { this(context, attrs, 0); } @@ -133,25 +135,34 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList return mCurrentAccessibilityAction; } + @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 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList 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 44d57d7a6b..79214e896a 100644 --- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java +++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java @@ -60,6 +60,7 @@ public class LauncherAccessibilityDelegate extends BaseAccessibilityDelegate