No Description

wrap_alpha.py 1.3KB

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