Skip to content

Commit

Permalink
Merge pull request #232 from dronekit/feature_solo_shots_api
Browse files Browse the repository at this point in the history
Feature solo api
  • Loading branch information
m4gr3d committed Aug 8, 2015
2 parents 71fad97 + 00ef6e3 commit 7c55213
Show file tree
Hide file tree
Showing 90 changed files with 1,193 additions and 729 deletions.
14 changes: 9 additions & 5 deletions ClientLib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
apply plugin: 'com.android.library'

ext {
VERSION_MAJOR = 2
VERSION_MINOR = 5
VERSION_PATCH = 21
VERSION_BUILD = 0

PUBLISH_ARTIFACT_ID = 'dronekit-android'
PUBLISH_VERSION = '2.5.15'
PUBLISH_VERSION = generateVersionName("", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)
PUBLISH_VERSION_CODE = computeVersionCode(VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_BUILD)
PROJECT_DESCRIPTION = "Android DroneKit client library."
PROJECT_LABELS = ['3DR', '3DR Services', 'DroneAPI', 'Android', 'DroneKit']
PROJECT_LICENSES = ['Apache-2.0']
}
/* Every time something is changed in the client library the versionCode and
PUBLISH_VERSION must be incremented.
*/

android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
versionCode 20515
versionCode PUBLISH_VERSION_CODE
versionName PUBLISH_VERSION
}

Expand Down
5 changes: 3 additions & 2 deletions ClientLib/src/main/java/com/o3dr/android/client/Drone.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.o3dr.services.android.lib.drone.attribute.AttributeEvent;
import com.o3dr.services.android.lib.drone.attribute.AttributeType;
import com.o3dr.services.android.lib.drone.calibration.magnetometer.MagnetometerCalibrationStatus;
import com.o3dr.services.android.lib.drone.companion.solo.SoloAttributes;
import com.o3dr.services.android.lib.drone.connection.ConnectionParameter;
import com.o3dr.services.android.lib.drone.connection.ConnectionResult;
import com.o3dr.services.android.lib.drone.mission.Mission;
Expand Down Expand Up @@ -358,8 +359,8 @@ private <T extends Parcelable> T getAttributeDefaultValue(String attributeType)
return (T) new MagnetometerCalibrationStatus();

case AttributeType.CAMERA:
case AttributeType.SOLOLINK_STATE:
case AttributeType.SOLOLINK_GOPRO_STATE:
case SoloAttributes.SOLO_STATE:
case SoloAttributes.SOLO_GOPRO_STATE:
default:
return null;
}
Expand Down
33 changes: 30 additions & 3 deletions ClientLib/src/main/java/com/o3dr/android/client/apis/Api.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
package com.o3dr.android.client.apis;

import com.o3dr.android.client.Drone;

import java.util.concurrent.ConcurrentHashMap;

/**
* Common interface for the drone set of api classes.
* Created by Fredia Huya-Kouadio on 7/5/15.
*/
interface Api {
public abstract class Api {

protected interface Builder<T extends Api> {
T build(Drone drone);
}

/**
* Retrieves the api instance bound to the given Drone object.
* @param drone Drone object
* @param apiCache Used to retrieve the api instance if it exists, or store it if it doesn't exist.
* @param apiBuilder Api instance generator.
* @param <T> Specific api instance type.
* @return The matching Api instance.
*/
protected static <T extends Api> T getApi(Drone drone, ConcurrentHashMap<Drone, T> apiCache, Api.Builder<T> apiBuilder){
if(drone == null || apiCache == null)
return null;

T apiInstance = apiCache.get(drone);
if(apiInstance == null && apiBuilder != null){
apiInstance = apiBuilder.build(drone);
final T previousInstance = apiCache.putIfAbsent(drone, apiInstance);
if(previousInstance != null)
apiInstance = previousInstance;
}

interface Builder<T extends Api> {
T build();
return apiInstance;
}
}
36 changes: 0 additions & 36 deletions ClientLib/src/main/java/com/o3dr/android/client/apis/ApiUtils.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
* Provides access to the calibration specific functionality.
* Created by Fredia Huya-Kouadio on 1/19/15.
*/
public class CalibrationApi implements Api {
public class CalibrationApi extends Api {

private static final ConcurrentHashMap<Drone, CalibrationApi> calibrationApiCache = new ConcurrentHashMap<>();
private static final Builder<CalibrationApi> apiBuilder = new Builder<CalibrationApi>() {
@Override
public CalibrationApi build(Drone drone) {
return new CalibrationApi(drone);
}
};

/**
* Retrieves a CalibrationApi instance.
Expand All @@ -33,12 +39,7 @@ public class CalibrationApi implements Api {
* @return a CalibrationApi instance.
*/
public static CalibrationApi getApi(final Drone drone) {
return ApiUtils.getApi(drone, calibrationApiCache, new Api.Builder<CalibrationApi>() {
@Override
public CalibrationApi build() {
return new CalibrationApi(drone);
}
});
return getApi(drone, calibrationApiCache, apiBuilder);
}

private final Drone drone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Allows to query the capabilities offered by the vehicle.
* Created by Fredia Huya-Kouadio on 7/5/15.
*/
public class CapabilityApi implements Api {
public class CapabilityApi extends Api {

/**
* Feature support check error. The drone is disconnected.
Expand All @@ -34,19 +34,20 @@ public class CapabilityApi implements Api {
public static final int FEATURE_UNSUPPORTED = 1;

private static final ConcurrentHashMap<Drone, CapabilityApi> capabilityApiCache = new ConcurrentHashMap<>();
private static final Builder<CapabilityApi> apiBuilder = new Builder<CapabilityApi>() {
@Override
public CapabilityApi build(Drone drone) {
return new CapabilityApi(drone);
}
};

/**
* Retrieves a capability api instance.
* @param drone target vehicle.
* @return a CapabilityApi instance.
*/
public static CapabilityApi getApi(final Drone drone){
return ApiUtils.getApi(drone, capabilityApiCache, new Builder<CapabilityApi>() {
@Override
public CapabilityApi build() {
return new CapabilityApi(drone);
}
});
return getApi(drone, capabilityApiCache, apiBuilder);
}

private final Drone drone;
Expand Down Expand Up @@ -84,7 +85,7 @@ public void run() {
});
break;

case FeatureIds.SOLOLINK_VIDEO_STREAMING:
case FeatureIds.SOLO_VIDEO_STREAMING:
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
drone.post(new Runnable() {
@Override
Expand Down Expand Up @@ -137,7 +138,7 @@ public static final class FeatureIds {
/**
* Id for the video feature.
*/
public static final String SOLOLINK_VIDEO_STREAMING = "feature_sololink_video_streaming";
public static final String SOLO_VIDEO_STREAMING = "feature_solo_video_streaming";

/**
* Id for the compass calibration feature.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@
/**
* Contains drone commands with no defined interaction model yet.
*/
public class ExperimentalApi implements Api {
public class ExperimentalApi extends Api {

private static final ConcurrentHashMap<Drone, ExperimentalApi> experimentalApiCache = new ConcurrentHashMap<>();
private static final Builder<ExperimentalApi> apiBuilder = new Builder<ExperimentalApi>() {
@Override
public ExperimentalApi build(Drone drone) {
return new ExperimentalApi(drone);
}
};

/**
* Retrieves an ExperimentalApi instance.
Expand All @@ -37,12 +43,7 @@ public class ExperimentalApi implements Api {
* @return a ExperimentalApi instance.
*/
public static ExperimentalApi getApi(final Drone drone) {
return ApiUtils.getApi(drone, experimentalApiCache, new Builder<ExperimentalApi>() {
@Override
public ExperimentalApi build() {
return new ExperimentalApi(drone);
}
});
return getApi(drone, experimentalApiCache, apiBuilder);
}

private final Drone drone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
* Provides access to the Follow me api.
* Created by Fredia Huya-Kouadio on 1/19/15.
*/
public class FollowApi implements Api {
public class FollowApi extends Api {

private static final ConcurrentHashMap<Drone, FollowApi> followApiCache = new ConcurrentHashMap<>();
private static final Builder<FollowApi> apiBuilder = new Builder<FollowApi>() {
@Override
public FollowApi build(Drone drone) {
return new FollowApi(drone);
}
};

/**
* Retrieves a FollowApi instance.
Expand All @@ -28,12 +34,7 @@ public class FollowApi implements Api {
* @return a FollowApi instance.
*/
public static FollowApi getApi(final Drone drone) {
return ApiUtils.getApi(drone, followApiCache, new Builder<FollowApi>() {
@Override
public FollowApi build() {
return new FollowApi(drone);
}
});
return getApi(drone, followApiCache, apiBuilder);
}

private final Drone drone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@

import static com.o3dr.services.android.lib.drone.action.GimbalActions.*;

public final class GimbalApi implements Api, DroneListener {
public final class GimbalApi extends Api implements DroneListener {

private static final ConcurrentHashMap<Drone, GimbalApi> gimbalApiCache = new ConcurrentHashMap<>();
private static final Builder<GimbalApi> apiBuilder = new Builder<GimbalApi>() {
@Override
public GimbalApi build(Drone drone) {
return new GimbalApi(drone);
}
};

public static GimbalApi getApi(final Drone drone){
return ApiUtils.getApi(drone, gimbalApiCache, new Builder<GimbalApi>() {
@Override
public GimbalApi build() {
return new GimbalApi(drone);
}
});
return getApi(drone, gimbalApiCache, apiBuilder);
}

public interface GimbalOrientationListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@
* Provides access to missions specific functionality.
* Created by Fredia Huya-Kouadio on 1/19/15.
*/
public class MissionApi implements Api {
public class MissionApi extends Api {

private static final ConcurrentHashMap<Drone, MissionApi> missionApiCache = new ConcurrentHashMap<>();
private static final Builder<MissionApi> apiBuilder = new Builder<MissionApi>() {
@Override
public MissionApi build(Drone drone) {
return new MissionApi(drone);
}
};

/**
* Retrieves a MissionApi instance.
* @param drone Target vehicle
* @return a MissionApi instance.
*/
public static MissionApi getApi(final Drone drone){
return ApiUtils.getApi(drone, missionApiCache, new Builder<MissionApi>() {
@Override
public MissionApi build() {
return new MissionApi(drone);
}
});
public static MissionApi getApi(final Drone drone) {
return getApi(drone, missionApiCache, apiBuilder);
}

private final Drone drone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,23 @@
/**
* Provides access to the vehicle specific functionality.
*/
public class VehicleApi implements Api {
public class VehicleApi extends Api {

private static final ConcurrentHashMap<Drone, VehicleApi> vehicleApiCache = new ConcurrentHashMap<>();
private static final Builder<VehicleApi> apiBuilder = new Builder<VehicleApi>() {
@Override
public VehicleApi build(Drone drone) {
return new VehicleApi(drone);
}
};

/**
* Retrieves a vehicle api instance.
* @param drone target vehicle
* @return a VehicleApi instance.
*/
public static VehicleApi getApi(final Drone drone){
return ApiUtils.getApi(drone, vehicleApiCache, new Builder<VehicleApi>() {
@Override
public VehicleApi build() {
return new VehicleApi(drone);
}
});
public static VehicleApi getApi(final Drone drone) {
return getApi(drone, vehicleApiCache, apiBuilder);
}

private final Drone drone;
Expand Down
Loading

0 comments on commit 7c55213

Please sign in to comment.