|
|
@ -29,13 +29,14 @@ import android.view.View
|
|
|
|
import android.view.View.OnClickListener
|
|
|
|
import android.view.View.OnClickListener
|
|
|
|
import android.view.View.OnLongClickListener
|
|
|
|
import android.view.View.OnLongClickListener
|
|
|
|
import org.isoron.uhabits.R
|
|
|
|
import org.isoron.uhabits.R
|
|
|
|
|
|
|
|
import org.isoron.uhabits.core.models.NumericalHabitType
|
|
|
|
import org.isoron.uhabits.core.preferences.Preferences
|
|
|
|
import org.isoron.uhabits.core.preferences.Preferences
|
|
|
|
import org.isoron.uhabits.inject.ActivityContext
|
|
|
|
import org.isoron.uhabits.inject.ActivityContext
|
|
|
|
import org.isoron.uhabits.utils.InterfaceUtils.getDimension
|
|
|
|
import org.isoron.uhabits.utils.InterfaceUtils.getDimension
|
|
|
|
import org.isoron.uhabits.utils.StyledResources
|
|
|
|
|
|
|
|
import org.isoron.uhabits.utils.dim
|
|
|
|
import org.isoron.uhabits.utils.dim
|
|
|
|
import org.isoron.uhabits.utils.getFontAwesome
|
|
|
|
import org.isoron.uhabits.utils.getFontAwesome
|
|
|
|
import org.isoron.uhabits.utils.showMessage
|
|
|
|
import org.isoron.uhabits.utils.showMessage
|
|
|
|
|
|
|
|
import org.isoron.uhabits.utils.sres
|
|
|
|
import java.text.DecimalFormat
|
|
|
|
import java.text.DecimalFormat
|
|
|
|
import javax.inject.Inject
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
|
|
|
@ -82,7 +83,19 @@ class NumberButtonView(
|
|
|
|
invalidate()
|
|
|
|
invalidate()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var threshold = 0.0
|
|
|
|
var lowerThreshold = 0.0
|
|
|
|
|
|
|
|
set(value) {
|
|
|
|
|
|
|
|
field = value
|
|
|
|
|
|
|
|
invalidate()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var higherThreshold = 0.0
|
|
|
|
|
|
|
|
set(value) {
|
|
|
|
|
|
|
|
field = value
|
|
|
|
|
|
|
|
invalidate()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var targetType = NumericalHabitType.AT_LEAST
|
|
|
|
set(value) {
|
|
|
|
set(value) {
|
|
|
|
field = value
|
|
|
|
field = value
|
|
|
|
invalidate()
|
|
|
|
invalidate()
|
|
|
@ -127,7 +140,6 @@ class NumberButtonView(
|
|
|
|
|
|
|
|
|
|
|
|
private val em: Float
|
|
|
|
private val em: Float
|
|
|
|
private val rect: RectF = RectF()
|
|
|
|
private val rect: RectF = RectF()
|
|
|
|
private val sr = StyledResources(context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val lowContrast: Int
|
|
|
|
private val lowContrast: Int
|
|
|
|
private val mediumContrast: Int
|
|
|
|
private val mediumContrast: Int
|
|
|
@ -148,15 +160,23 @@ class NumberButtonView(
|
|
|
|
|
|
|
|
|
|
|
|
init {
|
|
|
|
init {
|
|
|
|
em = pNumber.measureText("m")
|
|
|
|
em = pNumber.measureText("m")
|
|
|
|
lowContrast = sr.getColor(R.attr.contrast40)
|
|
|
|
lowContrast = sres.getColor(R.attr.contrast40)
|
|
|
|
mediumContrast = sr.getColor(R.attr.contrast60)
|
|
|
|
mediumContrast = sres.getColor(R.attr.contrast60)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun draw(canvas: Canvas) {
|
|
|
|
fun draw(canvas: Canvas) {
|
|
|
|
val activeColor = when {
|
|
|
|
var activeColor = if (targetType == NumericalHabitType.AT_LEAST) {
|
|
|
|
value <= 0.0 -> lowContrast
|
|
|
|
when {
|
|
|
|
value < threshold -> mediumContrast
|
|
|
|
value <= lowerThreshold -> lowContrast
|
|
|
|
else -> color
|
|
|
|
value < higherThreshold -> mediumContrast
|
|
|
|
|
|
|
|
else -> color
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
when {
|
|
|
|
|
|
|
|
value >= higherThreshold || value < 0 -> lowContrast
|
|
|
|
|
|
|
|
value > lowerThreshold -> mediumContrast
|
|
|
|
|
|
|
|
else -> color
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
val label: String
|
|
|
|
val label: String
|
|
|
@ -175,7 +195,7 @@ class NumberButtonView(
|
|
|
|
textSize = dim(R.dimen.smallerTextSize)
|
|
|
|
textSize = dim(R.dimen.smallerTextSize)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else -> {
|
|
|
|
else -> {
|
|
|
|
label = "0"
|
|
|
|
label = if (targetType == NumericalHabitType.AT_LEAST) "0" else "inf"
|
|
|
|
typeface = BOLD_TYPEFACE
|
|
|
|
typeface = BOLD_TYPEFACE
|
|
|
|
textSize = dim(R.dimen.smallTextSize)
|
|
|
|
textSize = dim(R.dimen.smallTextSize)
|
|
|
|
}
|
|
|
|
}
|
|
|
|