Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 27c28f8d authored by Winson's avatar Winson Committed by Winson Chung
Browse files

Fix exception when docking task.

- If a task fails to dock, animate the stack back to original state so 
  that the layout is not stuck in a "docked" state.

Bug: 28577229
Change-Id: If927b898a48cd5949764cb3b0c0798d22efd850a
parent 7e2d589c
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -70,7 +70,6 @@ import com.android.systemui.recents.events.ui.ShowIncompatibleAppOverlayEvent;
import com.android.systemui.recents.events.ui.StackViewScrolledEvent;
import com.android.systemui.recents.events.ui.UpdateFreeformTaskViewVisibilityEvent;
import com.android.systemui.recents.events.ui.UserInteractionEvent;
import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent;
import com.android.systemui.recents.events.ui.focus.DismissFocusedTaskViewEvent;
import com.android.systemui.recents.events.ui.focus.FocusNextTaskViewEvent;
import com.android.systemui.recents.events.ui.focus.FocusPreviousTaskViewEvent;
@@ -90,7 +89,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;

/**
 * The main Recents activity that is started from AlternateRecentsComponent.
 * The main Recents activity that is started from RecentsComponent.
 */
public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreDrawListener {

@@ -760,13 +759,6 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        mIgnoreAltTabRelease = true;
    }

    public final void onBusEvent(final DragEndEvent event) {
        // Handle the case where we drop onto a dock region
        if (event.dropTarget instanceof TaskStack.DockState) {
            mScrimViews.animateScrimToCurrentNavBarState(false /* hasStackTasks */);
        }
    }

    public final void onBusEvent(final DockedTopTaskEvent event) {
        mRecentsView.getViewTreeObserver().addOnPreDrawListener(mRecentsDrawnEventListener);
        mRecentsView.invalidate();
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.recents.events.ui.dragndrop;

import com.android.systemui.recents.events.EventBus;
import com.android.systemui.recents.model.Task;
import com.android.systemui.recents.model.TaskStack;
import com.android.systemui.recents.views.DropTarget;
import com.android.systemui.recents.views.TaskView;

/**
 * This event is sent whenever a drag end is cancelled because of an error.
 */
public class DragEndCancelledEvent extends EventBus.AnimatedEvent {

    public final TaskStack stack;
    public final Task task;
    public final TaskView taskView;

    public DragEndCancelledEvent(TaskStack stack, Task task, TaskView taskView) {
        this.stack = stack;
        this.task = task;
        this.taskView = taskView;
    }
}
+5 −4
Original line number Diff line number Diff line
@@ -393,18 +393,19 @@ public class SystemServicesProxy {
    }

    /** Docks a task to the side of the screen and starts it. */
    public void startTaskInDockedMode(int taskId, int createMode) {
        if (mIam == null) return;
    public boolean startTaskInDockedMode(int taskId, int createMode) {
        if (mIam == null) return false;

        try {
            // TODO: Determine what animation we want for the incoming task
            final ActivityOptions options = ActivityOptions.makeBasic();
            options.setDockCreateMode(createMode);
            options.setLaunchStackId(DOCKED_STACK_ID);
            mIam.startActivityFromRecents(taskId, options.toBundle());
        } catch (RemoteException e) {
            return true;
        } catch (RemoteException | IllegalArgumentException e) {
            e.printStackTrace();
        }
        return false;
    }

    /** Docks an already resumed task to the side of the screen. */
+12 −0
Original line number Diff line number Diff line
@@ -225,6 +225,18 @@ public class Utilities {
        animator.removeAllListeners();
    }

    /**
     * Sets the given {@link View}'s frame from its current translation.
     */
    public static void setViewFrameFromTranslation(View v) {
        RectF taskViewRect = new RectF(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
        taskViewRect.offset(v.getTranslationX(), v.getTranslationY());
        v.setTranslationX(0);
        v.setTranslationY(0);
        v.setLeftTopRightBottom((int) taskViewRect.left, (int) taskViewRect.top,
                (int) taskViewRect.right, (int) taskViewRect.bottom);
    }

    /**
     * Returns a view stub for the given view id.
     */
+41 −36
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import com.android.systemui.recents.events.ui.DismissAllTaskViewsEvent;
import com.android.systemui.recents.events.ui.DraggingInRecentsEndedEvent;
import com.android.systemui.recents.events.ui.DraggingInRecentsEvent;
import com.android.systemui.recents.events.ui.dragndrop.DragDropTargetChangedEvent;
import com.android.systemui.recents.events.ui.dragndrop.DragEndCancelledEvent;
import com.android.systemui.recents.events.ui.dragndrop.DragEndEvent;
import com.android.systemui.recents.events.ui.dragndrop.DragStartEvent;
import com.android.systemui.recents.misc.ReferenceCountedTrigger;
@@ -510,17 +511,13 @@ public class RecentsView extends FrameLayout {

            // We translated the view but we need to animate it back from the current layout-space
            // rect to its final layout-space rect
            int x = (int) event.taskView.getTranslationX();
            int y = (int) event.taskView.getTranslationY();
            Rect taskViewRect = new Rect(event.taskView.getLeft(), event.taskView.getTop(),
                    event.taskView.getRight(), event.taskView.getBottom());
            taskViewRect.offset(x, y);
            event.taskView.setTranslationX(0);
            event.taskView.setTranslationY(0);
            event.taskView.setLeftTopRightBottom(taskViewRect.left, taskViewRect.top,
                    taskViewRect.right, taskViewRect.bottom);

            final OnAnimationStartedListener startedListener = new OnAnimationStartedListener() {
            Utilities.setViewFrameFromTranslation(event.taskView);

            // Dock the task and launch it
            SystemServicesProxy ssp = Recents.getSystemServices();
            if (ssp.startTaskInDockedMode(event.task.key.id, dockState.createMode)) {
                final OnAnimationStartedListener startedListener =
                        new OnAnimationStartedListener() {
                    @Override
                    public void onAnimationStarted() {
                        EventBus.getDefault().send(new DockedFirstAnimationFrameEvent());
@@ -531,11 +528,9 @@ public class RecentsView extends FrameLayout {
                    }
                };

            // Dock the task and launch it
            SystemServicesProxy ssp = Recents.getSystemServices();
            ssp.startTaskInDockedMode(event.task.key.id, dockState.createMode);
                final Rect taskRect = getTaskRect(event.taskView);
            IAppTransitionAnimationSpecsFuture future = mTransitionHelper.getAppTransitionFuture(
                IAppTransitionAnimationSpecsFuture future =
                        mTransitionHelper.getAppTransitionFuture(
                                new AnimationSpecComposer() {
                                    @Override
                                    public List<AppTransitionAnimationSpec> composeSpecs() {
@@ -549,6 +544,10 @@ public class RecentsView extends FrameLayout {

                MetricsLogger.action(mContext, MetricsEvent.ACTION_WINDOW_DOCK_DRAG_DROP,
                        event.task.getTopComponent().flattenToShortString());
            } else {
                EventBus.getDefault().send(new DragEndCancelledEvent(mStack, event.task,
                        event.taskView));
            }
        } else {
            // Animate the overlay alpha back to 0
            updateVisibleDockRegions(null, true /* isDefaultDockState */, -1, -1,
@@ -565,6 +564,12 @@ public class RecentsView extends FrameLayout {
        }
    }

    public final void onBusEvent(final DragEndCancelledEvent event) {
        // Animate the overlay alpha back to 0
        updateVisibleDockRegions(null, true /* isDefaultDockState */, -1, -1,
                true /* animateAlpha */, false /* animateBounds */);
    }

    private Rect getTaskRect(TaskView taskView) {
        int[] location = taskView.getLocationOnScreen();
        int viewX = location[0];
Loading