Skip to content

Commit

Permalink
fix sample problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoker1 committed Feb 3, 2021
1 parent c2e3015 commit 37ffe51
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 77 deletions.
2 changes: 2 additions & 0 deletions Sample Code/app/build.gradle
Expand Up @@ -84,8 +84,10 @@ dependencies {
* Both will greatly reducing the size of the APK.
*/
exclude module: 'library-anti-distortion'
exclude module: 'utmiss'
//exclude module: 'fly-safe-database'
})
implementation 'com.dji:utmiss:1.0.8'
compileOnly 'com.dji:dji-sdk-provided:4.14-trial1'

implementation 'androidx.appcompat:appcompat:1.0.0'
Expand Down
Expand Up @@ -36,34 +36,38 @@ public RecordVideoView(Context context) {
protected void onAttachedToWindow() {
super.onAttachedToWindow();

if (ModuleVerificationUtil.isCameraModuleAvailable()) {
if (!ModuleVerificationUtil.isCameraModuleAvailable()) {
return;
}
if (ModuleVerificationUtil.isMavicAir2()){
DJISampleApplication.getProductInstance()
.getCamera()
.setMode(SettingsDefinitions.CameraMode.RECORD_VIDEO,
new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
ToastUtils.setResultToToast("SetCameraMode to recordVideo");
}
});
.setFlatMode(SettingsDefinitions.FlatCameraMode.VIDEO_NORMAL, djiError -> ToastUtils.setResultToToast("SetCameraMode to recordVideo"));
return;
}
DJISampleApplication.getProductInstance()
.getCamera()
.setMode(SettingsDefinitions.CameraMode.RECORD_VIDEO, djiError -> ToastUtils.setResultToToast("SetCameraMode to recordVideo"));
}

@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();

if (ModuleVerificationUtil.isCameraModuleAvailable()) {
return;
}

if (ModuleVerificationUtil.isMavicAir2()){
DJISampleApplication.getProductInstance()
.getCamera()
.setMode(SettingsDefinitions.CameraMode.SHOOT_PHOTO,
new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
ToastUtils.setResultToToast("SetCameraMode to shootPhoto");
}
});
.setFlatMode(SettingsDefinitions.FlatCameraMode.PHOTO_SINGLE, djiError -> ToastUtils.setResultToToast("SetCameraMode to shootPhoto"));
return;
}
DJISampleApplication.getProductInstance()
.getCamera()
.setMode(SettingsDefinitions.CameraMode.SHOOT_PHOTO, djiError -> ToastUtils.setResultToToast("SetCameraMode to shootPhoto"));

}

@Override
Expand Down Expand Up @@ -93,28 +97,25 @@ protected void handleLeftBtnClick() {
if (ModuleVerificationUtil.isCameraModuleAvailable()) {
DJISampleApplication.getProductInstance()
.getCamera()
.startRecordVideo(new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
//success so, start recording
if (null == djiError) {
ToastUtils.setResultToToast("Start record");
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
timeCounter = timeCounter + 1;
hours = TimeUnit.MILLISECONDS.toHours(timeCounter);
minutes =
TimeUnit.MILLISECONDS.toMinutes(timeCounter) - (hours * 60);
seconds = TimeUnit.MILLISECONDS.toSeconds(timeCounter) - ((hours
* 60
* 60) + (minutes * 60));
time = String.format("%02d:%02d:%02d", hours, minutes, seconds);
changeDescription(time);
}
}, 0, 1);
}
.startRecordVideo(djiError -> {
//success so, start recording
if (null == djiError) {
ToastUtils.setResultToToast("Start record");
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
timeCounter = timeCounter + 1;
hours = TimeUnit.MILLISECONDS.toHours(timeCounter);
minutes =
TimeUnit.MILLISECONDS.toMinutes(timeCounter) - (hours * 60);
seconds = TimeUnit.MILLISECONDS.toSeconds(timeCounter) - ((hours
* 60
* 60) + (minutes * 60));
time = String.format("%02d:%02d:%02d", hours, minutes, seconds);
changeDescription(time);
}
}, 0, 1);
}
});
}
Expand All @@ -126,14 +127,11 @@ protected void handleRightBtnClick() {
if (ModuleVerificationUtil.isCameraModuleAvailable()) {
DJISampleApplication.getProductInstance()
.getCamera()
.stopRecordVideo(new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {
ToastUtils.setResultToToast("StopRecord");
changeDescription("00:00:00");
timer.cancel();
timeCounter = 0;
}
.stopRecordVideo(djiError -> {
ToastUtils.setResultToToast("StopRecord");
changeDescription("00:00:00");
timer.cancel();
timeCounter = 0;
});
}
}
Expand Down
Expand Up @@ -5,6 +5,7 @@

import com.dji.sdk.sample.R;
import com.dji.sdk.sample.internal.controller.DJISampleApplication;
import com.dji.sdk.sample.internal.utils.ModuleVerificationUtil;
import com.dji.sdk.sample.internal.utils.ToastUtils;
import com.dji.sdk.sample.internal.view.BaseThreeBtnView;

Expand Down Expand Up @@ -32,18 +33,16 @@ public ShootSinglePhotoView(Context context) {
public void onAttachedToWindow() {
super.onAttachedToWindow();
Log.v("Attached To Window", "onAttachedToWindow");

if (isModuleAvailable()) {

if (ModuleVerificationUtil.isMavicAir2()){
DJISampleApplication.getProductInstance()
.getCamera()
.setFlatMode(SettingsDefinitions.FlatCameraMode.PHOTO_SINGLE, djiError -> ToastUtils.setResultToToast("SetCameraMode to shootPhoto"));
return;
}
DJISampleApplication.getProductInstance()
.getCamera()
.setMode(SettingsDefinitions.CameraMode.SHOOT_PHOTO,
new CommonCallbacks.CompletionCallback() {
@Override
public void onResult(DJIError djiError) {

}
});
.setMode(SettingsDefinitions.CameraMode.SHOOT_PHOTO, djiError -> ToastUtils.setResultToToast("SetCameraMode to shootPhoto"));
}
}

Expand Down
Expand Up @@ -371,7 +371,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
.build();

WaypointV2Action waypointAction0 = new WaypointV2Action.Builder()
.setActionID(0)
.setActionID(1)
.setTrigger(waypointAction0Trigger)
.setActuator(waypointAction0Actuator)
.build();
Expand All @@ -380,7 +380,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
WaypointTrigger waypointAction1Trigger = new WaypointTrigger.Builder()
.setTriggerType(ActionTypes.ActionTriggerType.ASSOCIATE)
.setAssociateParam(new WaypointV2AssociateTriggerParam.Builder()
.setAssociateActionID(0)
.setAssociateActionID(1)
.setAssociateType(ActionTypes.AssociatedTimingType.AFTER_FINISHED)
.setWaitingTime(0)
.build())
Expand All @@ -397,7 +397,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
.build();

WaypointV2Action waypointAction1 = new WaypointV2Action.Builder()
.setActionID(1)
.setActionID(2)
.setTrigger(waypointAction1Trigger)
.setActuator(waypointAction1Actuator)
.build();
Expand All @@ -406,7 +406,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
WaypointTrigger waypointAction2Trigger = new WaypointTrigger.Builder()
.setTriggerType(ActionTypes.ActionTriggerType.ASSOCIATE)
.setAssociateParam(new WaypointV2AssociateTriggerParam.Builder()
.setAssociateActionID(1)
.setAssociateActionID(2)
.setAssociateType(ActionTypes.AssociatedTimingType.AFTER_FINISHED)
.setWaitingTime(0)
.build())
Expand All @@ -427,7 +427,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
.build();

WaypointV2Action waypointAction2 = new WaypointV2Action.Builder()
.setActionID(2)
.setActionID(3)
.setTrigger(waypointAction2Trigger)
.setActuator(waypointAction2Actuator)
.build();
Expand All @@ -436,7 +436,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
WaypointTrigger waypointAction3Trigger = new WaypointTrigger.Builder()
.setTriggerType(ActionTypes.ActionTriggerType.ASSOCIATE)
.setAssociateParam(new WaypointV2AssociateTriggerParam.Builder()
.setAssociateActionID(2)
.setAssociateActionID(3)
.setAssociateType(ActionTypes.AssociatedTimingType.AFTER_FINISHED)
.setWaitingTime(0)
.build())
Expand All @@ -450,7 +450,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
.build();

WaypointV2Action waypointAction3 = new WaypointV2Action.Builder()
.setActionID(3)
.setActionID(4)
.setTrigger(waypointAction3Trigger)
.setActuator(waypointAction3Actuator)
.build();
Expand All @@ -459,7 +459,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
WaypointTrigger waypointAction4Trigger = new WaypointTrigger.Builder()
.setTriggerType(ActionTypes.ActionTriggerType.ASSOCIATE)
.setAssociateParam(new WaypointV2AssociateTriggerParam.Builder()
.setAssociateActionID(3)
.setAssociateActionID(4)
.setAssociateType(ActionTypes.AssociatedTimingType.AFTER_FINISHED)
.setWaitingTime(0)
.build())
Expand All @@ -480,7 +480,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
.build();

WaypointV2Action waypointAction4 = new WaypointV2Action.Builder()
.setActionID(4)
.setActionID(5)
.setTrigger(waypointAction4Trigger)
.setActuator(waypointAction4Actuator)
.build();
Expand All @@ -489,7 +489,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
WaypointTrigger waypointAction5Trigger = new WaypointTrigger.Builder()
.setTriggerType(ActionTypes.ActionTriggerType.ASSOCIATE)
.setAssociateParam(new WaypointV2AssociateTriggerParam.Builder()
.setAssociateActionID(4)
.setAssociateActionID(5)
.setAssociateType(ActionTypes.AssociatedTimingType.AFTER_FINISHED)
.setWaitingTime(0)
.build())
Expand All @@ -506,7 +506,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
.build();

WaypointV2Action waypointAction5 = new WaypointV2Action.Builder()
.setActionID(5)
.setActionID(6)
.setTrigger(waypointAction5Trigger)
.setActuator(waypointAction5Actuator)
.build();
Expand Down Expand Up @@ -535,7 +535,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
.build();

WaypointV2Action waypointAction6 = new WaypointV2Action.Builder()
.setActionID(6)
.setActionID(7)
.setTrigger(waypointAction6Trigger)
.setActuator(waypointAction6Actuator)
.build();
Expand Down Expand Up @@ -564,7 +564,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
.build();

WaypointV2Action waypointAction7 = new WaypointV2Action.Builder()
.setActionID(7)
.setActionID(8)
.setTrigger(waypointAction7Trigger)
.setActuator(waypointAction7Actuator)
.build();
Expand Down Expand Up @@ -593,7 +593,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
.build();

WaypointV2Action waypointAction8 = new WaypointV2Action.Builder()
.setActionID(8)
.setActionID(9)
.setTrigger(waypointAction8Trigger)
.setActuator(waypointAction8Actuator)
.build();
Expand All @@ -615,7 +615,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
.build();

WaypointV2Action waypointAction9 = new WaypointV2Action.Builder()
.setActionID(9)
.setActionID(10)
.setTrigger(waypointAction9Trigger)
.setActuator(waypointAction9Actuator)
.build();
Expand Down Expand Up @@ -647,7 +647,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
.build();

WaypointV2Action waypointAction10 = new WaypointV2Action.Builder()
.setActionID(10)
.setActionID(11)
.setTrigger(waypointAction10Trigger)
.setActuator(waypointAction10Actuator)
.build();
Expand All @@ -656,7 +656,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
WaypointTrigger waypointAction11Trigger = new WaypointTrigger.Builder()
.setTriggerType(ActionTypes.ActionTriggerType.ASSOCIATE)
.setAssociateParam(new WaypointV2AssociateTriggerParam.Builder()
.setAssociateActionID(10)
.setAssociateActionID(11)
.setAssociateType(ActionTypes.AssociatedTimingType.AFTER_FINISHED)
// Because set file name and shoot photo is the same module, it is better to set a waiting time.
.setWaitingTime(0.5f)
Expand All @@ -671,7 +671,7 @@ private void uploadWaypointAction(List<WaypointV2Action> waypointV2ActionList) {
.build();

WaypointV2Action waypointAction11 = new WaypointV2Action.Builder()
.setActionID(11)
.setActionID(12)
.setTrigger(waypointAction11Trigger)
.setActuator(waypointAction11Actuator)
.build();
Expand Down
Expand Up @@ -7,13 +7,12 @@
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.dji.sdk.sample.R;

import java.io.File;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
Expand Down
@@ -1,10 +1,9 @@
package com.dji.sdk.sample.internal.utils;


import androidx.annotation.Nullable;

import com.dji.sdk.sample.internal.controller.DJISampleApplication;

import androidx.annotation.Nullable;
import dji.common.product.Model;
import dji.sdk.accessory.AccessoryAggregation;
import dji.sdk.accessory.beacon.Beacon;
Expand Down Expand Up @@ -152,4 +151,12 @@ public static boolean isMavic2Product() {
return false;
}

public static boolean isMavicAir2(){
BaseProduct baseProduct = DJISampleApplication.getProductInstance();
if (baseProduct != null) {
return baseProduct.getModel() == Model.MAVIC_AIR_2;
}
return false;
}

}

0 comments on commit 37ffe51

Please sign in to comment.