Skip to content

Commit 6df9ebb

Browse files
author
Kunal
committed
Guide for robotic arm
1 parent 9f15fe2 commit 6df9ebb

File tree

4 files changed

+208
-2
lines changed

4 files changed

+208
-2
lines changed

app/src/main/java/io/pslab/activity/RoboticArmActivity.java

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,31 @@
22

33
import android.content.Context;
44
import android.content.Intent;
5+
import android.content.SharedPreferences;
56
import android.graphics.Point;
67
import android.location.Location;
78
import android.location.LocationManager;
89
import android.os.Build;
910
import android.os.CountDownTimer;
11+
import android.os.Handler;
12+
import android.support.annotation.NonNull;
13+
import android.support.design.widget.BottomSheetBehavior;
1014
import android.support.design.widget.Snackbar;
1115
import android.support.v7.app.AppCompatActivity;
1216
import android.os.Bundle;
1317
import android.view.Display;
1418
import android.view.DragEvent;
19+
import android.view.GestureDetector;
1520
import android.view.KeyEvent;
1621
import android.view.LayoutInflater;
22+
import android.view.MotionEvent;
1723
import android.view.View;
1824
import android.view.WindowManager;
1925
import android.view.inputmethod.EditorInfo;
2026
import android.widget.Button;
2127
import android.widget.EditText;
2228
import android.widget.HorizontalScrollView;
29+
import android.widget.ImageView;
2330
import android.widget.LinearLayout;
2431
import android.widget.RelativeLayout;
2532
import android.widget.TextView;
@@ -30,6 +37,8 @@
3037
import java.util.ArrayList;
3138
import java.util.Date;
3239

40+
import butterknife.BindView;
41+
import butterknife.ButterKnife;
3342
import io.pslab.R;
3443
import io.pslab.communication.ScienceLab;
3544
import io.pslab.models.SensorDataBlock;
@@ -38,13 +47,16 @@
3847
import io.pslab.others.CustomSnackBar;
3948
import io.pslab.others.GPSLogger;
4049
import io.pslab.others.LocalDataLog;
50+
import io.pslab.others.MathUtils;
4151
import io.pslab.others.ScienceLabCommon;
52+
import io.pslab.others.SwipeGestureDetector;
4253
import io.realm.Realm;
4354
import io.realm.RealmObject;
4455
import io.realm.RealmResults;
4556

4657
public class RoboticArmActivity extends AppCompatActivity {
4758

59+
private static final String PREF_NAME = "RoboticArmActivity";
4860
private EditText degreeText1, degreeText2, degreeText3, degreeText4;
4961
private SeekArc seekArc1, seekArc2, seekArc3, seekArc4;
5062
private LinearLayout servo1TimeLine, servo2TimeLine, servo3TimeLine, servo4TimeLine;
@@ -62,12 +74,32 @@ public class RoboticArmActivity extends AppCompatActivity {
6274
private final String DATA_BLOCK = "data_block";
6375
private int timelinePosition = 0;
6476
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;
6587

6688
@Override
6789
protected void onCreate(Bundle savedInstanceState) {
6890
super.onCreate(savedInstanceState);
6991
setContentView(R.layout.activity_robotic_arm);
7092

93+
setUpBottomSheet();
94+
parentLayout.setOnClickListener(new View.OnClickListener() {
95+
@Override
96+
public void onClick(View v) {
97+
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
98+
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
99+
parentLayout.setVisibility(View.GONE);
100+
}
101+
});
102+
71103
scienceLab = ScienceLabCommon.scienceLab;
72104
if (!scienceLab.isConnected()) {
73105
Toast.makeText(this, getResources().getString(R.string.device_not_connected), Toast.LENGTH_SHORT).show();
@@ -484,6 +516,79 @@ public void onClick(View v) {
484516
.getBlockOfServoRecords(getIntent().getExtras().getLong(DATA_BLOCK));
485517
setReceivedData();
486518
}
519+
520+
Button guideButton = findViewById(R.id.timeline_guide_button);
521+
guideButton.setOnClickListener(new View.OnClickListener() {
522+
@Override
523+
public void onClick(View v) {
524+
bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ?
525+
BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN);
526+
}
527+
});
528+
}
529+
530+
private void setUpBottomSheet() {
531+
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
532+
533+
final SharedPreferences settings = this.getSharedPreferences(PREF_NAME, MODE_PRIVATE);
534+
Boolean isFirstTime = settings.getBoolean("RoboticArmFirstTime", true);
535+
536+
if (isFirstTime) {
537+
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
538+
parentLayout.setVisibility(View.VISIBLE);
539+
parentLayout.setAlpha(0.8f);
540+
arrowUpDown.setRotation(180);
541+
bottomSheetSlideText.setText(R.string.hide_guide_text);
542+
SharedPreferences.Editor editor = settings.edit();
543+
editor.putBoolean("RoboticArmFirstTime", false);
544+
editor.apply();
545+
} else {
546+
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
547+
}
548+
549+
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
550+
private Handler handler = new Handler();
551+
private Runnable runnable = new Runnable() {
552+
@Override
553+
public void run() {
554+
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
555+
}
556+
};
557+
558+
@Override
559+
public void onStateChanged(@NonNull final View bottomSheet, int newState) {
560+
switch (newState) {
561+
case BottomSheetBehavior.STATE_EXPANDED:
562+
handler.removeCallbacks(runnable);
563+
bottomSheetSlideText.setText(R.string.hide_guide_text);
564+
break;
565+
566+
case BottomSheetBehavior.STATE_COLLAPSED:
567+
handler.postDelayed(runnable, 2000);
568+
break;
569+
570+
default:
571+
handler.removeCallbacks(runnable);
572+
bottomSheetSlideText.setText(R.string.show_guide_text);
573+
break;
574+
}
575+
}
576+
577+
@Override
578+
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
579+
Float value = (float) MathUtils.map((double) slideOffset, 0.0, 1.0, 0.0, 0.8);
580+
parentLayout.setVisibility(View.VISIBLE);
581+
parentLayout.setAlpha(value);
582+
arrowUpDown.setRotation(slideOffset * 180);
583+
}
584+
});
585+
gestureDetector = new GestureDetector(this, new SwipeGestureDetector(bottomSheetBehavior));
586+
}
587+
588+
@Override
589+
public boolean onTouchEvent(MotionEvent event) {
590+
gestureDetector.onTouchEvent(event); //Gesture detector need this to transfer touch event to the gesture detector.
591+
return super.onTouchEvent(event);
487592
}
488593

489594
private void toastInvalidValueMessage() {

app/src/main/res/layout/activity_robotic_arm.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout
2+
<android.support.design.widget.CoordinatorLayout
33
android:id="@+id/robotic_arm_relative_view"
44
xmlns:android="http://schemas.android.com/apk/res/android"
55
xmlns:tools="http://schemas.android.com/tools"
@@ -131,5 +131,13 @@
131131
</HorizontalScrollView>
132132
</LinearLayout>
133133

134+
<View
135+
android:id="@+id/parent_layout_robotic"
136+
android:layout_width="match_parent"
137+
android:layout_height="match_parent"
138+
android:alpha="0"
139+
android:background="@color/black" />
140+
141+
<include layout="@layout/bottomsheet_robotic_arm"/>
134142

135-
</RelativeLayout>
143+
</android.support.design.widget.CoordinatorLayout>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/bottom_sheet_robotic_arm"
5+
android:layout_width="match_parent"
6+
android:layout_height="wrap_content"
7+
android:layout_marginLeft="@dimen/bottom_sheet_side_margin"
8+
android:layout_marginRight="@dimen/bottom_sheet_side_margin"
9+
android:orientation="vertical"
10+
app:behavior_hideable="true"
11+
app:behavior_peekHeight="@dimen/peek_height"
12+
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
13+
14+
<Space
15+
android:layout_width="match_parent"
16+
android:layout_height="@dimen/extra_space_top" />
17+
18+
<LinearLayout
19+
android:layout_width="match_parent"
20+
android:layout_height="@dimen/btnsheet_top_section_height"
21+
android:background="@drawable/btn_sheet_back"
22+
android:orientation="vertical">
23+
24+
<ImageView
25+
android:id="@+id/img_arrow_robotic_arm"
26+
android:layout_width="wrap_content"
27+
android:layout_height="wrap_content"
28+
android:layout_gravity="center_horizontal"
29+
android:background="@color/colorPrimary"
30+
android:src="@drawable/ic_arrow_drop_up_white_24dp" />
31+
32+
<TextView
33+
android:id="@+id/sheet_slide_text_robotic_arm"
34+
android:layout_width="match_parent"
35+
android:layout_height="wrap_content"
36+
android:gravity="center_horizontal"
37+
android:text="@string/show_guide_text"
38+
android:textColor="@color/white" />
39+
40+
</LinearLayout>
41+
42+
<android.support.v4.widget.NestedScrollView
43+
android:layout_width="match_parent"
44+
android:layout_height="wrap_content"
45+
android:background="@color/white"
46+
android:orientation="vertical">
47+
48+
<io.pslab.others.ZoomLayout
49+
android:layout_width="match_parent"
50+
android:layout_height="wrap_content">
51+
52+
<LinearLayout
53+
android:layout_width="match_parent"
54+
android:layout_height="wrap_content"
55+
android:orientation="vertical"
56+
android:padding="@dimen/bottom_sheet_padding">
57+
58+
<Space
59+
android:layout_width="match_parent"
60+
android:layout_height="@dimen/space_length_btm_sheet" />
61+
62+
<TextView
63+
android:id="@+id/guide_title_robotic_arm"
64+
android:layout_width="match_parent"
65+
android:layout_height="wrap_content"
66+
android:text="@string/robotic_arm"
67+
android:textSize="@dimen/bottom_sheet_title_text"
68+
android:textStyle="bold" />
69+
70+
<TextView
71+
android:id="@+id/guide_intro_robotic_arm"
72+
android:layout_width="match_parent"
73+
android:layout_height="wrap_content"
74+
android:layout_margin="@dimen/bottom_sheet_margin"
75+
android:text="@string/robotic_arm_intro" />
76+
77+
<TextView
78+
android:id="@+id/guide_desc_robotic_arm"
79+
android:layout_width="match_parent"
80+
android:layout_height="wrap_content"
81+
android:layout_margin="@dimen/bottom_sheet_margin"
82+
android:background="@color/white"
83+
android:text="@string/robotic_arm_desc" />
84+
85+
</LinearLayout>
86+
87+
</io.pslab.others.ZoomLayout>
88+
89+
</android.support.v4.widget.NestedScrollView>
90+
91+
</LinearLayout>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,8 @@
740740
<string name="no_baro_sensor">Device does not have a barometer</string>
741741

742742
<string name="robotic_arm">Robotic Arm</string>
743+
<string name="robotic_arm_intro">A robotic arm is a type of mechanical arm, usually programmable, with similar functions to a human arm.</string>
744+
<string name="robotic_arm_desc">Your arm\'s job is to move your hand from place to place. Similarly, the robotic arm's job is to move an end effector from place to place. You can outfit robotic arms with all sorts of end effectors, which are suited to a particular application. One common end effector is a simplified version of the hand, which can grasp and carry different objects.</string>
743745
<string name="robotic_arm_descriptoin">Controls servos of a robotic arm</string>
744746
<string name="servo1_title">Servo 1</string>
745747
<string name="servo2_title">Servo 2</string>

0 commit comments

Comments
 (0)