Skip to content

Commit a93f8d0

Browse files
committed
增加跟随配置的appkey、appsecret
1 parent d6e4aed commit a93f8d0

File tree

5 files changed

+130
-12
lines changed

5 files changed

+130
-12
lines changed

sdk/video-link-android/src/main/java/com/tencent/iot/video/link/consts/VideoConst.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ object VideoConst {
2626
const val VIDEO_WLAN_PARAMS = "params"
2727
const val VIDEO_WLAN_DEV_NAMES = "deviceName"
2828
const val MULTI_VIDEO_P2P_INFO = "p2pInfo"
29+
const val VIDEO_APP_KEY = "appKey"
30+
const val VIDEO_APP_SECRET = "appSecret"
2931
const val VIDEO_DEV_CHANNELS = "VideoDevChannels"
3032
}

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/VideoTestInputActivity.kt

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package com.tencent.iot.explorer.link.demo.video
22

33
import android.content.ClipboardManager
44
import android.content.Intent
5-
import android.os.Bundle
65
import android.text.InputType
76
import android.view.View
87
import android.widget.RadioButton
98
import androidx.core.content.ContextCompat
9+
import androidx.core.view.isVisible
1010
import com.tencent.iot.explorer.link.core.utils.SharePreferenceUtil
1111
import com.tencent.iot.explorer.link.demo.R
1212
import com.tencent.iot.explorer.link.demo.VideoBaseActivity
@@ -16,12 +16,14 @@ import com.tencent.iot.video.link.consts.VideoConst
1616
import kotlinx.coroutines.CoroutineScope
1717
import kotlinx.coroutines.MainScope
1818

19-
class VideoTestInputActivity : VideoBaseActivity<ActivityVideoTestInputBinding>(), CoroutineScope by MainScope() {
19+
class VideoTestInputActivity : VideoBaseActivity<ActivityVideoTestInputBinding>(),
20+
CoroutineScope by MainScope() {
2021

2122
private var isStartCross = false
2223
private var protocol = "auto"
2324

24-
override fun getViewBinding(): ActivityVideoTestInputBinding = ActivityVideoTestInputBinding.inflate(layoutInflater)
25+
override fun getViewBinding(): ActivityVideoTestInputBinding =
26+
ActivityVideoTestInputBinding.inflate(layoutInflater)
2527

2628
override fun initView() {
2729
with(binding) {
@@ -40,10 +42,22 @@ class VideoTestInputActivity : VideoBaseActivity<ActivityVideoTestInputBinding>(
4042
VideoConst.VIDEO_CONFIG,
4143
VideoConst.MULTI_VIDEO_P2P_INFO
4244
)
45+
val appKey = SharePreferenceUtil.getString(
46+
this@VideoTestInputActivity,
47+
VideoConst.VIDEO_CONFIG,
48+
VideoConst.VIDEO_APP_KEY
49+
)
50+
val appSecret = SharePreferenceUtil.getString(
51+
this@VideoTestInputActivity,
52+
VideoConst.VIDEO_CONFIG,
53+
VideoConst.VIDEO_APP_SECRET
54+
)
4355
vTitle.tvTitle.setText(R.string.iot_test_demo_name)
44-
productIdLayout.tvTip.setText(R.string.product_id)
45-
deviceNameLayout.tvTip.setText(R.string.device_name)
46-
p2pInfoLayout.tvTip.setText(R.string.p2p_info)
56+
productIdLayout.tvTip.setText(R.string.product_id_text)
57+
deviceNameLayout.tvTip.setText(R.string.device_name_text)
58+
p2pInfoLayout.tvTip.setText(R.string.p2p_info_text)
59+
appKeyLayout.tvTip.setText(R.string.app_key_text)
60+
appSecretLayout.tvTip.setText(R.string.app_secret)
4761
if (productId.isNotEmpty()) {
4862
productIdLayout.evContent.setText(productId)
4963
}
@@ -59,6 +73,16 @@ class VideoTestInputActivity : VideoBaseActivity<ActivityVideoTestInputBinding>(
5973
}
6074
p2pInfoLayout.evContent.setHint(R.string.hint_p2p_info)
6175
p2pInfoLayout.evContent.inputType = InputType.TYPE_CLASS_TEXT
76+
if (appKey.isNotEmpty()) {
77+
appKeyLayout.evContent.setText(appKey)
78+
}
79+
appKeyLayout.evContent.setHint(R.string.hint_app_key)
80+
appKeyLayout.evContent.inputType = InputType.TYPE_CLASS_TEXT
81+
if (appSecret.isNotEmpty()) {
82+
appSecretLayout.evContent.setText(appSecret)
83+
}
84+
appSecretLayout.evContent.setHint(R.string.hint_app_secret)
85+
appSecretLayout.evContent.inputType = InputType.TYPE_CLASS_TEXT
6286
}
6387
}
6488

@@ -67,20 +91,43 @@ class VideoTestInputActivity : VideoBaseActivity<ActivityVideoTestInputBinding>(
6791
vTitle.ivBack.setOnClickListener { finish() }
6892
btnLogin.setOnClickListener(loginClickedListener)
6993
btnPaste.setOnClickListener {
70-
val clipboard = ContextCompat.getSystemService(this@VideoTestInputActivity, ClipboardManager::class.java);
94+
val clipboard = ContextCompat.getSystemService(
95+
this@VideoTestInputActivity,
96+
ClipboardManager::class.java
97+
)
7198
if (clipboard != null && clipboard.hasPrimaryClip()) {
7299
clipboard.primaryClip?.getItemAt(0)?.text.toString().split("\n")
73100
.forEachIndexed { index, s ->
74101
when (index) {
75102
0 -> productIdLayout.evContent.setText(s)
76103
1 -> deviceNameLayout.evContent.setText(s)
77104
2 -> p2pInfoLayout.evContent.setText(s)
105+
3 -> appKeyLayout.evContent.setText(s)
106+
4 -> appSecretLayout.evContent.setText(s)
107+
}
108+
}
109+
}
110+
}
111+
btnAppPaste.setOnClickListener {
112+
val clipboard = ContextCompat.getSystemService(
113+
this@VideoTestInputActivity,
114+
ClipboardManager::class.java
115+
)
116+
if (clipboard != null && clipboard.hasPrimaryClip()) {
117+
clipboard.primaryClip?.getItemAt(0)?.text.toString().split("\n")
118+
.forEachIndexed { index, s ->
119+
when (index) {
120+
0 -> appKeyLayout.evContent.setText(s)
121+
1 -> appSecretLayout.evContent.setText(s)
78122
}
79123
}
80124
}
81125
}
82126
swtCross.setOnCheckedChangeListener { _, checked ->
83127
isStartCross = checked
128+
btnAppPaste.isVisible = checked
129+
appKeyLayout.root.isVisible = checked
130+
appSecretLayout.root.isVisible = checked
84131
}
85132
rgProtocol.setOnCheckedChangeListener { group, checkedId ->
86133
protocol = group.findViewById<RadioButton>(checkedId).tag.toString()
@@ -115,6 +162,30 @@ class VideoTestInputActivity : VideoBaseActivity<ActivityVideoTestInputBinding>(
115162
show(getString(R.string.hint_p2p_info))
116163
return
117164
}
165+
if (isStartCross) {
166+
if (appKeyLayout.evContent.text.isNullOrEmpty()) {
167+
show(getString(R.string.hint_app_key))
168+
return
169+
}
170+
SharePreferenceUtil.saveString(
171+
this@VideoTestInputActivity,
172+
VideoConst.VIDEO_CONFIG,
173+
VideoConst.VIDEO_APP_KEY,
174+
appKeyLayout.evContent.text.toString()
175+
)
176+
if (appSecretLayout.evContent.text.isNullOrEmpty()) {
177+
show(getString(R.string.hint_app_secret))
178+
return
179+
}
180+
if (appSecretLayout.evContent.text.isNotEmpty()) {
181+
SharePreferenceUtil.saveString(
182+
this@VideoTestInputActivity,
183+
VideoConst.VIDEO_CONFIG,
184+
VideoConst.VIDEO_APP_SECRET,
185+
appSecretLayout.evContent.text.toString()
186+
)
187+
}
188+
}
118189
SharePreferenceUtil.saveString(
119190
this@VideoTestInputActivity,
120191
VideoConst.VIDEO_CONFIG,
@@ -125,6 +196,8 @@ class VideoTestInputActivity : VideoBaseActivity<ActivityVideoTestInputBinding>(
125196
intent.putExtra("productId", productIdLayout.evContent.text.toString())
126197
intent.putExtra("deviceName", deviceNameLayout.evContent.text.toString())
127198
intent.putExtra("p2pInfo", p2pInfoLayout.evContent.text.toString())
199+
intent.putExtra("appKey", appKeyLayout.evContent.text.toString())
200+
intent.putExtra("appSecret", appSecretLayout.evContent.text.toString())
128201
intent.putExtra("isStartCross", isStartCross)
129202
intent.putExtra("protocol", protocol)
130203
startActivity(intent)

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/preview/VideoTestActivity.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.tencent.iot.explorer.link.demo.video.utils.ListOptionsDialog
3232
import com.tencent.iot.explorer.link.demo.video.utils.TipToastDialog
3333
import com.tencent.iot.explorer.link.demo.video.utils.ToastDialog
3434
import com.tencent.iot.video.link.entity.DeviceStatus
35+
import com.tencent.iot.video.link.util.JsonManager
3536
import com.tencent.iot.video.link.util.audio.AudioRecordUtil
3637
import com.tencent.xnet.XP2P
3738
import com.tencent.xnet.XP2PAppConfig
@@ -98,6 +99,10 @@ class VideoTestActivity : VideoBaseActivity<ActivityVideoTestBinding>(), XP2PCal
9899
productId = intent.getStringExtra("productId")?.toString() ?: ""
99100
deviceName = intent.getStringExtra("deviceName")?.toString() ?: ""
100101
xp2pInfo = intent.getStringExtra("p2pInfo")?.toString() ?: ""
102+
val appKey = intent.getStringExtra("appKey")?.toString() ?: ""
103+
val appSecret = intent.getStringExtra("appSecret")?.toString() ?: ""
104+
xP2PAppConfig.appKey = appKey
105+
xP2PAppConfig.appSecret = appSecret
101106
xP2PAppConfig.autoConfigFromDevice = intent.getBooleanExtra("isStartCross", false)
102107
val protocol = intent.getStringExtra("protocol")?.toString() ?: "auto"
103108
if (protocol == "udp") {
@@ -107,7 +112,7 @@ class VideoTestActivity : VideoBaseActivity<ActivityVideoTestBinding>(), XP2PCal
107112
} else {
108113
xP2PAppConfig.type = XP2PProtocolType.XP2P_PROTOCOL_AUTO
109114
}
110-
115+
Log.d(TAG, "init params productId:${productId} deviceName:${deviceName} xp2pInfo:${xp2pInfo} xP2PAppConfig:${JsonManager.toJson(xP2PAppConfig)}")
111116
binding.vTitle.tvTitle.text = deviceName
112117
binding.tvVideoQuality.text = getString(R.string.video_quality_medium_str)
113118

sdkdemo/src/main/res/layout/activity_video_test_input.xml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@
5555
android:layout_height="wrap_content"
5656
android:layout_marginStart="16dp"
5757
android:layout_marginTop="16dp"
58-
android:text="是否开启双中转:"
58+
android:text="是否开启跟随设备配置:"
5959
app:layout_constraintStart_toStartOf="parent"
6060
app:layout_constraintTop_toBottomOf="@id/p2p_info_layout" />
6161

62+
6263
<Switch
6364
android:id="@+id/swt_cross"
6465
android:layout_width="wrap_content"
@@ -68,6 +69,35 @@
6869
app:layout_constraintTop_toTopOf="@+id/tv_cross"
6970
tools:ignore="UseSwitchCompatOrMaterialXml" />
7071

72+
<Button
73+
android:id="@+id/btn_app_paste"
74+
android:layout_width="60dp"
75+
android:layout_height="30dp"
76+
android:layout_marginStart="16dp"
77+
android:layout_marginTop="8dp"
78+
android:background="@drawable/background_blue_cell"
79+
android:text="粘贴"
80+
android:textColor="@color/blue_0052D9"
81+
android:visibility="gone"
82+
app:layout_constraintStart_toStartOf="parent"
83+
app:layout_constraintTop_toBottomOf="@id/tv_cross" />
84+
85+
<include
86+
android:id="@+id/app_key_layout"
87+
layout="@layout/input_item_layout"
88+
android:layout_width="match_parent"
89+
android:layout_height="56dp"
90+
android:visibility="gone"
91+
app:layout_constraintTop_toBottomOf="@id/btn_app_paste" />
92+
93+
<include
94+
android:id="@+id/app_Secret_layout"
95+
layout="@layout/input_item_layout"
96+
android:layout_width="match_parent"
97+
android:layout_height="56dp"
98+
android:visibility="gone"
99+
app:layout_constraintTop_toBottomOf="@id/app_key_layout" />
100+
71101
<TextView
72102
android:id="@+id/textView"
73103
android:layout_width="wrap_content"
@@ -76,7 +106,7 @@
76106
android:layout_marginTop="8dp"
77107
android:text="选择协议:"
78108
app:layout_constraintStart_toStartOf="parent"
79-
app:layout_constraintTop_toBottomOf="@+id/tv_cross" />
109+
app:layout_constraintTop_toBottomOf="@+id/app_Secret_layout" />
80110

81111
<RadioGroup
82112
android:id="@+id/rg_protocol"
@@ -115,15 +145,15 @@
115145
android:layout_width="match_parent"
116146
android:layout_height="45dp"
117147
android:layout_marginStart="16dp"
118-
android:layout_marginTop="50dp"
148+
android:layout_marginTop="16dp"
119149
android:layout_marginEnd="16dp"
120150
android:background="@drawable/background_blue_btn"
121151
android:text="@string/login"
122152
android:textColor="@color/white"
123153
android:textSize="@dimen/ts_17"
124154
app:layout_constraintEnd_toEndOf="parent"
125155
app:layout_constraintStart_toStartOf="parent"
126-
app:layout_constraintTop_toBottomOf="@id/tv_cross" />
156+
app:layout_constraintTop_toBottomOf="@id/rg_protocol" />
127157

128158

129159
</androidx.constraintlayout.widget.ConstraintLayout>

sdkdemo/src/main/res/values/strings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,12 @@
204204
<string name="multiple_channel_choose">多通道选择</string>
205205
<string name="channel_choose">通道选择: </string>
206206

207+
<string name="product_id_text">Product ID *</string>
208+
<string name="device_name_text">Device Name *</string>
209+
<string name="p2p_info_text">P2P INFO *</string>
210+
<string name="app_key_text">App Key *</string>
211+
<string name="hint_app_key">请输入App Key</string>
212+
<string name="app_secret">App Secret *</string>
213+
<string name="hint_app_secret">请输入App Secret</string>
214+
207215
</resources>

0 commit comments

Comments
 (0)