Debian Codegraph @

layoutlib-api/src/main/java/com/android/ide/common/rendering/api/IProjectCallback.java

raw
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
17 package com.android.ide.common.rendering.api;
18
19 import com.android.resources.ResourceType;
20 import com.android.util.Pair;
21
22 import java.net.URL;
23
24 /**
25 * Callback for project information needed by the Layout Library.
26 * Classes implementing this interface provide methods giving access to some project data, like
27 * resource resolution, namespace information, and instantiation of custom view.
28 * @deprecated use {@link LayoutlibCallback}
29 */
30 @Deprecated
31 public interface IProjectCallback {
32
33 enum ViewAttribute {
34 TEXT(String.class),
35 IS_CHECKED(Boolean.class),
36 SRC(URL.class),
37 COLOR(Integer.class);
38
39 private final Class<?> mClass;
40
41 ViewAttribute(Class<?> theClass) {
42 mClass = theClass;
43 }
44
45 public Class<?> getAttributeClass() {
46 return mClass;
47 }
48 }
49
50 /**
51 * Loads a custom class with the given constructor signature and arguments.
52 * <p>
53 * Despite the name, the method is used not just for views (android.view.View),
54 * but potentially any class in the project's namespace. However, when the
55 * method is used for loading non-view classes the error messages reported may
56 * not be ideal, since the the IDE may assume those classes to be a view and try
57 * to use a different constructor or replace it with a MockView.
58 * <p>
59 * This is done so that LayoutLib can continue to work on older versions of the IDE.
60 * Newer versions of LayoutLib should call {@link
61 * LayoutlibCallback#loadClass(String, Class[], Object[])} in such a case.
62 *
63 * @param name The fully qualified name of the class.
64 * @param constructorSignature The signature of the class to use
65 * @param constructorArgs The arguments to use on the constructor
66 * @return A newly instantiated object.
67 */
68 Object loadView(String name, Class[] constructorSignature, Object[] constructorArgs)
69 throws Exception;
70
71 /**
72 * Returns the namespace of the application.
73 * <p>This lets the Layout Lib load custom attributes for custom views.
74 */
75 String getNamespace();
76
77 /**
78 * Resolves the id of a resource Id.
79 * <p>The resource id is the value of a <code>R.&lt;type&gt;.&lt;name&gt;</code>, and
80 * this method will return both the type and name of the resource.
81 * @param id the Id to resolve.
82 * @return a Pair of {@link ResourceType} and resource name, or null if the id
83 * does not match any resource.
84 */
85 @SuppressWarnings("deprecation")
86 Pair<ResourceType, String> resolveResourceId(int id);
87
88 /**
89 * Resolves the id of a resource Id of type int[]
90 * <p>The resource id is the value of a R.styleable.&lt;name&gt;, and this method will
91 * return the name of the resource.
92 * @param id the Id to resolve.
93 * @return the name of the resource or <code>null</code> if not found.
94 */
95 String resolveResourceId(int[] id);
96
97 /**
98 * Returns the id of a resource.
99 * <p>The provided type and name must match an existing constant defined as
100 * <code>R.&lt;type&gt;.&lt;name&gt;</code>.
101 * @param type the type of the resource
102 * @param name the name of the resource
103 * @return an Integer containing the resource Id, or <code>null</code> if not found.
104 */
105 Integer getResourceId(ResourceType type, String name);
106
107 /**
108 * Returns a custom parser for the layout of the given name.
109 * @param layoutName the name of the layout.
110 * @return returns a custom parser or null if no custom parsers are needed.
111 * @deprecated This is replaced by {@link #getParser(ResourceValue)} but older version
112 * of the layoutlib (before API7) will still call this method.
113 */
114 @Deprecated
115 ILayoutPullParser getParser(String layoutName);
116
117 /**
118 * Returns a custom parser for a given layout.
119 * @param layoutResource The layout.
120 * @return returns a custom parser or null if no custom parsers are needed.
121 */
122 ILayoutPullParser getParser(ResourceValue layoutResource);
123
124 /**
125 * Returns the value of an item used by an adapter.
126 * @param adapterView The {@link ResourceReference} for the adapter view info.
127 * @param adapterCookie the view cookie for this particular view.
128 * @param itemRef the {@link ResourceReference} for the layout used by the adapter item.
129 * @param fullPosition the position of the item in the full list.
130 * @param positionPerType the position of the item if only items of the same type are
131 * considered. If there is only one type of items, this is the same as
132 * <var>fullPosition</var>.
133 * @param fullParentPosition the full position of the item's parent. This is only
134 * valid if the adapter view is an ExpandableListView.
135 * @param parentPositionPerType the position of the parent's item, only considering items
136 * of the same type. This is only valid if the adapter view is an ExpandableListView.
137 * If there is only one type of items, this is the same as <var>fullParentPosition</var>.
138 * @param viewRef The {@link ResourceReference} for the view we're trying to fill.
139 * @param viewAttribute the attribute being queried.
140 * @param defaultValue the default value for this attribute. The object class matches the
141 * class associated with the {@link ViewAttribute}.
142 * @return the item value or null if there's no value.
143 *
144 * @see ViewAttribute#getAttributeClass()
145 */
146 Object getAdapterItemValue(ResourceReference adapterView, Object adapterCookie,
147 ResourceReference itemRef,
148 int fullPosition, int positionPerType,
149 int fullParentPosition, int parentPositionPerType,
150 ResourceReference viewRef, ViewAttribute viewAttribute, Object defaultValue);
151
152 /**
153 * Returns an adapter binding for a given adapter view.
154 * This is only called if {@link SessionParams} does not have an {@link AdapterBinding} for
155 * the given {@link ResourceReference} already.
156 *
157 * @param adapterViewRef the reference of adapter view to return the adapter binding for.
158 * @param adapterCookie the view cookie for this particular view.
159 * @param viewObject the view object for the adapter.
160 * @return an adapter binding for the given view or null if there's no data.
161 */
162 AdapterBinding getAdapterBinding(ResourceReference adapterViewRef, Object adapterCookie,
163 Object viewObject);
164
165 /**
166 * Returns a callback for Action Bar information needed by the Layout Library. The callback
167 * provides information like the menus to add to the Action Bar.
168 *
169 * @since API 11
170 */
171 ActionBarCallback getActionBarCallback();
172 }