1 // Copyright (c) 2014 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.core;
7 import android.content.Context;
8 import android.util.Log;
10 import java.lang.reflect.Field;
12 public class XWalkInternalResources {
13 private static final String TAG = "XWalkInternalResources";
15 private static boolean loaded = false;
16 private final static String INTERNAL_RESOURCE_CLASSES[] = {
17 "org.chromium.content.R",
20 private final static String GENERATED_RESOURCE_CLASS = "org.xwalk.core.R";
22 // Doing org.chromium.content.R.<class>.<name> = org.xwalk.core.R.<class>.<name>
23 // Use reflection to iterate over the target class is to avoid hardcode.
24 private static void doResetIds(Context context) {
25 ClassLoader classLoader = context.getClassLoader();
26 for (String resourceClass : INTERNAL_RESOURCE_CLASSES) {
28 Class<?> internalResource = classLoader.loadClass(resourceClass);
29 Class<?>[] innerClazzs = internalResource.getClasses();
30 for (Class<?> innerClazz : innerClazzs) {
31 Class<?> generatedInnerClazz;
32 String generatedInnerClassName = innerClazz.getName().replace(
33 resourceClass, GENERATED_RESOURCE_CLASS);
35 generatedInnerClazz = classLoader.loadClass(generatedInnerClassName);
36 } catch (ClassNotFoundException e) {
37 Log.w(TAG, generatedInnerClassName + "is not found.");
40 Field[] fields = innerClazz.getFields();
41 for (Field field : fields) {
43 int value = generatedInnerClazz.getField(field.getName()).getInt(null);
44 field.setInt(null, value);
45 } catch (IllegalAccessException e) {
46 Log.w(TAG, generatedInnerClazz.getName() + "." +
47 field.getName() + " is not accessable.");
48 } catch (IllegalArgumentException e) {
49 Log.w(TAG, generatedInnerClazz.getName() + "." +
50 field.getName() + " is not int.");
51 } catch (NoSuchFieldException e) {
52 Log.w(TAG, generatedInnerClazz.getName() + "." +
53 field.getName() + " is not found.");
57 } catch (ClassNotFoundException e) {
58 Log.w(TAG, resourceClass + "is not found.");
63 static void resetIds(Context context) {