Skip to content

Commit dedebdf

Browse files
authored
Merge pull request dji-sdk#76 from skycatchci/feature/h20-ui-widgets
features H20N Widgets
2 parents 30ac757 + 3d8c701 commit dedebdf

File tree

100 files changed

+5845
-224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+5845
-224
lines changed

android-uxsdk-beta-cameracore/src/main/java/dji/ux/beta/cameracore/base/DJIRulerView.java

Lines changed: 498 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package dji.ux.beta.cameracore.widget.cameracontrols.cameraswitch
2+
3+
import dji.common.camera.SettingsDefinitions
4+
import dji.keysdk.CameraKey
5+
import dji.keysdk.DJIKey
6+
import dji.ux.beta.core.base.DJISDKModel
7+
import dji.ux.beta.core.base.WidgetModel
8+
import dji.ux.beta.core.communication.ObservableInMemoryKeyedStore
9+
import dji.ux.beta.core.util.CameraUtil
10+
import dji.ux.beta.core.util.DataProcessor
11+
import dji.ux.beta.core.util.SettingDefinitions
12+
import io.reactivex.rxjava3.core.Flowable
13+
14+
class CameraIRSwitchModel constructor(
15+
djiSdkModel: DJISDKModel,
16+
keyedStore: ObservableInMemoryKeyedStore
17+
) : WidgetModel(djiSdkModel, keyedStore) {
18+
var lensIndex = 0
19+
var cameraIndex = 0
20+
val disPlayModelDataProcessor =
21+
DataProcessor.create(SettingsDefinitions.DisplayMode.OTHER)
22+
private val cameraTypeDataProcessor = DataProcessor.create(SettingsDefinitions.CameraType.OTHER)
23+
val isIRCameraVideoSourceDataProcessor = DataProcessor.create(false)
24+
var disPlayModelKey: DJIKey? = null
25+
26+
override fun inSetup() {
27+
disPlayModelKey = djiSdkModel.createLensKey(CameraKey.DISPLAY_MODE, cameraIndex, lensIndex)
28+
bindDataProcessor(disPlayModelKey!!, disPlayModelDataProcessor)
29+
val cameraTypeKey = CameraKey.create(CameraKey.CAMERA_TYPE,cameraIndex)
30+
bindDataProcessor(cameraTypeKey, cameraTypeDataProcessor)
31+
}
32+
33+
fun getDisPlayModel(): Flowable<SettingsDefinitions.DisplayMode> {
34+
return disPlayModelDataProcessor.toFlowable()
35+
}
36+
37+
fun getCameraTypeModel(): Flowable<SettingsDefinitions.CameraType> {
38+
return cameraTypeDataProcessor.toFlowable()
39+
}
40+
41+
fun updateCameraSource(
42+
cameraIndex: SettingDefinitions.CameraIndex,
43+
lensType: SettingsDefinitions.LensType
44+
) {
45+
this.cameraIndex = cameraIndex.index
46+
this.lensIndex = lensType.value()
47+
val irVideoCameraSource = CameraUtil.isIRVideoCameraSource(lensType)
48+
isIRCameraVideoSourceDataProcessor.onNext(irVideoCameraSource)
49+
restart()
50+
}
51+
52+
53+
fun setDisPlayMode(disPlayMode: SettingsDefinitions.DisplayMode) {
54+
var disPlayModeComparable = djiSdkModel.setValue(disPlayModelKey!!, disPlayMode)
55+
if (disPlayMode == SettingsDefinitions.DisplayMode.PIP) {
56+
val pipPositionCameraKey = djiSdkModel.createLensKey(
57+
CameraKey.PIP_POSITION,
58+
cameraIndex,
59+
lensIndex
60+
)
61+
disPlayModeComparable = disPlayModeComparable.andThen(
62+
djiSdkModel.setValue(
63+
pipPositionCameraKey,
64+
SettingsDefinitions.PIPPosition.SIDE_BY_SIDE
65+
)
66+
)
67+
}
68+
addDisposable(disPlayModeComparable.subscribe {
69+
70+
})
71+
}
72+
73+
override fun inCleanup() {
74+
75+
}
76+
77+
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package dji.ux.beta.cameracore.widget.cameracontrols.cameraswitch
2+
3+
import android.content.Context
4+
import android.util.AttributeSet
5+
import android.view.View
6+
import android.widget.TextView
7+
import dji.common.camera.SettingsDefinitions
8+
import dji.ux.beta.cameracore.R
9+
import dji.ux.beta.core.base.DJISDKModel
10+
import dji.ux.beta.core.base.SchedulerProvider
11+
import dji.ux.beta.core.base.widget.ConstraintLayoutWidget
12+
import dji.ux.beta.core.communication.ObservableInMemoryKeyedStore
13+
import dji.ux.beta.core.util.PopUtils
14+
import dji.ux.beta.core.util.SettingDefinitions
15+
import io.reactivex.rxjava3.core.Flowable
16+
import io.reactivex.rxjava3.functions.BiFunction
17+
18+
class CameraIRSwitchWidget @JvmOverloads constructor(
19+
context: Context,
20+
attrs: AttributeSet? = null,
21+
defStyleAttr: Int = 0
22+
) : ConstraintLayoutWidget<CameraIRSwitchWidget.ModelState>(context, attrs, defStyleAttr) {
23+
private var tvDisPlayModel: TextView? = null
24+
private val widgetModel by lazy {
25+
CameraIRSwitchModel(
26+
DJISDKModel.getInstance(),
27+
ObservableInMemoryKeyedStore.getInstance()
28+
)
29+
}
30+
31+
override fun initView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) {
32+
View.inflate(context, R.layout.uxsdk_ir_switch, this)
33+
tvDisPlayModel = findViewById(R.id.tvDisPlayMode)
34+
tvDisPlayModel?.setOnClickListener {
35+
val ppDisPlayModelSelect = inflate(context, R.layout.uxsdk_pp_pip_ir, null)
36+
val tvDisPlayMode = ppDisPlayModelSelect.findViewById<TextView>(R.id.tvNextDisPlayMode)
37+
PopUtils.getPp(ppDisPlayModelSelect, it)
38+
val value = widgetModel.disPlayModelDataProcessor.value
39+
if (value == SettingsDefinitions.DisplayMode.PIP) {
40+
tvDisPlayMode.setText(R.string.uxsdk_ir)
41+
} else {
42+
tvDisPlayMode.setText(R.string.uxsdk_split)
43+
}
44+
tvDisPlayMode.setOnClickListener {
45+
if (value == SettingsDefinitions.DisplayMode.PIP) {
46+
widgetModel.setDisPlayMode(SettingsDefinitions.DisplayMode.THERMAL_ONLY)
47+
} else {
48+
widgetModel.setDisPlayMode(SettingsDefinitions.DisplayMode.PIP)
49+
}
50+
PopUtils.closePP()
51+
}
52+
}
53+
}
54+
55+
override fun onAttachedToWindow() {
56+
super.onAttachedToWindow()
57+
if (!isInEditMode) {
58+
widgetModel.setup()
59+
}
60+
}
61+
62+
override fun onDetachedFromWindow() {
63+
super.onDetachedFromWindow()
64+
if (!isInEditMode) {
65+
widgetModel.cleanup()
66+
}
67+
}
68+
69+
fun updateCameraSource(
70+
cameraIndex: SettingDefinitions.CameraIndex,
71+
lensType: SettingsDefinitions.LensType
72+
) {
73+
widgetModel.updateCameraSource(cameraIndex, lensType)
74+
}
75+
76+
override fun reactToModelChanges() {
77+
addReaction(Flowable.combineLatest(widgetModel.getCameraTypeModel(),
78+
widgetModel.getDisPlayModel(),
79+
BiFunction<SettingsDefinitions.CameraType, SettingsDefinitions.DisplayMode, Pair<SettingsDefinitions.CameraType, SettingsDefinitions.DisplayMode>> { cameraType, displayMode ->
80+
Pair<SettingsDefinitions.CameraType, SettingsDefinitions.DisplayMode>(
81+
cameraType,
82+
displayMode
83+
)
84+
}).observeOn(SchedulerProvider.ui()).subscribe {
85+
val cameraType = it.first
86+
if (cameraType != SettingsDefinitions.CameraType.DJICameraTypeGD610TripleLight) {
87+
visibility = GONE
88+
return@subscribe
89+
}
90+
91+
val irCameraVideoSourceDataProcessor = widgetModel.isIRCameraVideoSourceDataProcessor
92+
visibility = if (irCameraVideoSourceDataProcessor.value) {
93+
val second = it.second
94+
val text = if (second == SettingsDefinitions.DisplayMode.PIP) {
95+
R.string.uxsdk_split
96+
} else {
97+
R.string.uxsdk_ir
98+
}
99+
tvDisPlayModel?.setText(text)
100+
VISIBLE
101+
} else {
102+
GONE
103+
}
104+
})
105+
106+
}
107+
108+
109+
override fun getIdealDimensionRatioString(): String {
110+
return "16:9"
111+
}
112+
113+
sealed class ModelState
114+
}

android-uxsdk-beta-cameracore/src/main/java/dji/ux/beta/cameracore/widget/cameracontrols/lenscontrol/LensControlModel.kt

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import dji.ux.beta.core.util.DataProcessor
1212
import dji.ux.beta.core.util.LogUtil
1313
import dji.ux.beta.core.util.SettingDefinitions
1414
import io.reactivex.rxjava3.core.Completable
15-
import java.util.concurrent.atomic.AtomicInteger
15+
import io.reactivex.rxjava3.core.Flowable
1616

1717
/**
1818
* Class Description
@@ -28,11 +28,17 @@ open class LensControlModel constructor(
2828
) : WidgetModel(djiSdkModel, keyedStore), ICameraIndex {
2929

3030
private var cameraIndex = SettingDefinitions.CameraIndex.CAMERA_INDEX_0.index
31+
private val thermalKeyIndex = 1
32+
private var disPlayModeLensKey: CameraKey? = null
33+
private var disPlayModeRangeLensKey: CameraKey? = null
3134

3235
val cameraTypeProcessor: DataProcessor<SettingsDefinitions.CameraType> = DataProcessor.create(SettingsDefinitions.CameraType.OTHER)
3336
val cameraVideoStreamSourceProcessor: DataProcessor<CameraVideoStreamSource> = DataProcessor.create(CameraVideoStreamSource.UNKNOWN)
3437
val cameraVideoStreamSourceRangeProcessor: DataProcessor<Array<CameraVideoStreamSource>> = DataProcessor.create(arrayOf())
3538

39+
var cameraDisPlayMode = DataProcessor.create(SettingsDefinitions.DisplayMode.OTHER)
40+
var cameraDisPlayModeRange: DataProcessor<Array<SettingsDefinitions.DisplayMode>> = DataProcessor.create(arrayOf())
41+
3642
override fun getCameraIndex() = SettingDefinitions.CameraIndex.find(cameraIndex)
3743

3844
override fun getLensType() = SettingsDefinitions.LensType.UNKNOWN
@@ -47,8 +53,37 @@ open class LensControlModel constructor(
4753

4854
override fun inSetup() {
4955
bindDataProcessor(CameraKey.create(CameraKey.CAMERA_TYPE, cameraIndex),cameraTypeProcessor)
50-
bindDataProcessor(CameraKey.create(CameraKey.CAMERA_VIDEO_STREAM_SOURCE, cameraIndex),cameraVideoStreamSourceProcessor)
51-
bindDataProcessor(CameraKey.create(CameraKey.CAMERA_VIDEO_STREAM_SOURCE_RANGE, cameraIndex),cameraVideoStreamSourceRangeProcessor)
56+
{
57+
val cameraType = it as SettingsDefinitions.CameraType
58+
if (cameraType == SettingsDefinitions.CameraType.DJICameraTypeWM247) {
59+
disPlayModeLensKey = djiSdkModel.createLensKey(
60+
CameraKey.DISPLAY_MODE,
61+
cameraIndex,
62+
thermalKeyIndex
63+
)
64+
disPlayModeRangeLensKey = djiSdkModel.createLensKey(
65+
CameraKey.DISPLAY_MODE_RANGE,
66+
cameraIndex,
67+
thermalKeyIndex
68+
)
69+
bindDataProcessor(disPlayModeRangeLensKey!!, cameraDisPlayModeRange)
70+
bindDataProcessor(disPlayModeLensKey!!, cameraDisPlayMode)
71+
72+
} else {
73+
bindDataProcessor(CameraKey.create(CameraKey.CAMERA_VIDEO_STREAM_SOURCE, cameraIndex),cameraVideoStreamSourceProcessor)
74+
bindDataProcessor(CameraKey.create(CameraKey.CAMERA_VIDEO_STREAM_SOURCE_RANGE, cameraIndex),cameraVideoStreamSourceRangeProcessor)
75+
}
76+
77+
}
78+
79+
}
80+
81+
fun getDisPlayMode(): Flowable<SettingsDefinitions.DisplayMode> {
82+
return cameraDisPlayMode.toFlowable()
83+
}
84+
85+
fun getDisPlayModeRange(): Flowable<Array<SettingsDefinitions.DisplayMode>> {
86+
return cameraDisPlayModeRange.toFlowable()
5287
}
5388

5489
override fun inCleanup() {
@@ -60,4 +95,12 @@ open class LensControlModel constructor(
6095
}
6196
return djiSdkModel.setValue(CameraKey.create(CameraKey.CAMERA_VIDEO_STREAM_SOURCE, cameraIndex), source)
6297
}
98+
99+
fun setCameraDisPlayMode(disPlayMode: SettingsDefinitions.DisplayMode): Completable {
100+
if (!djiSdkModel.isAvailable) {
101+
return Completable.complete()
102+
}
103+
return djiSdkModel.setValue(disPlayModeLensKey!!, disPlayMode)
104+
}
105+
63106
}

0 commit comments

Comments
 (0)