Search in sources :

Example 1 with Task

use of com.android.systemui.shared.recents.model.Task in project android_packages_apps_Launcher3 by crdroidandroid.

the class RecentTasksList method loadTasksInBackground.

/**
 * Loads and creates a list of all the recent tasks.
 */
@VisibleForTesting
TaskLoadResult loadTasksInBackground(int numTasks, int requestId, boolean loadKeysOnly) {
    int currentUserId = Process.myUserHandle().getIdentifier();
    List<ActivityManager.RecentTaskInfo> rawTasks = mActivityManagerWrapper.getRecentTasks(numTasks, currentUserId);
    // The raw tasks are given in most-recent to least-recent order, we need to reverse it
    Collections.reverse(rawTasks);
    SparseBooleanArray tmpLockedUsers = new SparseBooleanArray() {

        @Override
        public boolean get(int key) {
            if (indexOfKey(key) < 0) {
                // Fill the cached locked state as we fetch
                put(key, mKeyguardManager.isDeviceLocked(key));
            }
            return super.get(key);
        }
    };
    TaskLoadResult allTasks = new TaskLoadResult(requestId, loadKeysOnly, rawTasks.size());
    for (ActivityManager.RecentTaskInfo rawTask : rawTasks) {
        Task.TaskKey taskKey = new Task.TaskKey(rawTask);
        Task task;
        if (!loadKeysOnly) {
            boolean isLocked = tmpLockedUsers.get(taskKey.userId);
            task = Task.from(taskKey, rawTask, isLocked);
        } else {
            task = new Task(taskKey);
        }
        task.setLastSnapshotData(rawTask);
        allTasks.add(task);
    }
    return allTasks;
}
Also used : Task(com.android.systemui.shared.recents.model.Task) SparseBooleanArray(android.util.SparseBooleanArray) ActivityManager(android.app.ActivityManager) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 2 with Task

use of com.android.systemui.shared.recents.model.Task in project android_packages_apps_Launcher3 by crdroidandroid.

the class TaskbarActivityContext method onTaskbarIconClicked.

protected void onTaskbarIconClicked(View view) {
    Object tag = view.getTag();
    if (tag instanceof Task) {
        Task task = (Task) tag;
        ActivityManagerWrapper.getInstance().startActivityFromRecents(task.key, ActivityOptions.makeBasic());
    } else if (tag instanceof FolderInfo) {
        FolderIcon folderIcon = (FolderIcon) view;
        Folder folder = folderIcon.getFolder();
        setTaskbarWindowFullscreen(true);
        getDragLayer().post(() -> {
            folder.animateOpen();
            folder.iterateOverItems((itemInfo, itemView) -> {
                itemView.setOnClickListener(mOnTaskbarIconClickListener);
                itemView.setOnLongClickListener(mOnTaskbarIconLongClickListener);
                // To play haptic when dragging, like other Taskbar items do.
                itemView.setHapticFeedbackEnabled(true);
                return false;
            });
        });
    } else if (tag instanceof WorkspaceItemInfo) {
        WorkspaceItemInfo info = (WorkspaceItemInfo) tag;
        if (!(info.isDisabled() && ItemClickHandler.handleDisabledItemClicked(info, this))) {
            Intent intent = new Intent(info.getIntent()).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try {
                if (mIsSafeModeEnabled && !PackageManagerHelper.isSystemApp(this, intent)) {
                    Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
                } else if (info.isPromise()) {
                    intent = new PackageManagerHelper(this).getMarketIntent(info.getTargetPackage()).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                } else if (info.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                    String id = info.getDeepShortcutId();
                    String packageName = intent.getPackage();
                    getSystemService(LauncherApps.class).startShortcut(packageName, id, null, null, info.user);
                } else if (info.user.equals(Process.myUserHandle())) {
                    startActivity(intent);
                } else {
                    getSystemService(LauncherApps.class).startMainActivity(intent.getComponent(), info.user, intent.getSourceBounds(), null);
                }
            } catch (NullPointerException | ActivityNotFoundException | SecurityException e) {
                Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
                Log.e(TAG, "Unable to launch. tag=" + info + " intent=" + intent, e);
            }
        }
    } else {
        Log.e(TAG, "Unknown type clicked: " + tag);
    }
    AbstractFloatingView.closeAllOpenViews(this);
}
Also used : Rect(android.graphics.Rect) Task(com.android.systemui.shared.recents.model.Task) NonNull(androidx.annotation.NonNull) WindowManager(android.view.WindowManager) Drawable(android.graphics.drawable.Drawable) DraggableView(com.android.launcher3.dragndrop.DraggableView) Process(android.os.Process) ITYPE_BOTTOM_TAPPABLE_ELEMENT(com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_BOTTOM_TAPPABLE_ELEMENT) ActivityOptions(android.app.ActivityOptions) ActivityManagerWrapper(com.android.systemui.shared.system.ActivityManagerWrapper) WindowManagerWrapper(com.android.systemui.shared.system.WindowManagerWrapper) LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS(android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) TYPE_APPLICATION_OVERLAY(android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY) ContextThemeWrapper(android.view.ContextThemeWrapper) FolderInfo(com.android.launcher3.model.data.FolderInfo) Display(android.view.Display) View(android.view.View) Log(android.util.Log) SysUINavigationMode(com.android.quickstep.SysUINavigationMode) Favorites(com.android.launcher3.LauncherSettings.Favorites) Mode(com.android.quickstep.SysUINavigationMode.Mode) LauncherApps(android.content.pm.LauncherApps) DeviceProfile(com.android.launcher3.DeviceProfile) DragOptions(com.android.launcher3.dragndrop.DragOptions) Nullable(androidx.annotation.Nullable) ActivityNotFoundException(android.content.ActivityNotFoundException) ITYPE_EXTRA_NAVIGATION_BAR(com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_EXTRA_NAVIGATION_BAR) Themes(com.android.launcher3.util.Themes) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) Folder(com.android.launcher3.folder.Folder) Context(android.content.Context) ItemInfo(com.android.launcher3.model.data.ItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) Intent(android.content.Intent) PixelFormat(android.graphics.PixelFormat) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Toast(android.widget.Toast) DragSource(com.android.launcher3.DragSource) ActivityContext(com.android.launcher3.views.ActivityContext) LayoutInflater(android.view.LayoutInflater) DropTarget(com.android.launcher3.DropTarget) DragController(com.android.launcher3.dragndrop.DragController) MATCH_PARENT(android.view.ViewGroup.LayoutParams.MATCH_PARENT) Point(android.graphics.Point) TaskbarButton(com.android.launcher3.taskbar.TaskbarNavButtonController.TaskbarButton) ItemClickHandler(com.android.launcher3.touch.ItemClickHandler) SystemProperties(android.os.SystemProperties) Gravity(android.view.Gravity) R(com.android.launcher3.R) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) DragView(com.android.launcher3.dragndrop.DragView) TraceHelper(com.android.launcher3.util.TraceHelper) Task(com.android.systemui.shared.recents.model.Task) Intent(android.content.Intent) LauncherApps(android.content.pm.LauncherApps) Folder(com.android.launcher3.folder.Folder) FolderInfo(com.android.launcher3.model.data.FolderInfo) ActivityNotFoundException(android.content.ActivityNotFoundException) FolderIcon(com.android.launcher3.folder.FolderIcon) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 3 with Task

use of com.android.systemui.shared.recents.model.Task in project android_packages_apps_Launcher3 by crdroidandroid.

the class RecentsView method createTaskLaunchAnimation.

public PendingAnimation createTaskLaunchAnimation(TaskView tv, long duration, Interpolator interpolator) {
    if (FeatureFlags.IS_STUDIO_BUILD && mPendingAnimation != null) {
        throw new IllegalStateException("Another pending animation is still running");
    }
    int count = getTaskViewCount();
    if (count == 0) {
        return new PendingAnimation(duration);
    }
    // When swiping down from overview to tasks, ensures the snapped page's scroll maintain
    // invariant between quick switch and overview, to ensure a smooth animation transition.
    updateGridProperties();
    updateScrollSynchronously();
    int targetSysUiFlags = tv.getThumbnail().getSysUiStatusNavFlags();
    final boolean[] passedOverviewThreshold = new boolean[] { false };
    ValueAnimator progressAnim = ValueAnimator.ofFloat(0, 1);
    progressAnim.addUpdateListener(animator -> {
        // tasks' flags
        if (animator.getAnimatedFraction() > UPDATE_SYSUI_FLAGS_THRESHOLD) {
            mActivity.getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, targetSysUiFlags);
        } else {
            mActivity.getSystemUiController().updateUiState(UI_STATE_FULLSCREEN_TASK, 0);
        }
        // Passing the threshold from taskview to fullscreen app will vibrate
        final boolean passed = animator.getAnimatedFraction() >= SUCCESS_TRANSITION_PROGRESS;
        if (passed != passedOverviewThreshold[0]) {
            passedOverviewThreshold[0] = passed;
            performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
        }
    });
    AnimatorSet anim = createAdjacentPageAnimForTaskLaunch(tv);
    DepthController depthController = getDepthController();
    if (depthController != null) {
        ObjectAnimator depthAnimator = ObjectAnimator.ofFloat(depthController, DEPTH, BACKGROUND_APP.getDepth(mActivity));
        anim.play(depthAnimator);
    }
    anim.play(progressAnim);
    anim.setInterpolator(interpolator);
    mPendingAnimation = new PendingAnimation(duration);
    mPendingAnimation.add(anim);
    if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
        mLiveTileTaskViewSimulator.addOverviewToAppAnim(mPendingAnimation, interpolator);
        mPendingAnimation.addOnFrameCallback(this::redrawLiveTile);
    }
    mPendingAnimation.addEndListener(isSuccess -> {
        if (isSuccess) {
            if (ENABLE_QUICKSTEP_LIVE_TILE.get() && tv.isRunningTask()) {
                finishRecentsAnimation(false, /* toRecents */
                null);
                onTaskLaunchAnimationEnd(true);
            } else {
                tv.launchTask(this::onTaskLaunchAnimationEnd);
            }
            Task task = tv.getTask();
            if (task != null) {
                mActivity.getStatsLogManager().logger().withItemInfo(tv.getItemInfo()).log(LAUNCHER_TASK_LAUNCH_SWIPE_DOWN);
            }
        } else {
            onTaskLaunchAnimationEnd(false);
        }
        mPendingAnimation = null;
    });
    return mPendingAnimation;
}
Also used : PendingAnimation(com.android.launcher3.anim.PendingAnimation) Task(com.android.systemui.shared.recents.model.Task) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) DepthController(com.android.launcher3.statehandlers.DepthController) TextPaint(android.text.TextPaint) Point(android.graphics.Point)

Example 4 with Task

use of com.android.systemui.shared.recents.model.Task in project android_packages_apps_Launcher3 by crdroidandroid.

the class RecentsView method applyLoadPlan.

protected void applyLoadPlan(ArrayList<Task> tasks) {
    if (mPendingAnimation != null) {
        mPendingAnimation.addEndListener(success -> applyLoadPlan(tasks));
        return;
    }
    if (tasks == null || tasks.isEmpty()) {
        removeTasksViewsAndClearAllButton();
        onTaskStackUpdated();
        return;
    }
    int currentTaskId = -1;
    TaskView currentTaskView = getTaskViewAtByAbsoluteIndex(mCurrentPage);
    if (currentTaskView != null) {
        currentTaskId = currentTaskView.getTask().key.id;
    }
    // Unload existing visible task data
    unloadVisibleTaskData(TaskView.FLAG_UPDATE_ALL);
    TaskView ignoreResetTaskView = mIgnoreResetTaskId == -1 ? null : getTaskView(mIgnoreResetTaskId);
    final int requiredTaskCount = tasks.size();
    if (getTaskViewCount() != requiredTaskCount) {
        for (int i = getTaskViewCount(); i < requiredTaskCount; i++) {
            addView(mTaskViewPool.getView());
        }
        while (getTaskViewCount() > requiredTaskCount) {
            removeView(getChildAt(getChildCount() - 1));
        }
    }
    // Rebind and reset all task views
    for (int i = requiredTaskCount - 1; i >= 0; i--) {
        final int pageIndex = requiredTaskCount - i - 1 + mTaskViewStartIndex;
        final Task task = tasks.get(i);
        final TaskView taskView = (TaskView) getChildAt(pageIndex);
        taskView.bind(task, mOrientationState);
    }
    updateTaskSize();
    int targetPage = -1;
    if (mNextPage == INVALID_PAGE) {
        // Set the current page to the running task, but not if settling on new task.
        TaskView runningTaskView = getRunningTaskView();
        if (runningTaskView != null) {
            targetPage = indexOfChild(runningTaskView);
        } else if (getTaskViewCount() > 0) {
            targetPage = indexOfChild(getTaskViewAt(0));
        }
    } else if (currentTaskId != -1) {
        currentTaskView = getTaskView(currentTaskId);
        if (currentTaskView != null) {
            targetPage = indexOfChild(currentTaskView);
        }
    }
    if (targetPage != -1 && mCurrentPage != targetPage) {
        setCurrentPage(targetPage);
    }
    if (mIgnoreResetTaskId != -1 && getTaskView(mIgnoreResetTaskId) != ignoreResetTaskView) {
        // If the taskView mapping is changing, do not preserve the visuals. Since we are
        // mostly preserving the first task, and new taskViews are added to the end, it should
        // generally map to the same task.
        mIgnoreResetTaskId = -1;
    }
    resetTaskVisuals();
    onTaskStackUpdated();
    updateEnabledOverlays();
}
Also used : Task(com.android.systemui.shared.recents.model.Task) TextPaint(android.text.TextPaint) Point(android.graphics.Point)

Example 5 with Task

use of com.android.systemui.shared.recents.model.Task in project android_packages_apps_Launcher3 by crdroidandroid.

the class RecentsView method onTaskIconChanged.

@Override
public void onTaskIconChanged(String pkg, UserHandle user) {
    for (int i = 0; i < getTaskViewCount(); i++) {
        TaskView tv = getTaskViewAt(i);
        Task task = tv.getTask();
        if (task != null && task.key != null && pkg.equals(task.key.getPackageName()) && task.key.userId == user.getIdentifier()) {
            task.icon = null;
            if (tv.getIconView().getDrawable() != null) {
                tv.onTaskListVisibilityChanged(true);
            }
        }
    }
}
Also used : Task(com.android.systemui.shared.recents.model.Task) TextPaint(android.text.TextPaint) Point(android.graphics.Point)

Aggregations

Task (com.android.systemui.shared.recents.model.Task)14 Point (android.graphics.Point)6 Intent (android.content.Intent)4 TextPaint (android.text.TextPaint)4 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)4 ActivityOptions (android.app.ActivityOptions)3 View (android.view.View)3 AnimatorSet (android.animation.AnimatorSet)2 ObjectAnimator (android.animation.ObjectAnimator)2 ActivityManager (android.app.ActivityManager)2 Context (android.content.Context)2 LauncherApps (android.content.pm.LauncherApps)2 Rect (android.graphics.Rect)2 Drawable (android.graphics.drawable.Drawable)2 Log (android.util.Log)2 Toast (android.widget.Toast)2 NonNull (androidx.annotation.NonNull)2 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)2 DeviceProfile (com.android.launcher3.DeviceProfile)2 R (com.android.launcher3.R)2