1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.autoquest.plugin.android.guimodel;
|
---|
16 |
|
---|
17 | import java.util.List;
|
---|
18 |
|
---|
19 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * <p>
|
---|
23 | * Implements the specification of {@link IGUIElement} for {@link ANDROIDGUIElement}s.
|
---|
24 | * </p>
|
---|
25 | *
|
---|
26 | * @version 1.0
|
---|
27 | * @author Florian Unger
|
---|
28 | */
|
---|
29 | public class ANDROIDGUIElementSpec implements IGUIElementSpec {
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * <p>
|
---|
33 | * default serial version UID
|
---|
34 | * </p>
|
---|
35 | */
|
---|
36 | private static final long serialVersionUID = 1L;
|
---|
37 |
|
---|
38 | /*
|
---|
39 | * (non-Javadoc) see de.ugoe.cs.autoquest.androidmonitor.AndroidmonitorLogFile#logComponent()
|
---|
40 | */
|
---|
41 | /**
|
---|
42 | * <p>
|
---|
43 | * Hash code of the GUI element. Used as unique identifier during parsing a log file. Note that
|
---|
44 | * it is possible that the hash code of an element changes over several log files even if they
|
---|
45 | * come from the same target.
|
---|
46 | * </p>
|
---|
47 | */
|
---|
48 | private int hashCode;
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * <p>
|
---|
52 | * Path to an element in an activity. e.g. a path of a button could look like
|
---|
53 | * MainActivity/DecorView/ActionBarOverlayLayout/FrameLayout/ RelativeLayout/Button
|
---|
54 | * </p>
|
---|
55 | */
|
---|
56 | private String path;
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * <p>
|
---|
60 | * id of the object as it is returned by view.getId()
|
---|
61 | * </p>
|
---|
62 | */
|
---|
63 | private int index;
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * <p>
|
---|
67 | * the type of GUI element represented by this specification, which is usually the java class of
|
---|
68 | * the android GUI element
|
---|
69 | * </p>
|
---|
70 | */
|
---|
71 | private String type;
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * <p>
|
---|
75 | * Type hierarchy of the class itself
|
---|
76 | * </p>
|
---|
77 | */
|
---|
78 | private List<String> typeHierarchy = null;
|
---|
79 |
|
---|
80 | /*
|
---|
81 | * (non-Javadoc)
|
---|
82 | *
|
---|
83 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getType()
|
---|
84 | */
|
---|
85 | @Override
|
---|
86 | public String getType() {
|
---|
87 | return type;
|
---|
88 | }
|
---|
89 |
|
---|
90 | /*
|
---|
91 | * (non-Javadoc)
|
---|
92 | *
|
---|
93 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getTypeHierarchy ()
|
---|
94 | */
|
---|
95 | @Override
|
---|
96 | public String[] getTypeHierarchy() {
|
---|
97 | if (typeHierarchy == null) {
|
---|
98 | return new String[]
|
---|
99 | { (getType()) };
|
---|
100 | }
|
---|
101 | else
|
---|
102 | return typeHierarchy.toArray(new String[typeHierarchy.size()]);
|
---|
103 | }
|
---|
104 |
|
---|
105 | @Override
|
---|
106 | public boolean getSimilarity(IGUIElementSpec other) {
|
---|
107 | if (this == other) {
|
---|
108 | return true;
|
---|
109 | }
|
---|
110 |
|
---|
111 | if (!(other instanceof ANDROIDGUIElementSpec)) {
|
---|
112 | return false;
|
---|
113 | }
|
---|
114 |
|
---|
115 | // Check wheter view.id() keeps the same even if something in the
|
---|
116 | // structure changes. The hash in the JFCMonitor seems to be unique at
|
---|
117 | // all. In the Androidmonitore the hash of an element changes even from
|
---|
118 | // one start of the activity to another.
|
---|
119 | /*
|
---|
120 | * Maybe some other comparisons will be necessary in the future.
|
---|
121 | */
|
---|
122 |
|
---|
123 | return false;
|
---|
124 | }
|
---|
125 |
|
---|
126 | /*
|
---|
127 | * (non-Javadoc)
|
---|
128 | *
|
---|
129 | * @see java.lang.Object#hashCode()
|
---|
130 | */
|
---|
131 | @Override
|
---|
132 | public int hashCode() {
|
---|
133 | return hashCode;
|
---|
134 | }
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * <p>
|
---|
138 | * Returns the path associated with the specified GUI element.
|
---|
139 | * </p>
|
---|
140 | *
|
---|
141 | * @return the path to an element
|
---|
142 | */
|
---|
143 | public String getPath() {
|
---|
144 | return path;
|
---|
145 | }
|
---|
146 |
|
---|
147 | public int getIndex() {
|
---|
148 | return index;
|
---|
149 | }
|
---|
150 |
|
---|
151 | public void setIndex(int index) {
|
---|
152 | this.index = index;
|
---|
153 | }
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Set the hash code associated with the GUI element.
|
---|
157 | *
|
---|
158 | * @param hash
|
---|
159 | * the hash of an element object
|
---|
160 | */
|
---|
161 | public void setHashCode(int hash) {
|
---|
162 | this.hashCode = hash;
|
---|
163 | }
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Set the path associated with the specified GUI element.
|
---|
167 | *
|
---|
168 | * @param path
|
---|
169 | * the path to an element
|
---|
170 | */
|
---|
171 | public void setPath(String path) {
|
---|
172 | this.path = path;
|
---|
173 | }
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * <p>
|
---|
177 | * Sets the type of the specified GUI element.
|
---|
178 | * </p>
|
---|
179 | *
|
---|
180 | * @param type
|
---|
181 | * the type
|
---|
182 | */
|
---|
183 | public void setType(String type) {
|
---|
184 | this.type = type;
|
---|
185 | }
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * <p>
|
---|
189 | * Sets the type hierarchy of the specified GUI element.
|
---|
190 | *
|
---|
191 | * @param typeHierarchy
|
---|
192 | * </p>
|
---|
193 | */
|
---|
194 | public void setTypeHierarchy(List<String> typeHierarchy) {
|
---|
195 | this.typeHierarchy = typeHierarchy;
|
---|
196 | }
|
---|
197 |
|
---|
198 | }
|
---|