扫码附件设备,链接设备动画
This commit is contained in:
@@ -2,6 +2,8 @@ package com.example.defenseapplication.home
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@@ -12,10 +14,12 @@ import com.example.defenseapplication.adapter.Device
|
||||
import com.example.defenseapplication.databinding.AddDeviceActivityBinding
|
||||
import com.gyf.immersionbar.ImmersionBar
|
||||
|
||||
//添加设备页面
|
||||
class AddDeviceActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: AddDeviceActivityBinding
|
||||
|
||||
private lateinit var adapter: AddDeviceAdapter
|
||||
private val mainHandler = Handler(Looper.getMainLooper())
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = AddDeviceActivityBinding.inflate(layoutInflater)
|
||||
@@ -28,7 +32,31 @@ class AddDeviceActivity : AppCompatActivity() {
|
||||
finish()
|
||||
}
|
||||
|
||||
setupDeviceList()
|
||||
// 开始播放扫描动画,动画结束后再显示设备列表
|
||||
startScanAnimationThenShowList()
|
||||
}
|
||||
|
||||
private fun startScanAnimationThenShowList() {
|
||||
// 显示动画层
|
||||
binding.animationContainer.visibility = View.VISIBLE
|
||||
binding.rvDevices.visibility = View.GONE
|
||||
|
||||
// 设置帧动画并启动
|
||||
binding.ivScanAnimation.setImageResource(R.drawable.device_frame_animation)
|
||||
val scanDrawable = binding.ivScanAnimation.drawable
|
||||
if (scanDrawable is android.graphics.drawable.AnimationDrawable) {
|
||||
scanDrawable.start()
|
||||
}
|
||||
|
||||
// 模拟扫描过程
|
||||
mainHandler.postDelayed({
|
||||
// 停止动画
|
||||
(binding.ivScanAnimation.drawable as? android.graphics.drawable.AnimationDrawable)?.stop()
|
||||
// 隐藏动画层,显示列表
|
||||
binding.animationContainer.visibility = View.GONE
|
||||
binding.rvDevices.visibility = View.VISIBLE
|
||||
setupDeviceList() // 加载设备列表
|
||||
}, 3000) // 动画播放时长,可根据实际帧动画总时长调整
|
||||
}
|
||||
|
||||
private fun setupDeviceList() {
|
||||
@@ -38,20 +66,38 @@ class AddDeviceActivity : AppCompatActivity() {
|
||||
)
|
||||
|
||||
if (devices.isEmpty()) {
|
||||
binding.emptyState.visibility = View.VISIBLE
|
||||
|
||||
binding.rvDevices.visibility = View.GONE
|
||||
} else {
|
||||
binding.emptyState.visibility = View.GONE
|
||||
|
||||
binding.rvDevices.visibility = View.VISIBLE
|
||||
|
||||
binding.rvDevices.layoutManager = GridLayoutManager(this, 2)
|
||||
// 传入点击回调
|
||||
binding.rvDevices.adapter = AddDeviceAdapter(devices) { device ->
|
||||
// 跳转到 AddFamilyActivity(选择Wi-Fi页面)
|
||||
adapter = AddDeviceAdapter(devices) { device ->
|
||||
val intent = Intent(this, AddFamilyActivity::class.java)
|
||||
intent.putExtra("device_name", device.name)
|
||||
startActivity(intent)
|
||||
}
|
||||
binding.rvDevices.adapter = adapter
|
||||
}
|
||||
}
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
// 停止所有可见 item 的动画
|
||||
for (i in 0 until binding.rvDevices.childCount) {
|
||||
val child = binding.rvDevices.getChildAt(i)
|
||||
val holder = binding.rvDevices.getChildViewHolder(child) as? AddDeviceAdapter.ViewHolder
|
||||
holder?.stopAnimation()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
// 重新启动所有可见 item 的动画
|
||||
for (i in 0 until binding.rvDevices.childCount) {
|
||||
val child = binding.rvDevices.getChildAt(i)
|
||||
val holder = binding.rvDevices.getChildViewHolder(child) as? AddDeviceAdapter.ViewHolder
|
||||
holder?.startAnimation()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user