From 53d1037573b6a70492f19fae52404259d9a6ad04 Mon Sep 17 00:00:00 2001 From: "hoker.wu" Date: Thu, 20 Jan 2022 21:51:26 +0800 Subject: [PATCH] update for 4.16 --- README.md | 10 +- sample/app/build.gradle | 4 +- .../dji/ux/sample/CompleteWidgetActivity.java | 126 +++++++++++------- .../ux/sample/CustomizedWidgetsActivity.java | 60 ++++++++- .../java/com/dji/ux/sample/DensityUtil.java | 16 +-- .../com/dji/ux/sample/FlyZoneDialogView.java | 53 +++++--- .../java/com/dji/ux/sample/MApplication.java | 4 +- .../java/com/dji/ux/sample/MainActivity.java | 60 +++------ .../com/dji/ux/sample/MapWidgetActivity.java | 46 +++---- .../custom/CustomizedBatteryWidget.java | 13 +- .../main/res/drawable/selector_icon_bg.xml | 4 +- .../layout/activity_customized_widgets.xml | 33 +++-- .../res/layout/activity_default_widgets.xml | 98 +++++++++++--- .../main/res/layout/activity_map_widget.xml | 4 - .../src/main/res/layout/dialog_fly_zone.xml | 12 +- .../app/src/main/res/values-zh-rCN/string.xml | 68 ++++++++++ sample/app/src/main/res/values/strings.xml | 7 +- 17 files changed, 417 insertions(+), 201 deletions(-) create mode 100644 sample/app/src/main/res/values-zh-rCN/string.xml diff --git a/README.md b/README.md index d5a8b44..10ca965 100644 --- a/README.md +++ b/README.md @@ -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? @@ -13,20 +13,20 @@ Declare dependency via Maven: com.dji dji-uxsdk - 4.15 + 4.16 com.dji dji-sdk-provided - 4.15.1 + 4.16 ~~~ 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 @@ -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. diff --git a/sample/app/build.gradle b/sample/app/build.gradle index eb1c165..4cbc700 100644 --- a/sample/app/build.gradle +++ b/sample/app/build.gradle @@ -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' diff --git a/sample/app/src/main/java/com/dji/ux/sample/CompleteWidgetActivity.java b/sample/app/src/main/java/com/dji/ux/sample/CompleteWidgetActivity.java index 14164bd..903e2fd 100644 --- a/sample/app/src/main/java/com/dji/ux/sample/CompleteWidgetActivity.java +++ b/sample/app/src/main/java/com/dji/ux/sample/CompleteWidgetActivity.java @@ -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 @@ -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; @@ -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) { @@ -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); } diff --git a/sample/app/src/main/java/com/dji/ux/sample/CustomizedWidgetsActivity.java b/sample/app/src/main/java/com/dji/ux/sample/CustomizedWidgetsActivity.java index aa1a0a1..3288d5e 100644 --- a/sample/app/src/main/java/com/dji/ux/sample/CustomizedWidgetsActivity.java +++ b/sample/app/src/main/java/com/dji/ux/sample/CustomizedWidgetsActivity.java @@ -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; @@ -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); @@ -44,6 +48,15 @@ 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);*/ } @@ -51,7 +64,8 @@ private void initView() { public void resizeView() { ViewGroup.LayoutParams params = fpvWidget.getLayoutParams(); - if (!isOriginalSize) { + if (!isOriginalSize) + { params.height = 2 * fpvWidget.getHeight(); params.width = 2 * fpvWidget.getWidth(); } else { @@ -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: @@ -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;*/ } } @@ -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; @@ -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); + }*/ } diff --git a/sample/app/src/main/java/com/dji/ux/sample/DensityUtil.java b/sample/app/src/main/java/com/dji/ux/sample/DensityUtil.java index 9eaa87d..dbead34 100644 --- a/sample/app/src/main/java/com/dji/ux/sample/DensityUtil.java +++ b/sample/app/src/main/java/com/dji/ux/sample/DensityUtil.java @@ -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); + } } diff --git a/sample/app/src/main/java/com/dji/ux/sample/FlyZoneDialogView.java b/sample/app/src/main/java/com/dji/ux/sample/FlyZoneDialogView.java index 7811148..b24a733 100644 --- a/sample/app/src/main/java/com/dji/ux/sample/FlyZoneDialogView.java +++ b/sample/app/src/main/java/com/dji/ux/sample/FlyZoneDialogView.java @@ -20,13 +20,23 @@ public class FlyZoneDialogView extends ScrollView { - private CheckBox all; - private CheckBox auth; - private CheckBox warning; - private CheckBox enhancedWarning; - private CheckBox restricted; - private Button btnCustomUnlockColor; - private Button btnCustomUnlockSync; + CheckBox all; + CheckBox auth; + CheckBox warning; + CheckBox enhancedWarning; + CheckBox restricted; + + Switch switchCustomUnlock; + + Button authColor; + Button warningColor; + Button enhancedWarningColor; + Button restrictedColor; + Button maxHeightColor; + Button selfUnlockColor; + Button btnCustomUnlockColor; + Button btnCustomUnlockSync; + public FlyZoneDialogView(Context context) { super(context); @@ -44,14 +54,15 @@ public void init(MapWidget mapWidget) { } public void initCheckboxes(final MapWidget mapWidget) { - all = findViewById(R.id.all); - auth = findViewById(R.id.auth); - warning = findViewById(R.id.warning); - enhancedWarning = findViewById(R.id.enhanced_warning); - restricted = findViewById(R.id.restricted); - Switch switchCustomUnlock = findViewById(R.id.custom_unlock_switch); + all = (CheckBox) findViewById(R.id.all); + auth = (CheckBox) findViewById(R.id.auth); + warning = (CheckBox) findViewById(R.id.warning); + enhancedWarning = (CheckBox) findViewById(R.id.enhanced_warning); + restricted = (CheckBox) findViewById(R.id.restricted); + switchCustomUnlock = (Switch) findViewById(R.id.custom_unlock_switch); switchCustomUnlock.setChecked(mapWidget.isCustomUnlockZonesVisible()); CompoundButton.OnCheckedChangeListener listener = new CompoundButton.OnCheckedChangeListener() { + @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { switch (compoundButton.getId()) { @@ -99,14 +110,14 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { } public void initColors(final MapWidget mapWidget) { - Button authColor = findViewById(R.id.auth_color); - Button warningColor = findViewById(R.id.warning_color); - Button enhancedWarningColor = findViewById(R.id.enhanced_warning_color); - Button restrictedColor = findViewById(R.id.restricted_color); - Button maxHeightColor = findViewById(R.id.max_height_color); - Button selfUnlockColor = findViewById(R.id.self_unlock_color); - btnCustomUnlockColor = findViewById(R.id.custom_unlock_color); - btnCustomUnlockSync = findViewById(R.id.custom_unlock_sync); + authColor = (Button) findViewById(R.id.auth_color); + warningColor = (Button) findViewById(R.id.warning_color); + enhancedWarningColor = (Button) findViewById(R.id.enhanced_warning_color); + restrictedColor = (Button) findViewById(R.id.restricted_color); + maxHeightColor = (Button) findViewById(R.id.max_height_color); + selfUnlockColor = (Button) findViewById(R.id.self_unlock_color); + btnCustomUnlockColor = (Button) findViewById(R.id.custom_unlock_color); + btnCustomUnlockSync = (Button) findViewById(R.id.custom_unlock_sync); btnCustomUnlockColor.setEnabled(mapWidget.isCustomUnlockZonesVisible()); btnCustomUnlockSync.setEnabled(mapWidget.isCustomUnlockZonesVisible()); diff --git a/sample/app/src/main/java/com/dji/ux/sample/MApplication.java b/sample/app/src/main/java/com/dji/ux/sample/MApplication.java index af8086a..f2ee9f7 100644 --- a/sample/app/src/main/java/com/dji/ux/sample/MApplication.java +++ b/sample/app/src/main/java/com/dji/ux/sample/MApplication.java @@ -7,8 +7,6 @@ import com.secneo.sdk.Helper; -import static com.dji.ux.sample.DJIConnectionControlActivity.ACCESSORY_ATTACHED; - public class MApplication extends Application { @Override @@ -16,7 +14,7 @@ public void onCreate() { super.onCreate(); BroadcastReceiver br = new OnDJIUSBAttachedReceiver(); IntentFilter filter = new IntentFilter(); - filter.addAction(ACCESSORY_ATTACHED); + filter.addAction(DJIConnectionControlActivity.ACCESSORY_ATTACHED); registerReceiver(br, filter); } diff --git a/sample/app/src/main/java/com/dji/ux/sample/MainActivity.java b/sample/app/src/main/java/com/dji/ux/sample/MainActivity.java index 6f373c3..4fb032c 100644 --- a/sample/app/src/main/java/com/dji/ux/sample/MainActivity.java +++ b/sample/app/src/main/java/com/dji/ux/sample/MainActivity.java @@ -23,10 +23,7 @@ import android.widget.TextView; import android.widget.Toast; -import androidx.annotation.NonNull; -import androidx.core.app.ActivityCompat; -import androidx.core.content.ContextCompat; - +import com.dji.frame.util.V_JsonUtil; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; @@ -34,16 +31,17 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import dji.common.error.DJIError; import dji.common.error.DJISDKError; -import dji.common.useraccount.UserAccountState; -import dji.common.util.CommonCallbacks; import dji.log.DJILog; +import dji.log.GlobalConfig; import dji.sdk.base.BaseComponent; import dji.sdk.base.BaseProduct; import dji.sdk.sdkmanager.DJISDKInitEvent; import dji.sdk.sdkmanager.DJISDKManager; -import dji.sdk.useraccount.UserAccountManager; /** Main activity that displays three choices to user */ public class MainActivity extends Activity implements View.OnClickListener, PopupMenu.OnMenuItemClickListener { @@ -57,15 +55,14 @@ public class MainActivity extends Activity implements View.OnClickListener, Popu public void onRegister(DJIError error) { isRegistrationInProgress.set(false); if (error == DJISDKError.REGISTRATION_SUCCESS) { - loginAccount(); DJISDKManager.getInstance().startConnectionToProduct(); Toast.makeText(getApplicationContext(), "SDK registration succeeded!", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(), - "Registration failed: " + error.getDescription(), - Toast.LENGTH_LONG).show(); + "SDK registration failed, check network and retry!" + error.getDescription(), + Toast.LENGTH_LONG).show(); } } @Override @@ -74,14 +71,13 @@ public void onProductDisconnect() { "product disconnect!", Toast.LENGTH_LONG).show(); } - @Override public void onProductConnect(BaseProduct product) { Toast.makeText(getApplicationContext(), "product connect!", Toast.LENGTH_LONG).show(); } - + @Override public void onProductChanged(BaseProduct product) { @@ -99,34 +95,19 @@ public void onComponentChange(BaseProduct.ComponentKey key, @Override public void onInitProcess(DJISDKInitEvent event, int totalProcess) { - + Toast.makeText(getApplicationContext(), + "onInitProcess," + event + "totalProcess," + totalProcess, + Toast.LENGTH_LONG).show(); } @Override public void onDatabaseDownloadProgress(long current, long total) { - + Toast.makeText(getApplicationContext(), + "onDatabaseDownloadProgress" + (int) (100 * current / total), + Toast.LENGTH_LONG).show(); } }; - private void loginAccount(){ - UserAccountManager.getInstance().logIntoDJIUserAccount(this, - new CommonCallbacks.CompletionCallbackWith() { - @Override - public void onSuccess(final UserAccountState userAccountState) { - Toast.makeText(getApplicationContext(), - "Login Success!", - Toast.LENGTH_LONG).show(); - } - @Override - public void onFailure(DJIError error) { - Toast.makeText(getApplicationContext(), - "Login Error!", - Toast.LENGTH_LONG).show(); - } - }); - - } - public static boolean isStarted() { return isAppStarted; } @@ -142,7 +123,6 @@ public static boolean isStarted() { Manifest.permission.BLUETOOTH, // Bluetooth connected products Manifest.permission.BLUETOOTH_ADMIN, // Bluetooth connected products Manifest.permission.READ_EXTERNAL_STORAGE, // Log files - Manifest.permission.READ_PHONE_STATE, // Device UUID accessed upon registration Manifest.permission.RECORD_AUDIO // Speaker accessory }; private static final int REQUEST_PERMISSION_CODE = 12345; @@ -158,17 +138,17 @@ protected void onCreate(Bundle savedInstanceState) { findViewById(R.id.bt_customized_ui_widgets).setOnClickListener(this); findViewById(R.id.bt_map_widget).setOnClickListener(this); TextView versionText = (TextView) findViewById(R.id.version); - versionText.setText(getResources().getString(R.string.sdk_version, DJISDKManager.getInstance().getSDKVersion())); + versionText.setText("Debug:" + GlobalConfig.DEBUG + ", " + getResources().getString(R.string.sdk_version, DJISDKManager.getInstance().getSDKVersion())); bridgeModeEditText = (EditText) findViewById(R.id.edittext_bridge_ip); bridgeModeEditText.setText(PreferenceManager.getDefaultSharedPreferences(this).getString(LAST_USED_BRIDGE_IP,"")); bridgeModeEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH - || actionId == EditorInfo.IME_ACTION_DONE - || event != null - && event.getAction() == KeyEvent.ACTION_DOWN - && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { + || actionId == EditorInfo.IME_ACTION_DONE + || event != null + && event.getAction() == KeyEvent.ACTION_DOWN + && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { if (event != null && event.isShiftPressed()) { return false; } else { @@ -251,7 +231,7 @@ public void onRequestPermissionsResult(int requestCode, if (missingPermission.isEmpty()) { startSDKRegistration(); } else { - Toast.makeText(getApplicationContext(), "Missing permissions! Will not register SDK to connect to aircraft.", Toast.LENGTH_LONG).show(); + Toast.makeText(getApplicationContext(), "Missing permissions! Will not register SDK to connect to aircraft." + V_JsonUtil.toJson(missingPermission), Toast.LENGTH_LONG).show(); } } diff --git a/sample/app/src/main/java/com/dji/ux/sample/MapWidgetActivity.java b/sample/app/src/main/java/com/dji/ux/sample/MapWidgetActivity.java index 5be7f98..2ef7a68 100644 --- a/sample/app/src/main/java/com/dji/ux/sample/MapWidgetActivity.java +++ b/sample/app/src/main/java/com/dji/ux/sample/MapWidgetActivity.java @@ -10,9 +10,6 @@ import android.graphics.Color; import android.graphics.drawable.VectorDrawable; import android.os.Bundle; -import androidx.annotation.ColorInt; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import android.view.View; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; @@ -54,6 +51,9 @@ import java.util.List; import java.util.Random; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import dji.common.flightcontroller.flyzone.FlyZoneCategory; import dji.ux.widget.MapWidget; @@ -70,7 +70,8 @@ public class MapWidgetActivity extends Activity implements CompoundButton.OnChec private int[] iconIds = {R.id.icon_1, R.id.icon_2, R.id.icon_3, R.id.icon_4, R.id.icon_5}; public static final String MAP_PROVIDER = "MapProvider"; - private Spinner iconSpinner, lineSpinner; + private Button flyZoneButton; + private Spinner mapSpinner, iconSpinner, lineSpinner; private SeekBar lineWidthPicker; private int lineWidthValue; private TextView lineColor; @@ -90,11 +91,11 @@ public class MapWidgetActivity extends Activity implements CompoundButton.OnChec public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_map_widget); - mapWidget = findViewById(R.id.map_widget); + mapWidget = (MapWidget) findViewById(R.id.map_widget); markerList = new ArrayList<>(); MapWidget.OnMapReadyListener onMapReadyListener = new MapWidget.OnMapReadyListener() { @Override - public void onMapReady(@NonNull final DJIMap map) { + public void onMapReady(@NonNull DJIMap map) { map.setMapType(DJIMap.MapType.NORMAL); map.setOnMarkerDragListener(new DJIMap.OnMarkerDragListener() { @@ -145,7 +146,7 @@ public void onMapClick(DJILatLng djiLatLng) { switch (mapProvider) { case 0: boolean success = setIsolatedDiskCacheRootPath( - getExternalFilesDir(null) + File.separator + ".here-maps-cache"); + getExternalFilesDir(null) + File.separator + ".here-maps"); if (success) { mapWidget.initHereMap(onMapReadyListener); } @@ -156,9 +157,8 @@ public void onMapClick(DJILatLng djiLatLng) { case 2: mapWidget.initAMap(onMapReadyListener); break; - default: case 3: - //TODO: Remove this key before putting on github + default: mapWidget.initMapboxMap(onMapReadyListener, getResources().getString(R.string.mapbox_id)); break; } @@ -175,22 +175,22 @@ public void onMapClick(DJILatLng djiLatLng) { ((CheckBox) findViewById(R.id.flyzone_legend)).setOnCheckedChangeListener(this); ((CheckBox) findViewById(R.id.login_state_indicator)).setOnCheckedChangeListener(this); ((RadioGroup) findViewById(R.id.map_center_selector)).setOnCheckedChangeListener(this); - scrollView = findViewById(R.id.settings_scroll_view); - btnPanel = findViewById(R.id.btn_settings); + scrollView = (ScrollView) findViewById(R.id.settings_scroll_view); + btnPanel = (ImageButton) findViewById(R.id.btn_settings); btnPanel.setOnClickListener(this); findViewById(R.id.clear_flight_path).setOnClickListener(this); - iconSpinner = findViewById(R.id.icon_spinner); + iconSpinner = (Spinner) findViewById(R.id.icon_spinner); iconSpinner.setOnItemSelectedListener(this); - Spinner mapSpinner = findViewById(R.id.map_spinner); + mapSpinner = (Spinner) findViewById(R.id.map_spinner); mapSpinner.setSelection(0, false); // so the listener won't be called before the map is initialized mapSpinner.setOnItemSelectedListener(this); findViewById(R.id.replace).setOnClickListener(this); - selectedIcon = findViewById(R.id.icon_1); + selectedIcon = (ImageView) findViewById(R.id.icon_1); for (int id : iconIds) { findViewById(id).setOnClickListener(this); } findViewById(R.id.icon_1).setSelected(true); - Button flyZoneButton = findViewById(R.id.btn_fly_zone); + flyZoneButton = (Button) findViewById(R.id.btn_fly_zone); mapWidget.showAllFlyZones(); flyZoneButton.setOnClickListener(new View.OnClickListener() { @Override @@ -199,11 +199,11 @@ public void onClick(View v) { } }); - lineSpinner = findViewById(R.id.line_spinner); + lineSpinner = (Spinner) findViewById(R.id.line_spinner); lineSpinner.setOnItemSelectedListener(this); - lineWidthPicker = findViewById(R.id.line_width_picker); + lineWidthPicker = (SeekBar) findViewById(R.id.line_width_picker); lineWidthPicker.setOnSeekBarChangeListener(this); - lineColor = findViewById(R.id.line_color); + lineColor = (TextView) findViewById(R.id.line_color); lineColor.setOnClickListener(this); } @@ -296,8 +296,8 @@ public void onClick(View view) { } private void movePanel() { - int translationStart; - int translationEnd; + int translationStart = 0; + int translationEnd = 0; if (isPanelOpen) { translationStart = 0; translationEnd = -scrollView.getWidth(); @@ -308,7 +308,7 @@ private void movePanel() { translationEnd = 0; } TranslateAnimation animate = new TranslateAnimation( - translationStart, translationEnd, 0, 0); + translationStart, translationEnd, 0, 0); animate.setDuration(300); animate.setFillAfter(true); animate.setAnimationListener(new Animation.AnimationListener() { @@ -501,8 +501,8 @@ private void addOverlay() { aMap = (AMap) mapWidget.getMap().getMap(); com.amap.api.maps.model.LatLng[] latlngs = new com.amap.api.maps.model.LatLng[500]; for (int i = 0; i < 500; i++) { - double x_; - double y_; + double x_ = 0; + double y_ = 0; x_ = Math.random() * 0.5 - 0.25; y_ = Math.random() * 0.5 - 0.25; latlngs[i] = new com.amap.api.maps.model.LatLng(testLat + x_, testLng + y_); diff --git a/sample/app/src/main/java/com/dji/ux/sample/custom/CustomizedBatteryWidget.java b/sample/app/src/main/java/com/dji/ux/sample/custom/CustomizedBatteryWidget.java index 311d3bc..48c6262 100644 --- a/sample/app/src/main/java/com/dji/ux/sample/custom/CustomizedBatteryWidget.java +++ b/sample/app/src/main/java/com/dji/ux/sample/custom/CustomizedBatteryWidget.java @@ -1,27 +1,24 @@ package com.dji.ux.sample.custom; import android.content.Context; -import android.graphics.Color; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.dji.ux.sample.R; - -import dji.ux.model.base.BaseDynamicWidgetAppearances; -import dji.ux.widget.BatteryWidget; import dji.common.battery.ConnectionState; /** * Override default battery widget with custom UI resources and logic */ -public class CustomizedBatteryWidget extends BatteryWidget { +public class CustomizedBatteryWidget extends dji.ux.widget.BatteryWidget { private TextView batteryValue; private ImageView batteryIcon; private int batteryIconRes; private int batteryIconErrorRes; + private static final String TAG = CustomizedBatteryWidget.class.getSimpleName(); public CustomizedBatteryWidget(Context context) { this(context, null, 0); @@ -46,11 +43,6 @@ public void initView(Context context, AttributeSet attrs, int defStyle) { batteryIcon.setImageResource(R.mipmap.battery_error); } - @Override - protected BaseDynamicWidgetAppearances getWidgetAppearances() { - return null; - } - /** Called when battery percentage changes */ @Override public void onBatteryPercentageChange(int percentage) { @@ -101,4 +93,5 @@ private void updateBatteryIcon() { batteryIcon.setImageResource(batteryIconRes); } } + } diff --git a/sample/app/src/main/res/drawable/selector_icon_bg.xml b/sample/app/src/main/res/drawable/selector_icon_bg.xml index ceaf0fd..4c68531 100644 --- a/sample/app/src/main/res/drawable/selector_icon_bg.xml +++ b/sample/app/src/main/res/drawable/selector_icon_bg.xml @@ -3,14 +3,14 @@ - + - + diff --git a/sample/app/src/main/res/layout/activity_customized_widgets.xml b/sample/app/src/main/res/layout/activity_customized_widgets.xml index 975a0ca..b66bec1 100644 --- a/sample/app/src/main/res/layout/activity_customized_widgets.xml +++ b/sample/app/src/main/res/layout/activity_customized_widgets.xml @@ -1,14 +1,20 @@ - + xmlns:tools="http://schemas.android.com/tools" + xmlns:custom="http://schemas.android.com/apk/res-auto" + android:id="@+id/activity_customized_widgets" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="#242d34" + android:orientation="horizontal" + tools:context="com.dji.ux.sample.CustomizedWidgetsActivity"> + + + android:layout_height="22dp" + /> - + + + + + \ No newline at end of file diff --git a/sample/app/src/main/res/layout/activity_default_widgets.xml b/sample/app/src/main/res/layout/activity_default_widgets.xml index 7997afc..e2976aa 100644 --- a/sample/app/src/main/res/layout/activity_default_widgets.xml +++ b/sample/app/src/main/res/layout/activity_default_widgets.xml @@ -1,24 +1,24 @@ + xmlns:tools="http://schemas.android.com/tools" + xmlns:custom="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@color/background_blue" + android:id="@+id/root_view" + tools:context=".MainActivity"> + android:layout_height="match_parent" + android:gravity = "center"> @@ -26,7 +26,7 @@ + android:layout_height="match_parent" /> + custom:videoSource="secondary" + custom:automaticHide="true"/> + android:layout_height="match_parent" /> + @@ -148,7 +157,7 @@ @@ -166,12 +175,12 @@ + tools:ignore="RtlHardcoded" /> + android:layout_height="25dp" + tools:ignore="TouchTargetSizeCheck" /> + android:layout_height="22dp" + tools:ignore="TouchTargetSizeCheck" /> + + + + + + + + + - \ No newline at end of file + + + + diff --git a/sample/app/src/main/res/layout/activity_map_widget.xml b/sample/app/src/main/res/layout/activity_map_widget.xml index bd6173e..5e77977 100644 --- a/sample/app/src/main/res/layout/activity_map_widget.xml +++ b/sample/app/src/main/res/layout/activity_map_widget.xml @@ -8,7 +8,6 @@ android:id="@+id/map_widget" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" /> @@ -65,7 +64,6 @@ android:background="@drawable/selector_map_type_bg" android:button="@null" android:checked="true" - android:drawableLeft="@drawable/ic_compass_aircraft" android:drawableStart="@drawable/ic_compass_aircraft" android:padding="8dp" android:textColor="@drawable/selector_map_type_text" /> @@ -76,7 +74,6 @@ android:layout_height="40dp" android:background="@drawable/selector_map_type_bg" android:button="@null" - android:drawableLeft="@drawable/ic_compass_home" android:drawableStart="@drawable/ic_compass_home" android:padding="8dp" android:textColor="@drawable/selector_map_type_text" /> @@ -87,7 +84,6 @@ android:layout_height="40dp" android:background="@drawable/selector_map_type_bg" android:button="@null" - android:drawableLeft="@android:drawable/ic_notification_clear_all" android:drawableStart="@android:drawable/ic_notification_clear_all" android:padding="8dp" android:textColor="@drawable/selector_map_type_text" /> diff --git a/sample/app/src/main/res/layout/dialog_fly_zone.xml b/sample/app/src/main/res/layout/dialog_fly_zone.xml index c2b25e6..1e8cf33 100644 --- a/sample/app/src/main/res/layout/dialog_fly_zone.xml +++ b/sample/app/src/main/res/layout/dialog_fly_zone.xml @@ -1,7 +1,7 @@ + android:layout_width="match_parent" + android:layout_height="match_parent"> + android:layout_height="2dp"> + + + android:layout_height="2dp"> + + \ No newline at end of file diff --git a/sample/app/src/main/res/values-zh-rCN/string.xml b/sample/app/src/main/res/values-zh-rCN/string.xml new file mode 100644 index 0000000..8089ffd --- /dev/null +++ b/sample/app/src/main/res/values-zh-rCN/string.xml @@ -0,0 +1,68 @@ + + + UXSDK示例代码 + 选择全部 + 不选 + 搜索 + 运行 + 主云台名称 + 副云台名称 + 主云台位置 + 副云台位置 + 主云台过曝警告 + 副云台过曝警告 + 对焦点 + 测光点 + 云台控制 + 显示网格线 + 显示中心点 + 更改网格线种类: + 更改中心点种类: + 更改中心点颜色: + 更改视频源: + 测试不同尺寸的FPV视图: + + 平行 + 对角线平行 + 自动 + + + 改变尺寸 + 版本:%1$s + WSBridge IP + Google Maps + Here Maps + AMaps + Mapbox + 地图尚未初始化 + 返航点方向 + 自动帧 + 解禁飞行区 + 显示飞行轨迹 + 显示返航点 + 显示云台偏航角 + 清除飞行轨迹 + 替换图标 + 飞行区 + 飞行区图例 + DJI账号登录器 + 新颜色 + 同步 + + 飞行器 + 返航点 + 云台偏航角 + 锁定的飞行区 + 解禁的飞行区 + + + 标准 + 卫星 + 混合 + + + 返航点方向 + 飞行轨迹 + 飞行区边界 + + diff --git a/sample/app/src/main/res/values/strings.xml b/sample/app/src/main/res/values/strings.xml index 61fb571..5f71355 100644 --- a/sample/app/src/main/res/values/strings.xml +++ b/sample/app/src/main/res/values/strings.xml @@ -1,5 +1,5 @@ - DJI UX Sample + DJI Sample App Select All Select None Search @@ -8,12 +8,16 @@ Secondary Camera Name Primary Camera Side Secondary Camera Side + Primary Overexposure Warning + Secondary Overexposure Warning Focus Point Metering Point Gimbal Control Display Grid + Display Center Point Change Grid Overlay Type: Change Center Point Type: + Change Center Point Color: Change Video Source: Test FPV widget view in different size: None @@ -62,4 +66,5 @@ Please enter the map box key here. + Please enter the fack book key here.