File: wrap_alpha.py

package info (click to toggle)
android-framework-23 6.0.1%2Br72-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 233,244 kB
  • sloc: java: 1,707,033; xml: 247,323; cpp: 211,819; ansic: 2,748; python: 2,640; sh: 1,517; yacc: 343; lex: 214; ruby: 183; perl: 88; makefile: 63; sed: 19
file content (47 lines) | stat: -rw-r--r-- 1,467 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/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

        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]
            if "ic_doc" in src or "ic_root" in src or "ic_grid_folder" in src:
                alpha_clause = '\n    android:tint="@*android:color/secondary_text_material_light"'
            else:
                alpha_clause = '\n    android:tint="?android:attr/colorControlNormal"'
        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))