CreateInfo.java revision 4b52ec49fee79b0488d6a9eaaa4ea5d74ce90905
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.tools.layoutlib.create;
18
19import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
20
21/**
22 * Describes the work to be done by {@link AsmGenerator}.
23 */
24public final class CreateInfo implements ICreateInfo {
25
26    /**
27     * Returns the list of class from layoutlib_create to inject in layoutlib.
28     * The list can be empty but must not be null.
29     */
30    public Class<?>[] getInjectedClasses() {
31        return INJECTED_CLASSES;
32    }
33
34    /**
35     * Returns the list of methods to rewrite as delegates.
36     * The list can be empty but must not be null.
37     */
38    public String[] getDelegateMethods() {
39        return DELEGATE_METHODS;
40    }
41
42    /**
43     * Returns the list of classes on which to delegate all native methods.
44     * The list can be empty but must not be null.
45     */
46    public String[] getDelegateClassNatives() {
47        return DELEGATE_CLASS_NATIVES;
48    }
49
50    /**
51     * Returns The list of methods to stub out. Each entry must be in the form
52     * "package.package.OuterClass$InnerClass#MethodName".
53     * The list can be empty but must not be null.
54     */
55    public String[] getOverriddenMethods() {
56        return OVERRIDDEN_METHODS;
57    }
58
59    /**
60     * Returns the list of classes to rename, must be an even list: the binary FQCN
61     * of class to replace followed by the new FQCN.
62     * The list can be empty but must not be null.
63     */
64    public String[] getRenamedClasses() {
65        return RENAMED_CLASSES;
66    }
67
68    /**
69     * Returns the list of classes for which the methods returning them should be deleted.
70     * The array contains a list of null terminated section starting with the name of the class
71     * to rename in which the methods are deleted, followed by a list of return types identifying
72     * the methods to delete.
73     * The list can be empty but must not be null.
74     */
75    public String[] getDeleteReturns() {
76        return DELETE_RETURNS;
77    }
78
79    //-----
80
81    /**
82     * The list of class from layoutlib_create to inject in layoutlib.
83     */
84    private final static Class<?>[] INJECTED_CLASSES = new Class<?>[] {
85            OverrideMethod.class,
86            MethodListener.class,
87            MethodAdapter.class,
88            ICreateInfo.class,
89            CreateInfo.class,
90            LayoutlibDelegate.class
91        };
92
93    /**
94     * The list of methods to rewrite as delegates.
95     */
96    private final static String[] DELEGATE_METHODS = new String[] {
97        "android.app.Fragment#instantiate", //(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;)Landroid/app/Fragment;",
98        "android.content.res.Resources$Theme#obtainStyledAttributes",
99        "android.content.res.Resources$Theme#resolveAttribute",
100        "android.graphics.BitmapFactory#finishDecode",
101        "android.os.Handler#sendMessageAtTime",
102        "android.os.Build#getString",
103        "android.view.LayoutInflater#rInflate",
104        "android.view.View#isInEditMode",
105        "com.android.internal.util.XmlUtils#convertValueToInt",
106        // TODO: comment out once DelegateClass is working
107    };
108
109    /**
110     * The list of classes on which to delegate all native methods.
111     */
112    private final static String[] DELEGATE_CLASS_NATIVES = new String[] {
113        "android.animation.PropertyValuesHolder",
114        "android.graphics.AvoidXfermode",
115        "android.graphics.Bitmap",
116        "android.graphics.BitmapFactory",
117        "android.graphics.BitmapShader",
118        "android.graphics.BlurMaskFilter",
119        "android.graphics.Canvas",
120        "android.graphics.ColorFilter",
121        "android.graphics.ColorMatrixColorFilter",
122        "android.graphics.ComposePathEffect",
123        "android.graphics.ComposeShader",
124        "android.graphics.CornerPathEffect",
125        "android.graphics.DashPathEffect",
126        "android.graphics.DiscretePathEffect",
127        "android.graphics.DrawFilter",
128        "android.graphics.EmbossMaskFilter",
129        "android.graphics.LayerRasterizer",
130        "android.graphics.LightingColorFilter",
131        "android.graphics.LinearGradient",
132        "android.graphics.MaskFilter",
133        "android.graphics.Matrix",
134        "android.graphics.NinePatch",
135        "android.graphics.Paint",
136        "android.graphics.PaintFlagsDrawFilter",
137        "android.graphics.Path",
138        "android.graphics.PathDashPathEffect",
139        "android.graphics.PathEffect",
140        "android.graphics.PixelXorXfermode",
141        "android.graphics.PorterDuffColorFilter",
142        "android.graphics.PorterDuffXfermode",
143        "android.graphics.RadialGradient",
144        "android.graphics.Rasterizer",
145        "android.graphics.Region",
146        "android.graphics.Shader",
147        "android.graphics.SumPathEffect",
148        "android.graphics.SweepGradient",
149        "android.graphics.Typeface",
150        "android.graphics.Xfermode",
151        "android.os.SystemClock",
152        "android.util.FloatMath",
153        "libcore.icu.ICU",
154    };
155
156    /**
157     * The list of methods to stub out. Each entry must be in the form
158     *  "package.package.OuterClass$InnerClass#MethodName".
159     */
160    private final static String[] OVERRIDDEN_METHODS = new String[] {
161    };
162
163    /**
164     *  The list of classes to rename, must be an even list: the binary FQCN
165     *  of class to replace followed by the new FQCN.
166     */
167    private final static String[] RENAMED_CLASSES =
168        new String[] {
169            "android.os.ServiceManager",            "android.os._Original_ServiceManager",
170            "android.view.SurfaceView",             "android.view._Original_SurfaceView",
171            "android.view.accessibility.AccessibilityManager", "android.view.accessibility._Original_AccessibilityManager",
172            "android.webkit.WebView",               "android.webkit._Original_WebView",
173        };
174
175    /**
176     * List of classes for which the methods returning them should be deleted.
177     * The array contains a list of null terminated section starting with the name of the class
178     * to rename in which the methods are deleted, followed by a list of return types identifying
179     * the methods to delete.
180     */
181    private final static String[] DELETE_RETURNS =
182        new String[] {
183            null };                         // separator, for next class/methods list.
184}
185
186