B4A Library DJI Drones UI - use DJI widgets in your App

This Library is based on the Source (thanx for sharing it!!) of the DJI Library posted here.
@Erel will combine the two libraries at some time. My permission is granted for this.

The difference in the two libs are that the DJI Drones UI Lib is using the Mobile UI Library from DJI. With the Mobile UI Library you are able to use some nice UI Widgets in your App.

Find out more about the UI Widget and their prefered Sizes here.

See this reference for a complete list of all widgets.
Please note that the "Panels" are not really working for me. I´m still investigating. But away from that there are some really nice to have Widgets and i do not want to hide them from you.

Here some examples:

DJITakeOffWidget

TAKEOFF.gif



DJIReturnHomeWidget

HOME.gif



DJIFlightModeWidget

FLIGHTMODE.gif





To use this Library instead of the Original DJI Library you need to replace the DJI.xml and DJI.jar with the ones attached to this post.
The Setup in the manifesteditor are the same. You can just use the Example

Additional you need to
download this Archive
(which contains the AAR and the additional jar). Copy all files in the zip to your additional Library folder.


DJI
Author:
Erel (Base) DonManfred (UIwidgets and additions)
Version: 4.5
  • CameraSettingAdvancedPanel
  • CameraSettingExposurePanel
  • DJICameraControlsWidget
  • DJIBatteryWidget
  • DJICameraControlsWidget
  • DJICompassWidget
  • DJIConnectionWidget
  • DJIDashboardWidget
  • DJIDistanceHomeWidget
  • DJIDistanceRCWidget
  • DJIExposureSettingsMenu
  • DJIFPVOverlayWidget
  • DJIFPVWidget
  • DJIFlightModeWidget
  • DJIFocusModeWidget
  • DJIGPSSignalWidget
  • DJIHorizontalVelocityWidget
  • DJIPictureVideoSwitch
  • DJIPreFlightCheckListPanel
  • DJIPreFlightStatusWidget
  • DJIRemainingFlightTimeWidget
  • DJIRemoteControlSignalWidget
  • DJIReturnHomeWidget
  • DJIVerticalVelocityWidget
  • DJIVideoSignalWidget
  • DJIWiFiSignalWidget
  • DJIAircraft
    Events:
    • BatteryState (Battery As Object, RemainingPercentage As Int)
    • ProductConnectivityChanged (Connected As Boolean)
    • Result (Success As Boolean, ErrorMessage As String)
    • ResultWithValue (Success As Boolean, ErrorMessage As String, Value As Object)
    Methods:
    • GetName As Object
      Gets the aircraft name. The ResultWithValue event will be raised.
      Returns an object that can be used as the sender filter parameter.
      Example:<code>
      Wait for (aircraft.GetName) Aircraft_ResultWithValue (Success As Boolean, ErrorMessage As String, Value As Object)
      If Success Then
      aircraftName = Value
      End If</code>
    • Initialize (EventName As String, AircraftData As Object)
      Initializes the object.
      EventName - Sets the subs that will handle the events.
      AircraftData - The parameter passed to DJISDKManager ProductChanged event.
    • IsInitialized As Boolean
    • RegisterBatteryStateEvent
      Registers the battery state listener.
    Properties:
    • BatteryReady As Boolean [read only]
      Returns true if the battery is ready.
    • CameraReady As Boolean [read only]
      Returns true if the camera is ready.
    • Connected As Boolean [read only]
    • Model As String [read only]
      Returns the model.
    • Tag As Object
  • DJIAltitudeWidget
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Padding()() As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
  • DJIAttitude
    Methods:
    • IsInitialized As Boolean
    Properties:
    • Pitch As Double [read only]
    • Roll As Double [read only]
    • Yaw As Double [read only]


  • DJICamera
    Events:
    • FrameReceived (Data() As Byte)
    Methods:
    • CreateVideoView As ConcreteViewWrapper
      Creates the view that will show the camera feed.
    • Initialize (EventName As String, Aircraft As DJIAircraftWrapper)
    • IsInitialized As Boolean
  • DJICameraCaptureWidget
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Padding()() As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Padding()() As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
  • DJIFlightController
    Events:
    • IMUStateChanged (State As DJIIMUState)
    • Result (Success As Boolean, ErrorMessage As String)
    • ResultWithValue (Success As Boolean, ErrorMessage As String, Value As Object)
    Methods:
    • AutoLanding As Object
      Starts an auto-landing action. The Result event will be raised.
      Returns an object that can be used as the sender filter parameter.
    • GetLEDsEnabled As Object
      Gets the LEDs status. The ResultWithValue event will be raised.
      Returns an object that can be used as the sender filter parameter.
      Example:<code>
      Wait For(controller.GetLEDsEnabled) Controller_ResultWithValue (Success As Boolean, ErrorMessage As String, Value As Object)
      If Success Then
      Log($"LED status: " ${Value}"$)
      End If</code>
    • GoHomeCancel As Object
      Cancels a go home action.
      The Result event will be raised.
    • GoHomeStart As Object
      Starts a go home action.
      The Result event will be raised.
    • Initialize (EventName As String, Aircraft As DJIAircraftWrapper)
      Initializes the flight controller.
    • IsInitialized As Boolean
    • SetGoHomeHeightInMeters (Height As Float) As Object
      Sets the go home flight height. Should be between 20 to 500.
      The Result event will be raised.
    • SetHomeLocationUsingAircraftCurrentLocation As Object
      Sets the home location based on the current aircraft location.
      The Result event will be raised.
      Example:<code>
      Dim sf As Object = controller.SetHomeLocationUsingAircraftCurrentLocation
      Wait For (sf) Controller_Result (Success As Boolean, ErrorMessage As String)
      If Success Then
      Log("Home location set.")
      Else
      Log("Error: " & ErrorMessage)
      End If</code>
    • SetLEDsEnabled (Enabled As Boolean) As Object
      Sets the LEDS status. The Result event will be raised.
      Returns an object that can be used as the sender filter parameter.
      Example: <code>
      Wait For (controller.SetLEDsEnabled(True)) Controller_Result (Success As Boolean, ErrorMessage As String)
      Log($"LED state changed. Success = ${Success}"$)</code>
    • TakeOff As Object
      Starts a takeoff action. The engine will start automatically.
      The Result event will be raised.
      Returns an object that can be used as the sender filter parameter.
    Properties:
    • Connected As Boolean [read only]
    • CurrentState As DJIFlightControllerCurrentStateWrapper [read only]
      Returns the current state.
    • Heading As Double [read only]
      Returns the aircraft heading.
    • SimulatorStarted As Boolean [read only]
      Returns true if the simulator has started.
    • Tag As Object
  • DJIFlightControllerCurrentState
    Methods:
    • IsInitialized As Boolean
    Properties:
    • AircraftLocation As DJILocation3DWrapper [read only]
      Returns the aircraft location.
    • AreMotorsOn As Boolean [read only]
      Returns true if the motors are on.
    • Attitude As DJIAttitudeWrapper [read only]
      Returns the aircraft attitude (pitch, roll and yaw).
    • FlightMode As String [read only]
      Returns the current flight mode.
      Possible values: Manual, Atti, AttiCourseLock, AttiHover, Hover, GPSBlake, GPSAtti, GPSCourseLock, GPSHomeLock, GPSHotPoint,
      AssistedTakeOff, AutoTakeOff, AutoLanding, AttiLanding, GPSWaypoint, GoHome, ClickGo, Joystick, AttiLimited,
      GPSAttiLimited, GPSFollowMe, Tracking, Pointing, PANO, Farming, FPV, GPSSport, GPSNovice,
      ConfirmLanding, TerrainTracking, NaviAdvGoHome, NaviAdvLanding, TripodGPS, TrackHeadLock, MotorsJustStarted, GPSGentle, Unknown
    • Flying As Boolean [read only]
      Returns True if the aircraft is flying.
    • GPSStatus As Int [read only]
      Returns 255 if there is no signal. Otherwise returns a value between 0 (weak signal) to 5 (strong signal).
    • GoHomeHeight As Float [read only]
      Returns the go home height in meters.
    • GoingHome As Boolean [read only]
      Returns True if the aircraft is going home.
    • HomeLocation As DJILocation2DWrapper [read only]
      Returns the home location.
    • HomeLocationSet As Boolean [read only]
      Returns true if the home location was set.
    • IMUPreheating As Boolean [read only]
      Returns True if the IMU is preheating.
    • SatelliteCount As Double [read only]
      Returns the number of GPS satellites found.
    • VelocityX As Double [read only]
      Returns the x-axis velocity measured in meters per second.
    • VelocityY As Double [read only]
      Returns the y-axis velocity measured in meters per second.
    • VelocityZ As Double [read only]
      Returns the z-axis velocity measured in meters per second.

  • DJIHotpointMissionOperator
    Events:
    • MissionFinish (Error As String)
    • MissionStart
    • MissionUpdate (Error As String, CurrentState As String, PreviousState As String, Radius As Float)
    • Result (Success As Boolean, ErrorMessage As String)
    • ResultWithValue (Success As Boolean, ErrorMessage As String, Value As Object)
    Methods:
    • Initialize (EventName As String)
      Initializes the mission operator.
    • IsInitialized As Boolean
    • Pause As Object
      Pauses a mission. The Result event will be raised.
    • Resume As Object
      Resumes a mission. The Result event will be raised.
    • StartMission (hotpointLat As Double, hotpointLon As Double, altitude As Double, radius As Double, angularVelocity As Float, isClockwise As Boolean, startPoint As String, heading As String) As Object
      Starts a mission. The Result event will be raised.
    • Stop As Object
      Stops a mission. The Result event will be raised.
    Properties:
    • Connected As Boolean [read only]
    • Tag As Object

  • DJIIMUState
    Methods:
    • IsInitialized As Boolean
    Properties:
    • AccelerometerStatus As String [read only]
      Returns one of the following values:
      UNKNOWN, DISCONNECTED, CALIBRATING, CALIBRATION_FAILED, DATA_EXCEPTION, WARMING_UP, IN_MOTION, NORMAL_BIAS, MEDIUM_BIAS, LARGE_BIAS.
    • CalibrationStatus As String [read only]
      Returns one of the following values:
      NONE, CALIBRATING, SUCCESSFUL, FAILED, UNKNOWN.
    • GyroscopeState As String [read only]
      Returns one of the following values:
      UNKNOWN, DISCONNECTED, CALIBRATING, CALIBRATION_FAILED, DATA_EXCEPTION, WARMING_UP, IN_MOTION, NORMAL_BIAS, MEDIUM_BIAS, LARGE_BIAS.

  • DJILocation2D
    Methods:
    • IsInitialized As Boolean
    Properties:
    • Latitude As Double [read only]
    • Longitude As Double [read only]

  • DJILocation3D
    Methods:
    • IsInitialized As Boolean
    Properties:
    • Altitude As Float [read only]
      Returns the altitude measured by barometer in meters (relative to the take off location).
    • Latitude As Double [read only]
    • Longitude As Double [read only]


  • DJISDKManager
    Events:
    • ComponentConnectivityChanged (Connected As Boolean)
    • ProductChanged (AircraftData As Object)
    • ProductConnectivityChanged (Connected As Boolean)
    • ProductName (Success As Boolean, Name As String)
    • RegisteredResult (Success As Boolean, ErrorMessage As String)
    Methods:
    • Initialize (EventName As String)
      Initializes the DJI SDK. The RegisteredResult event will be raised.
      Note that an internet connection is required on the first run.
    • StartConnectionToProduct
      Tries to connect to the product. The ProductChanged event will be raised.
    Properties:
    • Registered As Boolean [read only]
  • DJITakeOffWidget
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Padding()() As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int





  • DJIWaypoint
    Methods:
    • AddAction (Action As WaypointActionType, Parameter As Int)
      Adds an action that will be executed when the aircraft reaches the point.
      Action - One of the following values:
      STAY - Stays at the current point. Parameter = Period in milliseconds.
      START_TAKE_PHOTO - Starts to shoot a photo. Parameter is ignored.
      START_RECORD - Starts recordsing. Parameter is ignored.
      STOP_RECORD - Stops recording. Parameter is ignored.
      ROTATE_AIRCRAFT - Rotates the aircraft's yaw. Parameter should be between -180 to 180.
      GIMBAL_PITCH - Rotates the gimbal's pitch. Parameter should be between -90 to 0.
    • Initialize (Latitude As Double, Longitude As Double, Altitude As Float)
      Initializes the waypoint with the given coordinate and altitude (in meters).
    • IsInitialized As Boolean
    Properties:
    • TurnMode As String
    • actionRepeatTimes As Int
    • actionTimeoutInSeconds As Int
    • cornerRadiusInMeters As Float
    • gimbalPitch As Float
    • heading As Float
    • shootPhotoDistanceInterval As Float
    • shootPhotoTimeInterval As Float
    • speed As Float
    • waypointActions As List [read only]

  • DJIWaypointMissionBuilder
    Methods:
    • AddWaypoint (Waypoint As WaypointWrapper)
      Adds a waypoint.
    • Initialize
    • IsInitialized As Boolean
    • SetFinishAction (Action As WaypointMissionFinishedAction)
      Action that will be executed when the mission finishes.
      NO_ACTION - No further action will be taken on completion of mission.
      GO_HOME - The aircraft will go home and land.
      AUTO_LAND - The aircraft will land at the last waypoint.
      GO_FIRST_WAYPOINT - The aircraft will go to the first waypoint.
      CONTINUE_UNTIL_END - Mission will not end until StopMission is called.
    • setPointOfInterest (poiLat As Double, poiLon As Double)
    Properties:
    • AutoFlightSpeed As Float
      Gets or sets the auto flight speed (m/s). This is the default flight speed.
      Valid values are between -15 to 15.
    • HeadingMode As WaypointMissionHeadingMode
    • MaxFlightSpeed As Float
      Gets or sets the maximum flight speed (m/s). Maximum speed is achieved by pushing the throttle joystick.
    • PointOfInterest As LocationCoordinate2D [read only]
  • DJIWaypointMissionOperator
    Events:
    • MissionFinish (Error As String)
    • MissionProgress (ExecutionEvent As Object, TargetWaypointIndex As Int)
    • MissionStart
    • Result (Success As Boolean, ErrorMessage As String)
    • ResultWithValue (Success As Boolean, ErrorMessage As String, Value As Object)
    Methods:
    • Initialize (EventName As String)
      Initializes the mission operator.
    • IsInitialized As Boolean
    • LoadMission (MissionBuilder As WaypointMissionBuilderWrapper)
      Loads a mission. The next step is to upload it with UploadMission.
    • PauseMission As Object
      Pauses a mission. The Result event will be raised.
    • ResumeMission As Object
      Resumes a mission. The Result event will be raised.
    • StartMission As Object
      Starts a mission. The Result event will be raised.
    • StopMission As Object
      Stops a mission. The Result event will be raised.
    • UploadMission As Object
      Uploads a mission. The Result event will be raised.
    Properties:
    • Connected As Boolean [read only]
    • MissionState As String [read only]
      Returns the mission state.
      One of the following values: UNKNOWN, DISCONNECTED, NOT_SUPPORTED, RECOVERING, READY_TO_UPLOAD, UPLOADING, READY_TO_EXECUTE, EXECUTING, EXECUTION_PAUSED.
    • Tag As Object
 

Attachments

  • DJIUIV4.5.zip
    63.8 KB · Views: 653
  • src45.zip
    37 KB · Views: 647
Last edited:

DonManfred

Expert
Licensed User
Longtime User

shb777

Active Member
Licensed User
Longtime User
ok here's the program. I didn't know about the widgets preferred aspect ratio. I was making
them all square. This code isn't exactly what the pictures i uploaded before are.
i've made some changes since then. When I put the dashboard on the pnlCamera,
it shows up ok, but when I put it at the bottom of the mapfragment, it doesn't show up
at all. That's where I want to put it. Steve
 

Attachments

  • waldo - Copy.zip
    134.2 KB · Views: 432

shb777

Active Member
Licensed User
Longtime User
the panels did not work for me either. they are important. manfred, is it ok with you if i post to dji forum and include some of your source code?
 

PABLO2013

Well-Known Member
Licensed User
Longtime User
Sorry...i have notice the new ui (4.4 sdk) ....sorry you can update your library....many apologice...sorry and tks...in this year i will try it hard..
 

javiman6969

Member
Licensed User
Longtime User
Hi DonManfred !

Is it possible to download images from the SD from the DRON camera?
I am trying but it is very complex for me. I don't have much knowledge of JAVA.

Any example to guide me?
 
Top