CreateInfo.java revision f1dee199a009fec5e3a5d1469f654098261f8b06
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     * <p/>
55     * This usage is deprecated. Please use method 'delegates' instead.
56     */
57    public String[] getOverriddenMethods() {
58        return OVERRIDDEN_METHODS;
59    }
60
61    /**
62     * Returns the list of classes to rename, must be an even list: the binary FQCN
63     * of class to replace followed by the new FQCN.
64     * The list can be empty but must not be null.
65     */
66    public String[] getRenamedClasses() {
67        return RENAMED_CLASSES;
68    }
69
70    /**
71     * Returns the list of classes for which the methods returning them should be deleted.
72     * The array contains a list of null terminated section starting with the name of the class
73     * to rename in which the methods are deleted, followed by a list of return types identifying
74     * the methods to delete.
75     * The list can be empty but must not be null.
76     */
77    public String[] getDeleteReturns() {
78        return DELETE_RETURNS;
79    }
80
81    //-----
82
83    /**
84     * The list of class from layoutlib_create to inject in layoutlib.
85     */
86    private final static Class<?>[] INJECTED_CLASSES = new Class<?>[] {
87            OverrideMethod.class,
88            MethodListener.class,
89            MethodAdapter.class,
90            ICreateInfo.class,
91            CreateInfo.class,
92            LayoutlibDelegate.class
93        };
94
95    /**
96     * The list of methods to rewrite as delegates.
97     */
98    public final static String[] DELEGATE_METHODS = new String[] {
99        "android.app.Fragment#instantiate", //(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;)Landroid/app/Fragment;",
100        "android.content.res.Resources$Theme#obtainStyledAttributes",
101        "android.content.res.Resources$Theme#resolveAttribute",
102        "android.content.res.TypedArray#getValueAt",
103        "android.graphics.BitmapFactory#finishDecode",
104        "android.os.Handler#sendMessageAtTime",
105        "android.os.HandlerThread#run",
106        "android.os.Build#getString",
107        "android.view.Display#getWindowManager",
108        "android.view.LayoutInflater#rInflate",
109        "android.view.LayoutInflater#parseInclude",
110        "android.view.View#isInEditMode",
111        "android.view.inputmethod.InputMethodManager#getInstance",
112        "android.util.Log#println_native",
113        "com.android.internal.util.XmlUtils#convertValueToInt",
114        "com.android.internal.textservice.ITextServicesManager$Stub#asInterface",
115    };
116
117    /**
118     * The list of classes on which to delegate all native methods.
119     */
120    public final static String[] DELEGATE_CLASS_NATIVES = new String[] {
121        "android.animation.PropertyValuesHolder",
122        "android.graphics.AvoidXfermode",
123        "android.graphics.Bitmap",
124        "android.graphics.BitmapFactory",
125        "android.graphics.BitmapShader",
126        "android.graphics.BlurMaskFilter",
127        "android.graphics.Canvas",
128        "android.graphics.ColorFilter",
129        "android.graphics.ColorMatrixColorFilter",
130        "android.graphics.ComposePathEffect",
131        "android.graphics.ComposeShader",
132        "android.graphics.CornerPathEffect",
133        "android.graphics.DashPathEffect",
134        "android.graphics.DiscretePathEffect",
135        "android.graphics.DrawFilter",
136        "android.graphics.EmbossMaskFilter",
137        "android.graphics.LayerRasterizer",
138        "android.graphics.LightingColorFilter",
139        "android.graphics.LinearGradient",
140        "android.graphics.MaskFilter",
141        "android.graphics.Matrix",
142        "android.graphics.NinePatch",
143        "android.graphics.Paint",
144        "android.graphics.PaintFlagsDrawFilter",
145        "android.graphics.Path",
146        "android.graphics.PathDashPathEffect",
147        "android.graphics.PathEffect",
148        "android.graphics.PixelXorXfermode",
149        "android.graphics.PorterDuffColorFilter",
150        "android.graphics.PorterDuffXfermode",
151        "android.graphics.RadialGradient",
152        "android.graphics.Rasterizer",
153        "android.graphics.Region",
154        "android.graphics.Shader",
155        "android.graphics.SumPathEffect",
156        "android.graphics.SweepGradient",
157        "android.graphics.Typeface",
158        "android.graphics.Xfermode",
159        "android.os.SystemClock",
160        "android.text.AndroidBidi",
161        "android.util.FloatMath",
162        "android.view.Display",
163        "libcore.icu.ICU",
164    };
165
166    /**
167     * The list of methods to stub out. Each entry must be in the form
168     *  "package.package.OuterClass$InnerClass#MethodName".
169     *  This usage is deprecated. Please use method 'delegates' instead.
170     */
171    private final static String[] OVERRIDDEN_METHODS = new String[] {
172    };
173
174    /**
175     *  The list of classes to rename, must be an even list: the binary FQCN
176     *  of class to replace followed by the new FQCN.
177     */
178    private final static String[] RENAMED_CLASSES =
179        new String[] {
180            "android.os.ServiceManager",            "android.os._Original_ServiceManager",
181            "android.view.SurfaceView",             "android.view._Original_SurfaceView",
182            "android.view.accessibility.AccessibilityManager", "android.view.accessibility._Original_AccessibilityManager",
183            "android.webkit.WebView",               "android.webkit._Original_WebView",
184        };
185
186    /**
187     * List of classes for which the methods returning them should be deleted.
188     * The array contains a list of null terminated section starting with the name of the class
189     * to rename in which the methods are deleted, followed by a list of return types identifying
190     * the methods to delete.
191     */
192    private final static String[] DELETE_RETURNS =
193        new String[] {
194            null };                         // separator, for next class/methods list.
195}
196
197