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

Commit 0fa656b9 authored by Chong Zhang's avatar Chong Zhang
Browse files

Allow apps to pass in launch bounds when moving/starting a task

Pass in bounds via ActivityOptions for moveTaskToFront and
startActivityFromRecents. Allow bounds to be overriden by rects
in starting intents.

Set bounds to null in RecentsView for full screen layout.

Change-Id: I0ff79fd75068f4ba82d5e2c0a21881fabebdadb8
parent ed76be0c
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.app;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.IRemoteCallback;
@@ -58,6 +59,13 @@ public class ActivityOptions {
     */
    public static final String KEY_PACKAGE_NAME = "android:activity.packageName";

    /**
     * The bounds that the activity should be started in. Set to null explicitly
     * for full screen. If the key is not found, previous bounds will be preserved.
     * @hide
     */
    public static final String KEY_BOUNDS = "android:activity.bounds";

    /**
     * Type of animation that arguments specify.
     * @hide
@@ -163,6 +171,8 @@ public class ActivityOptions {
    public static final int ANIM_CLIP_REVEAL = 11;

    private String mPackageName;
    private boolean mHasBounds;
    private Rect mBounds;
    private int mAnimationType = ANIM_NONE;
    private int mCustomEnterResId;
    private int mCustomExitResId;
@@ -631,6 +641,10 @@ public class ActivityOptions {
        } catch (RuntimeException e) {
            Slog.w(TAG, e);
        }
        mHasBounds = opts.containsKey(KEY_BOUNDS);
        if (mHasBounds) {
            mBounds = opts.getParcelable(KEY_BOUNDS);
        }
        mAnimationType = opts.getInt(KEY_ANIM_TYPE);
        switch (mAnimationType) {
            case ANIM_CUSTOM:
@@ -676,11 +690,28 @@ public class ActivityOptions {
        }
    }

    /** @hide */
    public ActivityOptions setBounds(Rect bounds) {
        mHasBounds = true;
        mBounds = bounds;
        return this;
    }

    /** @hide */
    public String getPackageName() {
        return mPackageName;
    }

    /** @hide */
    public boolean hasBounds() {
        return mHasBounds;
    }

    /** @hide */
    public Rect getBounds(){
        return mBounds;
    }

    /** @hide */
    public int getAnimationType() {
        return mAnimationType;
@@ -867,6 +898,9 @@ public class ActivityOptions {
        if (mPackageName != null) {
            b.putString(KEY_PACKAGE_NAME, mPackageName);
        }
        if (mHasBounds) {
            b.putParcelable(KEY_BOUNDS, mBounds);
        }
        b.putInt(KEY_ANIM_TYPE, mAnimationType);
        if (mUsageTimeReport != null) {
            b.putParcelable(KEY_USAGE_TIME_REPORT, mUsageTimeReport);
+9 −5
Original line number Diff line number Diff line
@@ -197,6 +197,7 @@ public class RecentsResizeTaskDialog extends DialogFragment {
                break;
            case PLACE_FULL:
                // Nothing to change.
                mBounds[0] = null;
                break;
        }

@@ -213,10 +214,13 @@ public class RecentsResizeTaskDialog extends DialogFragment {
        dismiss();
        mRecentsActivity.dismissRecentsToHomeWithoutTransitionAnimation();

        // Resize all tasks beginning from the "oldest" one.
        // In debug mode, we force all task to be resizeable regardless of the
        // current app configuration.
        if (RecentsConfiguration.getInstance().multiStackEnabled) {
            for (int i = additionalTasks; i >= 0; --i) {
                if (mTasks[i] != null) {
               mSsp.resizeTask(mTasks[i].key.id, mBounds[i]);
                    mSsp.setTaskResizeable(mTasks[i].key.id);
                }
            }
        }

@@ -224,7 +228,7 @@ public class RecentsResizeTaskDialog extends DialogFragment {
        // the focus ends on the selected one.
        for (int i = additionalTasks; i >= 0; --i) {
            if (mTasks[i] != null) {
                mRecentsView.launchTask(mTasks[i]);
                mRecentsView.launchTask(mTasks[i], mBounds[i]);
            }
        }
    }
+3 −8
Original line number Diff line number Diff line
@@ -271,17 +271,12 @@ public class SystemServicesProxy {
        return null;
    }

    /** Resize a given task. */
    public void resizeTask(int taskId, Rect bounds) {
    /** Allow a task to resize. */
    public void setTaskResizeable(int taskId) {
        if (mIam == null) return;

        try {
            if (RecentsConfiguration.getInstance().multiStackEnabled) {
                // In debug mode, we force all task to be resizeable regardless of the
                // current app configuration.
            mIam.setTaskResizeable(taskId, true);
            }
            mIam.resizeTask(taskId, bounds);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
+16 −10
Original line number Diff line number Diff line
@@ -203,7 +203,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
                TaskView tv = taskViews.get(j);
                Task task = tv.getTask();
                if (tv.isFocusedTask()) {
                    onTaskViewClicked(stackView, tv, stack, task, false);
                    onTaskViewClicked(stackView, tv, stack, task, false, false, null);
                    return true;
                }
            }
@@ -212,7 +212,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
    }

    /** Launches a given task. */
    public boolean launchTask(Task task) {
    public boolean launchTask(Task task, Rect taskBounds) {
        // Get the first stack view
        List<TaskStackView> stackViews = getTaskStackViews();
        int stackCount = stackViews.size();
@@ -225,7 +225,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
            for (int j = 0; j < taskViewCount; j++) {
                TaskView tv = taskViews.get(j);
                if (tv.getTask() == task) {
                    onTaskViewClicked(stackView, tv, stack, task, false);
                    onTaskViewClicked(stackView, tv, stack, task, false, true, taskBounds);
                    return true;
                }
            }
@@ -250,7 +250,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
                    if (tasks.get(j).isLaunchTarget) {
                        Task task = tasks.get(j);
                        TaskView tv = stackView.getChildViewForTask(task);
                        onTaskViewClicked(stackView, tv, stack, task, false);
                        onTaskViewClicked(stackView, tv, stack, task, false, false, null);
                        return true;
                    }
                }
@@ -604,7 +604,8 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV

    @Override
    public void onTaskViewClicked(final TaskStackView stackView, final TaskView tv,
                                  final TaskStack stack, final Task task, final boolean lockToTask) {
                                  final TaskStack stack, final Task task, final boolean lockToTask,
                                  final boolean boundsValid, final Rect bounds) {

        // Notify any callbacks of the launching of a new task
        if (mCb != null) {
@@ -632,9 +633,9 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
        final SystemServicesProxy ssp =
                RecentsTaskLoader.getInstance().getSystemServicesProxy();
        ActivityOptions opts = null;
        ActivityOptions.OnAnimationStartedListener animStartedListener = null;
        if (task.thumbnail != null && task.thumbnail.getWidth() > 0 &&
                task.thumbnail.getHeight() > 0) {
            ActivityOptions.OnAnimationStartedListener animStartedListener = null;
            if (lockToTask) {
                animStartedListener = new ActivityOptions.OnAnimationStartedListener() {
                    boolean mTriggered = false;
@@ -665,9 +666,14 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
                        offsetX, offsetY, transform.rect.width(), transform.rect.height(),
                        sourceView.getHandler(), animStartedListener);
            }
        } else {
            opts = ActivityOptions.makeBasic();
        }
        if (boundsValid) {
            opts.setBounds(bounds);
        }

        final ActivityOptions launchOpts = opts;
        final boolean screenPinningRequested = (animStartedListener == null) && lockToTask;
        final Runnable launchRunnable = new Runnable() {
            @Override
            public void run() {
@@ -677,7 +683,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
                } else {
                    if (ssp.startActivityFromRecents(getContext(), task.key.id,
                            task.activityLabel, launchOpts)) {
                        if (launchOpts == null && lockToTask) {
                        if (screenPinningRequested) {
                            mCb.onScreenPinningRequest();
                        }
                    } else {
+2 −2
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
    /** The TaskView callbacks */
    interface TaskStackViewCallbacks {
        public void onTaskViewClicked(TaskStackView stackView, TaskView tv, TaskStack stack, Task t,
                                      boolean lockToTask);
                                      boolean lockToTask, boolean boundsValid, Rect bounds);
        public void onTaskViewAppInfoClicked(Task t);
        public void onTaskViewDismissed(Task t);
        public void onAllTaskViewsDismissed(ArrayList<Task> removedTasks);
@@ -1377,7 +1377,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal
        mUIDozeTrigger.stopDozing();

        if (mCb != null) {
            mCb.onTaskViewClicked(this, tv, mStack, task, lockToTask);
            mCb.onTaskViewClicked(this, tv, mStack, task, lockToTask, false, null);
        }
    }

Loading