Search in sources :

Example 91 with ActivityOptions

use of android.app.ActivityOptions in project android_frameworks_base by crdroidandroid.

the class TaskRecord method performClearTaskLocked.

/**
     * Perform clear operation as requested by
     * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
     * stack to the given task, then look for
     * an instance of that activity in the stack and, if found, finish all
     * activities on top of it and return the instance.
     *
     * @param newR Description of the new activity being started.
     * @return Returns the old activity that should be continued to be used,
     * or null if none was found.
     */
final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
    int numActivities = mActivities.size();
    for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
        ActivityRecord r = mActivities.get(activityNdx);
        if (r.finishing) {
            continue;
        }
        if (r.realActivity.equals(newR.realActivity)) {
            // Here it is!  Now finish everything in front...
            final ActivityRecord ret = r;
            for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
                r = mActivities.get(activityNdx);
                if (r.finishing) {
                    continue;
                }
                ActivityOptions opts = r.takeOptionsLocked();
                if (opts != null) {
                    ret.updateOptionsLocked(opts);
                }
                if (stack != null && stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear-task-stack", false)) {
                    --activityNdx;
                    --numActivities;
                }
            }
            // instance of the activity so a new fresh one can be started.
            if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) {
                if (!ret.finishing) {
                    if (stack != null) {
                        stack.finishActivityLocked(ret, Activity.RESULT_CANCELED, null, "clear-task-top", false);
                    }
                    return null;
                }
            }
            return ret;
        }
    }
    return null;
}
Also used : Point(android.graphics.Point) ActivityOptions(android.app.ActivityOptions)

Example 92 with ActivityOptions

use of android.app.ActivityOptions in project android_frameworks_base by crdroidandroid.

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)

Example 93 with ActivityOptions

use of android.app.ActivityOptions in project android_frameworks_base by crdroidandroid.

the class ActivityTestMain method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add("Animate!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            AlertDialog.Builder builder = new AlertDialog.Builder(ActivityTestMain.this, R.style.SlowDialog);
            builder.setTitle("This is a title");
            builder.show();
            return true;
        }
    });
    menu.add("Bind!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, SingleUserService.class);
            ServiceConnection conn = new ServiceConnection() {

                @Override
                public void onServiceConnected(ComponentName name, IBinder service) {
                    Log.i(TAG, "Service connected " + name + " " + service);
                }

                @Override
                public void onServiceDisconnected(ComponentName name) {
                    Log.i(TAG, "Service disconnected " + name);
                }
            };
            if (bindService(intent, conn, Context.BIND_AUTO_CREATE)) {
                mConnections.add(conn);
            } else {
                Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
            }
            return true;
        }
    });
    menu.add("Start!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, SingleUserService.class);
            startService(intent);
            return true;
        }
    });
    menu.add("Rebind Isolated!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, IsolatedService.class);
            ServiceConnection conn = new ServiceConnection() {

                @Override
                public void onServiceConnected(ComponentName name, IBinder service) {
                    Log.i(TAG, "Isolated service connected " + name + " " + service);
                }

                @Override
                public void onServiceDisconnected(ComponentName name) {
                    Log.i(TAG, "Isolated service disconnected " + name);
                }
            };
            if (mIsolatedConnection != null) {
                Log.i(TAG, "Unbinding existing service: " + mIsolatedConnection);
                unbindService(mIsolatedConnection);
                mIsolatedConnection = null;
            }
            Log.i(TAG, "Binding new service: " + conn);
            if (bindService(intent, conn, Context.BIND_AUTO_CREATE)) {
                mIsolatedConnection = conn;
            } else {
                Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
            }
            return true;
        }
    });
    menu.add("Send!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, SingleUserReceiver.class);
            sendOrderedBroadcast(intent, null, new BroadcastResultReceiver(), null, Activity.RESULT_OK, null, null);
            return true;
        }
    });
    menu.add("Call!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            ContentProviderClient cpl = getContentResolver().acquireContentProviderClient(SingleUserProvider.AUTHORITY);
            Bundle res = null;
            try {
                res = cpl.call("getuser", null, null);
            } catch (RemoteException e) {
            }
            int user = res != null ? res.getInt("user", -1) : -1;
            Toast.makeText(ActivityTestMain.this, "Provider executed as user " + (user >= 0 ? Integer.toString(user) : "unknown"), Toast.LENGTH_LONG).show();
            cpl.release();
            return true;
        }
    });
    menu.add("Send to user 0!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, UserTarget.class);
            sendOrderedBroadcastAsUser(intent, new UserHandle(0), null, new BroadcastResultReceiver(), null, Activity.RESULT_OK, null, null);
            return true;
        }
    });
    menu.add("Send to user " + mSecondUser + "!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, UserTarget.class);
            sendOrderedBroadcastAsUser(intent, new UserHandle(mSecondUser), null, new BroadcastResultReceiver(), null, Activity.RESULT_OK, null, null);
            return true;
        }
    });
    menu.add("Bind to user 0!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, ServiceUserTarget.class);
            ServiceConnection conn = new ServiceConnection() {

                @Override
                public void onServiceConnected(ComponentName name, IBinder service) {
                    Log.i(TAG, "Service connected " + name + " " + service);
                }

                @Override
                public void onServiceDisconnected(ComponentName name) {
                    Log.i(TAG, "Service disconnected " + name);
                }
            };
            if (bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, UserHandle.SYSTEM)) {
                mConnections.add(conn);
            } else {
                Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
            }
            return true;
        }
    });
    menu.add("Bind to user " + mSecondUser + "!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(ActivityTestMain.this, ServiceUserTarget.class);
            ServiceConnection conn = new ServiceConnection() {

                @Override
                public void onServiceConnected(ComponentName name, IBinder service) {
                    Log.i(TAG, "Service connected " + name + " " + service);
                }

                @Override
                public void onServiceDisconnected(ComponentName name) {
                    Log.i(TAG, "Service disconnected " + name);
                }
            };
            if (bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, new UserHandle(mSecondUser))) {
                mConnections.add(conn);
            } else {
                Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
            }
            return true;
        }
    });
    menu.add("Density!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (mOverrideConfig == null) {
                mOverrideConfig = new Configuration();
            }
            if (mOverrideConfig.densityDpi == Configuration.DENSITY_DPI_UNDEFINED) {
                mOverrideConfig.densityDpi = (getApplicationContext().getResources().getConfiguration().densityDpi * 2) / 3;
            } else {
                mOverrideConfig.densityDpi = Configuration.DENSITY_DPI_UNDEFINED;
            }
            recreate();
            return true;
        }
    });
    menu.add("HashArray").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            ArrayMapTests.run();
            return true;
        }
    });
    menu.add("Add App Recent").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            addAppRecents(1);
            return true;
        }
    });
    menu.add("Add App 10x Recent").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            addAppRecents(10);
            return true;
        }
    });
    menu.add("Exclude!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            setExclude(true);
            return true;
        }
    });
    menu.add("Include!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            setExclude(false);
            return true;
        }
    });
    menu.add("Open Doc").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            ActivityManager.AppTask task = findDocTask();
            if (task == null) {
                Intent intent = new Intent(ActivityTestMain.this, DocActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS);
                startActivity(intent);
            } else {
                task.moveToFront();
            }
            return true;
        }
    });
    menu.add("Stack Doc").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            ActivityManager.AppTask task = findDocTask();
            if (task != null) {
                ActivityManager.RecentTaskInfo recent = task.getTaskInfo();
                Intent intent = new Intent(ActivityTestMain.this, DocActivity.class);
                if (recent.id >= 0) {
                    // Stack on top.
                    intent.putExtra(DocActivity.LABEL, "Stacked");
                } else {
                    // Start root activity.
                    intent.putExtra(DocActivity.LABEL, "New Root");
                }
                task.startActivity(ActivityTestMain.this, intent, null);
            }
            return true;
        }
    });
    menu.add("Spam!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            scheduleSpam(false);
            return true;
        }
    });
    menu.add("Track time").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, "We are sharing this with you!");
            ActivityOptions options = ActivityOptions.makeBasic();
            Intent receiveIntent = new Intent(ActivityTestMain.this, TrackTimeReceiver.class);
            receiveIntent.putExtra("something", "yeah, this is us!");
            options.requestUsageTimeReport(PendingIntent.getBroadcast(ActivityTestMain.this, 0, receiveIntent, PendingIntent.FLAG_CANCEL_CURRENT));
            startActivity(Intent.createChooser(intent, "Who do you love?"), options.toBundle());
            return true;
        }
    });
    menu.add("Transaction fail").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.putExtra("gulp", new int[1024 * 1024]);
            startActivity(intent);
            return true;
        }
    });
    menu.add("Spam idle alarm").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            scheduleSpamAlarm(0);
            return true;
        }
    });
    menu.add("Ignore battery optimizations").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent;
            if (!mPower.isIgnoringBatteryOptimizations(getPackageName())) {
                intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
                intent.setData(Uri.fromParts("package", getPackageName(), null));
            } else {
                intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
            }
            startActivity(intent);
            return true;
        }
    });
    return true;
}
Also used : AlertDialog(android.app.AlertDialog) ServiceConnection(android.content.ServiceConnection) Configuration(android.content.res.Configuration) IBinder(android.os.IBinder) UserHandle(android.os.UserHandle) ComponentName(android.content.ComponentName) ActivityOptions(android.app.ActivityOptions) Bundle(android.os.Bundle) MenuItem(android.view.MenuItem) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RemoteException(android.os.RemoteException) ContentProviderClient(android.content.ContentProviderClient)

Example 94 with ActivityOptions

use of android.app.ActivityOptions in project android_frameworks_base by crdroidandroid.

the class SystemServicesProxy method startTaskInDockedMode.

/** Docks a task to the side of the screen and starts it. */
public boolean startTaskInDockedMode(int taskId, int createMode) {
    if (mIam == null)
        return false;
    try {
        final ActivityOptions options = ActivityOptions.makeBasic();
        options.setDockCreateMode(createMode);
        options.setLaunchStackId(DOCKED_STACK_ID);
        mIam.startActivityFromRecents(taskId, options.toBundle());
        return true;
    } catch (Exception e) {
        Log.e(TAG, "Failed to dock task: " + taskId + " with createMode: " + createMode, e);
    }
    return false;
}
Also used : RemoteException(android.os.RemoteException) IOException(java.io.IOException) ActivityOptions(android.app.ActivityOptions)

Example 95 with ActivityOptions

use of android.app.ActivityOptions in project android_frameworks_base by crdroidandroid.

the class RecentsImpl method showNextTask.

/**
     * Transitions to the next recent task in the stack.
     */
public void 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
    ActivityManager.RunningTaskInfo runningTask = ssp.getRunningTask();
    if (runningTask == null)
        return;
    // Find the task in the recents list
    boolean isRunningTaskInHomeStack = SystemServicesProxy.isHomeStack(runningTask.stackId);
    ArrayList<Task> tasks = focusedStack.getStackTasks();
    Task toTask = null;
    ActivityOptions launchOpts = null;
    int taskCount = tasks.size();
    for (int i = taskCount - 1; i >= 1; i--) {
        Task task = tasks.get(i);
        if (isRunningTaskInHomeStack) {
            toTask = tasks.get(i - 1);
            launchOpts = ActivityOptions.makeCustomAnimation(mContext, R.anim.recents_launch_next_affiliated_task_target, R.anim.recents_fast_toggle_app_home_exit);
            break;
        } else if (task.key.id == runningTask.id) {
            toTask = tasks.get(i - 1);
            launchOpts = ActivityOptions.makeCustomAnimation(mContext, R.anim.recents_launch_prev_affiliated_task_target, R.anim.recents_launch_prev_affiliated_task_source);
            break;
        }
    }
    // Return early if there is no next task
    if (toTask == null) {
        ssp.startInPlaceAnimationOnFrontMostApplication(ActivityOptions.makeCustomInPlaceAnimation(mContext, R.anim.recents_launch_prev_affiliated_task_bounce));
        return;
    }
    // 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) ActivityManager(android.app.ActivityManager) 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