Converting Android icon packs to icon themes

From postmarketOS
Revision as of 09:30, 16 November 2021 by HenriDellal (talk | contribs) (Created page with "== Downloading the icon pack == To use icons in Linux system one has to obtain them either bundled in .apk installation package or as separate images. Possible sources are:...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Downloading the icon pack

To use icons in Linux system one has to obtain them either bundled in .apk installation package or as separate images. Possible sources are:

  1. Application stores (Note that some application store clients - such as the official application of Google Play Store - do not save .apk files in storage to be accessed by user. In this case it is recommended to use other stores or third-party clients/frontends);
  2. Forums (e.g. XDA);
  3. Icon pack's repository.

Getting the icons

First of all, it is needed to find the directory which contains the icons. To do that, one has to check the list of files in the apk file first. It can be done with either an archiver application (e.g. xarchiver) or via command line.

Example:

$ unzip -Z -1 iconpack.apk | less

where -Z means zipinfo mode and -1 sets the verbosity level.

Icons are most likely to be stored at one of res/drawable* folders or in assets/.

If there are multiple folders with icons, extract the icons with needed dpi. Here is the list of folders from highest to lowest dpi:

Directory Approximate dpi Icon size
res/drawable-xxxdpi*/ 640 192x192
res/drawable-xxdpi*/ 480 144x144
res/drawable-xdpi*/ 320 96x96
res/drawable-hdpi*/ 240 72x72
res/drawable-tvdpi*/ 213 N/A
res/drawable-mdpi*/ 160 48x48
res/drawable-ldpi*/ 120 36x36

If not there, icons may be located at res/drawable-nodpi*/ which is for density-independent resources.

When the folder was found, one can do something like

$ unzip -j icon_pack.apk "res/drawable-nodpi-v4/*" -d "icon_theme_dir"

This command extracts all files from res/drawable-nodpi-v4/ to directory named icon_theme_dir. If this directory doesn't exist, it is created.

Creating a theme

Icon themes can be located in $HOME/.icons and /usr/share/icons/ and consist of index.theme file, which describes the theme, and directories with icons.

The basic index.theme contents are as follows:

[Icon Theme]
Name=Icon Theme Name
Comment=Detailed icon theme description goes here
Directories=48x48/apps,scalable/apps

[scalable/apps]
Size=48
Type=Scalable
MinSize=1
MaxSize=256
Context=Applications

[48x48/apps]
Size=48
Type=Fixed
Context=Applications

Directories key accepts the list of subdirectories separated by commas as value. There must be a section for every listed subdirectory. The subdirectories are checked from left to right. So, in this example, an icon from 48x48/apps is used if 48x48 icon is needed. If the size differs, a scalable icon is used instead.

Refer to the latest icon theme specification for example and detailed documentation.

To pick a proper filename for an icon, one should check the .desktop file of the related program in one of the directories

  1. /usr/share/applications
  2. /usr/share/applications
  3. ~/.local/share/applications

Example: for this desktop file

[Desktop Entry]
Name=random.txt
Exec=gedit /home/user/random.txt
Icon=gedit

icon name must be gedit.png, gedit.svg or gedit.xpm. It is possible to use symlinks to reuse the same icon for multiple programs.