Arcticons-Team / Arcticons

A monotone line-based icon pack for android
https://arcticons.com/
GNU General Public License v3.0
952 stars 310 forks source link

Apply Arcticons You on folder icon in Discreet Launcher #1859

Closed jcperil closed 6 months ago

jcperil commented 9 months ago

Hi, Discreet Launcher allows folders. Is there a way to apply Arcticons You on that?

Donnnno commented 9 months ago

If it has an intent (com.discretelauncher.something), we could make an icon for it.

Maybe the dev @falzonv know's if it's possible :)

TotallyAvailable commented 9 months ago
// Prepare the folder icon

SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this) ;
    int icon_size = Utils.getIconSize(this, settings) ;
    Drawable icon = new FolderIcon(this, icon_size, 0, getResources().getColor(R.color.for_icon_added_in_drawer)) ;
    icon.setBounds(0, 0, icon_size, icon_size) ;
public class FolderIcon extends Drawable
{
    // Attribute
    private final String number ;
    private final Bitmap icon ;
    private final Paint paint ;
    private final int icon_size ;

    /**
     * Constructor.
     */
    public FolderIcon(Context context, int icon_size_pixels, int applications_number, int color)
    {
        // Retrieve the folder icon
        icon_size = icon_size_pixels ;
        Drawable folderIcon = AppCompatResources.getDrawable(context, R.drawable.icon_folder) ;
        if(folderIcon != null)
            {
                // Convert the folder icon into a Bitmap of the correct size
                Bitmap convertedIcon = Bitmap.createBitmap(folderIcon.getIntrinsicWidth(), folderIcon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888) ;
                folderIcon.setBounds(0, 0, icon_size, icon_size) ;
                folderIcon.draw(new Canvas(convertedIcon)) ;

                // Get an editable copy of the Bitmap and change its color according to settings
                icon = convertedIcon.copy(Bitmap.Config.ARGB_8888, true) ;
                Paint iconPaint = new Paint() ;
                iconPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN)) ;
                new Canvas(icon).drawBitmap(icon, 0, 0, iconPaint) ;
            }
            else icon = null ;

        // Retrieve the number to write and define its settings
        this.number = "" + applications_number ;
        paint = new Paint() ;
        paint.setAntiAlias(true) ;
        paint.setTextSize(icon_size / 3f) ;
        paint.setColor(color) ;
        paint.setTextAlign(Paint.Align.CENTER) ;
    }

    /**
     * Draw the folder icon with the number of applications inside.
     */
    @Override
    public void draw(Canvas canvas)
    {
        canvas.drawBitmap(icon, 0, 0, paint) ;
        canvas.drawText(number, icon_size * 0.5f, icon_size * 0.875f, paint) ;
    }
}
Donnnno commented 9 months ago

@TotallyAvailable uhhhh, anything we can do with this block of code?

TotallyAvailable commented 9 months ago

Just part of how the Launcher seems to create the folder icons on demand.

Unless there's a link somewhere in the Icon Pack related code that looks for a suitable icon in the applied pack to use instead of the default internal one, it might not be as easy as just binding to an intent or activity.

Might be completely wrong here of course. And while the launcher is on maintenance only (as mentioned in issue 314) it shouldn't be to hard to actually make it work. Could be either the dev pointing out that it is already possible, add it as feature request or have someone with the knowledge do it via PR.

My initial comment actually included a couple more thoughts that I scrapped in the end as either potentially wrong or not viable as solution. Not that I'm currently more confident about anything above.

        // Initializations (the XML file need to be reloaded for each icon)
        XmlPullParser appfilter = pack_resources.getXml(appfilter_id) ;
        String component_info = "ComponentInfo{" + apk + "/" + name ;
        int i, j ;

        try
        {
            // Browse the appfilter.xml file
            int event = appfilter.getEventType() ;
            while(event != XmlPullParser.END_DOCUMENT)
            {
                // Search only the <item ...> tags
                if((event == XmlPullParser.START_TAG) && appfilter.getName().equals("item"))
                    {
                        // Browse up to the "component" attribute
                        for(i = 0 ; i < appfilter.getAttributeCount() ; i++)
                        {
                            if(appfilter.getAttributeName(i).equals("component"))
                                {
                                    // Check if this is the searched package
                                    if(appfilter.getAttributeValue(i).startsWith(component_info))
                                        {
                                            // Get the icon name in the pack
                                            String icon_name = "" ;
                                            for(j = 0 ; j < appfilter.getAttributeCount() ; j++)
                                                if(appfilter.getAttributeName(j).equals("drawable"))
                                                    icon_name = appfilter.getAttributeValue(j) ;

                                            // Try to load the icon from the pack
                                            int icon_id = pack_resources.getIdentifier(icon_name, "drawable", pack_name) ;
                                            if(icon_id > 0) return ResourcesCompat.getDrawable(pack_resources, icon_id, null) ;

Without the on demand generation it should've been easy to just have it pick one up here/add custom (discreetlauncher.folder + number of items inside) entries.

kaanelloed commented 9 months ago

The intent created for a folder is {discreetlauncher.folder/discreetlauncher.folder[folder name]}, so the launcher would have to be modified for this to work.

But it should be pretty easy to implement, I will try to do a PR

kaanelloed commented 9 months ago

The PR: https://github.com/falzonv/discreet-launcher/pull/322

We must hope that the dev will accept this

TotallyAvailable commented 9 months ago

Even if the 'bind to number' won't make it as default, just adding entries with commonly used folder names would work as well. (At the cost of not displaying the number of course) That would shift the code over to the icon pack application *part of Discreet and even allow for broader selection by binding custom icons to specific folder names/allow users to submit personalized bindings. (Or with hidden folder labels to restore functionality by naming the folder like the number of items inside. Bonus points for binding [Number] - [Actual Name] ) The possibilities could be endless.

Donnnno commented 9 months ago

Wow, thanks @kaanelloed that's amazing!

kaanelloed commented 9 months ago

@TotallyAvailable In any case, right now Discreet Launcher doesn't search icon packs for the folder. So we need to make a PR anyway. I'm not sure how useful it would be to search folder name, but if we find use case, we can make another PR that searches for folder name first and then for number of apps it contains.

TotallyAvailable commented 9 months ago

Absolutely Just me thinking ahead again in case the PR in its current form gets denied.

While the additional option for custom folder bindings would be fancy, I obviously don't even know how the launcher currently handles adaptive icon packs if the user assigned an icon manually. If those do not update correctly then that might potentially be something worth looking into if Arcticons Day/Night actually gets released.

Again a lot of ifs and I don't even use Discreet.

Donnnno commented 9 months ago

If Arcticons needs code, maybe it's better to apply it to the Candybar project as a whole. That way other icon packs can utilize it too :)

falzonv commented 7 months ago

Hello guys,

I am really sorry for the late answer! Since my announce in https://github.com/falzonv/discreet-launcher/issues/314 (maintenance mode), I now also have computer-related health issues (repetitive strain injuries in both wrists) and had to reduce a lot my computer activities, and especially programming which includes Discreet Launcher. Now it is going a bit better (thanks to a combination of reducing activities, having better ergonomics, using Workrave at work and at home, and seeing a hand therapist) but I honestly still feel quite far from a full recovery...

Thank you @kaanelloed for the very good PR :-) I wish to publish a release in February or March for some minor fixes and it will probably be included at the same time.

Some info about the current behavior:

Regarding the discussed options:

Perhaps another strategy could be to try picking only the base icon in the pack? That would require to adapt the PR to move its logic in the constructor of the FolderIcon class, and then let Discreet Launcher add the text and set the user-defined color. (Edit 11/02: another, perhaps better, way to adapt the PR would be to add a new parameter "Drawable base_icon" to the constructor of FolderIcon, to be investigated...)

And on the icon pack side:

What do you think about this?

Best regards.

(Note: I prefer not to say how long it took me to write all the above, which I think is necessary for the discussion, but don't expect too quick replies...)

Donnnno commented 6 months ago

Hi @falzonv thanks for all your hard work and detailed explanations of your implementation.

Sounds fantastic to me, also sorry for the late reply 😅

I've added the intent to Arcticons so it should work when you push a new update.

falzonv commented 6 months ago

Hi @Donnnno,

Thank you for the kind words and the addition of the intent :-)

With also some delay on my side since the merge of the PR, the new release is now published and should be available soon in F-Droid and Google Play.

Best regards

jcperil commented 5 months ago

I updated Discreet Launcher to latest v7.5.0 and Arcticons You to latest v9.0.0. The theme is not being applied.

kaanelloed commented 5 months ago

I think it's because version 9.0.0 have a double "{" in the component info : ComponentInfo{{discreetlauncher.folder/discreetlauncher.folder}

It's fixed in the main branch, so it should work in the next release.