/
AndroidElementClassMap.java
147 lines (139 loc) · 5.21 KB
/
AndroidElementClassMap.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package io.appium.android.bootstrap;
import io.appium.android.bootstrap.exceptions.AndroidCommandException;
import io.appium.android.bootstrap.exceptions.UnallowedTagNameException;
import java.util.ArrayList;
import java.util.HashMap;
/**
* Helper class to match up tag names and UI element class names.
*
*/
public class AndroidElementClassMap {
private final HashMap<String, String> map;
private final ArrayList<String> unallowed;
private static AndroidElementClassMap instance;
/**
* Generator
*
* @return
*/
private static AndroidElementClassMap getInstance() {
if (AndroidElementClassMap.instance == null) {
AndroidElementClassMap.instance = new AndroidElementClassMap();
}
return AndroidElementClassMap.instance;
}
/**
* Find a matching UI element class name based on the tag name.
*
* @param selector_text
* @return String
* @throws AndroidCommandException
*/
public static String match(String selector_text)
throws AndroidCommandException, UnallowedTagNameException {
final AndroidElementClassMap inst = AndroidElementClassMap.getInstance();
if (inst.unallowed.contains(selector_text)) {
throw new UnallowedTagNameException(selector_text);
} else {
final String mappedSel = inst.map.get(selector_text);
if ("view".equals(selector_text)) {
return "android.view.View";
} else if (mappedSel != null) {
return "android.widget." + mappedSel;
} else if (selector_text.contains(".")) {
return selector_text;
} else {
selector_text = selector_text.substring(0, 1).toUpperCase()
+ selector_text.substring(1);
return "android.widget." + selector_text;
}
}
}
public AndroidElementClassMap() {
map = new HashMap<String, String>();
unallowed = new ArrayList<String>();
map.put("abslist", "AbsListView");
map.put("absseek", "AbsSeekBar");
map.put("absspinner", "AbsSpinner");
map.put("absolute", "AbsoluteLayout");
map.put("adapterview", "AdapterView");
map.put("adapterviewanimator", "AdapterViewAnimator");
map.put("adapterviewflipper", "AdapterViewFlipper");
map.put("analogclock", "AnalogClock");
map.put("appwidgethost", "AppWidgetHostView");
map.put("autocomplete", "AutoCompleteTextView");
map.put("button", "Button");
map.put("breadcrumbs", "FragmentBreadCrumbs");
map.put("calendar", "CalendarView");
map.put("checkbox", "CheckBox");
map.put("checked", "CheckedTextView");
map.put("chronometer", "Chronometer");
map.put("compound", "CompoundButton");
map.put("datepicker", "DatePicker");
map.put("dialerfilter", "DialerFilter");
map.put("digitalclock", "DigitalClock");
map.put("drawer", "SlidingDrawer");
map.put("expandable", "ExpandableListView");
map.put("extract", "ExtractEditText");
map.put("fragmenttabhost", "FragmentTabHost");
map.put("frame", "FrameLayout");
map.put("gallery", "Gallery");
map.put("gesture", "GestureOverlayView");
map.put("glsurface", "GLSurfaceView");
map.put("grid", "GridView");
map.put("gridlayout", "GridLayout");
map.put("horizontal", "HorizontalScrollView");
map.put("image", "ImageView");
map.put("imagebutton", "ImageButton");
map.put("imageswitcher", "ImageSwitcher");
map.put("keyboard", "KeyboardView");
map.put("linear", "LinearLayout");
map.put("list", "ListView");
map.put("media", "MediaController");
map.put("mediaroutebutton", "MediaRouteButton");
map.put("multiautocomplete", "MultiAutoCompleteTextView");
map.put("numberpicker", "NumberPicker");
map.put("pagetabstrip", "PageTabStrip");
map.put("pagetitlestrip", "PageTitleStrip");
map.put("progress", "ProgressBar");
map.put("quickcontactbadge", "QuickContactBadge");
map.put("radio", "RadioButton");
map.put("radiogroup", "RadioGroup");
map.put("rating", "RatingBar");
map.put("relative", "RelativeLayout");
map.put("row", "TableRow");
map.put("rssurface", "RSSurfaceView");
map.put("rstexture", "RSTextureView");
map.put("scroll", "ScrollView");
map.put("search", "SearchView");
map.put("seek", "SeekBar");
map.put("space", "Space");
map.put("spinner", "Spinner");
map.put("stack", "StackView");
map.put("surface", "SurfaceView");
map.put("switch", "Switch");
map.put("tabhost", "TabHost");
map.put("tabwidget", "TabWidget");
map.put("table", "TableLayout");
map.put("text", "TextView");
map.put("textclock", "TextClock");
map.put("textswitcher", "TextSwitcher");
map.put("texture", "TextureView");
map.put("textfield", "EditText");
map.put("timepicker", "TimePicker");
map.put("toggle", "ToggleButton");
map.put("twolinelistitem", "TwoLineListItem");
map.put("video", "VideoView");
map.put("viewanimator", "ViewAnimator");
map.put("viewflipper", "ViewFlipper");
map.put("viewgroup", "ViewGroup");
map.put("viewpager", "ViewPager");
map.put("viewstub", "ViewStub");
map.put("viewswitcher", "ViewSwitcher");
map.put("web", "android.webkit.WebView");
map.put("window", "FrameLayout");
map.put("zoom", "ZoomButton");
map.put("zoomcontrols", "ZoomControls");
unallowed.add("secure");
}
}