diff options
author | Alan Viverette <alanv@google.com> | 2015-04-10 15:46:18 -0700 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2015-04-10 15:46:18 -0700 |
commit | 257d13b7cf66e9c64a1eaaa3e08b39208a4f90da (patch) | |
tree | 36c611e41570c5b03ab370b4b216d1a9a7b3d55b /wrap_alpha.py | |
parent | 35fba3eeafe47ccd900b3e18b6b64a16ad677462 (diff) | |
download | packages_apps_Settings-257d13b7cf66e9c64a1eaaa3e08b39208a4f90da.zip packages_apps_Settings-257d13b7cf66e9c64a1eaaa3e08b39208a4f90da.tar.gz packages_apps_Settings-257d13b7cf66e9c64a1eaaa3e08b39208a4f90da.tar.bz2 |
Wrap tintable icons with correctly tinted drawable XML
Replaces pre-tinted icons with flat black, grayscale versions suitable
for use as alpha masks.
Bug: 20143927
Change-Id: I0bca5dee6fcb273902db174c818cc529a5c13f91
Diffstat (limited to 'wrap_alpha.py')
-rwxr-xr-x | wrap_alpha.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/wrap_alpha.py b/wrap_alpha.py new file mode 100755 index 0000000..53db4eb --- /dev/null +++ b/wrap_alpha.py @@ -0,0 +1,43 @@ +#!/usr/bin/python + +import os + +# assume everything needs alpha suffixes +for root, dirs, files in os.walk('.'): + if "res/drawable-" not in root: continue + + for before in files: + if "_alpha.png" in before: continue + if not before.startswith("ic_settings_"): continue + + after = before.replace(".png", "_alpha.png") + os.rename(os.path.join(root, before), os.path.join(root, after)) + +# build xml redirection +for root, dirs, files in os.walk('.'): + if "res/drawable-" not in root: continue + + for src in files: + if not src.endswith(".png"): continue + src = src[0:-4] + + src_clause = '\n android:src="@drawable/%s"' % (src) + + alpha = src.endswith("_alpha") + if alpha: + src = src[0:-6] + alpha_clause = '\n android:tint="?android:attr/colorAccent"' + else: + alpha_clause = '' + + am = src.endswith("_am") + if am: + src = src[0:-3] + am_clause = '\n android:autoMirrored="true"' + else: + am_clause = '' + + with open("res/drawable/%s.xml" % (src), 'w') as xml: + xml.write("""<?xml version="1.0" encoding="utf-8"?> +<bitmap xmlns:android="http://schemas.android.com/apk/res/android"%s%s%s /> +""" % (src_clause, alpha_clause, am_clause)) |