Search in sources :

Example 1 with IconsHandler

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

the class AppEntry method getIconDrawable.

@WorkerThread
public Drawable getIconDrawable(Context context) {
    IconsHandler iconsHandler = TBApplication.getApplication(context).iconsHandler();
    if (iconInfo.customIcon != 0) {
        Drawable drawable = iconsHandler.getCustomIcon(getUserComponentName());
        if (drawable != null)
            return drawable;
        else
            iconsHandler.restoreDefaultIcon(this);
    }
    IconsHandler.IconInfo icon = iconsHandler.getIconForPackage(componentName, userHandle);
    iconInfo.setIconInfo(icon);
    return icon.getDrawable();
}
Also used : IconsHandler(rocks.tbog.tblauncher.handler.IconsHandler) Drawable(android.graphics.drawable.Drawable) AsyncSetEntryDrawable(rocks.tbog.tblauncher.result.AsyncSetEntryDrawable) WorkerThread(androidx.annotation.WorkerThread)

Example 2 with IconsHandler

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

the class SearchEntry method getIconDrawable.

// /////////////////////////////////////////////////////////////////////////////////////////////
// Result methods
// /////////////////////////////////////////////////////////////////////////////////////////////
@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) WorkerThread(androidx.annotation.WorkerThread)

Example 3 with IconsHandler

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

the class TagsManager method applyChanges.

public void applyChanges(@NonNull Context context) {
    TagsHandler tagsHandler = TBApplication.tagsHandler(context);
    IconsHandler iconsHandler = TBApplication.iconsHandler(context);
    TBLauncherActivity launcherActivity = TBApplication.launcherActivity(context);
    boolean changesMade = false;
    for (TagInfo tagInfo : mTagList) {
        if (tagInfo.staticEntry instanceof ActionEntry) {
            // can't delete actions (it's the show untagged action)
            if (tagInfo.action == TagInfo.Action.RENAME) {
                TBApplication.dataHandler(context).renameStaticEntry(tagInfo.staticEntry, tagInfo.name);
                changesMade = true;
            }
        } else {
            switch(tagInfo.action) {
                case RENAME:
                    if (tagsHandler.renameTag(tagInfo.tagName, tagInfo.name))
                        changesMade = true;
                    break;
                case DELETE:
                    if (tagInfo.staticEntry != null)
                        iconsHandler.restoreDefaultIcon(tagInfo.staticEntry);
                    tagInfo.icon = null;
                    if (tagsHandler.removeTag(tagInfo.tagName))
                        changesMade = true;
                    break;
            }
        }
        if (tagInfo.icon != null && tagInfo.staticEntry != null) {
            iconsHandler.changeIcon(tagInfo.staticEntry, tagInfo.icon);
            if (launcherActivity != null) {
                // force a result refresh to update the icon in the view
                launcherActivity.behaviour.refreshSearchRecord(tagInfo.staticEntry);
            }
        }
    }
    // make sure we're in sync
    if (changesMade) {
        if (launcherActivity != null)
            launcherActivity.queueDockReload();
        afterChangesMade(context);
    }
}
Also used : ActionEntry(rocks.tbog.tblauncher.entry.ActionEntry) TagsHandler(rocks.tbog.tblauncher.handler.TagsHandler) IconsHandler(rocks.tbog.tblauncher.handler.IconsHandler)

Example 4 with IconsHandler

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

the class IconSelectDialog method customIconApp.

private void customIconApp(Bundle args) {
    Context context = requireContext();
    String name = args.getString("componentName", "");
    long customIcon = args.getLong("customIcon", 0);
    if (name.isEmpty()) {
        dismiss();
        String entryName = args.getString("entryName", "");
        Toast.makeText(Utilities.getActivity(context), context.getString(R.string.entry_not_found, entryName), Toast.LENGTH_LONG).show();
        return;
    }
    IconsHandler iconsHandler = TBApplication.getApplication(context).iconsHandler();
    ComponentName cn = UserHandleCompat.unflattenComponentName(name);
    UserHandleCompat userHandle = UserHandleCompat.fromComponentName(context, name);
    // Preview
    initPreviewIcon(mPreviewLabel, ctx -> {
        Drawable drawable = customIcon != 0 ? iconsHandler.getCustomIcon(name) : null;
        if (drawable == null)
            drawable = iconsHandler.getDrawableIconForPackage(cn, userHandle);
        return drawable;
    });
}
Also used : Context(android.content.Context) IconsHandler(rocks.tbog.tblauncher.handler.IconsHandler) Drawable(android.graphics.drawable.Drawable) ComponentName(android.content.ComponentName) UserHandleCompat(rocks.tbog.tblauncher.utils.UserHandleCompat)

Example 5 with IconsHandler

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

the class IconSelectDialog method addIconPacks.

/**
 * Add ViewPager pages for every icon pack
 *
 * @param inflater used for inflating the page view
 * @return an array of pairs with the icon pack package name and icon pack name
 */
@NonNull
private ArrayList<Pair<String, String>> addIconPacks(LayoutInflater inflater) {
    Context context = inflater.getContext();
    IconsHandler iconsHandler = TBApplication.iconsHandler(context);
    Map<String, String> iconPackNames = iconsHandler.getIconPackNames();
    ArrayList<Pair<String, String>> iconPacks = new ArrayList<>(iconPackNames.size());
    for (Map.Entry<String, String> packInfo : iconPackNames.entrySet()) iconPacks.add(new Pair<>(packInfo.getKey(), packInfo.getValue()));
    IconPack<?> iconPack = iconsHandler.getCustomIconPack();
    String selectedPackPackageName = iconPack != null ? iconPack.getPackPackageName() : "";
    Collections.sort(iconPacks, (o1, o2) -> {
        if (selectedPackPackageName.equals(o1.first))
            return -1;
        if (selectedPackPackageName.equals(o2.first))
            return 1;
        return o1.second.compareTo(o2.second);
    });
    for (Pair<String, String> packInfo : iconPacks) {
        String packPackageName = packInfo.first;
        String packName = packInfo.second;
        if (selectedPackPackageName.equals(packPackageName))
            packName = context.getString(R.string.selected_pack, packName);
        // add page to ViewPager
        addIconPackPage(inflater, mViewPager, packName, packPackageName);
    }
    return iconPacks;
}
Also used : Context(android.content.Context) IconsHandler(rocks.tbog.tblauncher.handler.IconsHandler) ArrayList(java.util.ArrayList) Map(java.util.Map) Pair(android.util.Pair) NonNull(androidx.annotation.NonNull)

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