Search in sources :

Example 1 with RunnableList

use of com.android.launcher3.util.RunnableList in project android_packages_apps_Launcher3 by crdroidandroid.

the class QuickstepTransitionManager method getActivityLaunchOptions.

/**
 * @return ActivityOptions with remote animations that controls how the window of the opening
 * targets are displayed.
 */
public ActivityOptionsWrapper getActivityLaunchOptions(View v) {
    boolean fromRecents = isLaunchingFromRecents(v, null);
    RunnableList onEndCallback = new RunnableList();
    mAppLaunchRunner = new AppLaunchAnimationRunner(v, onEndCallback);
    RemoteAnimationRunnerCompat runner = new LauncherAnimationRunner(mHandler, mAppLaunchRunner, true);
    // Note that this duration is a guess as we do not know if the animation will be a
    // recents launch or not for sure until we know the opening app targets.
    long duration = fromRecents ? RECENTS_LAUNCH_DURATION : APP_LAUNCH_DURATION;
    long statusBarTransitionDelay = duration - STATUS_BAR_TRANSITION_DURATION - STATUS_BAR_TRANSITION_PRE_DELAY;
    RemoteAnimationAdapterCompat adapterCompat = new RemoteAnimationAdapterCompat(runner, duration, statusBarTransitionDelay);
    return new ActivityOptionsWrapper(ActivityOptionsCompat.makeRemoteAnimation(adapterCompat), onEndCallback);
}
Also used : RemoteAnimationAdapterCompat(com.android.systemui.shared.system.RemoteAnimationAdapterCompat) ActivityOptionsWrapper(com.android.launcher3.util.ActivityOptionsWrapper) RunnableList(com.android.launcher3.util.RunnableList) RemoteAnimationRunnerCompat(com.android.systemui.shared.system.RemoteAnimationRunnerCompat)

Example 2 with RunnableList

use of com.android.launcher3.util.RunnableList in project android_packages_apps_Launcher3 by crdroidandroid.

the class Workspace method onDrop.

@Override
public void onDrop(final DragObject d, DragOptions options) {
    mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
    CellLayout dropTargetLayout = mDropToLayout;
    // We want the point to be mapped to the dragTarget.
    if (dropTargetLayout != null) {
        mapPointFromDropLayout(dropTargetLayout, mDragViewVisualCenter);
    }
    boolean droppedOnOriginalCell = false;
    int snapScreen = -1;
    boolean resizeOnDrop = false;
    if (d.dragSource != this || mDragInfo == null) {
        final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1] };
        onDropExternal(touchXY, dropTargetLayout, d);
    } else {
        final View cell = mDragInfo.cell;
        final DragView dragView = d.dragView;
        boolean droppedOnOriginalCellDuringTransition = false;
        Runnable onCompleteRunnable = dragView::resumeColorExtraction;
        dragView.disableColorExtraction();
        if (dropTargetLayout != null && !d.cancelled) {
            // Move internally
            boolean hasMovedLayouts = (getParentCellLayoutForView(cell) != dropTargetLayout);
            boolean hasMovedIntoHotseat = mLauncher.isHotseatLayout(dropTargetLayout);
            int container = hasMovedIntoHotseat ? LauncherSettings.Favorites.CONTAINER_HOTSEAT : LauncherSettings.Favorites.CONTAINER_DESKTOP;
            int screenId = (mTargetCell[0] < 0) ? mDragInfo.screenId : getIdForScreen(dropTargetLayout);
            int spanX = mDragInfo != null ? mDragInfo.spanX : 1;
            int spanY = mDragInfo != null ? mDragInfo.spanY : 1;
            // First we find the cell nearest to point at which the item is
            // dropped, without any consideration to whether there is an item there.
            mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], spanX, spanY, dropTargetLayout, mTargetCell);
            float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
            // cell also contains a shortcut, then create a folder with the two shortcuts.
            if (createUserFolderIfNecessary(cell, container, dropTargetLayout, mTargetCell, distance, false, d) || addToExistingFolderIfNecessary(cell, dropTargetLayout, mTargetCell, distance, d, false)) {
                mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
                return;
            }
            // Aside from the special case where we're dropping a shortcut onto a shortcut,
            // we need to find the nearest cell location that is vacant
            ItemInfo item = d.dragInfo;
            int minSpanX = item.spanX;
            int minSpanY = item.spanY;
            if (item.minSpanX > 0 && item.minSpanY > 0) {
                minSpanX = item.minSpanX;
                minSpanY = item.minSpanY;
            }
            droppedOnOriginalCell = item.screenId == screenId && item.container == container && item.cellX == mTargetCell[0] && item.cellY == mTargetCell[1];
            droppedOnOriginalCellDuringTransition = droppedOnOriginalCell && mIsSwitchingState;
            // When quickly moving an item, a user may accidentally rearrange their
            // workspace. So instead we move the icon back safely to its original position.
            boolean returnToOriginalCellToPreventShuffling = !isFinishedSwitchingState() && !droppedOnOriginalCellDuringTransition && !dropTargetLayout.isRegionVacant(mTargetCell[0], mTargetCell[1], spanX, spanY);
            int[] resultSpan = new int[2];
            if (returnToOriginalCellToPreventShuffling) {
                mTargetCell[0] = mTargetCell[1] = -1;
            } else {
                mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, cell, mTargetCell, resultSpan, CellLayout.MODE_ON_DROP);
            }
            boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0;
            // if the widget resizes on drop
            if (foundCell && (cell instanceof AppWidgetHostView) && (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY)) {
                resizeOnDrop = true;
                item.spanX = resultSpan[0];
                item.spanY = resultSpan[1];
                AppWidgetHostView awhv = (AppWidgetHostView) cell;
                WidgetSizes.updateWidgetSizeRanges(awhv, mLauncher, resultSpan[0], resultSpan[1]);
            }
            if (foundCell) {
                if (getScreenIdForPageIndex(mCurrentPage) != screenId && !hasMovedIntoHotseat) {
                    snapScreen = getPageIndexForScreenId(screenId);
                    snapToPage(snapScreen);
                }
                final ItemInfo info = (ItemInfo) cell.getTag();
                if (hasMovedLayouts) {
                    // Reparent the view
                    CellLayout parentCell = getParentCellLayoutForView(cell);
                    if (parentCell != null) {
                        parentCell.removeView(cell);
                    } else if (mDragInfo.cell instanceof LauncherAppWidgetHostView) {
                        d.dragView.detachContentView(/* reattachToPreviousParent= */
                        false);
                    } else if (FeatureFlags.IS_STUDIO_BUILD) {
                        throw new NullPointerException("mDragInfo.cell has null parent");
                    }
                    addInScreen(cell, container, screenId, mTargetCell[0], mTargetCell[1], info.spanX, info.spanY);
                }
                // update the item's position after drop
                CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
                lp.cellX = lp.tmpCellX = mTargetCell[0];
                lp.cellY = lp.tmpCellY = mTargetCell[1];
                lp.cellHSpan = item.spanX;
                lp.cellVSpan = item.spanY;
                lp.isLockedToGrid = true;
                if (container != LauncherSettings.Favorites.CONTAINER_HOTSEAT && cell instanceof LauncherAppWidgetHostView) {
                    final CellLayout cellLayout = dropTargetLayout;
                    // We post this call so that the widget has a chance to be placed
                    // in its final location
                    final LauncherAppWidgetHostView hostView = (LauncherAppWidgetHostView) cell;
                    AppWidgetProviderInfo pInfo = hostView.getAppWidgetInfo();
                    if (pInfo != null && !options.isAccessibleDrag) {
                        final Runnable previousRunnable = onCompleteRunnable;
                        onCompleteRunnable = () -> {
                            previousRunnable.run();
                            if (!isPageInTransition()) {
                                AppWidgetResizeFrame.showForWidget(hostView, cellLayout);
                            }
                        };
                    }
                }
                mLauncher.getModelWriter().modifyItemInDatabase(info, container, screenId, lp.cellX, lp.cellY, item.spanX, item.spanY);
            } else {
                if (!returnToOriginalCellToPreventShuffling) {
                    onNoCellFound(dropTargetLayout);
                }
                if (mDragInfo.cell instanceof LauncherAppWidgetHostView) {
                    d.dragView.detachContentView(/* reattachToPreviousParent= */
                    true);
                }
                // If we can't find a drop location, we return the item to its original position
                CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
                mTargetCell[0] = lp.cellX;
                mTargetCell[1] = lp.cellY;
                CellLayout layout = (CellLayout) cell.getParent().getParent();
                layout.markCellsAsOccupiedForView(cell);
            }
        } else {
            // When drag is cancelled, reattach content view back to its original parent.
            if (mDragInfo.cell instanceof LauncherAppWidgetHostView) {
                d.dragView.detachContentView(/* reattachToPreviousParent= */
                true);
            }
        }
        final CellLayout parent = (CellLayout) cell.getParent().getParent();
        if (d.dragView.hasDrawn()) {
            if (droppedOnOriginalCellDuringTransition) {
                // Animate the item to its original position, while simultaneously exiting
                // spring-loaded mode so the page meets the icon where it was picked up.
                final RunnableList callbackList = new RunnableList();
                final Runnable onCompleteCallback = onCompleteRunnable;
                mLauncher.getDragController().animateDragViewToOriginalPosition(/* onComplete= */
                callbackList::executeAllAndDestroy, cell, SPRING_LOADED.getTransitionDuration(mLauncher));
                mLauncher.getStateManager().goToState(NORMAL, /* delay= */
                0, onCompleteCallback == null ? null : forSuccessCallback(() -> callbackList.add(onCompleteCallback)));
                mLauncher.getDropTargetBar().onDragEnd();
                parent.onDropChild(cell);
                return;
            }
            final ItemInfo info = (ItemInfo) cell.getTag();
            boolean isWidget = info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET || info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
            if (isWidget) {
                int animationType = resizeOnDrop ? ANIMATE_INTO_POSITION_AND_RESIZE : ANIMATE_INTO_POSITION_AND_DISAPPEAR;
                animateWidgetDrop(info, parent, d.dragView, null, animationType, cell, false);
            } else {
                int duration = snapScreen < 0 ? -1 : ADJACENT_SCREEN_DROP_DURATION;
                mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, cell, duration, this);
            }
        } else {
            d.deferDragViewCleanupPostAnimation = false;
            cell.setVisibility(VISIBLE);
        }
        parent.onDropChild(cell);
        mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY, forSuccessCallback(onCompleteRunnable));
        mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId).log(LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED);
    }
    if (d.stateAnnouncer != null && !droppedOnOriginalCell) {
        d.stateAnnouncer.completeAction(R.string.item_moved);
    }
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) DragView(com.android.launcher3.dragndrop.DragView) DraggableView(com.android.launcher3.dragndrop.DraggableView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) RunnableList(com.android.launcher3.util.RunnableList) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView)

Example 3 with RunnableList

use of com.android.launcher3.util.RunnableList in project android_packages_apps_Launcher3 by crdroidandroid.

the class OverviewCommandHelper method launchTask.

private boolean launchTask(RecentsView recents, @Nullable TaskView taskView, CommandInfo cmd) {
    RunnableList callbackList = null;
    if (taskView != null) {
        taskView.setEndQuickswitchCuj(true);
        callbackList = taskView.launchTaskAnimated();
    }
    if (callbackList != null) {
        callbackList.add(() -> scheduleNextTask(cmd));
        return false;
    } else {
        recents.startHome();
        return true;
    }
}
Also used : RunnableList(com.android.launcher3.util.RunnableList)

Example 4 with RunnableList

use of com.android.launcher3.util.RunnableList in project android_packages_apps_Launcher3 by crdroidandroid.

the class RecentsActivity method getActivityLaunchOptions.

@Override
public ActivityOptionsWrapper getActivityLaunchOptions(final View v, @Nullable ItemInfo item) {
    if (!(v instanceof TaskView)) {
        return super.getActivityLaunchOptions(v, item);
    }
    final TaskView taskView = (TaskView) v;
    RunnableList onEndCallback = new RunnableList();
    mActivityLaunchAnimationRunner = new RemoteAnimationFactory() {

        @Override
        public void onCreateAnimation(int transit, RemoteAnimationTargetCompat[] appTargets, RemoteAnimationTargetCompat[] wallpaperTargets, RemoteAnimationTargetCompat[] nonAppTargets, AnimationResult result) {
            AnimatorSet anim = composeRecentsLaunchAnimator(taskView, appTargets, wallpaperTargets, nonAppTargets);
            anim.addListener(resetStateListener());
            result.setAnimation(anim, RecentsActivity.this, onEndCallback::executeAllAndDestroy, true);
        }

        @Override
        public void onAnimationCancelled() {
            onEndCallback.executeAllAndDestroy();
        }
    };
    final LauncherAnimationRunner wrapper = new LauncherAnimationRunner(mUiHandler, mActivityLaunchAnimationRunner, true);
    RemoteAnimationAdapterCompat adapterCompat = new RemoteAnimationAdapterCompat(wrapper, RECENTS_LAUNCH_DURATION, RECENTS_LAUNCH_DURATION - STATUS_BAR_TRANSITION_DURATION - STATUS_BAR_TRANSITION_PRE_DELAY);
    final ActivityOptionsWrapper activityOptions = new ActivityOptionsWrapper(ActivityOptionsCompat.makeRemoteAnimation(adapterCompat), onEndCallback);
    activityOptions.options.setSplashscreenStyle(SplashScreen.SPLASH_SCREEN_STYLE_ICON);
    return activityOptions;
}
Also used : RemoteAnimationAdapterCompat(com.android.systemui.shared.system.RemoteAnimationAdapterCompat) TaskView(com.android.quickstep.views.TaskView) RemoteAnimationFactory(com.android.launcher3.LauncherAnimationRunner.RemoteAnimationFactory) RemoteAnimationTargetCompat(com.android.systemui.shared.system.RemoteAnimationTargetCompat) AnimationResult(com.android.launcher3.LauncherAnimationRunner.AnimationResult) ActivityOptionsWrapper(com.android.launcher3.util.ActivityOptionsWrapper) AnimatorSet(android.animation.AnimatorSet) LauncherAnimationRunner(com.android.launcher3.LauncherAnimationRunner) RunnableList(com.android.launcher3.util.RunnableList)

Example 5 with RunnableList

use of com.android.launcher3.util.RunnableList in project android_packages_apps_Launcher3 by crdroidandroid.

the class TaskView method launchTaskAnimated.

/**
 * Starts the task associated with this view and animates the startup.
 * @return CompletionStage to indicate the animation completion or null if the launch failed.
 */
public RunnableList launchTaskAnimated() {
    if (mTask != null) {
        TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "startActivityFromRecentsAsync", mTask);
        ActivityOptionsWrapper opts = mActivity.getActivityLaunchOptions(this, null);
        if (ActivityManagerWrapper.getInstance().startActivityFromRecents(mTask.key, opts.options)) {
            if (ENABLE_QUICKSTEP_LIVE_TILE.get() && getRecentsView().getRunningTaskId() != -1) {
                // Return a fresh callback in the live tile case, so that it's not accidentally
                // triggered by QuickstepTransitionManager.AppLaunchAnimationRunner.
                RunnableList callbackList = new RunnableList();
                getRecentsView().addSideTaskLaunchCallback(callbackList);
                return callbackList;
            }
            return opts.onEndCallback;
        } else {
            notifyTaskLaunchFailed(TAG);
            return null;
        }
    } else {
        return null;
    }
}
Also used : ActivityOptionsWrapper(com.android.launcher3.util.ActivityOptionsWrapper) RunnableList(com.android.launcher3.util.RunnableList)

Aggregations

RunnableList (com.android.launcher3.util.RunnableList)6 ActivityOptionsWrapper (com.android.launcher3.util.ActivityOptionsWrapper)4 Point (android.graphics.Point)2 RemoteAnimationAdapterCompat (com.android.systemui.shared.system.RemoteAnimationAdapterCompat)2 AnimatorSet (android.animation.AnimatorSet)1 SuppressLint (android.annotation.SuppressLint)1 ActivityOptions (android.app.ActivityOptions)1 AppWidgetHostView (android.appwidget.AppWidgetHostView)1 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)1 Rect (android.graphics.Rect)1 Drawable (android.graphics.drawable.Drawable)1 View (android.view.View)1 NonNull (androidx.annotation.NonNull)1 LauncherAnimationRunner (com.android.launcher3.LauncherAnimationRunner)1 AnimationResult (com.android.launcher3.LauncherAnimationRunner.AnimationResult)1 RemoteAnimationFactory (com.android.launcher3.LauncherAnimationRunner.RemoteAnimationFactory)1 DragView (com.android.launcher3.dragndrop.DragView)1 DraggableView (com.android.launcher3.dragndrop.DraggableView)1 ItemInfo (com.android.launcher3.model.data.ItemInfo)1 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)1