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.eventcore.gui;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * <p>
|
---|
19 | * Event type for a single touch events, i.e. touch on a mobile phone.
|
---|
20 | * </p>
|
---|
21 | *
|
---|
22 | * @version 1.0
|
---|
23 | * @author Florian Unger
|
---|
24 | */
|
---|
25 | public class TouchSingle extends TouchInteraction {
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * <p>
|
---|
29 | * Id for object serialization.
|
---|
30 | * </p>
|
---|
31 | */
|
---|
32 | private static final long serialVersionUID = 1L;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * <p>
|
---|
36 | * The x coordinate of the touched view in time of touch.
|
---|
37 | * </p>
|
---|
38 | */
|
---|
39 | /*
|
---|
40 | * (non-Javadoc)
|
---|
41 | *
|
---|
42 | * @see android.view.View#getX()
|
---|
43 | * http://developer.android.com/reference/android/view/View.html#getX()
|
---|
44 | */
|
---|
45 | private float x;
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * <p>
|
---|
49 | * The y coordinate of the touched view in time of touch.
|
---|
50 | * </p>
|
---|
51 | */
|
---|
52 | /*
|
---|
53 | * (non-Javadoc)
|
---|
54 | *
|
---|
55 | * @see android.view.View#getY()
|
---|
56 | * http://developer.android.com/reference/android/view/View.html#getY()
|
---|
57 | */
|
---|
58 | private float y;
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * <p>
|
---|
62 | * Constructor. Creates a new {@link TouchSingle} event type.
|
---|
63 | * </p>
|
---|
64 | */
|
---|
65 | public TouchSingle(float x, float y) {
|
---|
66 | this.x = x;
|
---|
67 | this.y = y;
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | public boolean startsLogicalSequence() {
|
---|
72 | return false;
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Override
|
---|
76 | public boolean finishesLogicalSequence() {
|
---|
77 | return false;
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Override
|
---|
81 | public String getName() {
|
---|
82 | return "TouchSingle";
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * @return the x position of the touched view in time of touch
|
---|
87 | */
|
---|
88 | public float getX() {
|
---|
89 | return x;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * @return the y position of the touched view in time of touch
|
---|
94 | */
|
---|
95 | public float getY() {
|
---|
96 | return y;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /*
|
---|
100 | * (non-Javadoc)
|
---|
101 | *
|
---|
102 | * @see java.lang.Object#equals(java.lang.Object)
|
---|
103 | */
|
---|
104 | @Override
|
---|
105 | public boolean equals(Object obj) {
|
---|
106 | if(obj == this){
|
---|
107 | return true;
|
---|
108 | }
|
---|
109 | if(!(obj instanceof TouchSingle)){
|
---|
110 | return false;
|
---|
111 | }
|
---|
112 | TouchSingle touch = (TouchSingle)obj;
|
---|
113 | return touch.getX() == x && touch.getY() == y;
|
---|
114 | }
|
---|
115 |
|
---|
116 | /*
|
---|
117 | * (non-Javadoc)
|
---|
118 | *
|
---|
119 | * @see java.lang.Object#hashCode()
|
---|
120 | */
|
---|
121 | @Override
|
---|
122 | public int hashCode() {
|
---|
123 | // 17 due to the reason that this is a prime number.
|
---|
124 | int result = 17;
|
---|
125 | /*
|
---|
126 | * 31 due to the reason that a lot of VM's could optimize this multiplication by a shift.
|
---|
127 | * Source: Effective Java, Joshua Bloch, 2008, p.48
|
---|
128 | */
|
---|
129 | result = 31 * result + Float.floatToIntBits(x);
|
---|
130 | result = 31 * result + Float.floatToIntBits(y);
|
---|
131 | return result;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /*
|
---|
135 | * (non-Javadoc)
|
---|
136 | *
|
---|
137 | * @see java.lang.Object#toString()
|
---|
138 | */
|
---|
139 | @Override
|
---|
140 | public String toString() {
|
---|
141 | return "SingleTouch(" + x + "," + y + ")";
|
---|
142 | }
|
---|
143 |
|
---|
144 | }
|
---|