Skip to content

Commit d487999

Browse files
committed
bug fixes, and code cleanup in preparation of release.
1 parent b3757e7 commit d487999

File tree

11 files changed

+240
-168
lines changed

11 files changed

+240
-168
lines changed

Android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies {
1111
compile 'com.android.support:cardview-v7:21.0.2'
1212
compile 'com.android.support:recyclerview-v7:21.0.2'
1313

14-
compile 'com.o3dr:3dr-services-lib:2.1.55'
14+
compile 'com.o3dr:3dr-services-lib:2.2.2'
1515

1616
compile files('libs/droneapi-java-0.3-SNAPSHOT.jar')
1717
compile files('libs/j2xx.jar')

Android/res/layout/fragment_telemetry.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@
7878
android:id="@+id/flight_time_layout"
7979
android:orientation="horizontal"
8080
android:layout_width="wrap_content"
81-
android:layout_height="wrap_content"
82-
android:minHeight="36dp"
81+
android:layout_height="48dp"
8382
android:layout_below="@+id/rollValueText"
8483
android:background="@drawable/round_rect_bg"
8584
android:layout_marginBottom="2dp"
@@ -94,15 +93,16 @@
9493
android:id="@+id/reset_flight_timer_button"
9594
android:src="@drawable/ic_restore_white_24dp"
9695
style="?android:attr/borderlessButtonStyle"
97-
android:layout_width="36dp"
98-
android:layout_height="wrap_content"/>
96+
android:layout_width="48dp"
97+
android:layout_height="48dp"/>
9998

10099
<TextView
101100
android:id="@+id/flight_timer"
102101
android:layout_width="match_parent"
103102
android:layout_height="wrap_content"
103+
android:paddingLeft="5dp"
104104
style="@style/largeTelemetryText"
105-
android:gravity="center"
105+
android:gravity="start|center_vertical"
106106
android:text="00:00"
107107
tools:text="99:99"/>
108108

Android/src/org/droidplanner/android/DroidPlannerApp.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import android.util.Log;
1313
import android.widget.Toast;
1414

15+
import com.o3dr.android.client.ControlTower;
1516
import com.o3dr.android.client.Drone;
16-
import com.o3dr.android.client.ServiceManager;
1717
import com.o3dr.android.client.interfaces.DroneListener;
18-
import com.o3dr.android.client.interfaces.ServiceListener;
18+
import com.o3dr.android.client.interfaces.TowerListener;
1919
import com.o3dr.services.android.lib.drone.attribute.AttributeEvent;
2020
import com.o3dr.services.android.lib.drone.connection.ConnectionParameter;
2121
import com.o3dr.services.android.lib.drone.connection.ConnectionResult;
@@ -33,7 +33,7 @@
3333
import java.util.ArrayList;
3434
import java.util.List;
3535

36-
public class DroidPlannerApp extends Application implements DroneListener, ServiceListener {
36+
public class DroidPlannerApp extends Application implements DroneListener, TowerListener {
3737

3838
private static final long DELAY_TO_DISCONNECTION = 30000l; // ms
3939

@@ -73,24 +73,27 @@ public void onReceive(Context context, Intent intent) {
7373
};
7474

7575
@Override
76-
public void onServiceConnected() {
76+
public void onTowerConnected() {
7777
if (notificationHandler == null) {
7878
notificationHandler = new NotificationHandler(getApplicationContext(), drone);
7979
}
8080

81-
if (!drone.isStarted()) {
82-
this.drone.start();
83-
this.drone.registerDroneListener(this);
84-
}
81+
drone.unregisterDroneListener(this);
82+
controlTower.registerDrone(drone, handler);
83+
drone.registerDroneListener(this);
8584

8685
notifyApiConnected();
8786
}
8887

8988
@Override
90-
public void onServiceInterrupted() {
89+
public void onTowerDisconnected() {
9190
notifyApiDisconnected();
9291
}
9392

93+
public DroidPlannerPrefs getAppPreferences() {
94+
return dpPrefs;
95+
}
96+
9497
public interface ApiListener {
9598
void onApiConnected();
9699

@@ -100,8 +103,8 @@ public interface ApiListener {
100103
private final Runnable disconnectionTask = new Runnable() {
101104
@Override
102105
public void run() {
103-
drone.destroy();
104-
serviceMgr.disconnect();
106+
controlTower.unregisterDrone(drone);
107+
controlTower.disconnect();
105108

106109
if (notificationHandler != null) {
107110
notificationHandler.terminate();
@@ -125,7 +128,7 @@ public void uncaughtException(Thread thread, Throwable ex) {
125128

126129
private Thread.UncaughtExceptionHandler exceptionHandler;
127130

128-
private ServiceManager serviceMgr;
131+
private ControlTower controlTower;
129132
private Drone drone;
130133

131134
private MissionProxy missionProxy;
@@ -141,8 +144,8 @@ public void onCreate() {
141144
dpPrefs = new DroidPlannerPrefs(context);
142145
lbm = LocalBroadcastManager.getInstance(context);
143146

144-
serviceMgr = new ServiceManager(context);
145-
drone = new Drone(serviceMgr, handler);
147+
controlTower = new ControlTower(context);
148+
drone = new Drone();
146149
missionProxy = new MissionProxy(context, this.drone);
147150

148151
exceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
@@ -162,13 +165,13 @@ public void addApiListener(ApiListener listener) {
162165
return;
163166

164167
handler.removeCallbacks(disconnectionTask);
165-
boolean isServiceConnected = serviceMgr.isServiceConnected();
166-
if (isServiceConnected)
168+
boolean isTowerConnected = controlTower.isTowerConnected();
169+
if (isTowerConnected)
167170
listener.onApiConnected();
168171

169-
if (!isServiceConnected) {
172+
if (!isTowerConnected) {
170173
try {
171-
serviceMgr.connect(this);
174+
controlTower.connect(this);
172175
} catch (IllegalStateException e) {
173176
//Ignore
174177
}
@@ -330,7 +333,7 @@ public void onDroneEvent(String event, Bundle extras) {
330333

331334
@Override
332335
public void onDroneServiceInterrupted(String errorMsg) {
333-
drone.destroy();
336+
controlTower.unregisterDrone(drone);
334337
if (notificationHandler != null) {
335338
notificationHandler.terminate();
336339
notificationHandler = null;

Android/src/org/droidplanner/android/activities/FlightActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.android.gms.common.ConnectionResult;
2222
import com.google.android.gms.common.GooglePlayServicesUtil;
2323
import com.o3dr.android.client.Drone;
24+
import com.o3dr.services.android.lib.coordinate.LatLong;
2425
import com.o3dr.services.android.lib.drone.attribute.AttributeEvent;
2526
import com.o3dr.services.android.lib.drone.attribute.AttributeEventExtra;
2627
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
@@ -410,6 +411,10 @@ private void setupMapFragment() {
410411
}
411412
}
412413

414+
public void setGuidedClickListener(FlightMapFragment.OnGuidedClickListener listener){
415+
mapFragment.setGuidedClickListener(listener);
416+
}
417+
413418
@Override
414419
public void onStart() {
415420
super.onStart();

Android/src/org/droidplanner/android/activities/helpers/SuperUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
167167
final MenuItem toggleConnectionItem = menu.findItem(R.id.menu_connect);
168168

169169
Drone dpApi = dpApp.getDrone();
170-
if (dpApi.isConnected()) {
170+
if (dpApi != null && dpApi.isConnected()) {
171171
menu.setGroupEnabled(R.id.menu_group_connected, true);
172172
menu.setGroupVisible(R.id.menu_group_connected, true);
173173

@@ -262,7 +262,7 @@ public void onNo() {
262262

263263
public void toggleDroneConnection() {
264264
final Drone drone = dpApp.getDrone();
265-
if (drone.isConnected())
265+
if (drone != null && drone.isConnected())
266266
dpApp.disconnectFromDrone();
267267
else
268268
dpApp.connectToDrone();

0 commit comments

Comments
 (0)