Commit 70f942ac authored by wanglei's avatar wanglei

[拆包]小控件ui

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