5
5
import android .graphics .Color ;
6
6
import android .graphics .Point ;
7
7
import android .os .Bundle ;
8
+ import android .os .Handler ;
8
9
import android .os .StrictMode ;
9
10
import android .os .Vibrator ;
10
11
import android .support .v7 .app .AppCompatActivity ;
17
18
import android .widget .Toast ;
18
19
19
20
import hs_mannheim .gestureframework .ConfigurationBuilder ;
20
- import hs_mannheim .gestureframework .gesture .approach .ApproachDetector ;
21
+ import hs_mannheim .gestureframework .gesture .swipe .SwipeDetector ;
22
+ import hs_mannheim .gestureframework .gesture .swipe .SwipeEvent ;
23
+ import hs_mannheim .gestureframework .gesture .swipe .TouchPoint ;
21
24
import hs_mannheim .gestureframework .messaging .IPacketReceiver ;
22
25
import hs_mannheim .gestureframework .messaging .Packet ;
23
26
import hs_mannheim .gestureframework .model .IViewContext ;
24
27
import hs_mannheim .gestureframework .model .InteractionApplication ;
25
28
import hs_mannheim .gestureframework .model .Selection ;
26
29
import hs_mannheim .gestureframework .model .SysplaceContext ;
27
30
import hs_mannheim .gestureframework .model .ViewWrapper ;
31
+ import hs_mannheim .sysplace .animations .PlugAnimator ;
32
+ import hs_mannheim .sysplace .animations .SocketAnimator ;
28
33
29
- public class MainActivity extends AppCompatActivity implements IViewContext , IPacketReceiver {
34
+ public class MainActivity extends AppCompatActivity implements IViewContext , IPacketReceiver , SwipeDetector . SwipeEventListener {
30
35
private static final String TAG = "[Main Activity]" ;
31
36
32
37
private TextView mTextView ;
@@ -35,6 +40,9 @@ public class MainActivity extends AppCompatActivity implements IViewContext, IPa
35
40
private Button mPhotoButton ;
36
41
private Button mDisconnectButton ;
37
42
private SysplaceContext mSysplaceContext ;
43
+ private PlugAnimator mPlugAnimator ;
44
+ private SocketAnimator mSocketAnimator ;
45
+ private boolean mIsConnectionEstablished ;
38
46
39
47
@ Override
40
48
protected void onCreate (Bundle savedInstanceState ) {
@@ -68,10 +76,17 @@ protected void onCreate(Bundle savedInstanceState) {
68
76
mSysplaceContext = ((InteractionApplication ) getApplicationContext ()).getSysplaceContext ();
69
77
mEditText .addTextChangedListener (new SysplaceTextWatcher (mSysplaceContext ));
70
78
79
+ //////////////////////////////////////
80
+
81
+ View plugView = findViewById (R .id .plug ), socketView = findViewById (R .id .socket );
82
+ mPlugAnimator = new PlugAnimator (this , plugView , getDisplaySize ());
83
+ mSocketAnimator = new SocketAnimator (this , socketView , getDisplaySize ());
84
+
85
+
86
+ //////////////////////////////////////
71
87
mSysplaceContext .activate (this );
72
88
73
- //TODO: take this out again. saves time on animation testing
74
- mPhotoButton .setEnabled (true );
89
+ mSysplaceContext .registerForSwipeEvents (this );
75
90
}
76
91
77
92
@@ -135,6 +150,14 @@ public void receive(Packet packet) {
135
150
//TODO: turn this on again. was getting on my nerves >:(
136
151
//((Vibrator) this.getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE)).vibrate(700);
137
152
153
+ mIsConnectionEstablished = true ;
154
+
155
+ if (mSwipeOrientation == SwipeEvent .Orientation .WEST ) {
156
+ mSocketAnimator .plugIn ();
157
+ } else if (mSwipeOrientation == SwipeEvent .Orientation .EAST ) {
158
+ mPlugAnimator .plugIn ();
159
+ }
160
+
138
161
break ;
139
162
case ConnectionLost :
140
163
mTextView .setText (R .string .not_connected_info );
@@ -151,5 +174,52 @@ public void receive(Packet packet) {
151
174
break ;
152
175
}
153
176
}
177
+
178
+ private SwipeEvent .Orientation mSwipeOrientation ;
179
+ private boolean isPeakedIn ;
180
+
181
+ @ Override
182
+ public void onSwipeDetected (SwipeDetector swipeDetector , SwipeEvent event ) {
183
+ mSwipeOrientation = event .getOrientation ();
184
+
185
+ if (!isPeakedIn ) {
186
+ if (mSwipeOrientation == SwipeEvent .Orientation .WEST ) {
187
+ mSocketAnimator .play ();
188
+ } else if (mSwipeOrientation == SwipeEvent .Orientation .EAST ) {
189
+ mPlugAnimator .play ();
190
+ }
191
+ isPeakedIn = true ;
192
+
193
+ new Handler ().postDelayed (new Runnable () {
194
+ @ Override
195
+ public void run () {
196
+ if (!mIsConnectionEstablished ) {
197
+ if (mSwipeOrientation == SwipeEvent .Orientation .WEST ) {
198
+ mSocketAnimator .retreat ();
199
+ } else if (mSwipeOrientation == SwipeEvent .Orientation .EAST ) {
200
+ mPlugAnimator .retreat ();
201
+ }
202
+
203
+ isPeakedIn = false ;
204
+ }
205
+ }
206
+ }, 5000 );
207
+ }
208
+ }
209
+
210
+ @ Override
211
+ public void onSwiping (SwipeDetector swipeDetector , TouchPoint touchPoint ) {
212
+
213
+ }
214
+
215
+ @ Override
216
+ public void onSwipeStart (SwipeDetector swipeDetector , TouchPoint touchPoint , View view ) {
217
+
218
+ }
219
+
220
+ @ Override
221
+ public void onSwipeEnd (SwipeDetector swipeDetector , TouchPoint touchPoint ) {
222
+
223
+ }
154
224
}
155
225
0 commit comments