2
2
3
3
import android .content .Context ;
4
4
import android .content .Intent ;
5
+ import android .content .SharedPreferences ;
5
6
import android .graphics .Point ;
6
7
import android .location .Location ;
7
8
import android .location .LocationManager ;
8
9
import android .os .Build ;
9
10
import android .os .CountDownTimer ;
11
+ import android .os .Handler ;
12
+ import android .support .annotation .NonNull ;
13
+ import android .support .design .widget .BottomSheetBehavior ;
10
14
import android .support .design .widget .Snackbar ;
11
15
import android .support .v7 .app .AppCompatActivity ;
12
16
import android .os .Bundle ;
13
17
import android .view .Display ;
14
18
import android .view .DragEvent ;
19
+ import android .view .GestureDetector ;
15
20
import android .view .KeyEvent ;
16
21
import android .view .LayoutInflater ;
22
+ import android .view .MotionEvent ;
17
23
import android .view .View ;
18
24
import android .view .WindowManager ;
19
25
import android .view .inputmethod .EditorInfo ;
20
26
import android .widget .Button ;
21
27
import android .widget .EditText ;
22
28
import android .widget .HorizontalScrollView ;
29
+ import android .widget .ImageView ;
23
30
import android .widget .LinearLayout ;
24
31
import android .widget .RelativeLayout ;
25
32
import android .widget .TextView ;
30
37
import java .util .ArrayList ;
31
38
import java .util .Date ;
32
39
40
+ import butterknife .BindView ;
41
+ import butterknife .ButterKnife ;
33
42
import io .pslab .R ;
34
43
import io .pslab .communication .ScienceLab ;
35
44
import io .pslab .models .SensorDataBlock ;
38
47
import io .pslab .others .CustomSnackBar ;
39
48
import io .pslab .others .GPSLogger ;
40
49
import io .pslab .others .LocalDataLog ;
50
+ import io .pslab .others .MathUtils ;
41
51
import io .pslab .others .ScienceLabCommon ;
52
+ import io .pslab .others .SwipeGestureDetector ;
42
53
import io .realm .Realm ;
43
54
import io .realm .RealmObject ;
44
55
import io .realm .RealmResults ;
45
56
46
57
public class RoboticArmActivity extends AppCompatActivity {
47
58
59
+ private static final String PREF_NAME = "RoboticArmActivity" ;
48
60
private EditText degreeText1 , degreeText2 , degreeText3 , degreeText4 ;
49
61
private SeekArc seekArc1 , seekArc2 , seekArc3 , seekArc4 ;
50
62
private LinearLayout servo1TimeLine , servo2TimeLine , servo3TimeLine , servo4TimeLine ;
@@ -62,11 +74,32 @@ public class RoboticArmActivity extends AppCompatActivity {
62
74
private final String DATA_BLOCK = "data_block" ;
63
75
private int timelinePosition = 0 ;
64
76
private ScienceLab scienceLab ;
77
+ private BottomSheetBehavior bottomSheetBehavior ;
78
+ private GestureDetector gestureDetector ;
79
+ @ BindView (R .id .sheet_slide_text_robotic_arm )
80
+ TextView bottomSheetSlideText ;
81
+ @ BindView (R .id .parent_layout_robotic )
82
+ View parentLayout ;
83
+ @ BindView (R .id .bottom_sheet_robotic_arm )
84
+ LinearLayout bottomSheet ;
85
+ @ BindView (R .id .img_arrow_robotic_arm )
86
+ ImageView arrowUpDown ;
65
87
66
88
@ Override
67
89
protected void onCreate (Bundle savedInstanceState ) {
68
90
super .onCreate (savedInstanceState );
69
91
setContentView (R .layout .activity_robotic_arm );
92
+ ButterKnife .bind (this );
93
+
94
+ setUpBottomSheet ();
95
+ parentLayout .setOnClickListener (new View .OnClickListener () {
96
+ @ Override
97
+ public void onClick (View v ) {
98
+ if (bottomSheetBehavior .getState () == BottomSheetBehavior .STATE_EXPANDED )
99
+ bottomSheetBehavior .setState (BottomSheetBehavior .STATE_HIDDEN );
100
+ parentLayout .setVisibility (View .GONE );
101
+ }
102
+ });
70
103
71
104
scienceLab = ScienceLabCommon .scienceLab ;
72
105
if (!scienceLab .isConnected ()) {
@@ -484,6 +517,79 @@ public void onClick(View v) {
484
517
.getBlockOfServoRecords (getIntent ().getExtras ().getLong (DATA_BLOCK ));
485
518
setReceivedData ();
486
519
}
520
+
521
+ Button guideButton = findViewById (R .id .timeline_guide_button );
522
+ guideButton .setOnClickListener (new View .OnClickListener () {
523
+ @ Override
524
+ public void onClick (View v ) {
525
+ bottomSheetBehavior .setState (bottomSheetBehavior .getState () == BottomSheetBehavior .STATE_HIDDEN ?
526
+ BottomSheetBehavior .STATE_EXPANDED : BottomSheetBehavior .STATE_HIDDEN );
527
+ }
528
+ });
529
+ }
530
+
531
+ private void setUpBottomSheet () {
532
+ bottomSheetBehavior = BottomSheetBehavior .from (bottomSheet );
533
+
534
+ final SharedPreferences settings = this .getSharedPreferences (PREF_NAME , MODE_PRIVATE );
535
+ Boolean isFirstTime = settings .getBoolean ("RoboticArmFirstTime" , true );
536
+
537
+ if (isFirstTime ) {
538
+ bottomSheetBehavior .setState (BottomSheetBehavior .STATE_EXPANDED );
539
+ parentLayout .setVisibility (View .VISIBLE );
540
+ parentLayout .setAlpha (0.8f );
541
+ arrowUpDown .setRotation (180 );
542
+ bottomSheetSlideText .setText (R .string .hide_guide_text );
543
+ SharedPreferences .Editor editor = settings .edit ();
544
+ editor .putBoolean ("RoboticArmFirstTime" , false );
545
+ editor .apply ();
546
+ } else {
547
+ bottomSheetBehavior .setState (BottomSheetBehavior .STATE_HIDDEN );
548
+ }
549
+
550
+ bottomSheetBehavior .setBottomSheetCallback (new BottomSheetBehavior .BottomSheetCallback () {
551
+ private Handler handler = new Handler ();
552
+ private Runnable runnable = new Runnable () {
553
+ @ Override
554
+ public void run () {
555
+ bottomSheetBehavior .setState (BottomSheetBehavior .STATE_HIDDEN );
556
+ }
557
+ };
558
+
559
+ @ Override
560
+ public void onStateChanged (@ NonNull final View bottomSheet , int newState ) {
561
+ switch (newState ) {
562
+ case BottomSheetBehavior .STATE_EXPANDED :
563
+ handler .removeCallbacks (runnable );
564
+ bottomSheetSlideText .setText (R .string .hide_guide_text );
565
+ break ;
566
+
567
+ case BottomSheetBehavior .STATE_COLLAPSED :
568
+ handler .postDelayed (runnable , 2000 );
569
+ break ;
570
+
571
+ default :
572
+ handler .removeCallbacks (runnable );
573
+ bottomSheetSlideText .setText (R .string .show_guide_text );
574
+ break ;
575
+ }
576
+ }
577
+
578
+ @ Override
579
+ public void onSlide (@ NonNull View bottomSheet , float slideOffset ) {
580
+ Float value = (float ) MathUtils .map ((double ) slideOffset , 0.0 , 1.0 , 0.0 , 0.8 );
581
+ parentLayout .setVisibility (View .VISIBLE );
582
+ parentLayout .setAlpha (value );
583
+ arrowUpDown .setRotation (slideOffset * 180 );
584
+ }
585
+ });
586
+ gestureDetector = new GestureDetector (this , new SwipeGestureDetector (bottomSheetBehavior ));
587
+ }
588
+
589
+ @ Override
590
+ public boolean onTouchEvent (MotionEvent event ) {
591
+ gestureDetector .onTouchEvent (event ); //Gesture detector need this to transfer touch event to the gesture detector.
592
+ return super .onTouchEvent (event );
487
593
}
488
594
489
595
private void toastInvalidValueMessage () {
@@ -545,7 +651,7 @@ private void saveTimeline() {
545
651
}
546
652
}
547
653
servoCSVLogger .writeCSVFile (data );
548
- CustomSnackBar .showSnackBar (findViewById (R .id .robotic_arm_relative_view ),
654
+ CustomSnackBar .showSnackBar (findViewById (R .id .robotic_arm_coordinator ),
549
655
getString (R .string .csv_store_text ) + " " + servoCSVLogger .getCurrentFilePath ()
550
656
, getString (R .string .open ), new View .OnClickListener () {
551
657
@ Override
0 commit comments