Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Arcticons You on folder icon in Discreet Launcher #1859

Closed
jcperil opened this issue Dec 10, 2023 · 16 comments
Closed

Apply Arcticons You on folder icon in Discreet Launcher #1859

jcperil opened this issue Dec 10, 2023 · 16 comments

Comments

@jcperil
Copy link

jcperil commented Dec 10, 2023

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

@Donnnno
Copy link
Collaborator

Donnnno commented Dec 10, 2023

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
Copy link
Contributor

// 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
Copy link
Collaborator

Donnnno commented Dec 11, 2023

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

@TotallyAvailable
Copy link
Contributor

TotallyAvailable commented Dec 11, 2023

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
Copy link
Contributor

kaanelloed commented Dec 13, 2023

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
Copy link
Contributor

The PR: falzonv/discreet-launcher#322

We must hope that the dev will accept this

@TotallyAvailable
Copy link
Contributor

TotallyAvailable commented Dec 13, 2023

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
Copy link
Collaborator

Donnnno commented Dec 13, 2023

Wow, thanks @kaanelloed that's amazing!

@kaanelloed
Copy link
Contributor

@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
Copy link
Contributor

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
Copy link
Collaborator

Donnnno commented Dec 15, 2023

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
Copy link

falzonv commented Feb 10, 2024

Hello guys,

I am really sorry for the late answer!
Since my announce in falzonv/discreet-launcher#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:

  • Folder icons are (re)generated only when the list of apps is updated and in the following way: there is a base icon on which the text for the number of apps in the folder is written, and the user-defined color for this folder is applied to both the base icon and the text (see the FolderIcon class in the first comment from @TotallyAvailable above).
  • Adding/removing apps to/from a folder, or changing its user-defined color triggers an update of the list of apps.
  • Since the base icon is the same for all folders, the user-defined color setting was added to better distinguish folders when their names are hidden.
  • There is no limit to the number of apps in a folder, however the text would start to conflict with the base icon after 99 (I considered this case to be rare enough to not handle it).
  • There is no restrictions on the user-defined color (same color picker than everywhere in the launcher), it can even have transparency.

Regarding the discussed options:

  • I am not sure searching by folder name would work well in practice, the folder name is free text and even for common stuff (ex: "Games", "Tools") it would require many variants (ex: the previous examples would be "Jeux" and "Outils" for a French user, or some people may want to use variants like "Gaming", "Gaming!!!" or "Toolbox").
  • Searching by number of apps is more reliable, but would require to create a lot of icons in the pack just to cover all numbers which is not very efficient...
  • In either case, the feature for user-defined color per folder would be lost which might be an issue for some users.

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:

  • The intent would be "{discreetlauncher.folder/discreetlauncher.folder}" (skipping the folder name at the end).
  • The icon would have to be designed in a way that allows the text (number of apps) to be added at the same position than the current base icon https://github.com/falzonv/discreet-launcher/blob/main/app/src/main/res/drawable/icon_folder.xml (see the initial comment above for a preview, the |__| shape at the bottom of the icon is just large enough to fit a 2-digit number with the same gap size with the sides and bottom lines).
  • The icon graphics should be monochromous (#FFFFFF) like in the current base icon.

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
Copy link
Collaborator

Donnnno commented Mar 10, 2024

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.

@Donnnno Donnnno closed this as completed Mar 10, 2024
@falzonv
Copy link

falzonv commented Mar 27, 2024

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
Copy link
Author

jcperil commented Apr 18, 2024

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

@kaanelloed
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants