Search in sources :

Example 6 with IconsHandler

use of rocks.tbog.tblauncher.handler.IconsHandler in project TBLauncher by TBog.

the class DialContactEntry method getIconDrawable.

@Override
protected Drawable getIconDrawable(Context ctx) {
    if (hasCustomIcon()) {
        IconsHandler iconsHandler = TBApplication.getApplication(ctx).iconsHandler();
        Drawable drawable = iconsHandler.getCustomIcon(this);
        if (drawable != null)
            return drawable;
        else
            iconsHandler.restoreDefaultIcon(this);
    }
    return super.getIconDrawable(ctx);
}
Also used : IconsHandler(rocks.tbog.tblauncher.handler.IconsHandler) Drawable(android.graphics.drawable.Drawable)

Example 7 with IconsHandler

use of rocks.tbog.tblauncher.handler.IconsHandler in project TBLauncher by TBog.

the class SystemPage method addSystemIcons.

private void addSystemIcons(Context context, ShapedIconAdapter adapter) {
    ArraySet<Bitmap> dSet = new ArraySet<>(3);
    // add default icon
    {
        IconsHandler iconsHandler = TBApplication.getApplication(context).iconsHandler();
        Drawable drawable = iconsHandler.getDrawableIconForPackage(componentName, userHandle);
        // checkDuplicateDrawable(dSet, drawable);
        ShapedIconInfo iconInfo = new DefaultIconInfo(drawable);
        iconInfo.textId = R.string.default_icon;
        adapter.addItem(iconInfo);
    }
    // add getActivityIcon(componentName)
    {
        Drawable drawable = null;
        try {
            drawable = context.getPackageManager().getActivityIcon(componentName);
        } catch (PackageManager.NameNotFoundException ignored) {
        }
        if (drawable != null) {
            if (checkDuplicateDrawable(dSet, drawable)) {
                {
                    Drawable shapedDrawable = DrawableUtils.applyIconMaskShape(context, drawable, mShape, mScale, mBackground);
                    addQuickOption(R.string.custom_icon_activity, shapedDrawable, drawable, adapter);
                }
                if (DrawableUtils.isAdaptiveIconDrawable(drawable)) {
                    Drawable noBackground = DrawableUtils.applyAdaptiveIconBackgroundShape(context, drawable, DrawableUtils.SHAPE_SQUARE, true);
                    Drawable shapedDrawable = DrawableUtils.applyIconMaskShape(context, noBackground, mShape, mScale, mBackground);
                    addQuickOption(R.string.custom_icon_activity_adaptive_no_background, shapedDrawable, noBackground, adapter);
                }
            }
        }
    }
    // add getApplicationIcon(packageName)
    {
        Drawable drawable = null;
        try {
            drawable = context.getPackageManager().getApplicationIcon(componentName.getPackageName());
        } catch (PackageManager.NameNotFoundException ignored) {
        }
        if (drawable != null) {
            if (checkDuplicateDrawable(dSet, drawable)) {
                Drawable shapedDrawable = DrawableUtils.applyIconMaskShape(context, drawable, mShape, mScale, mBackground);
                addQuickOption(R.string.custom_icon_application, shapedDrawable, drawable, adapter);
            }
        }
    }
    // add Activity BadgedIcon
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        LauncherApps launcher = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
        assert launcher != null;
        List<LauncherActivityInfo> icons = launcher.getActivityList(componentName.getPackageName(), userHandle.getRealHandle());
        for (LauncherActivityInfo info : icons) {
            Drawable drawable = info.getBadgedIcon(0);
            if (drawable != null) {
                if (checkDuplicateDrawable(dSet, drawable)) {
                    Drawable shapedDrawable = DrawableUtils.applyIconMaskShape(context, drawable, mShape, mScale, mBackground);
                    addQuickOption(R.string.custom_icon_badged, shapedDrawable, drawable, adapter);
                }
            }
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) ArraySet(androidx.collection.ArraySet) IconsHandler(rocks.tbog.tblauncher.handler.IconsHandler) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) LauncherApps(android.content.pm.LauncherApps)

Example 8 with IconsHandler

use of rocks.tbog.tblauncher.handler.IconsHandler in project TBLauncher by TBog.

the class ShortcutEntry method getAppDrawable.

@WorkerThread
public static Drawable getAppDrawable(@NonNull Context context, @NonNull String shortcutData, @NonNull String packageName, @Nullable ShortcutInfo shortcutInfo, boolean isBadge) {
    Drawable appDrawable = null;
    final PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> activities = null;
    if (shortcutInfo == null) {
        try {
            Intent intent = Intent.parseUri(shortcutData, 0);
            activities = packageManager.queryIntentActivities(intent, 0);
        } catch (URISyntaxException e) {
            Log.e("Shortcut", "parse `" + shortcutData + "`", e);
        }
    }
    final IconsHandler iconsHandler = TBApplication.iconsHandler(context);
    if (activities != null && !activities.isEmpty()) {
        ResolveInfo mainPackage = activities.get(0);
        String packName = mainPackage.activityInfo.applicationInfo.packageName;
        String actName = mainPackage.activityInfo.name;
        ComponentName className = new ComponentName(packName, actName);
        appDrawable = isBadge ? iconsHandler.getDrawableBadgeForPackage(className, UserHandleCompat.CURRENT_USER) : iconsHandler.getDrawableIconForPackage(className, UserHandleCompat.CURRENT_USER);
    }
    if (appDrawable == null && shortcutInfo != null) {
        // Retrieve app icon
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            UserHandleCompat user = new UserHandleCompat(context, shortcutInfo.getUserHandle());
            ComponentName componentName = shortcutInfo.getActivity();
            appDrawable = isBadge ? iconsHandler.getDrawableBadgeForPackage(componentName, user) : iconsHandler.getDrawableIconForPackage(componentName, user);
            if (appDrawable == null)
                try {
                    appDrawable = packageManager.getActivityIcon(componentName);
                } catch (PackageManager.NameNotFoundException e) {
                    Log.e(TAG, "Unable to find activity icon " + componentName.toString(), e);
                }
        }
    }
    if (appDrawable == null) {
        try {
            appDrawable = packageManager.getApplicationIcon(packageName);
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "get app shortcut icon", e);
            return null;
        }
        appDrawable = iconsHandler.getIconPack().applyBackgroundAndMask(context, appDrawable, true);
    }
    return appDrawable;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) IconsHandler(rocks.tbog.tblauncher.handler.IconsHandler) Drawable(android.graphics.drawable.Drawable) AsyncSetEntryDrawable(rocks.tbog.tblauncher.result.AsyncSetEntryDrawable) Intent(android.content.Intent) ComponentName(android.content.ComponentName) URISyntaxException(java.net.URISyntaxException) UserHandleCompat(rocks.tbog.tblauncher.utils.UserHandleCompat) WorkerThread(androidx.annotation.WorkerThread)

Example 9 with IconsHandler

use of rocks.tbog.tblauncher.handler.IconsHandler in project TBLauncher by TBog.

the class ShortcutEntry method getIcon.

public Drawable getIcon(@NonNull Context context) {
    if (customIcon > 0) {
        IconsHandler iconsHandler = TBApplication.getApplication(context).iconsHandler();
        Drawable drawable = iconsHandler.getCustomIcon(this);
        if (drawable != null)
            return drawable;
        else
            iconsHandler.restoreDefaultIcon(this);
    }
    Bitmap bitmap = ShortcutUtil.getInitialIcon(context, dbId);
    if (bitmap == null)
        return null;
    return TBApplication.iconsHandler(context).applyShortcutMask(context, bitmap);
}
Also used : Bitmap(android.graphics.Bitmap) IconsHandler(rocks.tbog.tblauncher.handler.IconsHandler) Drawable(android.graphics.drawable.Drawable) AsyncSetEntryDrawable(rocks.tbog.tblauncher.result.AsyncSetEntryDrawable)

Example 10 with IconsHandler

use of rocks.tbog.tblauncher.handler.IconsHandler in project TBLauncher by TBog.

the class StaticEntry method getIconDrawable.

@WorkerThread
public Drawable getIconDrawable(Context context) {
    if (hasCustomIcon()) {
        IconsHandler iconsHandler = TBApplication.getApplication(context).iconsHandler();
        Drawable drawable = iconsHandler.getCustomIcon(this);
        if (drawable != null)
            return drawable;
        else
            iconsHandler.restoreDefaultIcon(this);
    }
    return getDefaultDrawable(context);
}
Also used : IconsHandler(rocks.tbog.tblauncher.handler.IconsHandler) Drawable(android.graphics.drawable.Drawable) AsyncSetEntryDrawable(rocks.tbog.tblauncher.result.AsyncSetEntryDrawable) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

IconsHandler (rocks.tbog.tblauncher.handler.IconsHandler)10 Drawable (android.graphics.drawable.Drawable)8 WorkerThread (androidx.annotation.WorkerThread)4 AsyncSetEntryDrawable (rocks.tbog.tblauncher.result.AsyncSetEntryDrawable)4 ComponentName (android.content.ComponentName)2 Context (android.content.Context)2 Bitmap (android.graphics.Bitmap)2 UserHandleCompat (rocks.tbog.tblauncher.utils.UserHandleCompat)2 Intent (android.content.Intent)1 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)1 LauncherApps (android.content.pm.LauncherApps)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Pair (android.util.Pair)1 NonNull (androidx.annotation.NonNull)1 ArraySet (androidx.collection.ArraySet)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1