• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
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 package com.android.ide.eclipse.adt.internal.editors.layout.properties;
17 
18 import static com.android.SdkConstants.ATTR_CONTENT_DESCRIPTION;
19 import static com.android.SdkConstants.ATTR_HINT;
20 import static com.android.SdkConstants.ATTR_TEXT;
21 
22 import com.android.annotations.NonNull;
23 import com.android.annotations.Nullable;
24 
25 import java.util.HashSet;
26 import java.util.Set;
27 
28 /** Extra metadata about properties not available from the descriptors (yet) */
29 class PropertyMetadata {
isAdvanced(@onNull String name)30     static boolean isAdvanced(@NonNull String name) {
31         return sAdvanced.contains(name);
32     }
33 
isPreferred(@onNull String name)34     static boolean isPreferred(@NonNull String name) {
35         return sPreferred.contains(name);
36     }
37 
38     @Nullable
getCategory(@onNull String name)39     static String getCategory(@NonNull String name) {
40         //return sCategories.get(name);
41         assert false : "Disabled to save memory since this method is not currently used.";
42         return null;
43     }
44 
45     private static final int ADVANCED_MAP_SIZE = 134;
46     private static final Set<String> sAdvanced = new HashSet<String>(ADVANCED_MAP_SIZE);
47     static {
48         // This metadata about which attributes are "advanced" was generated as follows:
49         // First, I ran the sdk/attribute_stats project with the --list argument to dump out
50         // *all* referenced XML attributes found in layouts, run against a bunch of
51         // sample Android code (development/samples, packages/apps, vendor, etc.
52         //
53         // Then I iterated over the LayoutDescriptors' ViewElementDescriptors'
54         // AttributeDescriptors, and basically diffed the two: any attribute descriptor name
55         // which was *not* found in any of the representative layouts is added here
56         // as an advanced property.
57         //
58         // Then I manually edited in some attributes that were referenced in the sample
59         // layouts but which I still consider to be advanced:
60         // -- nothing right now
61 
62         // I also manually *removed* some entries from the below list:
63         //     drawableBottom   (the others, drawableTop, drawableLeft and drawableRight were all
64         //                       NOT on the list so keep bottom off for symmetry)
65         //     rating     (useful when you deal with a RatingsBar component)
66 
67 
68         // Automatically generated, see above:
69         sAdvanced.add("alwaysDrawnWithCache");
70         sAdvanced.add("animationCache");
71         sAdvanced.add("animationDuration");
72         sAdvanced.add("animationResolution");
73         sAdvanced.add("baseline");
74         sAdvanced.add("bufferType");
75         sAdvanced.add("calendarViewShown");
76         sAdvanced.add("completionHint");
77         sAdvanced.add("completionHintView");
78         sAdvanced.add("completionThreshold");
79         sAdvanced.add("cursorVisible");
80         sAdvanced.add("dateTextAppearance");
81         sAdvanced.add("dial");
82         sAdvanced.add("digits");
83         sAdvanced.add("disableChildrenWhenDisabled");
84         sAdvanced.add("disabledAlpha");
85         sAdvanced.add("drawableAlpha");
86         sAdvanced.add("drawableEnd");
87         sAdvanced.add("drawableStart");
88         sAdvanced.add("drawingCacheQuality");
89         sAdvanced.add("dropDownAnchor");
90         sAdvanced.add("dropDownHeight");
91         sAdvanced.add("dropDownHorizontalOffset");
92         sAdvanced.add("dropDownSelector");
93         sAdvanced.add("dropDownVerticalOffset");
94         sAdvanced.add("dropDownWidth");
95         sAdvanced.add("editorExtras");
96         sAdvanced.add("ems");
97         sAdvanced.add("endYear");
98         sAdvanced.add("eventsInterceptionEnabled");
99         sAdvanced.add("fadeDuration");
100         sAdvanced.add("fadeEnabled");
101         sAdvanced.add("fadeOffset");
102         sAdvanced.add("fadeScrollbars");
103         sAdvanced.add("filterTouchesWhenObscured");
104         sAdvanced.add("firstDayOfWeek");
105         sAdvanced.add("flingable");
106         sAdvanced.add("focusedMonthDateColor");
107         sAdvanced.add("foregroundInsidePadding");
108         sAdvanced.add("format");
109         sAdvanced.add("gestureColor");
110         sAdvanced.add("gestureStrokeAngleThreshold");
111         sAdvanced.add("gestureStrokeLengthThreshold");
112         sAdvanced.add("gestureStrokeSquarenessThreshold");
113         sAdvanced.add("gestureStrokeType");
114         sAdvanced.add("gestureStrokeWidth");
115         sAdvanced.add("hand_hour");
116         sAdvanced.add("hand_minute");
117         sAdvanced.add("hapticFeedbackEnabled");
118         sAdvanced.add("id");
119         sAdvanced.add("imeActionId");
120         sAdvanced.add("imeActionLabel");
121         sAdvanced.add("indeterminateDrawable");
122         sAdvanced.add("indeterminateDuration");
123         sAdvanced.add("inputMethod");
124         sAdvanced.add("interpolator");
125         sAdvanced.add("isScrollContainer");
126         sAdvanced.add("keepScreenOn");
127         sAdvanced.add("layerType");
128         sAdvanced.add("layoutDirection");
129         sAdvanced.add("maxDate");
130         sAdvanced.add("minDate");
131         sAdvanced.add("mode");
132         sAdvanced.add("numeric");
133         sAdvanced.add("paddingEnd");
134         sAdvanced.add("paddingStart");
135         sAdvanced.add("persistentDrawingCache");
136         sAdvanced.add("phoneNumber");
137         sAdvanced.add("popupBackground");
138         sAdvanced.add("popupPromptView");
139         sAdvanced.add("privateImeOptions");
140         sAdvanced.add("quickContactWindowSize");
141         //sAdvanced.add("rating");
142         sAdvanced.add("requiresFadingEdge");
143         sAdvanced.add("rotation");
144         sAdvanced.add("rotationX");
145         sAdvanced.add("rotationY");
146         sAdvanced.add("saveEnabled");
147         sAdvanced.add("scaleX");
148         sAdvanced.add("scaleY");
149         sAdvanced.add("scrollX");
150         sAdvanced.add("scrollY");
151         sAdvanced.add("scrollbarAlwaysDrawHorizontalTrack");
152         sAdvanced.add("scrollbarDefaultDelayBeforeFade");
153         sAdvanced.add("scrollbarFadeDuration");
154         sAdvanced.add("scrollbarSize");
155         sAdvanced.add("scrollbarThumbHorizontal");
156         sAdvanced.add("scrollbarThumbVertical");
157         sAdvanced.add("scrollbarTrackHorizontal");
158         sAdvanced.add("scrollbarTrackVertical");
159         sAdvanced.add("secondaryProgress");
160         sAdvanced.add("selectedDateVerticalBar");
161         sAdvanced.add("selectedWeekBackgroundColor");
162         sAdvanced.add("selectionDivider");
163         sAdvanced.add("selectionDividerHeight");
164         sAdvanced.add("showWeekNumber");
165         sAdvanced.add("shownWeekCount");
166         sAdvanced.add("solidColor");
167         sAdvanced.add("soundEffectsEnabled");
168         sAdvanced.add("spinnerMode");
169         sAdvanced.add("spinnersShown");
170         sAdvanced.add("startYear");
171         sAdvanced.add("switchMinWidth");
172         sAdvanced.add("switchPadding");
173         sAdvanced.add("switchTextAppearance");
174         sAdvanced.add("textColorHighlight");
175         sAdvanced.add("textCursorDrawable");
176         sAdvanced.add("textDirection");
177         sAdvanced.add("textEditNoPasteWindowLayout");
178         sAdvanced.add("textEditPasteWindowLayout");
179         sAdvanced.add("textEditSideNoPasteWindowLayout");
180         sAdvanced.add("textEditSidePasteWindowLayout");
181         sAdvanced.add("textEditSuggestionItemLayout");
182         sAdvanced.add("textIsSelectable");
183         sAdvanced.add("textOff");
184         sAdvanced.add("textOn");
185         sAdvanced.add("textScaleX");
186         sAdvanced.add("textSelectHandle");
187         sAdvanced.add("textSelectHandleLeft");
188         sAdvanced.add("textSelectHandleRight");
189         sAdvanced.add("thumbOffset");
190         sAdvanced.add("thumbTextPadding");
191         sAdvanced.add("tint");
192         sAdvanced.add("track");
193         sAdvanced.add("transformPivotX");
194         sAdvanced.add("transformPivotY");
195         sAdvanced.add("translationX");
196         sAdvanced.add("translationY");
197         sAdvanced.add("uncertainGestureColor");
198         sAdvanced.add("unfocusedMonthDateColor");
199         sAdvanced.add("unselectedAlpha");
200         sAdvanced.add("verticalScrollbarPosition");
201         sAdvanced.add("weekDayTextAppearance");
202         sAdvanced.add("weekNumberColor");
203         sAdvanced.add("weekSeparatorLineColor");
204 
sAdvanced.size()205         assert sAdvanced.size() == ADVANCED_MAP_SIZE : sAdvanced.size();
206 
207     }
208 
209     private static final int PREFERRED_MAP_SIZE = 7;
210     private static final Set<String> sPreferred = new HashSet<String>(PREFERRED_MAP_SIZE);
211     static {
212         // Manual registrations of attributes that should be treated as preferred if
213         // they are available on a widget even if they don't show up in the top 10% of
214         // usages (which the view metadata provides)
215         sPreferred.add(ATTR_TEXT);
216         sPreferred.add(ATTR_CONTENT_DESCRIPTION);
217         sPreferred.add(ATTR_HINT);
218         sPreferred.add("indeterminate");
219         sPreferred.add("progress");
220         sPreferred.add("rating");
221         sPreferred.add("max");
sPreferred.size()222         assert sPreferred.size() == PREFERRED_MAP_SIZE : sPreferred.size();
223     }
224 
225     /*
226     private static final int CATEGORY_MAP_SIZE = 62;
227     private static final Map<String, String> sCategories =
228             new HashMap<String, String>(CATEGORY_MAP_SIZE);
229     static {
230         sCategories.put("requiresFadingEdge", "Scrolling");
231         sCategories.put("fadingEdgeLength", "Scrolling");
232         sCategories.put("scrollbarSize", "Scrolling");
233         sCategories.put("scrollbarThumbVertical", "Scrolling");
234         sCategories.put("scrollbarThumbHorizontal", "Scrolling");
235         sCategories.put("scrollbarTrackHorizontal", "Scrolling");
236         sCategories.put("scrollbarTrackVertical", "Scrolling");
237         sCategories.put("scrollbarAlwaysDrawHorizontalTrack", "Scrolling");
238         sCategories.put("scrollbarAlwaysDrawVerticalTrack", "Scrolling");
239         sCategories.put("scrollViewStyle", "Scrolling");
240         sCategories.put("scrollbars", "Scrolling");
241         sCategories.put("scrollingCache", "Scrolling");
242         sCategories.put("scrollHorizontally", "Scrolling");
243         sCategories.put("scrollbarFadeDuration", "Scrolling");
244         sCategories.put("scrollbarDefaultDelayBeforeFade", "Scrolling");
245         sCategories.put("fastScrollEnabled", "Scrolling");
246         sCategories.put("smoothScrollbar", "Scrolling");
247         sCategories.put("isScrollContainer", "Scrolling");
248         sCategories.put("fadeScrollbars", "Scrolling");
249         sCategories.put("overScrollMode", "Scrolling");
250         sCategories.put("overScrollHeader", "Scrolling");
251         sCategories.put("overScrollFooter", "Scrolling");
252         sCategories.put("verticalScrollbarPosition", "Scrolling");
253         sCategories.put("fastScrollAlwaysVisible", "Scrolling");
254         sCategories.put("fastScrollThumbDrawable", "Scrolling");
255         sCategories.put("fastScrollPreviewBackgroundLeft", "Scrolling");
256         sCategories.put("fastScrollPreviewBackgroundRight", "Scrolling");
257         sCategories.put("fastScrollTrackDrawable", "Scrolling");
258         sCategories.put("fastScrollOverlayPosition", "Scrolling");
259         sCategories.put("horizontalScrollViewStyle", "Scrolling");
260         sCategories.put("fastScrollTextColor", "Scrolling");
261         sCategories.put("scrollbarSize", "Scrolling");
262         sCategories.put("scrollbarSize", "Scrolling");
263         sCategories.put("scrollbarSize", "Scrolling");
264         sCategories.put("scrollbarSize", "Scrolling");
265         sCategories.put("scrollbarSize", "Scrolling");
266 
267         // TODO: All the styles: radioButtonStyle, ratingBarStyle, progressBarStyle, ...
268 
269         sCategories.put("focusable", "Focus");
270         sCategories.put("focusableInTouchMode", "Focus");
271         sCategories.put("nextFocusLeft", "Focus");
272         sCategories.put("nextFocusRight", "Focus");
273         sCategories.put("nextFocusUp", "Focus");
274         sCategories.put("nextFocusDown", "Focus");
275         sCategories.put("descendantFocusability", "Focus");
276         sCategories.put("selectAllOnFocus", "Focus");
277         sCategories.put("nextFocusForward", "Focus");
278         sCategories.put("colorFocusedHighlight", "Focus");
279 
280         sCategories.put("rotation", "Transforms");
281         sCategories.put("scrollX", "Transforms");
282         sCategories.put("scrollY", "Transforms");
283         sCategories.put("rotationX", "Transforms");
284         sCategories.put("rotationY", "Transforms");
285         sCategories.put("transformPivotX", "Transforms");
286         sCategories.put("transformPivotY", "Transforms");
287         sCategories.put("translationX", "Transforms");
288         sCategories.put("translationY", "Transforms");
289         sCategories.put("scaleX", "Transforms");
290         sCategories.put("scaleY", "Transforms");
291 
292         sCategories.put("width", "Size");
293         sCategories.put("height", "Size");
294         sCategories.put("minWidth", "Size");
295         sCategories.put("minHeight", "Size");
296 
297         sCategories.put("longClickable", "Clicks");
298         sCategories.put("onClick", "Clicks");
299         sCategories.put("clickable", "Clicks");
300         sCategories.put("hapticFeedbackEnabled", "Clicks");
301 
302         sCategories.put("duplicateParentState", "State");
303         sCategories.put("addStatesFromChildren", "State");
304 
305         assert sCategories.size() == CATEGORY_MAP_SIZE : sCategories.size();
306     }
307     */
308 
309 //    private static final int PRIO_CLZ_LAYOUT = 1000;
310 //    private static final int PRIO_CLZ_TEXT = 2000;
311 //    private static final int PRIO_CLZ_DRAWABLE = 3000;
312 //    private static final int PRIO_CLZ_ANIMATION = 4000;
313 //    private static final int PRIO_CLZ_FOCUS = 5000;
314 //
315 //    private static final int PRIORITY_MAP_SIZE = 100;
316 //    private static final Map<String, Integer> sPriorities =
317 //            new HashMap<String, Integer>(PRIORITY_MAP_SIZE);
318 //    static {
319 //        // TODO: I should put all the properties roughly based on their original order: this
320 //        // will correspond to the rough order they came in with
321 //        // TODO: How can I make similar complex properties show up adjacent; e.g. min and max
322 //        sPriorities.put("min", PRIO_CLZ_LAYOUT);
323 //        sPriorities.put("max", PRIO_CLZ_LAYOUT);
324 //
325 //        assert sPriorities.size() == PRIORITY_MAP_SIZE : sPriorities.size();
326 //    }
327 
328     // TODO: Emit metadata into a file
329 }
330