Feat: Added a battery icon.
closes #43 Signed-off-by: HeCodes2Much <wayne6324@gmail.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import android.text.format.DateFormat
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.biometric.BiometricPrompt
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
@@ -123,7 +124,42 @@ class HomeFragment : Fragment(),
|
||||
val level: Int = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
|
||||
val scale: Int = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
|
||||
|
||||
// Get the TextView by its ID
|
||||
val batteryTextView: AppCompatTextView = binding.battery
|
||||
|
||||
val batteryLevel = level * 100 / scale.toFloat()
|
||||
|
||||
val batteryDrawable = when {
|
||||
batteryLevel >= 95 -> ContextCompat.getDrawable(
|
||||
requireContext(),
|
||||
R.drawable.app_battery100
|
||||
)
|
||||
|
||||
batteryLevel >= 70 -> ContextCompat.getDrawable(
|
||||
requireContext(),
|
||||
R.drawable.app_battery75
|
||||
)
|
||||
|
||||
batteryLevel >= 45 -> ContextCompat.getDrawable(
|
||||
requireContext(),
|
||||
R.drawable.app_battery50
|
||||
)
|
||||
|
||||
else -> ContextCompat.getDrawable(requireContext(), R.drawable.app_battery25)
|
||||
}
|
||||
|
||||
batteryDrawable?.let {
|
||||
// Resize the drawable to match the text size
|
||||
val textSize = batteryTextView.textSize.toInt()
|
||||
if (preferenceHelper.showBattery) {
|
||||
it.setBounds(0, 0, textSize, textSize)
|
||||
batteryTextView.setCompoundDrawables(it, null, null, null)
|
||||
} else {
|
||||
it.setBounds(0, 0, 0, 0)
|
||||
batteryTextView.setCompoundDrawables(null, null, null, null)
|
||||
}
|
||||
}
|
||||
|
||||
val batteryLevelText = getString(R.string.battery_level, batteryLevel.toString())
|
||||
binding.battery.text = batteryLevelText
|
||||
}
|
||||
@@ -148,6 +184,7 @@ class HomeFragment : Fragment(),
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
private fun observeFavoriteAppList() {
|
||||
viewModel.compareInstalledAppInfo()
|
||||
|
||||
@@ -339,6 +376,7 @@ class HomeFragment : Fragment(),
|
||||
binding.nestScrollView.hideKeyboard()
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
binding.nestScrollView.hideKeyboard()
|
||||
|
||||
30
app/src/main/res/drawable/app_battery100.xml
Normal file
30
app/src/main/res/drawable/app_battery100.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M16.542,4.392L14.981,4.392L14.981,2.844A0.499,0.496 0,0 0,14.484 2.35L10.468,2.35A0.5,0.497 0,0 0,9.971 2.844L9.971,4.392L8.408,4.392A1.577,1.567 0,0 0,7.29 4.852l-0.028,0.031a1.574,1.564 0,0 0,-0.437 1.075L6.825,19.641a1.588,1.578 0,0 0,1.583 1.574h8.135a1.574,1.564 0,0 0,1.117 -0.461v0a1.577,1.567 0,0 0,0.463 -1.112L18.122,5.966A1.588,1.578 0,0 0,16.539 4.392ZM8.408,5.313h8.135a0.653,0.649 0,0 1,0.65 0.646L17.193,19.641a0.647,0.643 0,0 1,-0.192 0.461v0A0.65,0.646 0,0 1,16.538 20.291L8.408,20.291A0.653,0.649 0,0 1,7.751 19.641L7.751,5.966A0.649,0.645 0,0 1,7.924 5.526l0.019,-0.017A0.65,0.646 0,0 1,8.406 5.319Z"
|
||||
android:strokeWidth="0.153984"
|
||||
android:fillColor="@color/white" />
|
||||
|
||||
<path
|
||||
android:pathData="M16.193,9.372V6.712A0.406,0.344 0,0 0,15.792 6.372H9.157A0.411,0.348 0,0 0,8.754 6.712v2.66z"
|
||||
android:fillColor="@color/green"
|
||||
android:fillType="evenOdd" />
|
||||
|
||||
<path
|
||||
android:pathData="M16.193,9.6l-7.44,-0l0,3l7.44,-0z"
|
||||
android:fillColor="@color/green"
|
||||
android:fillType="evenOdd" />
|
||||
|
||||
<path
|
||||
android:pathData="M16.193,12.839l-7.44,-0l0,3l7.44,-0z"
|
||||
android:fillColor="@color/green"
|
||||
android:fillType="evenOdd" />
|
||||
|
||||
<path
|
||||
android:pathData="M16.19,16.065H8.751v2.666a0.408,0.338 0,0 0,0.403 0.334H15.795a0.403,0.334 0,0 0,0.402 -0.334z"
|
||||
android:fillColor="@color/green"
|
||||
android:fillType="evenOdd" />
|
||||
</vector>
|
||||
15
app/src/main/res/drawable/app_battery25.xml
Normal file
15
app/src/main/res/drawable/app_battery25.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M16.542,4.392L14.981,4.392L14.981,2.844A0.499,0.496 0,0 0,14.484 2.35L10.468,2.35A0.5,0.497 0,0 0,9.971 2.844L9.971,4.392L8.408,4.392A1.577,1.567 0,0 0,7.29 4.852l-0.028,0.031a1.574,1.564 0,0 0,-0.437 1.075L6.825,19.641a1.588,1.578 0,0 0,1.583 1.574h8.135a1.574,1.564 0,0 0,1.117 -0.461v0a1.577,1.567 0,0 0,0.463 -1.112L18.122,5.966A1.588,1.578 0,0 0,16.539 4.392ZM8.408,5.313h8.135a0.653,0.649 0,0 1,0.65 0.646L17.193,19.641a0.647,0.643 0,0 1,-0.192 0.461v0A0.65,0.646 0,0 1,16.538 20.291L8.408,20.291A0.653,0.649 0,0 1,7.751 19.641L7.751,5.966A0.649,0.645 0,0 1,7.924 5.526l0.019,-0.017A0.65,0.646 0,0 1,8.406 5.319Z"
|
||||
android:strokeWidth="0.153984"
|
||||
android:fillColor="@color/white" />
|
||||
|
||||
<path
|
||||
android:pathData="M16.19,16.065H8.751v2.666a0.408,0.338 0,0 0,0.403 0.334H15.795a0.403,0.334 0,0 0,0.402 -0.334z"
|
||||
android:fillColor="@color/red"
|
||||
android:fillType="evenOdd" />
|
||||
</vector>
|
||||
20
app/src/main/res/drawable/app_battery50.xml
Normal file
20
app/src/main/res/drawable/app_battery50.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M16.542,4.392L14.981,4.392L14.981,2.844A0.499,0.496 0,0 0,14.484 2.35L10.468,2.35A0.5,0.497 0,0 0,9.971 2.844L9.971,4.392L8.408,4.392A1.577,1.567 0,0 0,7.29 4.852l-0.028,0.031a1.574,1.564 0,0 0,-0.437 1.075L6.825,19.641a1.588,1.578 0,0 0,1.583 1.574h8.135a1.574,1.564 0,0 0,1.117 -0.461v0a1.577,1.567 0,0 0,0.463 -1.112L18.122,5.966A1.588,1.578 0,0 0,16.539 4.392ZM8.408,5.313h8.135a0.653,0.649 0,0 1,0.65 0.646L17.193,19.641a0.647,0.643 0,0 1,-0.192 0.461v0A0.65,0.646 0,0 1,16.538 20.291L8.408,20.291A0.653,0.649 0,0 1,7.751 19.641L7.751,5.966A0.649,0.645 0,0 1,7.924 5.526l0.019,-0.017A0.65,0.646 0,0 1,8.406 5.319Z"
|
||||
android:strokeWidth="0.153984"
|
||||
android:fillColor="@color/white" />
|
||||
|
||||
<path
|
||||
android:pathData="M16.193,12.839l-7.44,-0l0,3l7.44,-0z"
|
||||
android:fillColor="@color/orange"
|
||||
android:fillType="evenOdd" />
|
||||
|
||||
<path
|
||||
android:pathData="M16.19,16.065H8.751v2.666a0.408,0.338 0,0 0,0.403 0.334H15.795a0.403,0.334 0,0 0,0.402 -0.334z"
|
||||
android:fillColor="@color/orange"
|
||||
android:fillType="evenOdd" />
|
||||
</vector>
|
||||
25
app/src/main/res/drawable/app_battery75.xml
Normal file
25
app/src/main/res/drawable/app_battery75.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M16.542,4.392L14.981,4.392L14.981,2.844A0.499,0.496 0,0 0,14.484 2.35L10.468,2.35A0.5,0.497 0,0 0,9.971 2.844L9.971,4.392L8.408,4.392A1.577,1.567 0,0 0,7.29 4.852l-0.028,0.031a1.574,1.564 0,0 0,-0.437 1.075L6.825,19.641a1.588,1.578 0,0 0,1.583 1.574h8.135a1.574,1.564 0,0 0,1.117 -0.461v0a1.577,1.567 0,0 0,0.463 -1.112L18.122,5.966A1.588,1.578 0,0 0,16.539 4.392ZM8.408,5.313h8.135a0.653,0.649 0,0 1,0.65 0.646L17.193,19.641a0.647,0.643 0,0 1,-0.192 0.461v0A0.65,0.646 0,0 1,16.538 20.291L8.408,20.291A0.653,0.649 0,0 1,7.751 19.641L7.751,5.966A0.649,0.645 0,0 1,7.924 5.526l0.019,-0.017A0.65,0.646 0,0 1,8.406 5.319Z"
|
||||
android:strokeWidth="0.153984"
|
||||
android:fillColor="@color/white" />
|
||||
|
||||
<path
|
||||
android:pathData="M16.193,9.6l-7.44,-0l0,3l7.44,-0z"
|
||||
android:fillColor="@color/orange"
|
||||
android:fillType="evenOdd" />
|
||||
|
||||
<path
|
||||
android:pathData="M16.193,12.839l-7.44,-0l0,3l7.44,-0z"
|
||||
android:fillColor="@color/orange"
|
||||
android:fillType="evenOdd" />
|
||||
|
||||
<path
|
||||
android:pathData="M16.19,16.065H8.751v2.666a0.408,0.338 0,0 0,0.403 0.334H15.795a0.403,0.334 0,0 0,0.402 -0.334z"
|
||||
android:fillColor="@color/orange"
|
||||
android:fillType="evenOdd" />
|
||||
</vector>
|
||||
@@ -23,4 +23,8 @@
|
||||
<color name="whiteTrans50">#65FFFFFF</color>
|
||||
<color name="whiteTrans80">#CCFFFFFF</color>
|
||||
<color name="whiteTrans90">#E6FFFFFF</color>
|
||||
|
||||
<color name="green">#4CAF50</color>
|
||||
<color name="orange">#AF684C</color>
|
||||
<color name="red">#AF4C4C</color>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user