22
33import android .graphics .Point ;
44import android .os .Build ;
5+ import android .os .CountDownTimer ;
56import android .support .v7 .app .AppCompatActivity ;
67import android .os .Bundle ;
78import android .view .Display ;
1516import android .view .inputmethod .EditorInfo ;
1617import android .widget .Button ;
1718import android .widget .EditText ;
19+ import android .widget .HorizontalScrollView ;
1820import android .widget .LinearLayout ;
1921import android .widget .RelativeLayout ;
2022import 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 () {
0 commit comments