Commit 70f942ac authored by wanglei's avatar wanglei

[拆包]小控件ui

parent 8480ba93
......@@ -12,12 +12,13 @@ import com.base.appzxhy.bean.FeatureBean.Companion.BATTERY_INFO
import com.base.appzxhy.bean.FeatureBean.Companion.setFunctionTodayUsed
import com.base.appzxhy.bean.config.AdConfigBean
import com.base.appzxhy.databinding.ActivityBatteryInfo2Binding
import com.base.appzxhy.databinding.ActivityBatteryInfoBinding
import com.base.appzxhy.ui.adapter.AdAdapter
import com.base.appzxhy.utils.LogEx
import com.base.appzxhy.utils.Utils
import kotlin.random.Random
class BatteryInfoActivity : BaseActivity<ActivityBatteryInfo2Binding>(ActivityBatteryInfo2Binding::inflate) {
class BatteryInfoActivity : BaseActivity<ActivityBatteryInfoBinding>(ActivityBatteryInfoBinding::inflate) {
private val concatAdapter = ConcatAdapter()
private val batteryHeadAdapter = BatteryOtherAdapter(R.layout.item_battery_head)
......@@ -58,113 +59,113 @@ class BatteryInfoActivity : BaseActivity<ActivityBatteryInfo2Binding>(ActivityBa
batteryReceiver = BatteryReceiver { updateBatteryInfo() }
registerReceiver(batteryReceiver, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
binding.rv.adapter = concatAdapter
concatAdapter.addAdapter(batteryHeadAdapter)
batteryHeadAdapter.submitList(
listOf(BatteryOtherBean(hashMapOf()))
)
if (AdConfigBean.adsConfigBean.isAdShow) {
concatAdapter.addAdapter(adAdapter)
}
concatAdapter.addAdapter(batteryInfoAdapter)
batteryInfoAdapter.submitList(listOf(batteryInfoList))
concatAdapter.addAdapter(batteryElectricAdapter)
batteryElectricAdapter.submitList(
listOf(BatteryOtherBean(hashMapOf()))
)
// binding.rv.adapter = concatAdapter
// concatAdapter.addAdapter(batteryHeadAdapter)
// batteryHeadAdapter.submitList(
// listOf(BatteryOtherBean(hashMapOf()))
// )
//
// if (AdConfigBean.adsConfigBean.isAdShow) {
// concatAdapter.addAdapter(adAdapter)
// }
// concatAdapter.addAdapter(batteryInfoAdapter)
// batteryInfoAdapter.submitList(listOf(batteryInfoList))
//
// concatAdapter.addAdapter(batteryElectricAdapter)
// batteryElectricAdapter.submitList(
// listOf(BatteryOtherBean(hashMapOf()))
// )
setFunctionTodayUsed(BATTERY_INFO)
}
override fun initListener() {
super.initListener()
binding.ivBack.setOnClickListener { onBackPressedDispatcher.onBackPressed() }
binding.flBack.setOnClickListener { onBackPressedDispatcher.onBackPressed() }
}
// @SuppressLint("SetTextI18n")
// private fun updateBatteryInfo() {
// val percent = BatteryReceiver.level / BatteryReceiver.scale.toFloat()
// val remainingCapacity = BatteryReceiver.mAh * percent
// val wTime = (remainingCapacity / 3.0f).toInt()
// val vTime = (remainingCapacity / 3.9f).toInt()
// val mTime = (remainingCapacity / 3.5f).toInt()
// val battery = (percent * 100).toInt()
// val temperature = Utils.divide(BatteryReceiver.temperature, 10)
// val voltage = Utils.divide(BatteryReceiver.voltage, 1000)
// binding.tvBattery.text = "${battery}%"
// binding.tvStandbyHour.text = "%02d".format(wTime / 60)
// binding.tvStandbyMinute.text = "%02d".format(wTime % 60)
// binding.tvVideoHour.text = "%02d".format(vTime / 60)
// binding.tvVideoMinute.text = "%02d".format(vTime % 60)
// binding.tvMusicHour.text = "%02d".format(mTime / 60)
// binding.tvMusicMinute.text = "%02d".format(mTime % 60)
// binding.tvTemperature.text = "$temperature℃"
// binding.tvVoltage.text = "${voltage}V"
// binding.tvPower.text = "${(BatteryReceiver.mAh * percent).toInt()}mAh"
// binding.tvBatteryType.text = BatteryReceiver.technology
// binding.tvBatteryCapacity.text = "${BatteryReceiver.mAh.toInt()}mAh"
// binding.tvBatteryStatus.text = getString(if (BatteryReceiver.isCharging) R.string.charging else R.string.normal)
// val resource = if (battery > 80) {
// R.drawable.dianchi100
// } else if (battery > 60) {
// R.drawable.dianchi80
// } else if (battery > 40) {
// R.drawable.dianchi60
// } else if (battery > 20) {
// R.drawable.dianchi40
// } else {
// R.drawable.dianchi20
// }
// binding.ivBattery.setImageResource(resource)
// }
// @SuppressLint("SetTextI18n")
private fun updateBatteryInfo() {
val percent = BatteryReceiver.level / BatteryReceiver.scale.toFloat()
val remainingCapacity = BatteryReceiver.mAh * percent
val wTime = (remainingCapacity / 3.0f).toInt()
batteryHeadAdapter.submitList(
listOf(
BatteryOtherBean(
HashMap<String, Any>().apply {
put("hour", wTime / 60)
put("min", wTime % 60)
}
)
)
)
batteryInfoList[1].tvValue = "${remainingCapacity.toInt()} / ${BatteryReceiver.mAh.toInt()} mAh"
val voltage = Utils.divide(BatteryReceiver.voltage, 1)
batteryInfoList[3].tvValue = "$voltage mV"
batteryInfoAdapter.submitList(listOf(batteryInfoList))
var current1 = BatteryReceiver.mA
if (current1 == 0f) {
current1 = Random.nextInt(50, 350).toFloat()
}
var current2 = BatteryReceiver.avmA
if (current2 == 0f) {
current2 = Random.nextInt(50, 300).toFloat()
val vTime = (remainingCapacity / 3.9f).toInt()
val mTime = (remainingCapacity / 3.5f).toInt()
val battery = (percent * 100).toInt()
val temperature = Utils.divide(BatteryReceiver.temperature, 10)
val voltage = Utils.divide(BatteryReceiver.voltage, 1000)
binding.tvBattery.text = "${battery}%"
binding.tvStandbyHour.text = "%02d".format(wTime / 60)
binding.tvStandbyMinute.text = "%02d".format(wTime % 60)
binding.tvVideoHour.text = "%02d".format(vTime / 60)
binding.tvVideoMinute.text = "%02d".format(vTime % 60)
binding.tvMusicHour.text = "%02d".format(mTime / 60)
binding.tvMusicMinute.text = "%02d".format(mTime % 60)
binding.tvTemperature.text = "$temperature℃"
binding.tvVoltage.text = "${voltage}V"
binding.tvPower.text = "${(BatteryReceiver.mAh * percent).toInt()}mAh"
binding.tvBatteryType.text = BatteryReceiver.technology
binding.tvBatteryCapacity.text = "${BatteryReceiver.mAh.toInt()}mAh"
binding.tvBatteryStatus.text = getString(if (BatteryReceiver.isCharging) R.string.charging else R.string.normal)
val resource = if (battery > 80) {
R.drawable.dianchi100
} else if (battery > 60) {
R.drawable.dianchi80
} else if (battery > 40) {
R.drawable.dianchi60
} else if (battery > 20) {
R.drawable.dianchi40
} else {
R.drawable.dianchi20
}
LogEx.logDebug(TAG, "current1=$current1 current2=$current2")
batteryElectricAdapter.submitList(
listOf(
BatteryOtherBean(
HashMap<String, Any>().apply {
put("current1", current1)
put("current2", current2)
}
)
)
)
binding.ivBattery.setImageResource(resource)
}
// private fun updateBatteryInfo() {
// val percent = BatteryReceiver.level / BatteryReceiver.scale.toFloat()
// val remainingCapacity = BatteryReceiver.mAh * percent
// val wTime = (remainingCapacity / 3.0f).toInt()
//
// batteryHeadAdapter.submitList(
// listOf(
// BatteryOtherBean(
// HashMap<String, Any>().apply {
// put("hour", wTime / 60)
// put("min", wTime % 60)
// }
// )
// )
// )
//
//
// batteryInfoList[1].tvValue = "${remainingCapacity.toInt()} / ${BatteryReceiver.mAh.toInt()} mAh"
//
// val voltage = Utils.divide(BatteryReceiver.voltage, 1)
// batteryInfoList[3].tvValue = "$voltage mV"
//
//
// batteryInfoAdapter.submitList(listOf(batteryInfoList))
//
// var current1 = BatteryReceiver.mA
// if (current1 == 0f) {
// current1 = Random.nextInt(50, 350).toFloat()
// }
// var current2 = BatteryReceiver.avmA
// if (current2 == 0f) {
// current2 = Random.nextInt(50, 300).toFloat()
// }
//
// LogEx.logDebug(TAG, "current1=$current1 current2=$current2")
// batteryElectricAdapter.submitList(
// listOf(
// BatteryOtherBean(
// HashMap<String, Any>().apply {
// put("current1", current1)
// put("current2", current2)
// }
// )
// )
// )
//
// }
}
\ No newline at end of file
......@@ -99,7 +99,7 @@
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="83dp"
android:layout_marginTop="@dimen/dp_60"
android:orientation="horizontal"
android:paddingHorizontal="38dp"
app:layout_constraintTop_toBottomOf="@id/iv_battery">
......
<?xml version="1.0" encoding="utf-8"?>
<!--<?xml version="1.0" encoding="utf-8"?>-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
......@@ -6,62 +6,62 @@
android:layout_height="match_parent"
android:background="@color/color_fafafa">
<FrameLayout
android:id="@+id/cl_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">
<!-- <FrameLayout-->
<!-- android:id="@+id/cl_top"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- app:layout_constraintTop_toTopOf="parent">-->
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/ivBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/dp_16"
android:src="@drawable/icon_back" />
<!-- <androidx.appcompat.widget.AppCompatImageView-->
<!-- android:id="@+id/ivBack"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:padding="@dimen/dp_16"-->
<!-- android:src="@drawable/icon_back" />-->
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/dp_66"
android:text="@string/battery_info"
android:textColor="@color/black"
android:textSize="20sp"
<!-- <androidx.appcompat.widget.AppCompatTextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:layout_marginStart="@dimen/dp_66"-->
<!-- android:text="@string/battery_info"-->
<!-- android:textColor="@color/black"-->
<!-- android:textSize="20sp"-->
android:textStyle="bold" />
<!-- android:textStyle="bold" />-->
</FrameLayout>
<!-- </FrameLayout>-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toTopOf="@id/tvBtn"
app:layout_constraintTop_toBottomOf="@id/cl_top">
<!-- <androidx.recyclerview.widget.RecyclerView-->
<!-- android:id="@+id/rv"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="0dp"-->
<!-- app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"-->
<!-- app:layout_constraintBottom_toTopOf="@id/tvBtn"-->
<!-- app:layout_constraintTop_toBottomOf="@id/cl_top">-->
</androidx.recyclerview.widget.RecyclerView>
<!-- </androidx.recyclerview.widget.RecyclerView>-->
<TextView
android:id="@+id/tvBtn"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_45"
android:layout_marginHorizontal="@dimen/dp_50"
android:layout_marginBottom="@dimen/dp_20"
android:background="@drawable/bg_btn_50"
android:foreground="?attr/selectableItemBackground"
android:gravity="center"
android:text="@string/finish"
android:textColor="@color/white"
android:textSize="@dimen/sp_17"
android:textStyle="bold"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent" />
<!-- <TextView-->
<!-- android:id="@+id/tvBtn"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="@dimen/dp_45"-->
<!-- android:layout_marginHorizontal="@dimen/dp_50"-->
<!-- android:layout_marginBottom="@dimen/dp_20"-->
<!-- android:background="@drawable/bg_btn_50"-->
<!-- android:foreground="?attr/selectableItemBackground"-->
<!-- android:gravity="center"-->
<!-- android:text="@string/finish"-->
<!-- android:textColor="@color/white"-->
<!-- android:textSize="@dimen/sp_17"-->
<!-- android:textStyle="bold"-->
<!-- android:visibility="invisible"-->
<!-- app:layout_constraintBottom_toBottomOf="parent" />-->
<include
android:id="@+id/layout_animation"
layout="@layout/layout_animation"
android:visibility="visible"
tools:visibility="invisible" />
<!-- <include-->
<!-- android:id="@+id/layout_animation"-->
<!-- layout="@layout/layout_animation"-->
<!-- android:visibility="visible"-->
<!-- tools:visibility="invisible" />-->
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment