Skip to content

Commit 80b5536

Browse files
neel1998CloudyPadmal
authored andcommitted
save timeline added to robotic arm controller (fossasia#1771)
1 parent 335e979 commit 80b5536

File tree

3 files changed

+74
-14
lines changed

3 files changed

+74
-14
lines changed

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

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package io.pslab.activity;
22

3+
import android.app.AlertDialog;
4+
import android.content.DialogInterface;
35
import android.graphics.Point;
46
import android.os.Build;
57
import android.os.CountDownTimer;
8+
import android.support.design.widget.Snackbar;
69
import android.support.v7.app.AppCompatActivity;
710
import android.os.Bundle;
811
import android.view.Display;
@@ -24,6 +27,8 @@
2427
import com.triggertrap.seekarc.SeekArc;
2528

2629
import io.pslab.R;
30+
import io.pslab.others.CSVLogger;
31+
import io.pslab.others.CustomSnackBar;
2732

2833
public class RoboticArmActivity extends AppCompatActivity {
2934

@@ -32,9 +37,11 @@ public class RoboticArmActivity extends AppCompatActivity {
3237
private LinearLayout servo1TimeLine, servo2TimeLine, servo3TimeLine, servo4TimeLine;
3338
private int degree;
3439
private boolean editEnter = false;
35-
private Button playButton, pauseButton, stopButton;
40+
private Button playPauseButton, stopButton, saveButton;
3641
private HorizontalScrollView scrollView;
3742
private CountDownTimer timeLine;
43+
private boolean isPlaying = false;
44+
private CSVLogger servoCSVLogger;
3845

3946
@Override
4047
protected void onCreate(Bundle savedInstanceState) {
@@ -63,11 +70,12 @@ protected void onCreate(Bundle savedInstanceState) {
6370
servo2TimeLine = findViewById(R.id.servo2_timeline);
6471
servo3TimeLine = findViewById(R.id.servo3_timeline);
6572
servo4TimeLine = findViewById(R.id.servo4_timeline);
66-
playButton = findViewById(R.id.timeline_play_button);
67-
pauseButton = findViewById(R.id.timeline_pause_button);
73+
playPauseButton = findViewById(R.id.timeline_play_pause_button);
6874
stopButton = findViewById(R.id.timeline_stop_button);
75+
saveButton = findViewById(R.id.timeline_save_button);
6976
scrollView = findViewById(R.id.horizontal_scroll_view);
7077
LinearLayout timeLineControlsLayout = findViewById(R.id.servo_timeline_controls);
78+
servoCSVLogger = new CSVLogger(getResources().getString(R.string.robotic_arm));
7179

7280
LinearLayout.LayoutParams servoControllerParams = new LinearLayout.LayoutParams(screen_width / 4 - 4, screen_height / 2 - 4);
7381
servoControllerParams.setMargins(2, 5, 2, 0);
@@ -341,17 +349,25 @@ public void onFinish() {
341349
}
342350
};
343351

344-
playButton.setOnClickListener(new View.OnClickListener() {
352+
playPauseButton.setOnClickListener(new View.OnClickListener() {
345353
@Override
346354
public void onClick(View v) {
347-
timeLine.start();
355+
if (isPlaying) {
356+
isPlaying = false;
357+
playPauseButton.setBackground(getResources().getDrawable(R.drawable.ic_play_arrow_white_24dp));
358+
timeLine.onFinish();
359+
}else {
360+
isPlaying = true;
361+
playPauseButton.setBackground(getResources().getDrawable(R.drawable.ic_pause_white_24dp));
362+
timeLine.start();
363+
}
348364
}
349365
});
350366

351-
pauseButton.setOnClickListener(new View.OnClickListener() {
367+
saveButton.setOnClickListener(new View.OnClickListener() {
352368
@Override
353369
public void onClick(View v) {
354-
timeLine.onFinish();
370+
saveTimeline();
355371
}
356372
});
357373

@@ -366,6 +382,48 @@ public void onClick(View v) {
366382
});
367383
}
368384

385+
private void saveTimeline() {
386+
servoCSVLogger.prepareLogFile();
387+
String data = "Servo1,Servo2,Servo3,Servo4\n";
388+
String degree1, degree2, degree3, degree4;
389+
for (int i = 0; i < 60; i ++) {
390+
degree1 = degree2 = degree3 = degree4 = "0";
391+
if (((TextView)servo1TimeLine.getChildAt(i).findViewById(R.id.timeline_box_degree_text)).getText().length() > 0) {
392+
degree1 = ((TextView) servo1TimeLine.getChildAt(i).findViewById(R.id.timeline_box_degree_text)).getText().toString();
393+
}
394+
if (((TextView)servo2TimeLine.getChildAt(i).findViewById(R.id.timeline_box_degree_text)).getText().length() > 0) {
395+
degree2 = ((TextView) servo2TimeLine.getChildAt(i).findViewById(R.id.timeline_box_degree_text)).getText().toString();
396+
}
397+
if (((TextView)servo3TimeLine.getChildAt(i).findViewById(R.id.timeline_box_degree_text)).getText().length() > 0) {
398+
degree3 = ((TextView) servo3TimeLine.getChildAt(i).findViewById(R.id.timeline_box_degree_text)).getText().toString();
399+
}
400+
if (((TextView)servo4TimeLine.getChildAt(i).findViewById(R.id.timeline_box_degree_text)).getText().length() > 0) {
401+
degree4 = ((TextView) servo4TimeLine.getChildAt(i).findViewById(R.id.timeline_box_degree_text)).getText().toString();
402+
}
403+
data += degree1 + "," + degree2 + "," + degree3 + "," + degree4 + "\n";
404+
}
405+
servoCSVLogger.writeCSVFile(data);
406+
CustomSnackBar.showSnackBar(findViewById(R.id.robotic_arm_relative_view),
407+
getString(R.string.csv_store_text) + " " + servoCSVLogger.getCurrentFilePath()
408+
, getString(R.string.delete_capital), new View.OnClickListener() {
409+
@Override
410+
public void onClick(View view) {
411+
new AlertDialog.Builder(RoboticArmActivity.this, R.style.AlertDialogStyle)
412+
.setTitle(R.string.delete_file)
413+
.setMessage(R.string.delete_warning)
414+
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
415+
@Override
416+
public void onClick(DialogInterface dialogInterface, int i) {
417+
servoCSVLogger.deleteFile();
418+
}
419+
})
420+
.setNegativeButton(R.string.cancel, null)
421+
.create()
422+
.show();
423+
}
424+
}, Snackbar.LENGTH_SHORT);
425+
}
426+
369427
private View.OnDragListener servo1DragListener = new View.OnDragListener() {
370428
@Override
371429
public boolean onDrag(View v, DragEvent event) {

app/src/main/java/io/pslab/others/CustomSnackBar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class CustomSnackBar {
1717

1818
public static Snackbar snackbar;
1919

20-
public static void showSnackBar(@NonNull CoordinatorLayout holderLayout, @NonNull String displayText,
20+
public static void showSnackBar(@NonNull View holderLayout, @NonNull String displayText,
2121
String actionText, View.OnClickListener clickListener, int duration) {
2222
snackbar = Snackbar.make(holderLayout, displayText, duration)
2323
.setAction(actionText, clickListener);

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<RelativeLayout
3+
android:id="@+id/robotic_arm_relative_view"
4+
xmlns:android="http://schemas.android.com/apk/res/android"
35
xmlns:tools="http://schemas.android.com/tools"
46
android:layout_width="match_parent"
57
android:layout_height="wrap_content"
@@ -99,25 +101,25 @@
99101
android:orientation="vertical">
100102

101103
<Button
102-
android:id="@+id/timeline_play_button"
104+
android:id="@+id/timeline_play_pause_button"
103105
android:layout_width="25dp"
104106
android:layout_height="25dp"
105107
android:layout_margin="5dp"
106108
android:background="@drawable/ic_play_arrow_white_24dp" />
107109

108110
<Button
109-
android:id="@+id/timeline_pause_button"
111+
android:id="@+id/timeline_stop_button"
110112
android:layout_width="25dp"
111113
android:layout_height="25dp"
112114
android:layout_margin="5dp"
113-
android:background="@drawable/ic_pause_white_24dp" />
115+
android:background="@drawable/ic_stop_white_24dp" />
114116

115117
<Button
116-
android:id="@+id/timeline_stop_button"
118+
android:id="@+id/timeline_save_button"
117119
android:layout_width="25dp"
118120
android:layout_height="25dp"
119121
android:layout_margin="5dp"
120-
android:background="@drawable/ic_stop_white_24dp" />
122+
android:background="@drawable/menu_icon_save" />
121123
</LinearLayout>
122124
</LinearLayout>
123125

0 commit comments

Comments
 (0)