|
1 | 1 | package com.o3dr.android.client;
|
2 | 2 |
|
| 3 | +import android.content.Context; |
3 | 4 | import android.os.Bundle;
|
4 | 5 | import android.os.Handler;
|
5 | 6 | import android.os.IBinder;
|
|
20 | 21 | import com.o3dr.services.android.lib.coordinate.LatLong;
|
21 | 22 | import com.o3dr.services.android.lib.drone.attribute.AttributeEvent;
|
22 | 23 | import com.o3dr.services.android.lib.drone.attribute.AttributeType;
|
| 24 | +import com.o3dr.services.android.lib.drone.calibration.magnetometer.MagnetometerCalibrationStatus; |
23 | 25 | import com.o3dr.services.android.lib.drone.camera.GoPro;
|
24 | 26 | import com.o3dr.services.android.lib.drone.connection.ConnectionParameter;
|
25 | 27 | import com.o3dr.services.android.lib.drone.connection.ConnectionResult;
|
@@ -109,7 +111,11 @@ public void binderDied() {
|
109 | 111 | private long startTime = 0;
|
110 | 112 | private long elapsedFlightTime = 0;
|
111 | 113 |
|
112 |
| - public Drone(){} |
| 114 | + private final Context context; |
| 115 | + |
| 116 | + public Drone(Context context){ |
| 117 | + this.context = context; |
| 118 | + } |
113 | 119 |
|
114 | 120 | void init(ControlTower controlTower, Handler handler){
|
115 | 121 | this.handler = handler;
|
@@ -232,7 +238,7 @@ public <T extends Parcelable> T getAttribute(String type) {
|
232 | 238 | }
|
233 | 239 |
|
234 | 240 | if (carrier != null) {
|
235 |
| - ClassLoader classLoader = getAttributeClassLoader(type); |
| 241 | + ClassLoader classLoader = this.context.getClassLoader(); |
236 | 242 | if (classLoader != null) {
|
237 | 243 | carrier.setClassLoader(classLoader);
|
238 | 244 | attribute = carrier.getParcelable(type);
|
@@ -317,59 +323,10 @@ private <T extends Parcelable> T getAttributeDefaultValue(String attributeType)
|
317 | 323 | case AttributeType.GOPRO:
|
318 | 324 | return (T) new GoPro();
|
319 | 325 |
|
320 |
| - case AttributeType.CAMERA: |
321 |
| - default: |
322 |
| - return null; |
323 |
| - } |
324 |
| - } |
325 |
| - |
326 |
| - private ClassLoader getAttributeClassLoader(String attributeType) { |
327 |
| - switch (attributeType) { |
328 |
| - case AttributeType.ALTITUDE: |
329 |
| - return Altitude.class.getClassLoader(); |
330 |
| - |
331 |
| - case AttributeType.GPS: |
332 |
| - return Gps.class.getClassLoader(); |
333 |
| - |
334 |
| - case AttributeType.STATE: |
335 |
| - return State.class.getClassLoader(); |
336 |
| - |
337 |
| - case AttributeType.PARAMETERS: |
338 |
| - return Parameters.class.getClassLoader(); |
339 |
| - |
340 |
| - case AttributeType.SPEED: |
341 |
| - return Speed.class.getClassLoader(); |
| 326 | + case AttributeType.MAGNETOMETER_CALIBRATION_STATUS: |
| 327 | + return (T) new MagnetometerCalibrationStatus(); |
342 | 328 |
|
343 | 329 | case AttributeType.CAMERA:
|
344 |
| - return CameraProxy.class.getClassLoader(); |
345 |
| - |
346 |
| - case AttributeType.ATTITUDE: |
347 |
| - return Attitude.class.getClassLoader(); |
348 |
| - |
349 |
| - case AttributeType.HOME: |
350 |
| - return Home.class.getClassLoader(); |
351 |
| - |
352 |
| - case AttributeType.BATTERY: |
353 |
| - return Battery.class.getClassLoader(); |
354 |
| - |
355 |
| - case AttributeType.MISSION: |
356 |
| - return Mission.class.getClassLoader(); |
357 |
| - |
358 |
| - case AttributeType.SIGNAL: |
359 |
| - return Signal.class.getClassLoader(); |
360 |
| - |
361 |
| - case AttributeType.GUIDED_STATE: |
362 |
| - return GuidedState.class.getClassLoader(); |
363 |
| - |
364 |
| - case AttributeType.TYPE: |
365 |
| - return Type.class.getClassLoader(); |
366 |
| - |
367 |
| - case AttributeType.FOLLOW_STATE: |
368 |
| - return FollowState.class.getClassLoader(); |
369 |
| - |
370 |
| - case AttributeType.GOPRO: |
371 |
| - return GoPro.class.getClassLoader(); |
372 |
| - |
373 | 330 | default:
|
374 | 331 | return null;
|
375 | 332 | }
|
@@ -527,18 +484,16 @@ public void arm(boolean arm) {
|
527 | 484 | DroneStateApi.arm(this, arm);
|
528 | 485 | }
|
529 | 486 |
|
530 |
| - public void startMagnetometerCalibration(double[] startPointsX, double[] startPointsY, double[] startPointsZ) { |
531 |
| - CalibrationApi.startMagnetometerCalibration(this, startPointsX, startPointsY, startPointsZ); |
532 |
| - } |
533 |
| - |
534 |
| - public void stopMagnetometerCalibration() { |
535 |
| - CalibrationApi.stopMagnetometerCalibration(this); |
536 |
| - } |
537 |
| - |
| 487 | + /** |
| 488 | + * @deprecated Use {@link CalibrationApi#startIMUCalibration(Drone)} instead. |
| 489 | + */ |
538 | 490 | public void startIMUCalibration() {
|
539 | 491 | CalibrationApi.startIMUCalibration(this);
|
540 | 492 | }
|
541 | 493 |
|
| 494 | + /** |
| 495 | + * @deprecated Use {@link CalibrationApi#sendIMUAck(Drone, int)} instead. |
| 496 | + */ |
542 | 497 | public void sendIMUCalibrationAck(int step) {
|
543 | 498 | CalibrationApi.sendIMUAck(this, step);
|
544 | 499 | }
|
@@ -597,6 +552,10 @@ public void run() {
|
597 | 552 | }
|
598 | 553 |
|
599 | 554 | void notifyAttributeUpdated(final String attributeEvent, final Bundle extras) {
|
| 555 | + //Update the bundle classloader |
| 556 | + if(extras != null) |
| 557 | + extras.setClassLoader(context.getClassLoader()); |
| 558 | + |
600 | 559 | if (AttributeEvent.STATE_UPDATED.equals(attributeEvent)) {
|
601 | 560 | getAttributeAsync(AttributeType.STATE, new OnAttributeRetrievedCallback<State>() {
|
602 | 561 | @Override
|
|
0 commit comments