Multiple Background according to BG Values
This commit is contained in:
parent
1379639229
commit
2f1e387cc9
2 changed files with 36 additions and 24 deletions
|
@ -17,11 +17,13 @@ import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipInputStream
|
import java.util.zip.ZipInputStream
|
||||||
import java.util.zip.ZipOutputStream
|
import java.util.zip.ZipOutputStream
|
||||||
|
|
||||||
val CUSTOM_VERSION = "0.5"
|
val CUSTOM_VERSION = "0.6"
|
||||||
enum class CustomWatchfaceDrawableDataKey(val key: String, @DrawableRes val icon: Int?, val fileName: String) {
|
enum class CustomWatchfaceDrawableDataKey(val key: String, @DrawableRes val icon: Int?, val fileName: String) {
|
||||||
UNKNOWN("unknown", null, "Unknown"),
|
UNKNOWN("unknown", null, "Unknown"),
|
||||||
CUSTOM_WATCHFACE("customWatchface", R.drawable.watchface_custom, "CustomWatchface"),
|
CUSTOM_WATCHFACE("customWatchface", R.drawable.watchface_custom, "CustomWatchface"),
|
||||||
BACKGROUND("background", R.drawable.background, "Background"),
|
BACKGROUND("background", R.drawable.background, "Background"),
|
||||||
|
BACKGROUND_HIGH("background", R.drawable.background, "BackgroundHigh"),
|
||||||
|
BACKGROUND_LOW("background", R.drawable.background, "BackgroundLow"),
|
||||||
COVERCHART("cover_chart", null, "CoverChart"),
|
COVERCHART("cover_chart", null, "CoverChart"),
|
||||||
COVERPLATE("cover_plate", R.drawable.simplified_dial, "CoverPlate"),
|
COVERPLATE("cover_plate", R.drawable.simplified_dial, "CoverPlate"),
|
||||||
HOURHAND("hour_hand", R.drawable.hour_hand, "HourHand"),
|
HOURHAND("hour_hand", R.drawable.hour_hand, "HourHand"),
|
||||||
|
|
|
@ -160,46 +160,56 @@ class CustomWatchface : BaseWatchFace() {
|
||||||
-1L -> lowColor
|
-1L -> lowColor
|
||||||
else -> midColor
|
else -> midColor
|
||||||
}
|
}
|
||||||
|
val backGroundDrawable = when (singleBg.sgvLevel) {
|
||||||
|
1L -> drawableDataMap[CustomWatchfaceDrawableDataKey.BACKGROUND_HIGH]?.toDrawable(resources) ?: drawableDataMap[CustomWatchfaceDrawableDataKey.BACKGROUND]?.toDrawable(resources)
|
||||||
|
0L -> drawableDataMap[CustomWatchfaceDrawableDataKey.BACKGROUND]?.toDrawable(resources)
|
||||||
|
-1L -> drawableDataMap[CustomWatchfaceDrawableDataKey.BACKGROUND_LOW]?.toDrawable(resources) ?: drawableDataMap[CustomWatchfaceDrawableDataKey.BACKGROUND]?.toDrawable(resources)
|
||||||
|
else -> drawableDataMap[CustomWatchfaceDrawableDataKey.BACKGROUND]?.toDrawable(resources)
|
||||||
|
}
|
||||||
|
|
||||||
binding.mainLayout.forEach { view ->
|
binding.mainLayout.forEach { view ->
|
||||||
CustomViews.fromId(view.id)?.let { id ->
|
CustomViews.fromId(view.id)?.let { id ->
|
||||||
if (json.has(id.key)) {
|
if (json.has(id.key)) {
|
||||||
var viewjson = json.getJSONObject(id.key)
|
val viewJson = json.getJSONObject(id.key)
|
||||||
var wrapContent = LayoutParams.WRAP_CONTENT
|
val wrapContent = LayoutParams.WRAP_CONTENT
|
||||||
val width = if (viewjson.has("width")) (viewjson.getInt("width") * zoomFactor).toInt() else wrapContent
|
val width = if (viewJson.has("width")) (viewJson.getInt("width") * zoomFactor).toInt() else wrapContent
|
||||||
val height = if (viewjson.has("height")) (viewjson.getInt("height") * zoomFactor).toInt() else wrapContent
|
val height = if (viewJson.has("height")) (viewJson.getInt("height") * zoomFactor).toInt() else wrapContent
|
||||||
var params = FrameLayout.LayoutParams(width, height)
|
val params = FrameLayout.LayoutParams(width, height)
|
||||||
params.topMargin = if (viewjson.has("topmargin")) (viewjson.getInt("topmargin") * zoomFactor).toInt() else 0
|
params.topMargin = if (viewJson.has("topmargin")) (viewJson.getInt("topmargin") * zoomFactor).toInt() else 0
|
||||||
params.leftMargin = if (viewjson.has("leftmargin")) (viewjson.getInt("leftmargin") * zoomFactor).toInt() else 0
|
params.leftMargin = if (viewJson.has("leftmargin")) (viewJson.getInt("leftmargin") * zoomFactor).toInt() else 0
|
||||||
view.setLayoutParams(params)
|
view.layoutParams = params
|
||||||
view.visibility = if (viewjson.has("visibility")) setVisibility(viewjson.getString("visibility"), id.visibility(sp)) else View.GONE
|
view.visibility = if (viewJson.has("visibility")) setVisibility(viewJson.getString("visibility"), id.visibility(sp)) else View.GONE
|
||||||
if (view is TextView) {
|
if (view is TextView) {
|
||||||
view.rotation = if (viewjson.has("rotation")) viewjson.getInt("rotation").toFloat() else 0F
|
view.rotation = if (viewJson.has("rotation")) viewJson.getInt("rotation").toFloat() else 0F
|
||||||
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, ((if (viewjson.has("textsize")) viewjson.getInt("textsize") else 22) * zoomFactor).toFloat())
|
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, ((if (viewJson.has("textsize")) viewJson.getInt("textsize") else 22) * zoomFactor).toFloat())
|
||||||
view.gravity = GravityMap.gravity(if (viewjson.has("gravity")) viewjson.getString("gravity") else GravityMap.CENTER.key)
|
view.gravity = GravityMap.gravity(if (viewJson.has("gravity")) viewJson.getString("gravity") else GravityMap.CENTER.key)
|
||||||
view.setTypeface(
|
view.setTypeface(
|
||||||
FontMap.font(if (viewjson.has("font")) viewjson.getString("font") else FontMap.DEFAULT.key),
|
FontMap.font(if (viewJson.has("font")) viewJson.getString("font") else FontMap.DEFAULT.key),
|
||||||
StyleMap.style(if (viewjson.has("fontStyle")) viewjson.getString("fontStyle") else StyleMap.NORMAL.key)
|
StyleMap.style(if (viewJson.has("fontStyle")) viewJson.getString("fontStyle") else StyleMap.NORMAL.key)
|
||||||
)
|
)
|
||||||
if (viewjson.has("fontColor"))
|
if (viewJson.has("fontColor"))
|
||||||
view.setTextColor(getColor(viewjson.getString("fontColor")))
|
view.setTextColor(getColor(viewJson.getString("fontColor")))
|
||||||
|
|
||||||
if (viewjson.has("textvalue"))
|
if (viewJson.has("textvalue"))
|
||||||
view.text = viewjson.getString("textvalue")
|
view.text = viewJson.getString("textvalue")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view is ImageView) {
|
if (view is ImageView) {
|
||||||
view.clearColorFilter()
|
view.clearColorFilter()
|
||||||
drawableDataMap[CustomWatchfaceDrawableDataKey.fromKey(id.key)]?.toDrawable(resources)?.also {
|
val drawable = if (id.key == CustomWatchfaceDrawableDataKey.BACKGROUND.key)
|
||||||
if (viewjson.has("color"))
|
backGroundDrawable
|
||||||
it.colorFilter = changeDrawableColor(getColor(viewjson.getString("color")))
|
else
|
||||||
|
drawableDataMap[CustomWatchfaceDrawableDataKey.fromKey(id.key)]?.toDrawable(resources)
|
||||||
|
drawable?.let {
|
||||||
|
if (viewJson.has("color"))
|
||||||
|
it.colorFilter = changeDrawableColor(getColor(viewJson.getString("color")))
|
||||||
else
|
else
|
||||||
it.clearColorFilter()
|
it.clearColorFilter()
|
||||||
view.setImageDrawable(it)
|
view.setImageDrawable(it)
|
||||||
} ?: apply {
|
} ?: apply {
|
||||||
view.setImageDrawable(CustomWatchfaceDrawableDataKey.fromKey(id.key).icon?.let { context.getDrawable(it) })
|
view.setImageDrawable(CustomWatchfaceDrawableDataKey.fromKey(id.key).icon?.let { context.getDrawable(it) })
|
||||||
if (viewjson.has("color"))
|
if (viewJson.has("color"))
|
||||||
view.setColorFilter(getColor(viewjson.getString("color")))
|
view.setColorFilter(getColor(viewJson.getString("color")))
|
||||||
else
|
else
|
||||||
view.clearColorFilter()
|
view.clearColorFilter()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue