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

Commit b161ff8f authored by Vadim Tryshev's avatar Vadim Tryshev Committed by Android (Google) Code Review
Browse files

Merge "Dragging the best available activity from Recents (to Pinned)."

parents 284e1dbf 0e81f48b
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -97,11 +97,16 @@ class NavigationBarApps extends LinearLayout {
        }
    };

    public NavigationBarApps(Context context, AttributeSet attrs) {
        super(context, attrs);
    public static NavigationBarAppsModel getModel(Context context) {
        if (sAppsModel == null) {
            sAppsModel = new NavigationBarAppsModel(context);
        }
        return sAppsModel;
    }

    public NavigationBarApps(Context context, AttributeSet attrs) {
        super(context, attrs);
        getModel(context);
        mPackageManager = context.getPackageManager();
        mUserManager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
        mLayoutInflater = LayoutInflater.from(context);
+31 −10
Original line number Diff line number Diff line
@@ -151,7 +151,7 @@ class NavigationBarRecents extends LinearLayout {
        button.setOnLongClickListener(mAppLongClickListener);
        addView(button);

        ComponentName activityName = getRealActivityForTask(task);
        ComponentName activityName = getActivityForTask(task);
        CharSequence appLabel = NavigationBarApps.getAppLabel(mPackageManager, activityName);
        button.setContentDescription(appLabel);

@@ -180,8 +180,17 @@ class NavigationBarRecents extends LinearLayout {
        });
    }

    private static ComponentName getRealActivityForTask(RecentTaskInfo task) {
        // Prefer the activity that started the task.
    private static ComponentName getActivityForTask(RecentTaskInfo task) {
        // If the task was started from an alias, return the actual activity component that was
        // initially started.
        if (task.origActivity != null) {
            return task.origActivity;
        }
        // Prefer the first activity of the task.
        if (task.baseActivity != null) {
            return task.baseActivity;
        }
        // Then goes the activity that started the task.
        if (task.realActivity != null) {
            return task.realActivity;
        }
@@ -257,16 +266,28 @@ class NavigationBarRecents extends LinearLayout {
            // The drag will go to the pinned section, which wants to launch the main activity
            // for the task's package.
            RecentTaskInfo task = (RecentTaskInfo) v.getTag();
            String packageName = getRealActivityForTask(task).getPackageName();
            ComponentName component = getLaunchComponentForPackage(packageName, task.userId);
            ComponentName componentName = getActivityForTask(task);
            UserHandle taskUser = new UserHandle(task.userId);
            AppInfo appInfo = new AppInfo(componentName, taskUser);

            if (NavigationBarApps.getModel(mContext).buildAppLaunchIntent(appInfo) == null) {
                // If task's activity is not launcheable, fall back to a launch component of the
                // task's package.
                ComponentName component = getLaunchComponentForPackage(
                        componentName.getPackageName(), task.userId);

                if (component == null) {
                    return false;
                }

            if (DEBUG) Slog.d(TAG, "Start drag with " + component);
                appInfo = new AppInfo(component, taskUser);
            }

            if (DEBUG) {
                Slog.d(TAG, "Start drag with " + appInfo.getComponentName().flattenToString());
            }

            NavigationBarApps.startAppDrag(
                    icon, new AppInfo(component, new UserHandle(task.userId)));
            NavigationBarApps.startAppDrag(icon, appInfo);
            return true;
        }
    }