Skip to content

Commit 56a513c

Browse files
Kunal RaiCloudyPadmal
authored andcommitted
Play,Pause,Stop button working in Robotic arm (#1769)
1 parent d55e296 commit 56a513c

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.graphics.Point;
44
import android.os.Build;
5+
import android.os.CountDownTimer;
56
import android.support.v7.app.AppCompatActivity;
67
import android.os.Bundle;
78
import android.view.Display;
@@ -15,6 +16,7 @@
1516
import android.view.inputmethod.EditorInfo;
1617
import android.widget.Button;
1718
import android.widget.EditText;
19+
import android.widget.HorizontalScrollView;
1820
import android.widget.LinearLayout;
1921
import android.widget.RelativeLayout;
2022
import android.widget.TextView;
@@ -31,6 +33,8 @@ public class RoboticArmActivity extends AppCompatActivity {
3133
private int degree;
3234
private boolean editEnter = false;
3335
private Button playButton, pauseButton, stopButton;
36+
private HorizontalScrollView scrollView;
37+
private CountDownTimer timeLine;
3438

3539
@Override
3640
protected void onCreate(Bundle savedInstanceState) {
@@ -62,6 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {
6266
playButton = findViewById(R.id.timeline_play_button);
6367
pauseButton = findViewById(R.id.timeline_pause_button);
6468
stopButton = findViewById(R.id.timeline_stop_button);
69+
scrollView = findViewById(R.id.horizontal_scroll_view);
6570
LinearLayout timeLineControlsLayout = findViewById(R.id.servo_timeline_controls);
6671

6772
LinearLayout.LayoutParams servoControllerParams = new LinearLayout.LayoutParams(screen_width / 4 - 4, screen_height / 2 - 4);
@@ -317,8 +322,48 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
317322

318323
LinearLayout timeIndicatorLayout = findViewById(R.id.time_indicator);
319324
LinearLayout.LayoutParams timeIndicatorParams = new LinearLayout.LayoutParams(screen_width / 6 - 2, 12);
320-
timeIndicatorParams.setMargins(3, 0, 0, 0);
325+
timeIndicatorParams.setMarginStart(3);
321326
timeIndicatorLayout.setLayoutParams(timeIndicatorParams);
327+
328+
timeLine = new CountDownTimer(60000, 1000) {
329+
@Override
330+
public void onTick(long millisUntilFinished) {
331+
timeIndicatorParams.setMarginStart(timeIndicatorParams
332+
.getMarginStart()+screen_width/6);
333+
timeIndicatorLayout.setLayoutParams(timeIndicatorParams);
334+
scrollView.smoothScrollBy(screen_width/6,0);
335+
}
336+
337+
@Override
338+
public void onFinish() {
339+
timeIndicatorLayout.setLayoutParams(timeIndicatorParams);
340+
cancel();
341+
}
342+
};
343+
344+
playButton.setOnClickListener(new View.OnClickListener() {
345+
@Override
346+
public void onClick(View v) {
347+
timeLine.start();
348+
}
349+
});
350+
351+
pauseButton.setOnClickListener(new View.OnClickListener() {
352+
@Override
353+
public void onClick(View v) {
354+
timeLine.onFinish();
355+
}
356+
});
357+
358+
stopButton.setOnClickListener(new View.OnClickListener() {
359+
@Override
360+
public void onClick(View v) {
361+
timeLine.cancel();
362+
timeIndicatorParams.setMarginStart(3);
363+
timeIndicatorLayout.setLayoutParams(timeIndicatorParams);
364+
scrollView.fullScroll(HorizontalScrollView.FOCUS_LEFT);
365+
}
366+
});
322367
}
323368

324369
private View.OnDragListener servo1DragListener = new View.OnDragListener() {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
<HorizontalScrollView
4949
android:layout_width="wrap_content"
5050
android:layout_height="wrap_content"
51-
android:layout_weight="0.9">
51+
android:layout_weight="0.9"
52+
android:id="@+id/horizontal_scroll_view">
5253

5354
<LinearLayout
5455
android:layout_width="wrap_content"

0 commit comments

Comments
 (0)