OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Convert Android xml resources to API 14 compatible. | 7 """Convert Android xml resources to API 14 compatible. |
8 | 8 |
9 There are two reasons that we cannot just use API 17 attributes, | 9 There are two reasons that we cannot just use API 17 attributes, |
10 so we are generating another set of resources by this script. | 10 so we are generating another set of resources by this script. |
11 | 11 |
12 1. paddingStart attribute can cause a crash on Galaxy Tab 2. | 12 1. paddingStart attribute can cause a crash on Galaxy Tab 2. |
13 2. There is a bug that paddingStart does not override paddingLeft on | 13 2. There is a bug that paddingStart does not override paddingLeft on |
14 JB-MR1. This is fixed on JB-MR2. | 14 JB-MR1. This is fixed on JB-MR2. |
15 | 15 |
16 Therefore, this resource generation script can be removed when | 16 Therefore, this resource generation script can be removed when |
17 we drop the support for JB-MR1. | 17 we drop the support for JB-MR1. |
18 | 18 |
19 Please refer to http://crbug.com/235118 for the details. | 19 Please refer to http://crbug.com/235118 for the details. |
20 """ | 20 """ |
21 | 21 |
22 import optparse | 22 import optparse |
23 import os | 23 import os |
24 import re | |
24 import shutil | 25 import shutil |
25 import sys | 26 import sys |
26 import xml.dom.minidom as minidom | 27 import xml.dom.minidom as minidom |
27 | 28 |
28 from util import build_utils | 29 from util import build_utils |
29 | 30 |
30 # Note that we are assuming 'android:' is an alias of | 31 # Note that we are assuming 'android:' is an alias of |
31 # the namespace 'http://schemas.android.com/apk/res/android'. | 32 # the namespace 'http://schemas.android.com/apk/res/android'. |
32 | 33 |
33 GRAVITY_ATTRIBUTES = ('android:gravity', 'android:layout_gravity') | 34 GRAVITY_ATTRIBUTES = ('android:gravity', 'android:layout_gravity') |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 build_utils.MakeDirectory(options.res_v14_compatibility_dir) | 235 build_utils.MakeDirectory(options.res_v14_compatibility_dir) |
235 | 236 |
236 for name in os.listdir(options.res_dir): | 237 for name in os.listdir(options.res_dir): |
237 if not os.path.isdir(os.path.join(options.res_dir, name)): | 238 if not os.path.isdir(os.path.join(options.res_dir, name)): |
238 continue | 239 continue |
239 | 240 |
240 dir_pieces = name.split('-') | 241 dir_pieces = name.split('-') |
241 resource_type = dir_pieces[0] | 242 resource_type = dir_pieces[0] |
242 qualifiers = dir_pieces[1:] | 243 qualifiers = dir_pieces[1:] |
243 | 244 |
245 api_version_qualifier_index = -1 | |
newt (away)
2013/06/07 04:24:09
super minor nit: "api_level"
Kibeom Kim (inactive)
2013/06/07 05:07:19
Done.
| |
246 api_version_qualifier = '' | |
247 for index, qualifier in enumerate(qualifiers): | |
248 if re.match('\Av[0-9]+$', qualifier): | |
newt (away)
2013/06/07 04:24:09
"^" instead of "\A" for familiarity and consistenc
Kibeom Kim (inactive)
2013/06/07 05:07:19
Done.
| |
249 api_version_qualifier_index = index | |
250 api_version_qualifier = qualifier | |
251 break | |
252 | |
244 # Android pre-v17 API doesn't support RTL. Skip. | 253 # Android pre-v17 API doesn't support RTL. Skip. |
245 if 'ldrtl' in qualifiers: | 254 if 'ldrtl' in qualifiers: |
246 continue | 255 continue |
247 | 256 |
248 # We also need to copy the original v17 resource to *-v17 directory | 257 # We also need to copy the original v17 resource to *-v17 directory |
249 # because the generated v14 resource will hide the original resource. | 258 # because the generated v14 resource will hide the original resource. |
250 input_dir = os.path.join(options.res_dir, name) | 259 input_dir = os.path.join(options.res_dir, name) |
251 output_v14_dir = os.path.join(options.res_v14_compatibility_dir, name) | 260 output_v14_dir = os.path.join(options.res_v14_compatibility_dir, name) |
252 output_v17_dir = os.path.join(options.res_v14_compatibility_dir, name + | 261 output_v17_dir = os.path.join(options.res_v14_compatibility_dir, name + |
253 '-v17') | 262 '-v17') |
254 | 263 |
255 # We only convert layout resources under layout*/, xml*/, | 264 # We only convert layout resources under layout*/, xml*/, |
256 # and style resources under values*/. | 265 # and style resources under values*/. |
257 # TODO(kkimlabs): don't process xml directly once all layouts have | 266 # TODO(kkimlabs): don't process xml directly once all layouts have |
newt (away)
2013/06/07 04:24:09
you can probably remove this TODO, since we decide
Kibeom Kim (inactive)
2013/06/07 05:07:19
Done.
| |
258 # been moved out of XML directory. see http://crbug.com/238458 | 267 # been moved out of XML directory. see http://crbug.com/238458 |
259 if resource_type in ('layout', 'xml'): | 268 if resource_type in ('layout', 'xml'): |
260 GenerateV14LayoutResourcesInDir(input_dir, output_v14_dir, output_v17_dir) | 269 if not api_version_qualifier: |
270 GenerateV14LayoutResourcesInDir(input_dir, output_v14_dir, | |
271 output_v17_dir) | |
261 elif resource_type == 'values': | 272 elif resource_type == 'values': |
262 if 'v17' in qualifiers: | 273 if api_version_qualifier == 'v17': |
263 output_qualifiers = qualifiers[:] | 274 output_qualifiers = qualifiers[:] |
264 del output_qualifiers[qualifiers.index('v17')] | 275 del output_qualifiers[api_version_qualifier_index] |
265 output_v14_dir = os.path.join(options.res_v14_compatibility_dir, | 276 output_v14_dir = os.path.join(options.res_v14_compatibility_dir, |
266 '-'.join([resource_type] + | 277 '-'.join([resource_type] + |
267 output_qualifiers)) | 278 output_qualifiers)) |
268 GenerateV14StyleResourcesInDir(input_dir, output_v14_dir) | 279 GenerateV14StyleResourcesInDir(input_dir, output_v14_dir) |
269 else: | 280 elif not api_version_qualifier: |
270 ErrorIfStyleResourceExistsInDir(input_dir) | 281 ErrorIfStyleResourceExistsInDir(input_dir) |
271 | 282 |
272 if options.stamp: | 283 if options.stamp: |
273 build_utils.Touch(options.stamp) | 284 build_utils.Touch(options.stamp) |
274 | 285 |
275 if __name__ == '__main__': | 286 if __name__ == '__main__': |
276 sys.exit(main(sys.argv)) | 287 sys.exit(main(sys.argv)) |
277 | 288 |
OLD | NEW |