1 | // Copyright 2014 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 | * the type of GUI element represented by this specification, which is
|
---|
62 | * usually the java class of the android GUI element
|
---|
63 | * </p>
|
---|
64 | */
|
---|
65 | private String type;
|
---|
66 |
|
---|
67 | /*
|
---|
68 | * (non-Javadoc)
|
---|
69 | *
|
---|
70 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getType()
|
---|
71 | */
|
---|
72 | @Override
|
---|
73 | public String getType() {
|
---|
74 | return type;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /*
|
---|
78 | * (non-Javadoc)
|
---|
79 | *
|
---|
80 | * @see
|
---|
81 | * de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getTypeHierarchy
|
---|
82 | * ()
|
---|
83 | */
|
---|
84 | @Override
|
---|
85 | public String[] getTypeHierarchy() {
|
---|
86 | return new String[] { (getType()) };
|
---|
87 | // TODO change this part after adding ancestors in
|
---|
88 | // de.ugoe.cs.autoquest.androidmonitor.AndroidmonitorLogFile#addComponent
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Override
|
---|
92 | public boolean getSimilarity(IGUIElementSpec other) {
|
---|
93 | if (this == other) {
|
---|
94 | return true;
|
---|
95 | }
|
---|
96 |
|
---|
97 | if (!(other instanceof AndroidGUIElementSpec)) {
|
---|
98 | return false;
|
---|
99 | }
|
---|
100 |
|
---|
101 | // Check wheter view.id() keeps the same even if something in the
|
---|
102 | // structure changes. The hash in the JFCMonitor seems to be unique at
|
---|
103 | // all. In the Androidmonitore the hash of an element changes even from
|
---|
104 | // one start of the activity to another.
|
---|
105 | /*
|
---|
106 | * Maybe some other comparisons will be necessary in the future.
|
---|
107 | */
|
---|
108 |
|
---|
109 | return false;
|
---|
110 | }
|
---|
111 |
|
---|
112 | /*
|
---|
113 | * (non-Javadoc)
|
---|
114 | *
|
---|
115 | * @see java.lang.Object#hashCode()
|
---|
116 | */
|
---|
117 | @Override
|
---|
118 | public int hashCode() {
|
---|
119 | return hashCode;
|
---|
120 | }
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * <p>
|
---|
124 | * Returns the path associated with the specified GUI element.
|
---|
125 | * </p>
|
---|
126 | * @return the path to an element
|
---|
127 | */
|
---|
128 | public String getPath() {
|
---|
129 | return path;
|
---|
130 | }
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Set the hash code associated with the GUI element.
|
---|
134 | * @param hash
|
---|
135 | * the hash of an element object
|
---|
136 | */
|
---|
137 | public void setHashCode(int hash){
|
---|
138 | this.hashCode = hash;
|
---|
139 | }
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Set the path associated with the specified GUI element.
|
---|
143 | * @param path
|
---|
144 | * the path to an element
|
---|
145 | */
|
---|
146 | public void setPath(String path) {
|
---|
147 | this.path = path;
|
---|
148 | }
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * <p>
|
---|
152 | * Sets the type of the specified GUI element.
|
---|
153 | * </p>
|
---|
154 | *
|
---|
155 | * @param type
|
---|
156 | * the type
|
---|
157 | */
|
---|
158 | public void setType(String type) {
|
---|
159 | this.type = type;
|
---|
160 | }
|
---|
161 |
|
---|
162 | }
|
---|