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 | package de.ugoe.cs.autoquest.plugin.android.guimodel;
|
---|
15 |
|
---|
16 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * <p>
|
---|
20 | * Implements the specification of {@link IGUIElement} for
|
---|
21 | * {@link AndroidGUIElement}s.
|
---|
22 | * </p>
|
---|
23 | *
|
---|
24 | * @version 1.0
|
---|
25 | * @author Florian Unger
|
---|
26 | */
|
---|
27 | public class AndroidGUIElementSpec implements IGUIElementSpec {
|
---|
28 |
|
---|
29 | // TODO Why is serialVersionUID = 1L initialized by 1L?
|
---|
30 | /**
|
---|
31 | * <p>
|
---|
32 | * default serial version UID
|
---|
33 | * </p>
|
---|
34 | */
|
---|
35 | private static final long serialVersionUID = 1L;
|
---|
36 |
|
---|
37 | /*
|
---|
38 | * (non-Javadoc) see
|
---|
39 | * 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
|
---|
44 | * log file. Note that it is possible that the hash code of an element
|
---|
45 | * changes over several log files even if they 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
|
---|
53 | * like MainActivity/DecorView/ActionBarOverlayLayout/FrameLayout/
|
---|
54 | * RelativeLayout/Button
|
---|
55 | * </p>
|
---|
56 | */
|
---|
57 | private String path;
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * <p>
|
---|
61 | * id of the object as it is returned by view.getId()
|
---|
62 | * </p>
|
---|
63 | */
|
---|
64 | private int index;
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * <p>
|
---|
68 | * the type of GUI element represented by this specification, which is
|
---|
69 | * usually the java class of the android GUI element
|
---|
70 | * </p>
|
---|
71 | */
|
---|
72 | private String type;
|
---|
73 |
|
---|
74 | /*
|
---|
75 | * (non-Javadoc)
|
---|
76 | *
|
---|
77 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getType()
|
---|
78 | */
|
---|
79 | @Override
|
---|
80 | public String getType() {
|
---|
81 | return type;
|
---|
82 | }
|
---|
83 |
|
---|
84 | /*
|
---|
85 | * (non-Javadoc)
|
---|
86 | *
|
---|
87 | * @see
|
---|
88 | * de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getTypeHierarchy
|
---|
89 | * ()
|
---|
90 | */
|
---|
91 | @Override
|
---|
92 | public String[] getTypeHierarchy() {
|
---|
93 | return new String[] { (getType()) };
|
---|
94 | // TODO change this part after adding ancestors in
|
---|
95 | // de.ugoe.cs.autoquest.androidmonitor.AndroidmonitorLogFile#addComponent
|
---|
96 | }
|
---|
97 |
|
---|
98 | @Override
|
---|
99 | public boolean getSimilarity(IGUIElementSpec other) {
|
---|
100 | if (this == other) {
|
---|
101 | return true;
|
---|
102 | }
|
---|
103 |
|
---|
104 | if (!(other instanceof AndroidGUIElementSpec)) {
|
---|
105 | return false;
|
---|
106 | }
|
---|
107 |
|
---|
108 | // Check wheter view.id() keeps the same even if something in the
|
---|
109 | // structure changes. The hash in the JFCMonitor seems to be unique at
|
---|
110 | // all. In the Androidmonitore the hash of an element changes even from
|
---|
111 | // one start of the activity to another.
|
---|
112 | /*
|
---|
113 | * Maybe some other comparisons will be necessary in the future.
|
---|
114 | */
|
---|
115 |
|
---|
116 | return false;
|
---|
117 | }
|
---|
118 |
|
---|
119 | /*
|
---|
120 | * (non-Javadoc)
|
---|
121 | *
|
---|
122 | * @see java.lang.Object#hashCode()
|
---|
123 | */
|
---|
124 | @Override
|
---|
125 | public int hashCode() {
|
---|
126 | return hashCode;
|
---|
127 | }
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * <p>
|
---|
131 | * Returns the path associated with the specified GUI element.
|
---|
132 | * </p>
|
---|
133 | * @return the path to an element
|
---|
134 | */
|
---|
135 | public String getPath() {
|
---|
136 | return path;
|
---|
137 | }
|
---|
138 |
|
---|
139 | public int getIndex() {
|
---|
140 | return index;
|
---|
141 | }
|
---|
142 |
|
---|
143 | public void setIndex(int index) {
|
---|
144 | this.index = index;
|
---|
145 | }
|
---|
146 |
|
---|
147 | /**
|
---|
148 | * Set the hash code associated with the GUI element.
|
---|
149 | * @param hash
|
---|
150 | * the hash of an element object
|
---|
151 | */
|
---|
152 | public void setHashCode(int hash){
|
---|
153 | this.hashCode = hash;
|
---|
154 | }
|
---|
155 |
|
---|
156 | /**
|
---|
157 | * Set the path associated with the specified GUI element.
|
---|
158 | * @param path
|
---|
159 | * the path to an element
|
---|
160 | */
|
---|
161 | public void setPath(String path) {
|
---|
162 | this.path = path;
|
---|
163 | }
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * <p>
|
---|
167 | * Sets the type of the specified GUI element.
|
---|
168 | * </p>
|
---|
169 | *
|
---|
170 | * @param type
|
---|
171 | * the type
|
---|
172 | */
|
---|
173 | public void setType(String type) {
|
---|
174 | this.type = type;
|
---|
175 | }
|
---|
176 |
|
---|
177 | }
|
---|