1 |
|
package game.shad.tempus.hearts; |
2 |
|
|
3 |
|
import java.util.ArrayList; |
4 |
|
|
5 |
|
import android.graphics.Rect; |
6 |
|
import android.view.GestureDetector; |
7 |
|
import android.view.MotionEvent; |
8 |
|
import android.widget.Toast; |
9 |
|
|
|
|
| 0% |
Uncovered Elements: 56 (56) |
Complexity: 22 |
Complexity Density: 0,69 |
|
10 |
|
public class Gestures implements GestureDetector.OnGestureListener, |
11 |
|
GestureDetector.OnDoubleTapListener |
12 |
|
{ |
13 |
|
|
14 |
|
private GameView gameView; |
15 |
|
private static final int SWIPE_MIN_DISTANCE = 100; |
16 |
|
private static final int SWIPE_MAX_OFF_PATH = 250; |
17 |
|
private static final int SWIPE_THRESHOLD_VELOCITY = 200; |
18 |
|
|
19 |
|
private DeckHolder deckView = null; |
20 |
|
private TableHolder tableView = null; |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
21 |
0
|
public Gestures(GameView gameView)... |
22 |
|
{ |
23 |
|
|
24 |
0
|
this.gameView = gameView; |
25 |
0
|
this.deckView = gameView.getDeckHolder(); |
26 |
0
|
this.tableView = gameView.getTableHolder(); |
27 |
|
|
28 |
|
} |
29 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
30 |
0
|
@Override... |
31 |
|
public boolean onDoubleTap(MotionEvent e) |
32 |
|
{ |
33 |
|
|
34 |
0
|
Toast.makeText(gameView.context, "Double Tap", Toast.LENGTH_SHORT).show(); |
35 |
0
|
return false; |
36 |
|
} |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
38 |
0
|
@Override... |
39 |
|
public boolean onDoubleTapEvent(MotionEvent e) |
40 |
|
{ |
41 |
|
|
42 |
|
|
43 |
0
|
return false; |
44 |
|
} |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0,27 |
|
46 |
0
|
@Override... |
47 |
|
public boolean onSingleTapConfirmed(MotionEvent e) |
48 |
|
{ |
49 |
|
|
50 |
0
|
int x = (int) e.getX(); |
51 |
0
|
int y = (int) e.getY(); |
52 |
0
|
Rect bondsDV=deckView.getBounds(); |
53 |
0
|
Rect bondsTV=tableView.getBounds(); |
54 |
|
|
55 |
0
|
if(bondsDV.contains(x, y)){ |
56 |
0
|
int y2=y-bondsDV.top; |
57 |
0
|
Toast.makeText(gameView.context, "DeckView", Toast.LENGTH_SHORT).show(); |
58 |
|
|
59 |
0
|
gameView.deckViewTouched(x, y2); |
60 |
|
} |
61 |
0
|
else if(bondsTV.contains(x, y)){ |
62 |
0
|
Toast.makeText(gameView.context, "TableView", Toast.LENGTH_SHORT).show(); |
63 |
|
} |
64 |
0
|
return false; |
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
0
|
@Override... |
68 |
|
public boolean onDown(MotionEvent e) |
69 |
|
{ |
70 |
|
|
71 |
0
|
return false; |
72 |
|
} |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 11 |
Complexity Density: 0,92 |
|
74 |
0
|
@Override... |
75 |
|
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, |
76 |
|
float velocityY) |
77 |
|
{ |
78 |
|
|
79 |
0
|
try { |
80 |
0
|
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) |
81 |
0
|
return false; |
82 |
|
|
83 |
0
|
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { |
84 |
|
|
85 |
0
|
this.deckView.swipeLeft(); |
86 |
0
|
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { |
87 |
|
|
88 |
0
|
this.deckView.swipeRight(); |
89 |
|
} |
90 |
0
|
else if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { |
91 |
0
|
Toast.makeText(gameView.context, "Swipe up", Toast.LENGTH_SHORT).show(); |
92 |
0
|
} else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { |
93 |
0
|
Toast.makeText(gameView.context, "Swipe down", Toast.LENGTH_SHORT).show(); |
94 |
|
} |
95 |
|
} catch (Exception e) { |
96 |
|
|
97 |
|
} |
98 |
|
|
99 |
0
|
return false; |
100 |
|
} |
101 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
102 |
0
|
@Override... |
103 |
|
public void onLongPress(MotionEvent e) |
104 |
|
{ |
105 |
|
|
106 |
|
|
107 |
|
} |
108 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
109 |
0
|
@Override... |
110 |
|
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, |
111 |
|
float distanceY) |
112 |
|
{ |
113 |
|
|
114 |
0
|
return false; |
115 |
|
} |
116 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
117 |
0
|
@Override... |
118 |
|
public void onShowPress(MotionEvent e) |
119 |
|
{ |
120 |
|
|
121 |
|
|
122 |
|
} |
123 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
0
|
@Override... |
125 |
|
public boolean onSingleTapUp(MotionEvent e) |
126 |
|
{ |
127 |
|
|
128 |
0
|
return false; |
129 |
|
} |
130 |
|
|
131 |
|
} |