|
| 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 | +} |
0 commit comments