Search in sources :

Example 16 with Launcher

use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by crdroidandroid.

the class DatabaseWidgetPreviewLoader method removeObsoletePreviews.

/**
 * Updates the persistent DB:
 *   1. Any preview generated for an old package version is removed
 *   2. Any preview for an absent package is removed
 * This ensures that we remove entries for packages which changed while the launcher was dead.
 *
 * @param packageUser if provided, specifies that list only contains previews for the
 *                    given package/user, otherwise the list contains all previews
 */
public void removeObsoletePreviews(ArrayList<? extends ComponentKey> list, @Nullable PackageUserKey packageUser) {
    Preconditions.assertWorkerThread();
    LongSparseArray<HashSet<String>> validPackages = new LongSparseArray<>();
    for (ComponentKey key : list) {
        final long userId = mUserCache.getSerialNumberForUser(key.user);
        HashSet<String> packages = validPackages.get(userId);
        if (packages == null) {
            packages = new HashSet<>();
            validPackages.put(userId, packages);
        }
        packages.add(key.componentName.getPackageName());
    }
    LongSparseArray<HashSet<String>> packagesToDelete = new LongSparseArray<>();
    long passedUserId = packageUser == null ? 0 : mUserCache.getSerialNumberForUser(packageUser.mUser);
    Cursor c = null;
    try {
        c = mDb.query(new String[] { CacheDb.COLUMN_USER, CacheDb.COLUMN_PACKAGE, CacheDb.COLUMN_LAST_UPDATED, CacheDb.COLUMN_VERSION }, null, null);
        while (c.moveToNext()) {
            long userId = c.getLong(0);
            String pkg = c.getString(1);
            long lastUpdated = c.getLong(2);
            long version = c.getLong(3);
            if (packageUser != null && (!pkg.equals(packageUser.mPackageName) || userId != passedUserId)) {
                // This preview is associated with a different package/user, no need to remove.
                continue;
            }
            HashSet<String> packages = validPackages.get(userId);
            if (packages != null && packages.contains(pkg)) {
                long[] versions = getPackageVersion(pkg);
                if (versions[0] == version && versions[1] == lastUpdated) {
                    // Every thing checks out
                    continue;
                }
            }
            // We need to delete this package.
            packages = packagesToDelete.get(userId);
            if (packages == null) {
                packages = new HashSet<>();
                packagesToDelete.put(userId, packages);
            }
            packages.add(pkg);
        }
        for (int i = 0; i < packagesToDelete.size(); i++) {
            long userId = packagesToDelete.keyAt(i);
            UserHandle user = mUserCache.getUserForSerialNumber(userId);
            for (String pkg : packagesToDelete.valueAt(i)) {
                removePackage(pkg, user, userId);
            }
        }
    } catch (SQLException e) {
        Log.e(TAG, "Error updating widget previews", e);
    } finally {
        if (c != null) {
            c.close();
        }
    }
}
Also used : LongSparseArray(android.util.LongSparseArray) SQLException(android.database.SQLException) ComponentKey(com.android.launcher3.util.ComponentKey) Cursor(android.database.Cursor) Paint(android.graphics.Paint) UserHandle(android.os.UserHandle) HashSet(java.util.HashSet)

Example 17 with Launcher

use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by crdroidandroid.

the class AbsSwipeUpHandler method createWindowAnimationToPip.

private SwipePipToHomeAnimator createWindowAnimationToPip(HomeAnimationFactory homeAnimFactory, RemoteAnimationTargetCompat runningTaskTarget, float startProgress) {
    // Directly animate the app to PiP (picture-in-picture) mode
    final ActivityManager.RunningTaskInfo taskInfo = mGestureState.getRunningTask();
    final RecentsOrientedState orientationState = mTaskViewSimulator.getOrientationState();
    final int windowRotation = orientationState.getDisplayRotation();
    final int homeRotation = orientationState.getRecentsActivityRotation();
    final Matrix homeToWindowPositionMap = new Matrix();
    final RectF startRect = updateProgressForStartRect(homeToWindowPositionMap, startProgress);
    // Move the startRect to Launcher space as floatingIconView runs in Launcher
    final Matrix windowToHomePositionMap = new Matrix();
    homeToWindowPositionMap.invert(windowToHomePositionMap);
    windowToHomePositionMap.mapRect(startRect);
    final Rect destinationBounds = SystemUiProxy.INSTANCE.get(mContext).startSwipePipToHome(taskInfo.topActivity, taskInfo.topActivityInfo, runningTaskTarget.taskInfo.pictureInPictureParams, homeRotation, mDp.hotseatBarSizePx);
    final SwipePipToHomeAnimator.Builder builder = new SwipePipToHomeAnimator.Builder().setContext(mContext).setTaskId(runningTaskTarget.taskId).setComponentName(taskInfo.topActivity).setLeash(runningTaskTarget.leash.getSurfaceControl()).setSourceRectHint(runningTaskTarget.taskInfo.pictureInPictureParams.getSourceRectHint()).setAppBounds(taskInfo.configuration.windowConfiguration.getBounds()).setHomeToWindowPositionMap(homeToWindowPositionMap).setStartBounds(startRect).setDestinationBounds(destinationBounds).setCornerRadius(mRecentsView.getPipCornerRadius()).setAttachedView(mRecentsView);
    // is not ROTATION_0 (which implies the rotation is turned on in launcher settings).
    if (homeRotation == ROTATION_0 && (windowRotation == ROTATION_90 || windowRotation == ROTATION_270)) {
        builder.setFromRotation(mTaskViewSimulator, windowRotation, taskInfo.displayCutoutInsets);
    }
    final SwipePipToHomeAnimator swipePipToHomeAnimator = builder.build();
    AnimatorPlaybackController activityAnimationToHome = homeAnimFactory.createActivityAnimationToHome();
    swipePipToHomeAnimator.addAnimatorListener(new AnimatorListenerAdapter() {

        private boolean mHasAnimationEnded;

        @Override
        public void onAnimationStart(Animator animation) {
            if (mHasAnimationEnded)
                return;
            // Ensure Launcher ends in NORMAL state
            activityAnimationToHome.dispatchOnStart();
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mHasAnimationEnded)
                return;
            mHasAnimationEnded = true;
            activityAnimationToHome.getAnimationPlayer().end();
            if (mRecentsAnimationController == null) {
                // skip doing any future work here for the current gesture.
                return;
            }
            // Finalize the state and notify of the change
            mGestureState.setState(STATE_END_TARGET_ANIMATION_FINISHED);
        }
    });
    setupWindowAnimation(swipePipToHomeAnimator);
    return swipePipToHomeAnimator;
}
Also used : Rect(android.graphics.Rect) AnimatorPlaybackController(com.android.launcher3.anim.AnimatorPlaybackController) RecentsOrientedState(com.android.quickstep.util.RecentsOrientedState) ActivityManager(android.app.ActivityManager) RectF(android.graphics.RectF) Matrix(android.graphics.Matrix) SwipePipToHomeAnimator(com.android.quickstep.util.SwipePipToHomeAnimator) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SwipePipToHomeAnimator(com.android.quickstep.util.SwipePipToHomeAnimator)

Example 18 with Launcher

use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by crdroidandroid.

the class AbsSwipeUpHandler method onActivityInit.

protected boolean onActivityInit(Boolean alreadyOnHome) {
    if (mStateCallback.hasStates(STATE_HANDLER_INVALIDATED)) {
        return false;
    }
    T createdActivity = mActivityInterface.getCreatedActivity();
    if (createdActivity != null) {
        initTransitionEndpoints(createdActivity.getDeviceProfile());
    }
    final T activity = mActivityInterface.getCreatedActivity();
    if (mActivity == activity) {
        return true;
    }
    if (mActivity != null) {
        if (mStateCallback.hasStates(STATE_GESTURE_COMPLETED)) {
            // If the activity has restarted between setting the page scroll settling callback
            // and actually receiving the callback, just mark the gesture completed
            mGestureState.setState(STATE_RECENTS_SCROLLING_FINISHED);
            return true;
        }
        // The launcher may have been recreated as a result of device rotation.
        int oldState = mStateCallback.getState() & ~LAUNCHER_UI_STATES;
        initStateCallbacks();
        mStateCallback.setState(oldState);
    }
    mWasLauncherAlreadyVisible = alreadyOnHome;
    mActivity = activity;
    // up, or until we transition home and the home animation is composed
    if (alreadyOnHome) {
        mActivity.clearForceInvisibleFlag(STATE_HANDLER_INVISIBILITY_FLAGS);
    } else {
        mActivity.addForceInvisibleFlag(STATE_HANDLER_INVISIBILITY_FLAGS);
    }
    mRecentsView = activity.getOverviewPanel();
    mRecentsView.setOnPageTransitionEndCallback(null);
    mStateCallback.setState(STATE_LAUNCHER_PRESENT);
    if (alreadyOnHome) {
        onLauncherStart();
    } else {
        activity.runOnceOnStart(this::onLauncherStart);
    }
    // Set up a entire animation lifecycle callback to notify the current recents view when
    // the animation is canceled
    mGestureState.runOnceAtState(STATE_RECENTS_ANIMATION_CANCELED, () -> {
        ThumbnailData snapshot = mGestureState.consumeRecentsAnimationCanceledSnapshot();
        if (snapshot != null) {
            mRecentsView.switchToScreenshot(snapshot, () -> {
                if (mRecentsAnimationController != null) {
                    mRecentsAnimationController.cleanupScreenshot();
                }
            });
            mRecentsView.onRecentsAnimationComplete();
        }
    });
    setupRecentsViewUi();
    linkRecentsViewScroll();
    return true;
}
Also used : LAUNCHER_QUICKSWITCH_RIGHT(com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_QUICKSWITCH_RIGHT) STATE_END_TARGET_SET(com.android.quickstep.GestureState.STATE_END_TARGET_SET) LAUNCHER_QUICKSWITCH_LEFT(com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_QUICKSWITCH_LEFT) LENGTH_SHORT(android.widget.Toast.LENGTH_SHORT) ThumbnailData(com.android.systemui.shared.recents.model.ThumbnailData)

Example 19 with Launcher

use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherTaskbarUIController method createAnimToLauncher.

/**
 * Create Taskbar animation when going from an app to Launcher.
 * @param toState If known, the state we will end up in when reaching Launcher.
 */
public Animator createAnimToLauncher(@Nullable LauncherState toState, long duration) {
    PendingAnimation anim = new PendingAnimation(duration);
    anim.add(mTaskbarAnimationController.createAnimToBackgroundAlpha(0, duration));
    if (toState != null) {
        mTaskbarStateHandler.setStateWithAnimation(toState, new StateAnimationConfig(), anim);
    }
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            mIsAnimatingToLauncher = true;
            mTaskbarView.setHolesAllowedInLayout(true);
            mTaskbarView.updateHotseatItemsVisibility();
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mIsAnimatingToLauncher = false;
            setTaskbarViewVisible(false);
        }
    });
    return anim.buildAnim();
}
Also used : PendingAnimation(com.android.launcher3.anim.PendingAnimation) Animator(android.animation.Animator) StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Example 20 with Launcher

use of com.android.launcher3.Launcher in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherActivityInterface method onOneHandedModeStateChanged.

@Override
public void onOneHandedModeStateChanged(boolean activated) {
    Launcher launcher = getCreatedActivity();
    if (launcher == null) {
        return;
    }
    launcher.onOneHandedStateChanged(activated);
}
Also used : Launcher(com.android.launcher3.Launcher) BaseQuickstepLauncher(com.android.launcher3.BaseQuickstepLauncher)

Aggregations

Launcher (com.android.launcher3.Launcher)30 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)18 Test (org.junit.Test)17 ItemInfo (com.android.launcher3.model.data.ItemInfo)13 Point (android.graphics.Point)12 DeviceProfile (com.android.launcher3.DeviceProfile)12 ArrayList (java.util.ArrayList)12 ComponentName (android.content.ComponentName)11 Intent (android.content.Intent)11 View (android.view.View)11 LargeTest (androidx.test.filters.LargeTest)11 Context (android.content.Context)10 BaseQuickstepLauncher (com.android.launcher3.BaseQuickstepLauncher)10 Rect (android.graphics.Rect)9 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)9 RecentsView (com.android.quickstep.views.RecentsView)9 LauncherApps (android.content.pm.LauncherApps)6 Paint (android.graphics.Paint)6 UserHandle (android.os.UserHandle)5 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)5