Search in sources :

Example 11 with Launcher

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

the class LauncherModel method startLoader.

/**
 * Starts the loader. Tries to bind {@params synchronousBindPage} synchronously if possible.
 * @return true if the page could be bound synchronously.
 */
public boolean startLoader() {
    // Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
    ItemInstallQueue.INSTANCE.get(mApp.getContext()).pauseModelPush(ItemInstallQueue.FLAG_LOADER_RUNNING);
    synchronized (mLock) {
        // Don't bother to start the thread if we know it's not going to do anything
        final Callbacks[] callbacksList = getCallbacks();
        if (callbacksList.length > 0) {
            // Clear any pending bind-runnables from the synchronized load process.
            for (Callbacks cb : callbacksList) {
                MAIN_EXECUTOR.execute(cb::clearPendingBinds);
            }
            // If there is already one running, tell it to stop.
            stopLoader();
            LoaderResults loaderResults = new LoaderResults(mApp, mBgDataModel, mBgAllAppsList, callbacksList);
            if (mModelLoaded && !mIsLoaderTaskRunning) {
                // Divide the set of loaded items into those that we are binding synchronously,
                // and everything else that is to be bound normally (asynchronously).
                loaderResults.bindWorkspace();
                // For now, continue posting the binding of AllApps as there are other
                // issues that arise from that.
                loaderResults.bindAllApps();
                loaderResults.bindDeepShortcuts();
                loaderResults.bindWidgets();
                return true;
            } else {
                stopLoader();
                mLoaderTask = new LoaderTask(mApp, mBgAllAppsList, mBgDataModel, mModelDelegate, loaderResults);
                // Always post the loader task, instead of running directly
                // (even on same thread) so that we exit any nested synchronized blocks
                MODEL_EXECUTOR.post(mLoaderTask);
            }
        }
    }
    return false;
}
Also used : Callbacks(com.android.launcher3.model.BgDataModel.Callbacks) LoaderTask(com.android.launcher3.model.LoaderTask) LoaderResults(com.android.launcher3.model.LoaderResults)

Example 12 with Launcher

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

the class Utilities method getBadge.

/**
 * For apps icons and shortcut icons that have badges, this method creates a drawable that can
 * later on be rendered on top of the layers for the badges. For app icons, work profile badges
 * can only be applied. For deep shortcuts, when dragged from the pop up container, there's no
 * badge. When dragged from workspace or folder, it may contain app AND/OR work profile badge
 */
@TargetApi(Build.VERSION_CODES.O)
public static Drawable getBadge(Launcher launcher, ItemInfo info, Object obj) {
    LauncherAppState appState = LauncherAppState.getInstance(launcher);
    int iconSize = appState.getInvariantDeviceProfile().iconBitmapSize;
    if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
        boolean iconBadged = (info instanceof ItemInfoWithIcon) && (((ItemInfoWithIcon) info).runtimeStatusFlags & FLAG_ICON_BADGED) > 0;
        if ((info.id == ItemInfo.NO_ID && !iconBadged) || !(obj instanceof ShortcutInfo)) {
            // The item is not yet added on home screen.
            return new FixedSizeEmptyDrawable(iconSize);
        }
        ShortcutInfo si = (ShortcutInfo) obj;
        Bitmap badge = LauncherAppState.getInstance(appState.getContext()).getIconCache().getShortcutInfoBadge(si).icon;
        float badgeSize = LauncherIcons.getBadgeSizeForIconSize(iconSize);
        float insetFraction = (iconSize - badgeSize) / iconSize;
        return new InsetDrawable(new FastBitmapDrawable(badge), insetFraction, insetFraction, 0, 0);
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
        return ((FolderAdaptiveIcon) obj).getBadge();
    } else {
        return launcher.getPackageManager().getUserBadgedIcon(new FixedSizeEmptyDrawable(iconSize), info.user);
    }
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Bitmap(android.graphics.Bitmap) ShortcutInfo(android.content.pm.ShortcutInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) InsetDrawable(android.graphics.drawable.InsetDrawable) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) Paint(android.graphics.Paint) Point(android.graphics.Point) TargetApi(android.annotation.TargetApi)

Example 13 with Launcher

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

the class DiscoveryBounce method showForHomeIfNeeded.

private static void showForHomeIfNeeded(Launcher launcher, boolean withDelay) {
    OnboardingPrefs onboardingPrefs = launcher.getOnboardingPrefs();
    if (!launcher.isInState(NORMAL) || onboardingPrefs.getBoolean(OnboardingPrefs.HOME_BOUNCE_SEEN) || AbstractFloatingView.getTopOpenView(launcher) != null || launcher.getSystemService(UserManager.class).isDemoUser() || Utilities.IS_RUNNING_IN_TEST_HARNESS) {
        return;
    }
    if (withDelay) {
        new Handler().postDelayed(() -> showForHomeIfNeeded(launcher, false), DELAY_MS);
        return;
    }
    onboardingPrefs.incrementEventCount(OnboardingPrefs.HOME_BOUNCE_COUNT);
    new DiscoveryBounce(launcher).show();
}
Also used : OnboardingPrefs(com.android.launcher3.util.OnboardingPrefs) UserManager(android.os.UserManager) Handler(android.os.Handler)

Example 14 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 15 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)

Aggregations

Launcher (com.android.launcher3.Launcher)194 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)102 Test (org.junit.Test)102 View (android.view.View)87 LargeTest (androidx.test.filters.LargeTest)83 ItemInfo (com.android.launcher3.model.data.ItemInfo)83 Rect (android.graphics.Rect)80 Point (android.graphics.Point)77 Intent (android.content.Intent)71 ArrayList (java.util.ArrayList)69 DeviceProfile (com.android.launcher3.DeviceProfile)66 BaseQuickstepLauncher (com.android.launcher3.BaseQuickstepLauncher)64 Context (android.content.Context)61 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)49 RecentsView (com.android.quickstep.views.RecentsView)46 DragLayer (com.android.launcher3.dragndrop.DragLayer)45 ComponentName (android.content.ComponentName)43 FolderInfo (com.android.launcher3.model.data.FolderInfo)42 ViewGroup (android.view.ViewGroup)41 AllApps (com.android.launcher3.tapl.AllApps)40