Skip to content

Commit

Permalink
update for 4.16
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoker1 committed Jan 20, 2022
1 parent d876566 commit 53d1037
Show file tree
Hide file tree
Showing 17 changed files with 417 additions and 201 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DJI UX SDK for Android Latest Version 4.15
# DJI UX SDK for Android Latest Version 4.16

## What is This?

Expand All @@ -13,20 +13,20 @@ Declare dependency via Maven:
<dependency>
<groupId>com.dji</groupId>
<artifactId>dji-uxsdk</artifactId>
<version>4.15</version>
<version>4.16</version>
</dependency>

<dependency>
<groupId>com.dji</groupId>
<artifactId>dji-sdk-provided</artifactId>
<version>4.15.1</version>
<version>4.16</version>
</dependency>
~~~

or Gradle:

~~~groovy
implementation ('com.dji:dji-uxsdk:4.15', {
implementation ('com.dji:dji-uxsdk:4.16', {
/**
* Comment the "library-anti-distortion" if your app does need Anti Distortion for Mavic 2 Pro and Mavic 2 Zoom.
* Comment the "fly-safe-database" if you do not need database for release, or we will download it when DJISDKManager.getInstance().registerApp
Expand All @@ -42,7 +42,7 @@ implementation ('com.dji:dji-uxsdk:4.15', {
*/
// exclude group: 'com.amap.api'
})
compileOnly ('com.dji:dji-sdk-provided:4.15.1')
compileOnly ('com.dji:dji-sdk-provided:4.16')
~~~

For further detail on how to integrate the DJI UX SDK into your Android Studio project, please check the [Getting Started with UX SDK](http://developer.dji.com/mobile-sdk/documentation/android-tutorials/UXSDKDemo.html#import-maven-dependency) tutorial.
Expand Down
4 changes: 2 additions & 2 deletions sample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ android {
}

dependencies {
implementation ('com.dji:dji-uxsdk:4.15', {
implementation ('com.dji:dji-uxsdk:4.16', {
/**
* Uncomment the following line to exclude amap from the app.
* Note that Google Play Store does not allow APKs that include this library.
*/
// exclude group: 'com.amap.api'
})
compileOnly ('com.dji:dji-sdk-provided:4.15.1')
compileOnly ('com.dji:dji-sdk-provided:4.16')

// AMAP: Do not include if publishing to Google Play Store
implementation 'com.amap.api:3dmap:7.3.0'
Expand Down
126 changes: 79 additions & 47 deletions sample/app/src/main/java/com/dji/ux/sample/CompleteWidgetActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,26 @@
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;

import com.dji.mapkit.core.maps.DJIMap;
import com.dji.mapkit.core.models.DJILatLng;

import dji.common.airlink.PhysicalSource;
import dji.keysdk.CameraKey;
import dji.keysdk.KeyManager;
import dji.sdk.camera.VideoFeeder;
import dji.ux.panel.CameraSettingAdvancedPanel;
import dji.ux.panel.CameraSettingExposurePanel;
import dji.ux.utils.DJIProductUtil;
import dji.ux.widget.FPVOverlayWidget;
import dji.ux.widget.FPVWidget;
import dji.ux.widget.MapWidget;
import dji.ux.widget.ThermalPaletteWidget;
import dji.ux.widget.config.CameraConfigApertureWidget;
import dji.ux.widget.config.CameraConfigEVWidget;
import dji.ux.widget.config.CameraConfigISOAndEIWidget;
import dji.ux.widget.config.CameraConfigSSDWidget;
import dji.ux.widget.config.CameraConfigShutterWidget;
import dji.ux.widget.config.CameraConfigStorageWidget;
import dji.ux.widget.config.CameraConfigWBWidget;
import dji.ux.widget.controls.CameraControlsWidget;
import dji.ux.widget.controls.LensControlWidget;

/**
* Activity that shows all the UI elements together
Expand All @@ -35,10 +43,25 @@ public class CompleteWidgetActivity extends Activity {
private ViewGroup parentView;
private FPVWidget fpvWidget;
private FPVWidget secondaryFPVWidget;
private FPVOverlayWidget fpvOverlayWidget;
private RelativeLayout primaryVideoView;
private FrameLayout secondaryVideoView;
private boolean isMapMini = true;

private CameraSettingExposurePanel cameraSettingExposurePanel;
private CameraSettingAdvancedPanel cameraSettingAdvancedPanel;
private CameraConfigISOAndEIWidget cameraConfigISOAndEIWidget;
private CameraConfigShutterWidget cameraConfigShutterWidget;
private CameraConfigApertureWidget cameraConfigApertureWidget;
private CameraConfigEVWidget cameraConfigEVWidget;
private CameraConfigWBWidget cameraConfigWBWidget;
private CameraConfigStorageWidget cameraConfigStorageWidget;
private CameraConfigSSDWidget cameraConfigSSDWidget;
private CameraControlsWidget controlsWidget;
private LensControlWidget lensControlWidget;
private ThermalPaletteWidget thermalPaletteWidget;


private int height;
private int width;
private int margin;
Expand All @@ -61,47 +84,38 @@ protected void onCreate(Bundle savedInstanceState) {
deviceHeight = outPoint.y;
deviceWidth = outPoint.x;

mapWidget = findViewById(R.id.map_widget);
mapWidget.initAMap(new MapWidget.OnMapReadyListener() {
@Override
public void onMapReady(@NonNull DJIMap map) {
map.setOnMapClickListener(new DJIMap.OnMapClickListener() {
@Override
public void onMapClick(DJILatLng latLng) {
onViewClick(mapWidget);
}
});
map.getUiSettings().setZoomControlsEnabled(false);
}
});
mapWidget = (MapWidget) findViewById(R.id.map_widget);
mapWidget.initAMap(map -> map.setOnMapClickListener((DJIMap.OnMapClickListener) latLng -> onViewClick(mapWidget)));
mapWidget.onCreate(savedInstanceState);

initCameraView();
parentView = (ViewGroup) findViewById(R.id.root_view);

fpvWidget = findViewById(R.id.fpv_widget);
fpvWidget.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onViewClick(fpvWidget);
}
});
primaryVideoView = (RelativeLayout) findViewById(R.id.fpv_container);
secondaryVideoView = (FrameLayout) findViewById(R.id.secondary_video_view);
fpvWidget.setOnClickListener(view -> onViewClick(fpvWidget));
fpvOverlayWidget = findViewById(R.id.fpv_overlay_widget);
primaryVideoView = findViewById(R.id.fpv_container);
secondaryVideoView = findViewById(R.id.secondary_video_view);
secondaryFPVWidget = findViewById(R.id.secondary_fpv_widget);
secondaryFPVWidget.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
swapVideoSource();
}
});
if (VideoFeeder.getInstance() != null) {
//If secondary video feed is already initialized, get video source
updateSecondaryVideoVisibility(VideoFeeder.getInstance().getSecondaryVideoFeed().getVideoSource() != PhysicalSource.UNKNOWN);
//If secondary video feed is not yet initialized, wait for active status
VideoFeeder.getInstance().getSecondaryVideoFeed()
.addVideoActiveStatusListener(isActive ->
runOnUiThread(() -> updateSecondaryVideoVisibility(isActive)));
}
secondaryFPVWidget.setOnClickListener(view -> swapVideoSource());

fpvWidget.setCameraIndexListener((cameraIndex, lensIndex) -> cameraWidgetKeyIndexUpdated(fpvWidget.getCameraKeyIndex(), fpvWidget.getLensKeyIndex()));
updateSecondaryVideoVisibility();
}

private void initCameraView() {
cameraSettingExposurePanel = findViewById(R.id.camera_setting_exposure_panel);
cameraSettingAdvancedPanel = findViewById(R.id.camera_setting_advanced_panel);
cameraConfigISOAndEIWidget = findViewById(R.id.camera_config_iso_and_ei_widget);
cameraConfigShutterWidget = findViewById(R.id.camera_config_shutter_widget);
cameraConfigApertureWidget = findViewById(R.id.camera_config_aperture_widget);
cameraConfigEVWidget = findViewById(R.id.camera_config_ev_widget);
cameraConfigWBWidget = findViewById(R.id.camera_config_wb_widget);
cameraConfigStorageWidget = findViewById(R.id.camera_config_storage_widget);
cameraConfigSSDWidget = findViewById(R.id.camera_config_ssd_widget);
lensControlWidget = findViewById(R.id.camera_lens_control);
controlsWidget = findViewById(R.id.CameraCapturePanel);
thermalPaletteWidget = findViewById(R.id.thermal_pallette_widget);
}

private void onViewClick(View view) {
Expand Down Expand Up @@ -158,29 +172,47 @@ private void swapVideoSource() {
}
}

private void updateSecondaryVideoVisibility(boolean isActive) {
if (isActive) {
secondaryVideoView.setVisibility(View.VISIBLE);
} else {
private void cameraWidgetKeyIndexUpdated(int keyIndex, int subKeyIndex) {
controlsWidget.updateKeyOnIndex(keyIndex, subKeyIndex);
cameraSettingExposurePanel.updateKeyOnIndex(keyIndex, subKeyIndex);
cameraSettingAdvancedPanel.updateKeyOnIndex(keyIndex, subKeyIndex);
cameraConfigISOAndEIWidget.updateKeyOnIndex(keyIndex, subKeyIndex);
cameraConfigShutterWidget.updateKeyOnIndex(keyIndex, subKeyIndex);
cameraConfigApertureWidget.updateKeyOnIndex(keyIndex, subKeyIndex);
cameraConfigEVWidget.updateKeyOnIndex(keyIndex, subKeyIndex);
cameraConfigWBWidget.updateKeyOnIndex(keyIndex, subKeyIndex);
cameraConfigStorageWidget.updateKeyOnIndex(keyIndex, subKeyIndex);
cameraConfigSSDWidget.updateKeyOnIndex(keyIndex, subKeyIndex);
controlsWidget.updateKeyOnIndex(keyIndex, subKeyIndex);
lensControlWidget.updateKeyOnIndex(keyIndex, subKeyIndex);
thermalPaletteWidget.updateKeyOnIndex(keyIndex, subKeyIndex);

fpvOverlayWidget.updateKeyOnIndex(keyIndex, subKeyIndex);
}

private void updateSecondaryVideoVisibility() {
if (secondaryFPVWidget.getVideoSource() == null || !DJIProductUtil.isSupportMultiCamera()) {
secondaryVideoView.setVisibility(View.GONE);
} else {
secondaryVideoView.setVisibility(View.VISIBLE);
}
}

private void hidePanels() {
//These panels appear based on keys from the drone itself.
if (KeyManager.getInstance() != null) {
KeyManager.getInstance().setValue(CameraKey.create(CameraKey.HISTOGRAM_ENABLED), false, null);
KeyManager.getInstance().setValue(CameraKey.create(CameraKey.COLOR_WAVEFORM_ENABLED), false, null);
KeyManager.getInstance().setValue(CameraKey.create(CameraKey.HISTOGRAM_ENABLED, fpvWidget.getCameraKeyIndex()), false, null);
KeyManager.getInstance().setValue(CameraKey.create(CameraKey.COLOR_WAVEFORM_ENABLED, fpvWidget.getCameraKeyIndex()), false, null);
}

//These panels have buttons that toggle them, so call the methods to make sure the button state is correct.
CameraControlsWidget controlsWidget = findViewById(R.id.CameraCapturePanel);
controlsWidget.setAdvancedPanelVisibility(false);
controlsWidget.setExposurePanelVisibility(false);

//These panels don't have a button state, so we can just hide them.
findViewById(R.id.pre_flight_check_list).setVisibility(View.GONE);
findViewById(R.id.rtk_panel).setVisibility(View.GONE);
//findViewById(R.id.simulator_panel).setVisibility(View.GONE);
findViewById(R.id.spotlight_panel).setVisibility(View.GONE);
findViewById(R.id.speaker_panel).setVisibility(View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import dji.ux.widget.FPVWidget;

public class CustomizedWidgetsActivity extends Activity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
private final static String TAG = "CustomizedWidgetsActivity";
private FPVWidget fpvWidget;
private FPVOverlayWidget fpvOverlayWidget;
private FPVWidget secondaryFpvWidget;
Expand All @@ -32,10 +33,13 @@ private void initView() {
((CheckBox) findViewById(R.id.checkbox_secondary_camera_name)).setOnCheckedChangeListener(this);
((CheckBox) findViewById(R.id.checkbox_primary_camera_side)).setOnCheckedChangeListener(this);
((CheckBox) findViewById(R.id.checkbox_secondary_camera_side)).setOnCheckedChangeListener(this);
//((CheckBox) findViewById(R.id.checkbox_primary_overexposure_warning)).setOnCheckedChangeListener(this);
//((CheckBox) findViewById(R.id.checkbox_secondary_overexposure_warning)).setOnCheckedChangeListener(this);
((CheckBox) findViewById(R.id.checkbox_touch_focus)).setOnCheckedChangeListener(this);
((CheckBox) findViewById(R.id.checkbox_touch_metering)).setOnCheckedChangeListener(this);
((CheckBox) findViewById(R.id.checkbox_gimbal_control)).setOnCheckedChangeListener(this);
((CheckBox) findViewById(R.id.checkbox_display_grid)).setOnCheckedChangeListener(this);
//((CheckBox) findViewById(R.id.checkbox_display_center_point)).setOnCheckedChangeListener(this);

findViewById(R.id.primary_video_feed).setOnClickListener(this);
findViewById(R.id.secondary_video_feed).setOnClickListener(this);
Expand All @@ -44,14 +48,24 @@ private void initView() {
findViewById(R.id.grid_type_none).setOnClickListener(this);
findViewById(R.id.grid_type_parallel).setOnClickListener(this);
findViewById(R.id.grid_type_parallel_diagonal).setOnClickListener(this);
/*findViewById(R.id.center_point_none).setOnClickListener(this);
findViewById(R.id.center_point_standard).setOnClickListener(this);
findViewById(R.id.center_point_cross).setOnClickListener(this);
findViewById(R.id.center_point_narrow_cross).setOnClickListener(this);
findViewById(R.id.center_point_frame).setOnClickListener(this);
findViewById(R.id.center_point_frame_and_cross).setOnClickListener(this);
findViewById(R.id.center_point_square).setOnClickListener(this);
findViewById(R.id.center_point_square_and_cross).setOnClickListener(this);
findViewById(R.id.center_point_color).setOnClickListener(this);*/
}


// On click event for button
public void resizeView() {

ViewGroup.LayoutParams params = fpvWidget.getLayoutParams();
if (!isOriginalSize) {
if (!isOriginalSize)
{
params.height = 2 * fpvWidget.getHeight();
params.width = 2 * fpvWidget.getWidth();
} else {
Expand All @@ -69,10 +83,12 @@ public void onClick(View v) {
switch (v.getId()) {
case R.id.primary_video_feed:
fpvWidget.setVideoSource(FPVWidget.VideoSource.PRIMARY);
//fpvOverlayWidget.setOverlayVideoSource(FPVWidget.VideoSource.PRIMARY);
secondaryFpvWidget.setVideoSource(FPVWidget.VideoSource.SECONDARY);
break;
case R.id.secondary_video_feed:
fpvWidget.setVideoSource(FPVWidget.VideoSource.SECONDARY);
//fpvOverlayWidget.setOverlayVideoSource(FPVWidget.VideoSource.SECONDARY);
secondaryFpvWidget.setVideoSource(FPVWidget.VideoSource.PRIMARY);
break;
case R.id.auto_video_feed:
Expand All @@ -90,6 +106,33 @@ public void onClick(View v) {
case R.id.grid_type_parallel_diagonal:
fpvOverlayWidget.setCurrentGridOverlayType(FPVOverlayWidget.GridOverlayType.PARALLEL_DIAGONAL);
break;
/*case R.id.center_point_none:
fpvOverlayWidget.setCenterPointType(FPVOverlayWidget.CenterPointType.NONE);
break;
case R.id.center_point_standard:
fpvOverlayWidget.setCenterPointType(FPVOverlayWidget.CenterPointType.STANDARD);
break;
case R.id.center_point_cross:
fpvOverlayWidget.setCenterPointType(FPVOverlayWidget.CenterPointType.CROSS);
break;
case R.id.center_point_narrow_cross:
fpvOverlayWidget.setCenterPointType(FPVOverlayWidget.CenterPointType.NARROW_CROSS);
break;
case R.id.center_point_frame:
fpvOverlayWidget.setCenterPointType(FPVOverlayWidget.CenterPointType.FRAME);
break;
case R.id.center_point_frame_and_cross:
fpvOverlayWidget.setCenterPointType(FPVOverlayWidget.CenterPointType.FRAME_AND_CROSS);
break;
case R.id.center_point_square:
fpvOverlayWidget.setCenterPointType(FPVOverlayWidget.CenterPointType.SQUARE);
break;
case R.id.center_point_square_and_cross:
fpvOverlayWidget.setCenterPointType(FPVOverlayWidget.CenterPointType.SQUARE_AND_CROSS);
break;
case R.id.center_point_color:
setRandomCenterPointColor();
break;*/
}

}
Expand All @@ -109,6 +152,12 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
case R.id.checkbox_secondary_camera_side:
secondaryFpvWidget.setSourceCameraSideVisibility(isChecked);
break;
/*case R.id.checkbox_primary_overexposure_warning:
fpvWidget.setOverexposureWarningEnabled(isChecked);
break;
case R.id.checkbox_secondary_overexposure_warning:
secondaryFpvWidget.setOverexposureWarningEnabled(isChecked);
break;*/
case R.id.checkbox_touch_focus:
fpvOverlayWidget.setTouchFocusEnabled(isChecked);
break;
Expand All @@ -121,7 +170,16 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
case R.id.checkbox_display_grid:
fpvOverlayWidget.setGridOverlayEnabled(isChecked);
break;
//case R.id.checkbox_display_center_point:
//fpvOverlayWidget.setCenterPointEnabled(isChecked);
//break;
}

}

/*private void setRandomCenterPointColor() {
Random rnd = new Random();
@ColorInt int randomColor = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
fpvOverlayWidget.setCenterPointColor(randomColor);
}*/
}
16 changes: 8 additions & 8 deletions sample/app/src/main/java/com/dji/ux/sample/DensityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

public class DensityUtil {

public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}

public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}
public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}
}
Loading

0 comments on commit 53d1037

Please sign in to comment.