Search in sources :

Example 21 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project android_packages_apps_Launcher3 by ProtonAOSP.

the class TaskbarEduController method createWaveAnim.

/**
 * Creates a staggered "wave" animation where each icon translates and scales up in succession.
 */
private Animator createWaveAnim() {
    AnimatorSet waveAnim = new AnimatorSet();
    View[] icons = mControllers.taskbarViewController.getIconViews();
    for (int i = 0; i < icons.length; i++) {
        View icon = icons[i];
        AnimatorSet iconAnim = new AnimatorSet();
        Keyframe[] scaleKeyframes = new Keyframe[] { Keyframe.ofFloat(0, 1f), Keyframe.ofFloat(WAVE_ANIM_FRACTION_TOP, WAVE_ANIM_ICON_SCALE), Keyframe.ofFloat(WAVE_ANIM_FRACTION_BOTTOM, 1f), Keyframe.ofFloat(1f, 1f) };
        scaleKeyframes[1].setInterpolator(WAVE_ANIM_TO_TOP_INTERPOLATOR);
        scaleKeyframes[2].setInterpolator(WAVE_ANIM_TO_BOTTOM_INTERPOLATOR);
        Keyframe[] translationYKeyframes = new Keyframe[] { Keyframe.ofFloat(0, 0f), Keyframe.ofFloat(WAVE_ANIM_FRACTION_TOP, -mWaveAnimTranslationY), Keyframe.ofFloat(WAVE_ANIM_FRACTION_BOTTOM, 0f), // Half of the remaining fraction overshoots, then the other half returns to 0.
        Keyframe.ofFloat(WAVE_ANIM_FRACTION_BOTTOM + (1 - WAVE_ANIM_FRACTION_BOTTOM) / 2f, mWaveAnimTranslationYReturnOvershoot), Keyframe.ofFloat(1f, 0f) };
        translationYKeyframes[1].setInterpolator(WAVE_ANIM_TO_TOP_INTERPOLATOR);
        translationYKeyframes[2].setInterpolator(WAVE_ANIM_TO_BOTTOM_INTERPOLATOR);
        translationYKeyframes[3].setInterpolator(WAVE_ANIM_OVERSHOOT_INTERPOLATOR);
        translationYKeyframes[4].setInterpolator(WAVE_ANIM_OVERSHOOT_RETURN_INTERPOLATOR);
        iconAnim.play(ObjectAnimator.ofPropertyValuesHolder(icon, PropertyValuesHolder.ofKeyframe(SCALE_PROPERTY, scaleKeyframes)).setDuration(WAVE_ANIM_EACH_ICON_DURATION));
        iconAnim.play(ObjectAnimator.ofPropertyValuesHolder(icon, PropertyValuesHolder.ofKeyframe(View.TRANSLATION_Y, translationYKeyframes)).setDuration(WAVE_ANIM_EACH_ICON_DURATION));
        if (icon instanceof PredictedAppIcon) {
            // Play slot machine animation through random icons from AllAppsList.
            PredictedAppIcon predictedAppIcon = (PredictedAppIcon) icon;
            ItemInfo itemInfo = (ItemInfo) icon.getTag();
            List<BitmapInfo> iconsToAnimate = mControllers.uiController.getAppIconsForEdu().filter(appInfo -> !TextUtils.equals(appInfo.title, itemInfo.title)).map(appInfo -> appInfo.bitmap).filter(bitmap -> !bitmap.isNullOrLowRes()).collect(Collectors.toList());
            // Pick n icons at random.
            Collections.shuffle(iconsToAnimate);
            if (iconsToAnimate.size() > WAVE_ANIM_SLOT_MACHINE_NUM_ICONS) {
                iconsToAnimate = iconsToAnimate.subList(0, WAVE_ANIM_SLOT_MACHINE_NUM_ICONS);
            }
            Animator slotMachineAnim = predictedAppIcon.createSlotMachineAnim(iconsToAnimate);
            if (slotMachineAnim != null) {
                iconAnim.play(slotMachineAnim.setDuration(WAVE_ANIM_SLOT_MACHINE_DURATION));
            }
        }
        iconAnim.setStartDelay(WAVE_ANIM_STAGGER * i);
        waveAnim.play(iconAnim);
    }
    waveAnim.setStartDelay(WAVE_ANIM_DELAY);
    return waveAnim;
}
Also used : TimeInterpolator(android.animation.TimeInterpolator) ObjectAnimator(android.animation.ObjectAnimator) ItemInfo(com.android.launcher3.model.data.ItemInfo) DEACCEL(com.android.launcher3.anim.Interpolators.DEACCEL) TextUtils(android.text.TextUtils) PredictedAppIcon(com.android.launcher3.uioverrides.PredictedAppIcon) ACCEL_2(com.android.launcher3.anim.Interpolators.ACCEL_2) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Collectors(java.util.stream.Collectors) FAST_OUT_SLOW_IN(com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN) BitmapInfo(com.android.launcher3.icons.BitmapInfo) List(java.util.List) PropertyValuesHolder(android.animation.PropertyValuesHolder) R(com.android.launcher3.R) Keyframe(android.animation.Keyframe) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) SCALE_PROPERTY(com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY) Collections(java.util.Collections) ACCEL_DEACCEL(com.android.launcher3.anim.Interpolators.ACCEL_DEACCEL) Resources(android.content.res.Resources) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) Keyframe(android.animation.Keyframe) ItemInfo(com.android.launcher3.model.data.ItemInfo) PredictedAppIcon(com.android.launcher3.uioverrides.PredictedAppIcon) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) BitmapInfo(com.android.launcher3.icons.BitmapInfo)

Example 22 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project android_packages_apps_Launcher3 by ProtonAOSP.

the class ModelUtils method fromLegacyShortcutIntent.

/**
 * Creates a workspace item info for the legacy shortcut intent
 */
@SuppressWarnings("deprecation")
public static WorkspaceItemInfo fromLegacyShortcutIntent(Context context, Intent data) {
    if (!isValidExtraType(data, Intent.EXTRA_SHORTCUT_INTENT, Intent.class) || !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.class)) || !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON, Bitmap.class))) {
        Log.e(TAG, "Invalid install shortcut intent");
        return null;
    }
    Intent launchIntent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String label = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (launchIntent == null || label == null) {
        Log.e(TAG, "Invalid install shortcut intent");
        return null;
    }
    final WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.user = Process.myUserHandle();
    BitmapInfo iconInfo = null;
    try (LauncherIcons li = LauncherIcons.obtain(context)) {
        Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
        if (bitmap != null) {
            iconInfo = li.createIconBitmap(bitmap);
        } else {
            info.iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
            if (info.iconResource != null) {
                iconInfo = li.createIconBitmap(info.iconResource);
            }
        }
    }
    if (iconInfo == null) {
        Log.e(TAG, "Invalid icon by the app");
        return null;
    }
    info.bitmap = iconInfo;
    info.contentDescription = info.title = Utilities.trim(label);
    info.intent = launchIntent;
    return info;
}
Also used : Bitmap(android.graphics.Bitmap) LauncherIcons(com.android.launcher3.icons.LauncherIcons) Intent(android.content.Intent) BitmapInfo(com.android.launcher3.icons.BitmapInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 23 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project android_packages_apps_Launcher3 by ProtonAOSP.

the class IconCache method getShortcutInfoBadge.

/**
 * Returns the badging info for the shortcut
 */
public BitmapInfo getShortcutInfoBadge(ShortcutInfo shortcutInfo) {
    ComponentName cn = shortcutInfo.getActivity();
    if (cn != null) {
        // Get the app info for the source activity.
        AppInfo appInfo = new AppInfo();
        appInfo.user = shortcutInfo.getUserHandle();
        appInfo.componentName = cn;
        appInfo.intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(cn);
        getTitleAndIcon(appInfo, false);
        return appInfo.bitmap;
    } else {
        PackageItemInfo pkgInfo = new PackageItemInfo(shortcutInfo.getPackage(), shortcutInfo.getUserHandle());
        getTitleAndIconForApp(pkgInfo, false);
        return pkgInfo.bitmap;
    }
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) ComponentName(android.content.ComponentName) Intent(android.content.Intent) AppInfo(com.android.launcher3.model.data.AppInfo)

Example 24 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project android_packages_apps_Launcher3 by ProtonAOSP.

the class TaskIconCache method getCacheEntry.

@WorkerThread
private TaskCacheEntry getCacheEntry(Task task) {
    TaskCacheEntry entry = mIconCache.getAndInvalidateIfModified(task.key);
    if (entry != null) {
        return entry;
    }
    TaskDescription desc = task.taskDescription;
    TaskKey key = task.key;
    ActivityInfo activityInfo = null;
    // Create new cache entry
    entry = new TaskCacheEntry();
    // Load icon
    // TODO: Load icon resource (b/143363444)
    Bitmap icon = TaskDescriptionCompat.getIcon(desc, key.userId);
    if (icon != null) {
        /* isInstantApp */
        entry.icon = getBitmapInfo(new BitmapDrawable(mContext.getResources(), icon), key.userId, desc.getPrimaryColor(), false).newIcon(mContext);
    } else {
        activityInfo = PackageManagerWrapper.getInstance().getActivityInfo(key.getComponent(), key.userId);
        if (activityInfo != null) {
            BitmapInfo bitmapInfo = getBitmapInfo(mIconProvider.getIcon(activityInfo), key.userId, desc.getPrimaryColor(), activityInfo.applicationInfo.isInstantApp());
            entry.icon = bitmapInfo.newIcon(mContext);
        } else {
            entry.icon = getDefaultIcon(key.userId);
        }
    }
    // Loading content descriptions if accessibility or low RAM recents is enabled.
    if (GO_LOW_RAM_RECENTS_ENABLED || mAccessibilityManager.isEnabled()) {
        // Skip loading the content description if the activity no longer exists
        if (activityInfo == null) {
            activityInfo = PackageManagerWrapper.getInstance().getActivityInfo(key.getComponent(), key.userId);
        }
        if (activityInfo != null) {
            entry.contentDescription = getBadgedContentDescription(activityInfo, task.key.userId, task.taskDescription);
        }
    }
    mIconCache.put(task.key, entry);
    return entry;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) Bitmap(android.graphics.Bitmap) TaskDescription(android.app.ActivityManager.TaskDescription) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TaskKey(com.android.systemui.shared.recents.model.Task.TaskKey) BitmapInfo(com.android.launcher3.icons.BitmapInfo) WorkerThread(androidx.annotation.WorkerThread)

Example 25 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project android_packages_apps_Launcher3 by ProtonAOSP.

the class TaskIconCache method getBitmapInfo.

@WorkerThread
private BitmapInfo getBitmapInfo(Drawable drawable, int userId, int primaryColor, boolean isInstantApp) {
    try (BaseIconFactory bif = getIconFactory()) {
        bif.disableColorExtraction();
        bif.setWrapperBackgroundColor(primaryColor);
        // User version code O, so that the icon is always wrapped in an adaptive icon container
        return bif.createBadgedIconBitmap(drawable, UserHandle.of(userId), Build.VERSION_CODES.O, isInstantApp);
    }
}
Also used : BaseIconFactory(com.android.launcher3.icons.BaseIconFactory) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

BitmapInfo (com.android.launcher3.icons.BitmapInfo)33 LauncherIcons (com.android.launcher3.icons.LauncherIcons)21 Intent (android.content.Intent)18 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)18 Bitmap (android.graphics.Bitmap)15 ComponentName (android.content.ComponentName)14 Context (android.content.Context)14 IconCache (com.android.launcher3.icons.IconCache)13 WorkerThread (androidx.annotation.WorkerThread)11 ItemInfo (com.android.launcher3.model.data.ItemInfo)11 List (java.util.List)9 ShortcutInfo (android.content.pm.ShortcutInfo)8 PackageInfo (android.content.pm.PackageInfo)7 BitmapDrawable (android.graphics.drawable.BitmapDrawable)6 TaskDescription (android.app.ActivityManager.TaskDescription)5 ActivityInfo (android.content.pm.ActivityInfo)5 LauncherApps (android.content.pm.LauncherApps)5 UserManager (android.os.UserManager)5 R (com.android.launcher3.R)5 BaseIconFactory (com.android.launcher3.icons.BaseIconFactory)5