Skip to content

Commit 31154d9

Browse files
neel1998mariobehling
authored andcommitted
WIP fossasia#1719 layout to control servo of robotic arm created (fossasia#1732)
* layout to control servo of robotic arm ceated * new layout created with circular seekbars * started working on drag and drop feature for robotic arm * drag and drop of servo controllers working, timeline and UI needs to be changed * timeline layout created, timeline controlls panel added
1 parent 30f6102 commit 31154d9

File tree

8 files changed

+483
-4
lines changed

8 files changed

+483
-4
lines changed

app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ dependencies {
6666
implementation "org.apache.commons:commons-lang3:$rootProject.commonLangVersion"
6767
implementation "com.squareup.picasso:picasso:$rootProject.picassoVersion"
6868

69+
implementation 'com.github.GoodieBag:ProtractorView:v1.2'
70+
implementation 'com.github.Triggertrap:SeekArc:v1.1'
71+
6972
implementation "com.jakewharton:butterknife:$rootProject.butterKnifeVersion"
7073
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
7174
annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.butterKnifeVersion"

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
package="io.pslab">
45

56
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@@ -14,13 +15,16 @@
1415
<uses-feature android:name="android.hardware.usb.host" />
1516

1617
<application
18+
tools:replace="android:icon"
1719
android:name=".PSLabApplication"
1820
android:allowBackup="true"
1921
android:icon="@drawable/app_icon"
2022
android:label="@string/app_name"
2123
android:roundIcon="@drawable/app_icon_round"
2224
android:supportsRtl="true"
2325
android:theme="@style/AppTheme">
26+
<activity android:name=".activity.RoboticArmActivity"
27+
android:screenOrientation="landscape"/>
2428
<activity
2529
android:name=".activity.SplashActivity"
2630
android:screenOrientation="portrait"
@@ -71,8 +75,9 @@
7175
<activity
7276
android:name=".activity.WaveGeneratorActivity"
7377
android:screenOrientation="userLandscape" />
74-
<activity android:name=".activity.AccelerometerActivity"
75-
android:screenOrientation="portrait"/>
78+
<activity
79+
android:name=".activity.AccelerometerActivity"
80+
android:screenOrientation="portrait" />
7681
<activity android:name=".activity.DataLoggerActivity" />
7782
<activity
7883
android:name=".activity.BarometerActivity"
@@ -84,7 +89,6 @@
8489
<activity
8590
android:name=".activity.GyroscopeActivity"
8691
android:screenOrientation="portrait" />
87-
8892
<activity android:name=".activity.MapsActivity" />
8993

9094
<receiver android:name=".receivers.USBDetachReceiver" />
Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
package io.pslab.activity;
2+
3+
import android.graphics.Point;
4+
import android.os.Build;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.os.Bundle;
7+
import android.view.Display;
8+
import android.view.DragEvent;
9+
import android.view.LayoutInflater;
10+
import android.view.View;
11+
import android.view.WindowManager;
12+
import android.widget.LinearLayout;
13+
import android.widget.TextView;
14+
15+
import com.triggertrap.seekarc.SeekArc;
16+
17+
import io.pslab.R;
18+
19+
public class RoboticArmActivity extends AppCompatActivity {
20+
21+
private TextView degreeText1, degreeText2, degreeText3, degreeText4;
22+
private SeekArc seekArc1, seekArc2, seekArc3, seekArc4;
23+
private LinearLayout servo1TimeLine, servo2TimeLine, servo3TimeLine, servo4TimeLine;
24+
25+
@Override
26+
protected void onCreate(Bundle savedInstanceState) {
27+
super.onCreate(savedInstanceState);
28+
setContentView(R.layout.activity_robotic_arm);
29+
30+
Display display = getWindowManager().getDefaultDisplay();
31+
Point size = new Point();
32+
display.getSize(size);
33+
int screen_width = size.x;
34+
int screen_height = size.y;
35+
36+
View servo1Layout = findViewById(R.id.servo_1);
37+
View servo2Layout = findViewById(R.id.servo_2);
38+
View servo3Layout = findViewById(R.id.servo_3);
39+
View servo4Layout = findViewById(R.id.servo_4);
40+
degreeText1 = servo1Layout.findViewById(R.id.degreeText);
41+
degreeText2 = servo2Layout.findViewById(R.id.degreeText);
42+
degreeText3 = servo3Layout.findViewById(R.id.degreeText);
43+
degreeText4 = servo4Layout.findViewById(R.id.degreeText);
44+
seekArc1 = servo1Layout.findViewById(R.id.seek_arc);
45+
seekArc2 = servo2Layout.findViewById(R.id.seek_arc);
46+
seekArc3 = servo3Layout.findViewById(R.id.seek_arc);
47+
seekArc4 = servo4Layout.findViewById(R.id.seek_arc);
48+
servo1TimeLine = findViewById(R.id.servo1_timeline);
49+
servo2TimeLine = findViewById(R.id.servo2_timeline);
50+
servo3TimeLine = findViewById(R.id.servo3_timeline);
51+
servo4TimeLine = findViewById(R.id.servo4_timeline);
52+
LinearLayout timeLineControlsLayout = findViewById(R.id.servo_timeline_controls);
53+
54+
LinearLayout.LayoutParams servoControllerParams = new LinearLayout.LayoutParams(screen_width / 4 - 4, screen_height / 2 - 4);
55+
servoControllerParams.setMargins(2, 5, 2, 0);
56+
servo1Layout.setLayoutParams(servoControllerParams);
57+
servo2Layout.setLayoutParams(servoControllerParams);
58+
servo3Layout.setLayoutParams(servoControllerParams);
59+
servo4Layout.setLayoutParams(servoControllerParams);
60+
61+
LinearLayout.LayoutParams servoTimeLineParams = new LinearLayout.LayoutParams(screen_width - 4 - screen_width / 15, screen_height / 8 - 2);
62+
servoTimeLineParams.setMargins(2, 2, 2, 0);
63+
64+
servo1TimeLine.setLayoutParams(servoTimeLineParams);
65+
servo2TimeLine.setLayoutParams(servoTimeLineParams);
66+
servo3TimeLine.setLayoutParams(servoTimeLineParams);
67+
servo4TimeLine.setLayoutParams(servoTimeLineParams);
68+
69+
LinearLayout.LayoutParams timeLineControlsParams = new LinearLayout.LayoutParams(screen_width / 15, screen_height / 2);
70+
timeLineControlsLayout.setLayoutParams(timeLineControlsParams);
71+
72+
TextView servo1Title = servo1Layout.findViewById(R.id.servo_title);
73+
servo1Title.setText(getResources().getString(R.string.servo1_title));
74+
75+
TextView servo2Title = servo2Layout.findViewById(R.id.servo_title);
76+
servo2Title.setText(getResources().getString(R.string.servo2_title));
77+
78+
TextView servo3Title = servo3Layout.findViewById(R.id.servo_title);
79+
servo3Title.setText(getResources().getString(R.string.servo3_title));
80+
81+
TextView servo4Title = servo4Layout.findViewById(R.id.servo_title);
82+
servo4Title.setText(getResources().getString(R.string.servo4_title));
83+
84+
85+
seekArc1.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
86+
@Override
87+
public void onProgressChanged(SeekArc seekArc, int i, boolean b) {
88+
degreeText1.setText(String.valueOf(Math.round(i * 3.6)));
89+
}
90+
91+
@Override
92+
public void onStartTrackingTouch(SeekArc seekArc) {
93+
94+
}
95+
96+
@Override
97+
public void onStopTrackingTouch(SeekArc seekArc) {
98+
99+
}
100+
});
101+
102+
seekArc2.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
103+
@Override
104+
public void onProgressChanged(SeekArc seekArc, int i, boolean b) {
105+
degreeText2.setText(String.valueOf(Math.round(i * 3.6)));
106+
}
107+
108+
@Override
109+
public void onStartTrackingTouch(SeekArc seekArc) {
110+
111+
}
112+
113+
@Override
114+
public void onStopTrackingTouch(SeekArc seekArc) {
115+
116+
}
117+
});
118+
119+
seekArc3.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
120+
@Override
121+
public void onProgressChanged(SeekArc seekArc, int i, boolean b) {
122+
degreeText3.setText(String.valueOf(Math.round(i * 3.6)));
123+
}
124+
125+
@Override
126+
public void onStartTrackingTouch(SeekArc seekArc) {
127+
128+
}
129+
130+
@Override
131+
public void onStopTrackingTouch(SeekArc seekArc) {
132+
133+
}
134+
});
135+
136+
seekArc4.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
137+
@Override
138+
public void onProgressChanged(SeekArc seekArc, int i, boolean b) {
139+
degreeText4.setText(String.valueOf(Math.round(i * 3.6)));
140+
}
141+
142+
@Override
143+
public void onStartTrackingTouch(SeekArc seekArc) {
144+
145+
}
146+
147+
@Override
148+
public void onStopTrackingTouch(SeekArc seekArc) {
149+
150+
}
151+
});
152+
153+
servo1Layout.findViewById(R.id.drag_handle).setOnLongClickListener(new View.OnLongClickListener() {
154+
@Override
155+
public boolean onLongClick(View v) {
156+
View.DragShadowBuilder myShadow = new View.DragShadowBuilder(servo1Layout);
157+
v.startDrag(null, myShadow, servo1Layout, 0);
158+
return true;
159+
}
160+
});
161+
162+
servo1TimeLine.setOnDragListener(new View.OnDragListener() {
163+
@Override
164+
public boolean onDrag(View v, DragEvent event) {
165+
if (event.getAction() == DragEvent.ACTION_DRAG_ENTERED) {
166+
View view = (View) event.getLocalState();
167+
TextView text = view.findViewById(R.id.degreeText);
168+
TextView new_text = (TextView) LayoutInflater.from(RoboticArmActivity.this).inflate(R.layout.robotic_arm_timeline_textview, null);
169+
LinearLayout.LayoutParams timeLineTextParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
170+
timeLineTextParams.setMargins(5, 1, 1, 1);
171+
new_text.setLayoutParams(timeLineTextParams);
172+
new_text.setText(text.getText());
173+
if (view.getId() == R.id.servo_1) {
174+
servo1TimeLine.addView(new_text, servo1TimeLine.getChildCount());
175+
}
176+
}
177+
return true;
178+
}
179+
});
180+
181+
servo2Layout.findViewById(R.id.drag_handle).setOnLongClickListener(new View.OnLongClickListener() {
182+
@Override
183+
public boolean onLongClick(View v) {
184+
View.DragShadowBuilder myShadow = new View.DragShadowBuilder(servo2Layout);
185+
v.startDrag(null, myShadow, servo2Layout, 0);
186+
return true;
187+
}
188+
});
189+
190+
servo2TimeLine.setOnDragListener(new View.OnDragListener() {
191+
@Override
192+
public boolean onDrag(View v, DragEvent event) {
193+
if (event.getAction() == DragEvent.ACTION_DRAG_ENTERED) {
194+
View view = (View) event.getLocalState();
195+
TextView text = view.findViewById(R.id.degreeText);
196+
TextView new_text = (TextView) LayoutInflater.from(RoboticArmActivity.this).inflate(R.layout.robotic_arm_timeline_textview, null);
197+
LinearLayout.LayoutParams timeLineTextParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
198+
timeLineTextParams.setMargins(5, 1, 1, 1);
199+
new_text.setLayoutParams(timeLineTextParams);
200+
new_text.setText(text.getText());
201+
if (view.getId() == R.id.servo_2) {
202+
servo2TimeLine.addView(new_text, servo2TimeLine.getChildCount());
203+
}
204+
}
205+
return true;
206+
}
207+
});
208+
209+
servo3Layout.findViewById(R.id.drag_handle).setOnLongClickListener(new View.OnLongClickListener() {
210+
@Override
211+
public boolean onLongClick(View v) {
212+
View.DragShadowBuilder myShadow = new View.DragShadowBuilder(servo3Layout);
213+
v.startDrag(null, myShadow, servo3Layout, 0);
214+
return true;
215+
}
216+
});
217+
218+
servo3TimeLine.setOnDragListener(new View.OnDragListener() {
219+
@Override
220+
public boolean onDrag(View v, DragEvent event) {
221+
if (event.getAction() == DragEvent.ACTION_DRAG_ENTERED) {
222+
View view = (View) event.getLocalState();
223+
TextView text = view.findViewById(R.id.degreeText);
224+
TextView new_text = (TextView) LayoutInflater.from(RoboticArmActivity.this).inflate(R.layout.robotic_arm_timeline_textview, null);
225+
LinearLayout.LayoutParams timeLineTextParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
226+
timeLineTextParams.setMargins(5, 1, 1, 1);
227+
new_text.setLayoutParams(timeLineTextParams);
228+
new_text.setText(text.getText());
229+
if (view.getId() == R.id.servo_3) {
230+
servo3TimeLine.addView(new_text, servo3TimeLine.getChildCount());
231+
}
232+
}
233+
return true;
234+
}
235+
});
236+
237+
servo4Layout.findViewById(R.id.drag_handle).setOnLongClickListener(new View.OnLongClickListener() {
238+
@Override
239+
public boolean onLongClick(View v) {
240+
View.DragShadowBuilder myShadow = new View.DragShadowBuilder(servo4Layout);
241+
v.startDrag(null, myShadow, servo4Layout, 0);
242+
return true;
243+
}
244+
});
245+
246+
servo4TimeLine.setOnDragListener(new View.OnDragListener() {
247+
@Override
248+
public boolean onDrag(View v, DragEvent event) {
249+
if (event.getAction() == DragEvent.ACTION_DRAG_ENTERED) {
250+
View view = (View) event.getLocalState();
251+
TextView text = view.findViewById(R.id.degreeText);
252+
TextView new_text = (TextView) LayoutInflater.from(RoboticArmActivity.this).inflate(R.layout.robotic_arm_timeline_textview, null);
253+
LinearLayout.LayoutParams timeLineTextParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
254+
timeLineTextParams.setMargins(5, 1, 1, 1);
255+
new_text.setLayoutParams(timeLineTextParams);
256+
new_text.setText(text.getText());
257+
if (view.getId() == R.id.servo_4) {
258+
servo4TimeLine.addView(new_text, servo4TimeLine.getChildCount());
259+
}
260+
}
261+
return true;
262+
}
263+
});
264+
}
265+
266+
@Override
267+
protected void onResume() {
268+
super.onResume();
269+
removeStatusBar();
270+
}
271+
272+
private void removeStatusBar() {
273+
if (Build.VERSION.SDK_INT < 16) {
274+
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
275+
WindowManager.LayoutParams.FLAG_FULLSCREEN);
276+
} else {
277+
View decorView = getWindow().getDecorView();
278+
279+
decorView.setSystemUiVisibility((View.SYSTEM_UI_FLAG_LAYOUT_STABLE
280+
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
281+
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
282+
| View.SYSTEM_UI_FLAG_FULLSCREEN
283+
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
284+
| View.SYSTEM_UI_FLAG_FULLSCREEN
285+
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY));
286+
}
287+
}
288+
}

app/src/main/java/io/pslab/fragment/InstrumentsFragment.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.pslab.activity.MultimeterActivity;
2525
import io.pslab.activity.OscilloscopeActivity;
2626
import io.pslab.activity.PowerSourceActivity;
27+
import io.pslab.activity.RoboticArmActivity;
2728
import io.pslab.activity.SensorActivity;
2829
import io.pslab.activity.WaveGeneratorActivity;
2930
import io.pslab.adapters.ApplicationAdapter;
@@ -106,6 +107,10 @@ public void onItemClick(ApplicationItem item) {
106107
intent = new Intent(context, GyroscopeActivity.class);
107108
startActivity(intent);
108109
break;
110+
case "Robotic Arm":
111+
intent = new Intent(context, RoboticArmActivity.class);
112+
startActivity(intent);
113+
break;
109114
default:
110115
break;
111116
}
@@ -149,7 +154,8 @@ protected Void doInBackground(Void... params) {
149154
R.string.accelerometer_description,
150155
R.string.baro_meter_description,
151156
R.string.compass_description,
152-
R.string.gyroscope_description
157+
R.string.gyroscope_description,
158+
R.string.robotic_arm_descriptoin
153159
};
154160

155161
applicationItemList.add(new ApplicationItem(
@@ -185,6 +191,9 @@ protected Void doInBackground(Void... params) {
185191
applicationItemList.add(new ApplicationItem(
186192
getResources().getString(R.string.gyroscope), R.drawable.gyroscope_logo, getResources().getString(descriptions[10])
187193
));
194+
applicationItemList.add(new ApplicationItem(
195+
getResources().getString(R.string.robotic_arm), R.drawable.gyroscope_logo, getResources().getString(descriptions[11])
196+
));
188197
return null;
189198
}
190199

0 commit comments

Comments
 (0)