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