Merge pull request #2915 from Philoul/wear/cwfBackgroundColor
Wear CWF Manage Background Color for TextView and ImageView (including DynData
This commit is contained in:
commit
9cc08855a5
|
@ -252,6 +252,7 @@ enum class JsonKeys(val key: String) {
|
||||||
IMAGE("image"),
|
IMAGE("image"),
|
||||||
INVALIDIMAGE("invalidImage"),
|
INVALIDIMAGE("invalidImage"),
|
||||||
INVALIDCOLOR("invalidColor"),
|
INVALIDCOLOR("invalidColor"),
|
||||||
|
INVALIDFONTCOLOR("invalidFontColor"),
|
||||||
TWINVIEW("twinView"),
|
TWINVIEW("twinView"),
|
||||||
TOPOFFSETTWINHIDDEN("topOffsetTwinHidden"),
|
TOPOFFSETTWINHIDDEN("topOffsetTwinHidden"),
|
||||||
LEFTOFFSETTWINHIDDEN("leftOffsetTwinHidden")
|
LEFTOFFSETTWINHIDDEN("leftOffsetTwinHidden")
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -106,13 +106,13 @@ class CustomWatchface : BaseWatchFace() {
|
||||||
|
|
||||||
override fun setColorDark() {
|
override fun setColorDark() {
|
||||||
setWatchfaceStyle()
|
setWatchfaceStyle()
|
||||||
if ((ViewMap.SGV.dynData?.stepColor ?: 0) == 0)
|
if ((ViewMap.SGV.dynData?.stepFontColor ?: 0) == 0)
|
||||||
binding.sgv.setTextColor(bgColor)
|
binding.sgv.setTextColor(bgColor)
|
||||||
if ((ViewMap.DIRECTION.dynData?.stepColor ?: 0) == 0)
|
if ((ViewMap.DIRECTION.dynData?.stepColor ?: 0) == 0)
|
||||||
binding.direction2.colorFilter = changeDrawableColor(bgColor)
|
binding.direction2.colorFilter = changeDrawableColor(bgColor)
|
||||||
if (ageLevel != 1 && (ViewMap.TIMESTAMP.dynData?.stepColor ?: 0) == 0)
|
if (ageLevel != 1 && (ViewMap.TIMESTAMP.dynData?.stepFontColor ?: 0) == 0)
|
||||||
binding.timestamp.setTextColor(ContextCompat.getColor(this, R.color.dark_TimestampOld))
|
binding.timestamp.setTextColor(ContextCompat.getColor(this, R.color.dark_TimestampOld))
|
||||||
if (status.batteryLevel != 1 && (ViewMap.UPLOADER_BATTERY.dynData?.stepColor ?: 0) == 0)
|
if (status.batteryLevel != 1 && (ViewMap.UPLOADER_BATTERY.dynData?.stepFontColor ?: 0) == 0)
|
||||||
binding.uploaderBattery.setTextColor(lowBatColor)
|
binding.uploaderBattery.setTextColor(lowBatColor)
|
||||||
if ((ViewMap.LOOP.dynData?.stepDraw ?: 0) == 0) // Apply automatic background image only if no dynData or no step images
|
if ((ViewMap.LOOP.dynData?.stepDraw ?: 0) == 0) // Apply automatic background image only if no dynData or no step images
|
||||||
when (loopLevel) {
|
when (loopLevel) {
|
||||||
|
@ -431,7 +431,7 @@ class CustomWatchface : BaseWatchFace() {
|
||||||
);
|
);
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
val TRANSPARENT = "#00000000"
|
||||||
fun init(cwf: CustomWatchface) = values().forEach {
|
fun init(cwf: CustomWatchface) = values().forEach {
|
||||||
it.cwf = cwf
|
it.cwf = cwf
|
||||||
// reset all customized drawable when new watchface is loaded
|
// reset all customized drawable when new watchface is loaded
|
||||||
|
@ -508,11 +508,19 @@ class CustomWatchface : BaseWatchFace() {
|
||||||
FontMap.font(viewJson.optString(FONT.key, FontMap.DEFAULT.key)),
|
FontMap.font(viewJson.optString(FONT.key, FontMap.DEFAULT.key)),
|
||||||
StyleMap.style(viewJson.optString(FONTSTYLE.key, StyleMap.NORMAL.key))
|
StyleMap.style(viewJson.optString(FONTSTYLE.key, StyleMap.NORMAL.key))
|
||||||
)
|
)
|
||||||
view.setTextColor(dynData?.getColor() ?: cwf.getColor(viewJson.optString(FONTCOLOR.key)))
|
view.setTextColor(dynData?.getFontColor() ?: cwf.getColor(viewJson.optString(FONTCOLOR.key)))
|
||||||
view.isAllCaps = viewJson.optBoolean(ALLCAPS.key)
|
view.isAllCaps = viewJson.optBoolean(ALLCAPS.key)
|
||||||
if (viewJson.has(TEXTVALUE.key))
|
if (viewJson.has(TEXTVALUE.key))
|
||||||
view.text = viewJson.optString(TEXTVALUE.key)
|
view.text = viewJson.optString(TEXTVALUE.key)
|
||||||
view.background = dynData?.getDrawable() ?: textDrawable()
|
(dynData?.getDrawable() ?: textDrawable())?.let {
|
||||||
|
if (viewJson.has(COLOR.key) || (dynData?.stepColor ?: 0) > 0) // Note only works on bitmap (png or jpg) not for svg files
|
||||||
|
it.colorFilter = cwf.changeDrawableColor(dynData?.getColor() ?: cwf.getColor(viewJson.optString(COLOR.key)))
|
||||||
|
else
|
||||||
|
it.clearColorFilter()
|
||||||
|
view.background = it
|
||||||
|
} ?: apply { // if no drawable loaded either background key or dynData, then apply color to text background
|
||||||
|
view.setBackgroundColor(dynData?.getColor() ?: cwf.getColor(viewJson.optString(COLOR.key, TRANSPARENT), Color.TRANSPARENT))
|
||||||
|
}
|
||||||
} ?: apply { view.text = "" }
|
} ?: apply { view.text = "" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,26 +529,35 @@ class CustomWatchface : BaseWatchFace() {
|
||||||
view.clearColorFilter()
|
view.clearColorFilter()
|
||||||
viewJson?.let { viewJson ->
|
viewJson?.let { viewJson ->
|
||||||
drawable?.let {
|
drawable?.let {
|
||||||
if (viewJson.has(COLOR.key) || (dynData?.stepColor ?: 0) > 0) // Note only works on bitmap (png or jpg) or xml included into res, not for svg files
|
if (viewJson.has(COLOR.key) || (dynData?.stepColor ?: 0) > 0) // Note only works on bitmap (png or jpg) not for svg files
|
||||||
it.colorFilter = cwf.changeDrawableColor(dynData?.getColor() ?: cwf.getColor(viewJson.optString(COLOR.key)))
|
it.colorFilter = cwf.changeDrawableColor(dynData?.getColor() ?: cwf.getColor(viewJson.optString(COLOR.key)))
|
||||||
else
|
else
|
||||||
it.clearColorFilter()
|
it.clearColorFilter()
|
||||||
view.setImageDrawable(it)
|
view.setImageDrawable(it)
|
||||||
} ?: apply {
|
} ?: apply {
|
||||||
view.setImageDrawable(defaultDrawable?.let { cwf.resources.getDrawable(it) })
|
view.setImageDrawable(defaultDrawable?.let { cwf.resources.getDrawable(it) })
|
||||||
if (viewJson.has(COLOR.key) || (dynData?.stepColor ?: 0) > 0)
|
if (viewJson.has(COLOR.key) || (dynData?.stepColor ?: 0) > 0) // works on xml included into res files
|
||||||
view.setColorFilter(dynData?.getColor() ?: cwf.getColor(viewJson.optString(COLOR.key)))
|
view.setColorFilter(dynData?.getColor() ?: cwf.getColor(viewJson.optString(COLOR.key)))
|
||||||
else
|
else
|
||||||
view.clearColorFilter()
|
view.clearColorFilter()
|
||||||
}
|
}
|
||||||
|
if (view.drawable == null) // if no drowable (either default, hardcoded or dynData, then apply color to background
|
||||||
|
view.setBackgroundColor(dynData?.getColor() ?: cwf.getColor(viewJson.optString(COLOR.key, TRANSPARENT), Color.TRANSPARENT))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun customizeGraphView(view: lecho.lib.hellocharts.view.LineChartView) {
|
fun customizeGraphView(view: lecho.lib.hellocharts.view.LineChartView) {
|
||||||
customizeViewCommon(view)
|
customizeViewCommon(view)
|
||||||
viewJson?.let { viewJson ->
|
viewJson?.let { viewJson ->
|
||||||
view.setBackgroundColor(dynData?.getColor() ?: cwf.getColor(viewJson.optString(COLOR.key, "#0000000000"), Color.TRANSPARENT))
|
(dynData?.getDrawable() ?: textDrawable())?.let {
|
||||||
view.background = dynData?.getDrawable() ?: textDrawable()
|
if (viewJson.has(COLOR.key) || (dynData?.stepColor ?: 0) > 0) // Note only works on bitmap (png or jpg) not for svg files
|
||||||
|
it.colorFilter = cwf.changeDrawableColor(dynData?.getColor() ?: cwf.getColor(viewJson.optString(COLOR.key)))
|
||||||
|
else
|
||||||
|
it.clearColorFilter()
|
||||||
|
view.background = it
|
||||||
|
} ?: apply { // if no drowable loaded, then apply color to background
|
||||||
|
view.setBackgroundColor(dynData?.getColor() ?: cwf.getColor(viewJson.optString(COLOR.key, TRANSPARENT), Color.TRANSPARENT))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -695,6 +712,7 @@ class CustomWatchface : BaseWatchFace() {
|
||||||
|
|
||||||
private val dynDrawable = mutableMapOf<Int, Drawable?>()
|
private val dynDrawable = mutableMapOf<Int, Drawable?>()
|
||||||
private val dynColor = mutableMapOf<Int, Int>()
|
private val dynColor = mutableMapOf<Int, Int>()
|
||||||
|
private val dynFontColor = mutableMapOf<Int, Int>()
|
||||||
private var dataRange: DataRange? = null
|
private var dataRange: DataRange? = null
|
||||||
private var topRange: DataRange? = null
|
private var topRange: DataRange? = null
|
||||||
private var leftRange: DataRange? = null
|
private var leftRange: DataRange? = null
|
||||||
|
@ -703,6 +721,8 @@ class CustomWatchface : BaseWatchFace() {
|
||||||
get() = dynDrawable.size - 1
|
get() = dynDrawable.size - 1
|
||||||
val stepColor: Int
|
val stepColor: Int
|
||||||
get() = dynColor.size - 1
|
get() = dynColor.size - 1
|
||||||
|
val stepFontColor: Int
|
||||||
|
get() = dynFontColor.size - 1
|
||||||
|
|
||||||
val dataValue: Double?
|
val dataValue: Double?
|
||||||
get() = when (valueMap) {
|
get() = when (valueMap) {
|
||||||
|
@ -727,6 +747,7 @@ class CustomWatchface : BaseWatchFace() {
|
||||||
?: (leftRange.invalidData * cwf.zoomFactor).toInt() } } ?: 0
|
?: (leftRange.invalidData * cwf.zoomFactor).toInt() } } ?: 0
|
||||||
fun getRotationOffset(): Int = dataRange?.let { dataRange -> rotationRange?.let { rotRange -> dataValue?.let { valueMap.dynValue(it, dataRange, rotRange) } ?: rotRange.invalidData } } ?: 0
|
fun getRotationOffset(): Int = dataRange?.let { dataRange -> rotationRange?.let { rotRange -> dataValue?.let { valueMap.dynValue(it, dataRange, rotRange) } ?: rotRange.invalidData } } ?: 0
|
||||||
fun getDrawable() = dataRange?.let { dataRange -> dataValue?.let { dynDrawable[valueMap.stepValue(it, dataRange, stepDraw)] } ?: dynDrawable[0] }
|
fun getDrawable() = dataRange?.let { dataRange -> dataValue?.let { dynDrawable[valueMap.stepValue(it, dataRange, stepDraw)] } ?: dynDrawable[0] }
|
||||||
|
fun getFontColor() = if (stepFontColor > 0) dataRange?.let { dataRange -> dataValue?.let { dynFontColor[valueMap.stepValue(it, dataRange, stepFontColor)] } ?: dynFontColor[0] } else null
|
||||||
fun getColor() = if (stepColor > 0) dataRange?.let { dataRange -> dataValue?.let { dynColor[valueMap.stepValue(it, dataRange, stepColor)] } ?: dynColor[0] } else null
|
fun getColor() = if (stepColor > 0) dataRange?.let { dataRange -> dataValue?.let { dynColor[valueMap.stepValue(it, dataRange, stepColor)] } ?: dynColor[0] } else null
|
||||||
private fun load() {
|
private fun load() {
|
||||||
dynDrawable[0] = dataJson.optString(INVALIDIMAGE.key)?.let { cwf.resDataMap[it]?.toDrawable(cwf.resources, width, height) }
|
dynDrawable[0] = dataJson.optString(INVALIDIMAGE.key)?.let { cwf.resDataMap[it]?.toDrawable(cwf.resources, width, height) }
|
||||||
|
@ -741,6 +762,12 @@ class CustomWatchface : BaseWatchFace() {
|
||||||
dynColor[idx] = cwf.getColor(dataJson.optString("${COLOR.key}$idx"))
|
dynColor[idx] = cwf.getColor(dataJson.optString("${COLOR.key}$idx"))
|
||||||
idx++
|
idx++
|
||||||
}
|
}
|
||||||
|
dynFontColor[0] = cwf.getColor(dataJson.optString(INVALIDFONTCOLOR.key))
|
||||||
|
idx = 1
|
||||||
|
while (dataJson.has("${FONTCOLOR.key}$idx")) {
|
||||||
|
dynFontColor[idx] = cwf.getColor(dataJson.optString("${FONTCOLOR.key}$idx"))
|
||||||
|
idx++
|
||||||
|
}
|
||||||
DataRange(dataJson.optDouble(MINDATA.key, valueMap.min), dataJson.optDouble(MAXDATA.key, valueMap.max)).let { defaultRange ->
|
DataRange(dataJson.optDouble(MINDATA.key, valueMap.min), dataJson.optDouble(MAXDATA.key, valueMap.max)).let { defaultRange ->
|
||||||
dataRange = defaultRange
|
dataRange = defaultRange
|
||||||
topRange = parseDataRange(dataJson.optJSONObject(TOPOFFSET.key), defaultRange)
|
topRange = parseDataRange(dataJson.optJSONObject(TOPOFFSET.key), defaultRange)
|
||||||
|
|
Loading…
Reference in a new issue