1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.xwalk.app.runtime;
7 import android.content.res.Resources;
8 import android.content.res.TypedArray;
9 import android.content.res.XmlResourceParser;
10 import android.util.TypedValue;
13 * XWalkMixedResources is used to combine the resources
14 * from two different packages.
16 * Chromium uses resources through:
17 * R.layout; R.id; R.string; R.dimen; R.drawable;
18 * R.attr; R.style; R.menu ; R.color
19 * R.layout and R.menu is covered by Resources.getLayout()
20 * R.string is covered by Resources.getText()
21 * R.dimen, R.drawable and R.color is covered by getValue()
23 * For R.id, if it's used like findViewById(R.id.xxx), R.id.xxx
24 * is const at compile time within library context. It works
25 * if the view in hierachy has the same id, which needs inflate
26 * with layout resource from library context. Layout is covered
27 * by getLayout(), so R.id is OK.
30 * For R.attr and R.style, I have no confidence that it's covered.
31 * But the only place use this R.attr and R.style is "select" tag
32 * which is verified working well with this MixedResources.
34 public class XWalkMixedResources extends Resources {
36 private Resources mExtend;
38 XWalkMixedResources(Resources base, Resources extend) {
39 super(base.getAssets(), base.getDisplayMetrics(),
40 base.getConfiguration());
45 public CharSequence getText(int id) throws NotFoundException {
47 return mExtend.getText(id);
48 } catch (NotFoundException e) {
49 return super.getText(id);
54 public XmlResourceParser getLayout(int id) throws NotFoundException {
56 return mExtend.getLayout(id);
57 } catch (NotFoundException e) {
58 return super.getLayout(id);
63 public void getValue(int id, TypedValue outValue, boolean resolveRefs) {
65 mExtend.getValue(id, outValue, resolveRefs);
66 } catch (NotFoundException e) {
67 super.getValue(id, outValue, resolveRefs);
72 public void getValueForDensity(int id, int density, TypedValue outValue, boolean resolveRefs) {
74 mExtend.getValueForDensity(id, density, outValue, resolveRefs);
75 } catch (NotFoundException e) {
76 super.getValueForDensity(id, density, outValue, resolveRefs);
81 public int getIdentifier(String name, String defType, String defPackage) {
82 int id = mExtend.getIdentifier(name, defType, defPackage);
83 return id != 0 ? id : super.getIdentifier(name, defType, defPackage);