Merge remote-tracking branch 'origin/dev' into refactor
This commit is contained in:
commit
2904991e14
1 changed files with 139 additions and 122 deletions
|
@ -54,6 +54,7 @@ import org.json.JSONObject
|
|||
import java.io.ByteArrayOutputStream
|
||||
import javax.inject.Inject
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
class CustomWatchface : BaseWatchFace() {
|
||||
|
||||
@Inject lateinit var context: Context
|
||||
|
@ -88,7 +89,6 @@ class CustomWatchface : BaseWatchFace() {
|
|||
.build()
|
||||
}
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
override fun setDataFields() {
|
||||
super.setDataFields()
|
||||
binding.direction2.setImageDrawable(TrendArrowMap.drawable(singleBg.slopeArrow, resources, resDataMap))
|
||||
|
@ -141,7 +141,6 @@ class CustomWatchface : BaseWatchFace() {
|
|||
binding.secondHand.visibility = (binding.secondHand.visibility == View.VISIBLE && showSecond).toVisibility()
|
||||
}
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
private fun setWatchfaceStyle() {
|
||||
val customWatchface = persistence.readCustomWatchface() ?: persistence.readCustomWatchface(true)
|
||||
customWatchface?.let {
|
||||
|
@ -185,35 +184,11 @@ class CustomWatchface : BaseWatchFace() {
|
|||
view.visibility = setVisibility(viewJson.optString(VISIBILITY.key, JsonKeyValues.GONE.key), id.visibility(sp))
|
||||
when (view) {
|
||||
is TextView -> {
|
||||
view.rotation = viewJson.optInt(ROTATION.key).toFloat()
|
||||
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, (viewJson.optInt(TEXTSIZE.key, 22) * zoomFactor).toFloat())
|
||||
view.gravity = GravityMap.gravity(viewJson.optString(GRAVITY.key, GravityMap.CENTER.key))
|
||||
view.setTypeface(
|
||||
FontMap.font(viewJson.optString(FONT.key, FontMap.DEFAULT.key)),
|
||||
StyleMap.style(viewJson.optString(FONTSTYLE.key, StyleMap.NORMAL.key))
|
||||
)
|
||||
view.setTextColor(getColor(viewJson.optString(FONTCOLOR.key)))
|
||||
view.isAllCaps = viewJson.optBoolean(ALLCAPS.key)
|
||||
if (viewJson.has(TEXTVALUE.key))
|
||||
view.text = viewJson.optString(TEXTVALUE.key)
|
||||
view.background = resDataMap[viewJson.optString(BACKGROUND.key)]?.toDrawable(resources, width, height)
|
||||
id.customizeTextView(view, viewJson, resDataMap, zoomFactor, resources, ::getColor)
|
||||
}
|
||||
|
||||
is ImageView -> {
|
||||
view.clearColorFilter()
|
||||
id.drawable(resources, resDataMap, singleBg.sgvLevel)?.let {
|
||||
if (viewJson.has(COLOR.key)) // Note only works on bitmap (png or jpg) or xml included into res, not for svg files
|
||||
it.colorFilter = changeDrawableColor(getColor(viewJson.optString(COLOR.key)))
|
||||
else
|
||||
it.clearColorFilter()
|
||||
view.setImageDrawable(it)
|
||||
} ?: apply {
|
||||
view.setImageDrawable(id.defaultDrawable?.let { resources.getDrawable(it) })
|
||||
if (viewJson.has(COLOR.key))
|
||||
view.setColorFilter(getColor(viewJson.optString(COLOR.key)))
|
||||
else
|
||||
view.clearColorFilter()
|
||||
}
|
||||
id.customizeImageView(view, viewJson, resDataMap, singleBg, resources, ::getColor, ::changeDrawableColor)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -506,6 +481,45 @@ class CustomWatchface : BaseWatchFace() {
|
|||
else -> drawableDataMap[cd.fileName]?.toDrawable(resources)
|
||||
}
|
||||
}
|
||||
|
||||
fun customizeTextView(view: TextView, viewJson: JSONObject, resDataMap: CwfResDataMap, zoomFactor: Double, resources: Resources, getColor: (String) -> Int) {
|
||||
view.rotation = viewJson.optInt(ROTATION.key).toFloat()
|
||||
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, (viewJson.optInt(TEXTSIZE.key, 22) * zoomFactor).toFloat())
|
||||
view.gravity = GravityMap.gravity(viewJson.optString(GRAVITY.key, GravityMap.CENTER.key))
|
||||
view.setTypeface(
|
||||
FontMap.font(viewJson.optString(FONT.key, FontMap.DEFAULT.key)),
|
||||
StyleMap.style(viewJson.optString(FONTSTYLE.key, StyleMap.NORMAL.key))
|
||||
)
|
||||
view.setTextColor(getColor(viewJson.optString(FONTCOLOR.key)))
|
||||
view.isAllCaps = viewJson.optBoolean(ALLCAPS.key)
|
||||
if (viewJson.has(TEXTVALUE.key))
|
||||
view.text = viewJson.optString(TEXTVALUE.key)
|
||||
view.background = resDataMap[viewJson.optString(BACKGROUND.key)]?.toDrawable(resources, view.width, view.height)
|
||||
}
|
||||
|
||||
fun customizeImageView(
|
||||
view: ImageView,
|
||||
viewJson: JSONObject,
|
||||
resDataMap: CwfResDataMap,
|
||||
singleBg: EventData.SingleBg,
|
||||
resources: Resources,
|
||||
getColor: (String) -> Int,
|
||||
changeDrawableColor: (Int) -> ColorFilter
|
||||
) {
|
||||
view.clearColorFilter()
|
||||
drawable(resources, resDataMap, singleBg.sgvLevel)?.let {
|
||||
if (viewJson.has(COLOR.key)) // Note only works on bitmap (png or jpg) or xml included into res, not for svg files
|
||||
it.colorFilter = changeDrawableColor(getColor(viewJson.optString(COLOR.key)))
|
||||
else
|
||||
it.clearColorFilter()
|
||||
view.setImageDrawable(it)
|
||||
} ?: apply {
|
||||
view.setImageDrawable(defaultDrawable?.let { resources.getDrawable(it) })
|
||||
if (viewJson.has(COLOR.key))
|
||||
view.setColorFilter(getColor(viewJson.optString(COLOR.key)))
|
||||
else
|
||||
view.clearColorFilter()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -531,7 +545,9 @@ private enum class TrendArrowMap(val symbol: String, @DrawableRes val icon: Int,
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
private enum class GravityMap(val key: String, val gravity: Int) {
|
||||
|
||||
CENTER(JsonKeyValues.CENTER.key, Gravity.CENTER),
|
||||
LEFT(JsonKeyValues.LEFT.key, Gravity.LEFT),
|
||||
RIGHT(JsonKeyValues.RIGHT.key, Gravity.RIGHT);
|
||||
|
@ -608,5 +624,6 @@ private enum class PrefMap(val key: String, @StringRes val prefKey: Int) {
|
|||
SHOW_LOOP_STATUS(CwfMetadataKey.CWF_PREF_WATCH_SHOW_LOOP_STATUS.key, R.string.key_show_external_status),
|
||||
SHOW_WEEK_NUMBER(CwfMetadataKey.CWF_PREF_WATCH_SHOW_WEEK_NUMBER.key, R.string.key_show_week_number)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue