custom attributes, update StatValue

Circularprogressview bar colors using custom attributes, StatValue more kotliny
This commit is contained in:
Hafiz 2022-06-20 03:42:52 -04:00
parent 78ac6d7adc
commit a556edb643
4 changed files with 31 additions and 57 deletions

View file

@ -76,7 +76,7 @@ class CircularProgressView(
}
private fun drawInnerArc(canvas: Canvas) {
val percentageToFill = getCurrentPercentageToFill()
val percentageToFill = getCurrentAngleToFill()
canvas.drawArc(ovalSpace, 270f, percentageToFill, false, fillArcPaint)
}
@ -122,6 +122,6 @@ class CircularProgressView(
const val PERCENTAGE_VALUE_HOLDER = "percentage"
}
private fun getCurrentPercentageToFill() = if(currentPercentage > 0) {(ARC_FULL_ROTATION_DEGREE.toFloat() * (currentPercentage.toFloat() / PERCENTAGE_DIVIDER.toFloat()))} else {1f}
private fun getCurrentAngleToFill() = if(currentPercentage > 0) {(ARC_FULL_ROTATION_DEGREE.toFloat() * (currentPercentage.toFloat() / PERCENTAGE_DIVIDER.toFloat()))} else {1f}
}

View file

@ -4,55 +4,27 @@ import android.content.Context
import android.graphics.Bitmap
import android.graphics.Color
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import com.habitrpg.android.habitica.R
import com.habitrpg.common.habitica.views.HabiticaIconsHelper.init
import androidx.constraintlayout.widget.ConstraintLayout
import com.habitrpg.android.habitica.databinding.StatValueLayoutBinding
import com.habitrpg.common.habitica.extensions.layoutInflater
class StatValue : FrameLayout {
var view: View? = null
var bitmapImageView: ImageView? = null
var currentValueTextView: TextView? = null
var maxValueTextView: TextView? = null
constructor(context: Context) : super(context) {
init(context)
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init(context)
}
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
class StatValue @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) :
ConstraintLayout(
context,
attrs,
defStyle
) {
init(context)
}
init {
initView()
}
private fun initView() {
view = inflate(context, R.layout.stat_value_layout, this)
bitmapImageView = view?.findViewById(R.id.bitmap)
currentValueTextView = view?.findViewById(R.id.current_value)
maxValueTextView = view?.findViewById(R.id.max_value)
}
var binding = StatValueLayoutBinding.inflate(context.layoutInflater, this)
fun setStatValue(maxValue: Int, currentValue: Int, bitmap: Bitmap, bitmapColor: Int) {
bitmapImageView?.setImageBitmap(bitmap)
currentValueTextView?.text = currentValue.toString()
currentValueTextView?.setTextColor(
binding.bitmap.setImageBitmap(bitmap)
binding.currentValue.text = currentValue.toString()
binding.currentValue.setTextColor(
context?.resources?.getColor(bitmapColor, null) ?: Color.WHITE
)
maxValueTextView?.text = "/$maxValue"
view?.invalidate()
binding.maxValue.text = "/$maxValue"
invalidate()
}

View file

@ -1,53 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_height="match_parent">
<com.habitrpg.wearos.habitica.ui.views.CircularProgressView
android:id="@+id/hp_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:offset="10"
app:arcFillColor="@color/hp_bar_color"
app:backgroundArcColor="@color/bar_background_color"
app:arcFillColor="@color/hp_bar_color"/>
app:offset="10" />
<com.habitrpg.wearos.habitica.ui.views.CircularProgressView
android:id="@+id/exp_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:offset="28"
app:arcFillColor="@color/exp_bar_color"
app:backgroundArcColor="@color/bar_background_color"
app:arcFillColor="@color/exp_bar_color"/>
app:offset="28" />
<com.habitrpg.wearos.habitica.ui.views.CircularProgressView
android:id="@+id/mp_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:offset="46"
app:arcFillColor="@color/mp_bar_color"
app:backgroundArcColor="@color/bar_background_color"
app:arcFillColor="@color/mp_bar_color"/>
app:offset="46" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_centerInParent="true"
android:layout_marginStart="16dp"
android:orientation="vertical">
<com.habitrpg.wearos.habitica.ui.views.StatValue
android:id="@+id/hp_stat_value"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.habitrpg.wearos.habitica.ui.views.StatValue
android:id="@+id/exp_stat_value"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.habitrpg.wearos.habitica.ui.views.StatValue
android:id="@+id/mp_stat_value"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View file

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<merge 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"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_height="30dp">
tools:parentTag="com.habitrpg.wearos.habitica.ui.views.StatValue">
<View
android:id="@+id/view"
@ -30,9 +32,9 @@
android:id="@+id/current_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:autoSizeMaxTextSize="18sp"
android:autoSizeMinTextSize="12sp"
android:layout_marginEnd="2dp"
android:autoSizeStepGranularity="2sp"
android:autoSizeTextType="uniform"
android:fontFamily="@font/press_start_reg"
@ -58,4 +60,4 @@
app:layout_constraintStart_toEndOf="@+id/view"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</merge>