1#!/usr/bin/python 2 3import os 4 5""" 6# assume everything needs alpha suffixes 7for root, dirs, files in os.walk('.'): 8 if "res/drawable-" not in root: continue 9 10 for before in files: 11 if "_alpha.png" in before: continue 12 13 after = before.replace(".png", "_alpha.png") 14 os.rename(os.path.join(root, before), os.path.join(root, after)) 15""" 16 17# build xml redirection 18for root, dirs, files in os.walk('.'): 19 if "res/drawable-" not in root: continue 20 21 for src in files: 22 if not src.endswith(".png"): continue 23 src = src[0:-4] 24 25 src_clause = '\n android:src="@drawable/%s"' % (src) 26 27 alpha = src.endswith("_alpha") 28 if alpha: 29 src = src[0:-6] 30 if "ic_doc" in src or "ic_root" in src or "ic_grid_folder" in src: 31 alpha_clause = '\n android:tint="@*android:color/secondary_text_material_light"' 32 else: 33 alpha_clause = '\n android:tint="?android:attr/colorControlNormal"' 34 else: 35 alpha_clause = '' 36 37 am = src.endswith("_am") 38 if am: 39 src = src[0:-3] 40 am_clause = '\n android:autoMirrored="true"' 41 else: 42 am_clause = '' 43 44 with open("res/drawable/%s.xml" % (src), 'w') as xml: 45 xml.write("""<?xml version="1.0" encoding="utf-8"?> 46<bitmap xmlns:android="http://schemas.android.com/apk/res/android"%s%s%s /> 47""" % (src_clause, alpha_clause, am_clause)) 48