dji-sdk / Mobile-UXSDK-Android

DJI Mobile UXSDK is a suite of product agnostic UI objects that fast tracks the development of Android applications using the DJI Mobile SDK.
Other
152 stars 110 forks source link

[Help] Issue with custom widgets #152

Open huongta157 opened 3 months ago

huongta157 commented 3 months ago

I customize the battery widget like this, but the battery widget is not showing Note: show normal when I used battery widget default Please help me check it.

class CustomBatteryWidget : BatteryWidget {

    constructor(context: Context) : super(context, null, 0)

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs, 0)
    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
        context,
        attrs,
        defStyle
    )

    private var textviewBatteryValue: TextView? = null

    override fun initView(context: Context, p1: AttributeSet, p2: Int) {
        Log.i(TAG, "initView: ")
        val view = LayoutInflater.from(context).inflate(R.layout.customized_battery_widget, this)
        textviewBatteryValue = view.findViewById<View>(R.id.textview_battery_value) as TextView
        val batteryIcon = view.findViewById<View>(R.id.imageview_battery_icon) as ImageView
        textviewBatteryValue?.text = "0%"
        batteryIcon.setImageResource(R.drawable.ic_mode_photo)
    }

    /** Called when battery percentage changes */
    override fun onBatteryPercentageChange(percentage: Int) {
        Log.i(TAG, "onBatteryPercentageChange textviewBatteryValue: $textviewBatteryValue")
        Log.i(TAG, "onBatteryPercentageChange percentage: $percentage")
        textviewBatteryValue?.text = "$percentage %"
    }

    /** Called when battery state changes from error to normal or vice versa */
    override fun onBatteryConnectionStateChange(status: ConnectionState?) {
        Log.i(TAG, "onBatteryConnectionStateChange: $status")
    }
}
<LinearLayout
        android:id="@+id/topWidgetBar"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:background="#80000000"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <xxx.xx.xx.CustomBatteryWidget
            android:layout_width="96dp"
            android:layout_height="28dp"
            custom:excludeView="singleVoltage|doubleVoltage" />
    </LinearLayout>
dji-dev commented 3 months ago

Agent comment from yating.liao in Zendesk ticket #103335:

Your code has overridden the original initView of BatteryWidget, causing changes in the initialization of the widget. We do not recommend doing this. Are you trying to implement your own battery component? In fact, we provide an open-source version that you can modify based on:https://github.com/dji-sdk/Mobile-UXSDK-Beta-Android

°°°

dji-dev commented 3 months ago

Agent comment from yating.liao in Zendesk ticket #103335:

The recommendation is not to make custom modifications on the controls of the UXSDK, but your requirements can be met with the open-source version. The open-source version includes most of the controls in the UXSDK.

°°°

huongta157 commented 3 months ago

@dji-dev I got it, thank you so much. I have a new question, How to update the flight mode (Normal/ Sport/ Cine) for drone? Is this SDK supported or not?

dji-dev commented 3 months ago

Agent comment from yating.liao in Zendesk ticket #103335:

Do you want to change the flight mode (Normal/ Sport/ Cine) through the SDK? This is not possible on the SDK as it can only listen to its changes. To make modifications, you will need to do it on the remote controller.

°°°

huongta157 commented 3 months ago

@dji-dev thank you so much

dji-dev commented 3 months ago

Agent comment from yating.liao in Zendesk ticket #103335:

I am glad to help you.

°°°

huongta157 commented 3 months ago

@dji-dev Is this SDK supported to zoom in/out camera?

dji-dev commented 3 months ago

Agent comment from yating.liao in Zendesk ticket #103335:

Could you please inform us about the model of the drone you are using? The SDK supports controlling the camera zoom.

°°°

huongta157 commented 3 months ago

Drone model: Dji Air 2s Could you share with me the widget/function to implement camera zoom?

dji-dev commented 3 months ago

Agent comment from yating.liao in Zendesk ticket #103335:

The UXSDK does not provide zoom widget. There is an article here that provides the interface for zooming on the DJI AIR 2S, which you can use as a basis for implementing zoom functionality. It is important to note that the DJI AIR 2S can only zoom in camera recording mode. https://sdk-forum.dji.net/hc/en-us/articles/10716410128537-How-does-DJI-Air-2S-zoom

°°°