Search in sources :

Example 21 with ActivityOptions

use of android.app.ActivityOptions in project platform_frameworks_base by android.

the class RecentsTvTransitionHelper method launchTaskFromRecents.

public void launchTaskFromRecents(final TaskStack stack, @Nullable final Task task, final TaskStackHorizontalGridView stackView, final TaskCardView taskView, final Rect bounds, int destinationStack) {
    final ActivityOptions opts = ActivityOptions.makeBasic();
    if (bounds != null) {
        opts.setLaunchBounds(bounds.isEmpty() ? null : bounds);
    }
    final ActivityOptions.OnAnimationStartedListener animStartedListener;
    if (task.thumbnail != null && task.thumbnail.getWidth() > 0 && task.thumbnail.getHeight() > 0) {
        animStartedListener = new ActivityOptions.OnAnimationStartedListener() {

            @Override
            public void onAnimationStarted() {
                // If we are launching into another task, cancel the previous task's
                // window transition
                EventBus.getDefault().send(new CancelEnterRecentsWindowAnimationEvent(task));
                EventBus.getDefault().send(new ExitRecentsWindowFirstAnimationFrameEvent());
            }
        };
    } else {
        // This is only the case if the task is not on screen (scrolled offscreen for example)
        animStartedListener = new ActivityOptions.OnAnimationStartedListener() {

            @Override
            public void onAnimationStarted() {
                EventBus.getDefault().send(new ExitRecentsWindowFirstAnimationFrameEvent());
            }
        };
    }
    if (taskView == null) {
        // If there is no task view, then we do not need to worry about animating out occluding
        // task views, and we can launch immediately
        startTaskActivity(stack, task, taskView, opts, animStartedListener);
    } else {
        LaunchTvTaskStartedEvent launchStartedEvent = new LaunchTvTaskStartedEvent(taskView);
        EventBus.getDefault().send(launchStartedEvent);
        startTaskActivity(stack, task, taskView, opts, animStartedListener);
    }
}
Also used : ActivityOptions(android.app.ActivityOptions)

Example 22 with ActivityOptions

use of android.app.ActivityOptions in project platform_frameworks_base by android.

the class RecentsImpl method startRecentsActivity.

/**
     * Shows the recents activity
     */
protected void startRecentsActivity(ActivityManager.RunningTaskInfo runningTask, boolean isHomeStackVisible, boolean animate, int growTarget) {
    RecentsTaskLoader loader = Recents.getTaskLoader();
    RecentsActivityLaunchState launchState = Recents.getConfiguration().getLaunchState();
    SystemServicesProxy ssp = Recents.getSystemServices();
    boolean isBlacklisted = (runningTask != null) ? ssp.isBlackListedActivity(runningTask.baseActivity.getClassName()) : false;
    int runningTaskId = !mLaunchedWhileDocking && !isBlacklisted && (runningTask != null) ? runningTask.id : -1;
    // the stacks might have changed.
    if (mLaunchedWhileDocking || mTriggeredFromAltTab || sInstanceLoadPlan == null) {
        // Create a new load plan if preloadRecents() was never triggered
        sInstanceLoadPlan = loader.createLoadPlan(mContext);
    }
    if (mLaunchedWhileDocking || mTriggeredFromAltTab || !sInstanceLoadPlan.hasTasks()) {
        loader.preloadTasks(sInstanceLoadPlan, runningTaskId, !isHomeStackVisible);
    }
    TaskStack stack = sInstanceLoadPlan.getTaskStack();
    boolean hasRecentTasks = stack.getTaskCount() > 0;
    boolean useThumbnailTransition = (runningTask != null) && !isHomeStackVisible && hasRecentTasks;
    // Update the launch state that we need in updateHeaderBarLayout()
    launchState.launchedFromHome = !useThumbnailTransition && !mLaunchedWhileDocking;
    launchState.launchedFromApp = useThumbnailTransition || mLaunchedWhileDocking;
    launchState.launchedFromBlacklistedApp = launchState.launchedFromApp && isBlacklisted;
    launchState.launchedViaDockGesture = mLaunchedWhileDocking;
    launchState.launchedViaDragGesture = mDraggingInRecents;
    launchState.launchedToTaskId = runningTaskId;
    launchState.launchedWithAltTab = mTriggeredFromAltTab;
    // Preload the icon (this will be a null-op if we have preloaded the icon already in
    // preloadRecents())
    preloadIcon(runningTaskId);
    // Update the header bar if necessary
    Rect windowOverrideRect = getWindowRectOverride(growTarget);
    updateHeaderBarLayout(stack, windowOverrideRect);
    // Prepare the dummy stack for the transition
    TaskStackLayoutAlgorithm.VisibilityReport stackVr = mDummyStackView.computeStackVisibilityReport();
    // Update the remaining launch state
    launchState.launchedNumVisibleTasks = stackVr.numVisibleTasks;
    launchState.launchedNumVisibleThumbnails = stackVr.numVisibleThumbnails;
    if (!animate) {
        startRecentsActivity(ActivityOptions.makeCustomAnimation(mContext, -1, -1));
        return;
    }
    ActivityOptions opts;
    if (isBlacklisted) {
        opts = getUnknownTransitionActivityOptions();
    } else if (useThumbnailTransition) {
        // Try starting with a thumbnail transition
        opts = getThumbnailTransitionActivityOptions(runningTask, mDummyStackView, windowOverrideRect);
    } else {
        // If there is no thumbnail transition, but is launching from home into recents, then
        // use a quick home transition
        opts = hasRecentTasks ? getHomeTransitionActivityOptions() : getUnknownTransitionActivityOptions();
    }
    startRecentsActivity(opts);
    mLastToggleTime = SystemClock.elapsedRealtime();
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) TaskStack(com.android.systemui.recents.model.TaskStack) Rect(android.graphics.Rect) RecentsTaskLoader(com.android.systemui.recents.model.RecentsTaskLoader) TaskStackLayoutAlgorithm(com.android.systemui.recents.views.TaskStackLayoutAlgorithm) ActivityOptions(android.app.ActivityOptions)

Example 23 with ActivityOptions

use of android.app.ActivityOptions in project platform_frameworks_base by android.

the class RecentsImpl method showRelativeAffiliatedTask.

/**
     * Transitions to the next affiliated task.
     */
public void showRelativeAffiliatedTask(boolean showNextTask) {
    SystemServicesProxy ssp = Recents.getSystemServices();
    RecentsTaskLoader loader = Recents.getTaskLoader();
    RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext);
    loader.preloadTasks(plan, -1, false);
    TaskStack focusedStack = plan.getTaskStack();
    // Return early if there are no tasks in the focused stack
    if (focusedStack == null || focusedStack.getTaskCount() == 0)
        return;
    // Return early if there is no running task (can't determine affiliated tasks in this case)
    ActivityManager.RunningTaskInfo runningTask = ssp.getRunningTask();
    if (runningTask == null)
        return;
    // Return early if the running task is in the home stack (optimization)
    if (SystemServicesProxy.isHomeStack(runningTask.stackId))
        return;
    // Find the task in the recents list
    ArrayList<Task> tasks = focusedStack.getStackTasks();
    Task toTask = null;
    ActivityOptions launchOpts = null;
    int taskCount = tasks.size();
    int numAffiliatedTasks = 0;
    for (int i = 0; i < taskCount; i++) {
        Task task = tasks.get(i);
        if (task.key.id == runningTask.id) {
            TaskGrouping group = task.group;
            Task.TaskKey toTaskKey;
            if (showNextTask) {
                toTaskKey = group.getNextTaskInGroup(task);
                launchOpts = ActivityOptions.makeCustomAnimation(mContext, R.anim.recents_launch_next_affiliated_task_target, R.anim.recents_launch_next_affiliated_task_source);
            } else {
                toTaskKey = group.getPrevTaskInGroup(task);
                launchOpts = ActivityOptions.makeCustomAnimation(mContext, R.anim.recents_launch_prev_affiliated_task_target, R.anim.recents_launch_prev_affiliated_task_source);
            }
            if (toTaskKey != null) {
                toTask = focusedStack.findTaskWithId(toTaskKey.id);
            }
            numAffiliatedTasks = group.getTaskCount();
            break;
        }
    }
    // Return early if there is no next task
    if (toTask == null) {
        if (numAffiliatedTasks > 1) {
            if (showNextTask) {
                ssp.startInPlaceAnimationOnFrontMostApplication(ActivityOptions.makeCustomInPlaceAnimation(mContext, R.anim.recents_launch_next_affiliated_task_bounce));
            } else {
                ssp.startInPlaceAnimationOnFrontMostApplication(ActivityOptions.makeCustomInPlaceAnimation(mContext, R.anim.recents_launch_prev_affiliated_task_bounce));
            }
        }
        return;
    }
    // Keep track of actually launched affiliated tasks
    MetricsLogger.count(mContext, "overview_affiliated_task_launch", 1);
    // Launch the task
    ssp.startActivityFromRecents(mContext, toTask.key, toTask.title, launchOpts);
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) TaskStack(com.android.systemui.recents.model.TaskStack) Task(com.android.systemui.recents.model.Task) RecentsTaskLoadPlan(com.android.systemui.recents.model.RecentsTaskLoadPlan) RecentsTaskLoader(com.android.systemui.recents.model.RecentsTaskLoader) TaskGrouping(com.android.systemui.recents.model.TaskGrouping) ActivityManager(android.app.ActivityManager) ActivityOptions(android.app.ActivityOptions)

Example 24 with ActivityOptions

use of android.app.ActivityOptions in project platform_frameworks_base by android.

the class Am method runStart.

private void runStart() throws Exception {
    Intent intent = makeIntent(UserHandle.USER_CURRENT);
    if (mUserId == UserHandle.USER_ALL) {
        System.err.println("Error: Can't start service with user 'all'");
        return;
    }
    String mimeType = intent.getType();
    if (mimeType == null && intent.getData() != null && "content".equals(intent.getData().getScheme())) {
        mimeType = mAm.getProviderMimeType(intent.getData(), mUserId);
    }
    do {
        if (mStopOption) {
            String packageName;
            if (intent.getComponent() != null) {
                packageName = intent.getComponent().getPackageName();
            } else {
                List<ResolveInfo> activities = mPm.queryIntentActivities(intent, mimeType, 0, mUserId).getList();
                if (activities == null || activities.size() <= 0) {
                    System.err.println("Error: Intent does not match any activities: " + intent);
                    return;
                } else if (activities.size() > 1) {
                    System.err.println("Error: Intent matches multiple activities; can't stop: " + intent);
                    return;
                }
                packageName = activities.get(0).activityInfo.packageName;
            }
            System.out.println("Stopping: " + packageName);
            mAm.forceStopPackage(packageName, mUserId);
            Thread.sleep(250);
        }
        System.out.println("Starting: " + intent);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ParcelFileDescriptor fd = null;
        ProfilerInfo profilerInfo = null;
        if (mProfileFile != null) {
            try {
                fd = openForSystemServer(new File(mProfileFile), ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE | ParcelFileDescriptor.MODE_WRITE_ONLY);
            } catch (FileNotFoundException e) {
                System.err.println("Error: Unable to open file: " + mProfileFile);
                System.err.println("Consider using a file under /data/local/tmp/");
                return;
            }
            profilerInfo = new ProfilerInfo(mProfileFile, fd, mSamplingInterval, mAutoStop, mStreaming);
        }
        IActivityManager.WaitResult result = null;
        int res;
        final long startTime = SystemClock.uptimeMillis();
        ActivityOptions options = null;
        if (mStackId != INVALID_STACK_ID) {
            options = ActivityOptions.makeBasic();
            options.setLaunchStackId(mStackId);
        }
        if (mWaitOption) {
            result = mAm.startActivityAndWait(null, null, intent, mimeType, null, null, 0, mStartFlags, profilerInfo, options != null ? options.toBundle() : null, mUserId);
            res = result.result;
        } else {
            res = mAm.startActivityAsUser(null, null, intent, mimeType, null, null, 0, mStartFlags, profilerInfo, options != null ? options.toBundle() : null, mUserId);
        }
        final long endTime = SystemClock.uptimeMillis();
        PrintStream out = mWaitOption ? System.out : System.err;
        boolean launched = false;
        switch(res) {
            case ActivityManager.START_SUCCESS:
                launched = true;
                break;
            case ActivityManager.START_SWITCHES_CANCELED:
                launched = true;
                out.println("Warning: Activity not started because the " + " current activity is being kept for the user.");
                break;
            case ActivityManager.START_DELIVERED_TO_TOP:
                launched = true;
                out.println("Warning: Activity not started, intent has " + "been delivered to currently running " + "top-most instance.");
                break;
            case ActivityManager.START_RETURN_INTENT_TO_CALLER:
                launched = true;
                out.println("Warning: Activity not started because intent " + "should be handled by the caller");
                break;
            case ActivityManager.START_TASK_TO_FRONT:
                launched = true;
                out.println("Warning: Activity not started, its current " + "task has been brought to the front");
                break;
            case ActivityManager.START_INTENT_NOT_RESOLVED:
                out.println("Error: Activity not started, unable to " + "resolve " + intent.toString());
                break;
            case ActivityManager.START_CLASS_NOT_FOUND:
                out.println(NO_CLASS_ERROR_CODE);
                out.println("Error: Activity class " + intent.getComponent().toShortString() + " does not exist.");
                break;
            case ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT:
                out.println("Error: Activity not started, you requested to " + "both forward and receive its result");
                break;
            case ActivityManager.START_PERMISSION_DENIED:
                out.println("Error: Activity not started, you do not " + "have permission to access it.");
                break;
            case ActivityManager.START_NOT_VOICE_COMPATIBLE:
                out.println("Error: Activity not started, voice control not allowed for: " + intent);
                break;
            case ActivityManager.START_NOT_CURRENT_USER_ACTIVITY:
                out.println("Error: Not allowed to start background user activity" + " that shouldn't be displayed for all users.");
                break;
            default:
                out.println("Error: Activity not started, unknown error code " + res);
                break;
        }
        if (mWaitOption && launched) {
            if (result == null) {
                result = new IActivityManager.WaitResult();
                result.who = intent.getComponent();
            }
            System.out.println("Status: " + (result.timeout ? "timeout" : "ok"));
            if (result.who != null) {
                System.out.println("Activity: " + result.who.flattenToShortString());
            }
            if (result.thisTime >= 0) {
                System.out.println("ThisTime: " + result.thisTime);
            }
            if (result.totalTime >= 0) {
                System.out.println("TotalTime: " + result.totalTime);
            }
            System.out.println("WaitTime: " + (endTime - startTime));
            System.out.println("Complete");
        }
        mRepeat--;
        if (mRepeat > 0) {
            mAm.unhandledBack();
        }
    } while (mRepeat > 0);
}
Also used : ProfilerInfo(android.app.ProfilerInfo) PrintStream(java.io.PrintStream) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) ParcelFileDescriptor(android.os.ParcelFileDescriptor) File(java.io.File) IActivityManager(android.app.IActivityManager) ActivityOptions(android.app.ActivityOptions)

Example 25 with ActivityOptions

use of android.app.ActivityOptions in project platform_frameworks_base by android.

the class ForcedResizableInfoActivityController method showPending.

private void showPending() {
    mHandler.removeCallbacks(mTimeoutRunnable);
    for (int i = mPendingTaskIds.size() - 1; i >= 0; i--) {
        Intent intent = new Intent(mContext, ForcedResizableInfoActivity.class);
        ActivityOptions options = ActivityOptions.makeBasic();
        options.setLaunchTaskId(mPendingTaskIds.valueAt(i));
        options.setTaskOverlay(true);
        mContext.startActivityAsUser(intent, options.toBundle(), UserHandle.CURRENT);
    }
    mPendingTaskIds.clear();
}
Also used : Intent(android.content.Intent) ActivityOptions(android.app.ActivityOptions)

Aggregations

ActivityOptions (android.app.ActivityOptions)178 Intent (android.content.Intent)88 RemoteException (android.os.RemoteException)33 Point (android.graphics.Point)30 RecentsTaskLoader (com.android.systemui.recents.model.RecentsTaskLoader)20 TaskStack (com.android.systemui.recents.model.TaskStack)20 PendingIntent (android.app.PendingIntent)18 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)15 ActivityManager (android.app.ActivityManager)14 ComponentName (android.content.ComponentName)13 ActivityInfo (android.content.pm.ActivityInfo)13 ResolveInfo (android.content.pm.ResolveInfo)12 UserHandle (android.os.UserHandle)12 Configuration (android.content.res.Configuration)10 ReferrerIntent (com.android.internal.content.ReferrerIntent)10 RecentsTaskLoadPlan (com.android.systemui.recents.model.RecentsTaskLoadPlan)10 Task (com.android.systemui.recents.model.Task)10 Bundle (android.os.Bundle)9 ActivityNotFoundException (android.content.ActivityNotFoundException)8 RecyclerView (android.support.v7.widget.RecyclerView)8