Merge pull request #2784 from Philoul/wear/new_custom_watchface
Wear CWF Add Week Number field and custom background image for text fields
This commit is contained in:
commit
24c7647d09
8 changed files with 44 additions and 17 deletions
|
@ -12,7 +12,6 @@ import info.nightscout.shared.R
|
|||
import kotlinx.serialization.Serializable
|
||||
import org.json.JSONObject
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
|
@ -77,7 +76,7 @@ enum class ResFormat(val extension: String) {
|
|||
@Serializable
|
||||
data class ResData(val value: ByteArray, val format: ResFormat) {
|
||||
|
||||
fun toDrawable(resources: Resources): Drawable? {
|
||||
fun toDrawable(resources: Resources, width: Int? = null, height: Int? = null): Drawable? {
|
||||
try {
|
||||
return when (format) {
|
||||
ResFormat.PNG, ResFormat.JPG -> {
|
||||
|
@ -86,7 +85,9 @@ data class ResData(val value: ByteArray, val format: ResFormat) {
|
|||
}
|
||||
|
||||
ResFormat.SVG -> {
|
||||
val svg = SVG.getFromInputStream(ByteArrayInputStream(value))
|
||||
val svg = SVG.getFromString(String(value))
|
||||
svg.documentWidth = width?.toFloat() ?: svg.documentWidth
|
||||
svg.documentHeight = height?.toFloat() ?: svg.documentHeight
|
||||
val picture = svg.renderToPicture()
|
||||
PictureDrawable(picture).apply {
|
||||
setBounds(0, 0, svg.documentWidth.toInt(), svg.documentHeight.toInt())
|
||||
|
@ -160,7 +161,8 @@ enum class CwfMetadataKey(val key: String, @StringRes val label: Int, val isPref
|
|||
CWF_PREF_WATCH_SHOW_DIRECTION("key_show_direction", R.string.pref_show_direction_arrow, true),
|
||||
CWF_PREF_WATCH_SHOW_AGO("key_show_ago", R.string.pref_show_ago, true),
|
||||
CWF_PREF_WATCH_SHOW_BG("key_show_bg", R.string.pref_show_bg, true),
|
||||
CWF_PREF_WATCH_SHOW_LOOP_STATUS("key_show_loop_status", R.string.pref_show_loop_status, true);
|
||||
CWF_PREF_WATCH_SHOW_LOOP_STATUS("key_show_loop_status", R.string.pref_show_loop_status, true),
|
||||
CWF_PREF_WATCH_SHOW_WEEK_NUMBER("key_show_week_number", R.string.pref_show_week_number, true);
|
||||
|
||||
companion object {
|
||||
|
||||
|
@ -195,6 +197,7 @@ enum class ViewKeys(val key: String, @StringRes val comment: Int) {
|
|||
TIMEPERIOD("timePeriod", R.string.cwf_comment_timePeriod),
|
||||
DAY_NAME("day_name", R.string.cwf_comment_day_name),
|
||||
DAY("day", R.string.cwf_comment_day),
|
||||
WEEKNUMBER("week_number",R.string.cwf_comment_week_number),
|
||||
MONTH("month", R.string.cwf_comment_month),
|
||||
LOOP("loop", R.string.cwf_comment_loop),
|
||||
DIRECTION("direction", R.string.cwf_comment_direction),
|
||||
|
@ -233,7 +236,8 @@ enum class JsonKeys(val key: String) {
|
|||
COLOR("color"),
|
||||
ALLCAPS("allCaps"),
|
||||
DAYNAMEFORMAT("dayNameFormat"),
|
||||
MONTHFORMAT("monthFormat")
|
||||
MONTHFORMAT("monthFormat"),
|
||||
BACKGROUND("background")
|
||||
}
|
||||
|
||||
enum class JsonKeyValues(val key: String) {
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
<string name="pref_show_bgi">Show BGI</string>
|
||||
<string name="pref_show_direction_arrow">Show Direction Arrow</string>
|
||||
<string name="pref_show_ago">Show Ago</string>
|
||||
<string name="pref_show_week_number">Show Week number</string>
|
||||
<string name="default_custom_watchface_comment">Default watchface, you can click on EXPORT WATCHFACE button to generate a template</string>
|
||||
<string name="wear_default_watchface">Default Watchface</string>
|
||||
<string name="cwf_comment_background">Background image</string>
|
||||
|
@ -88,12 +89,13 @@
|
|||
<string name="cwf_comment_timePeriod">AM or PM</string>
|
||||
<string name="cwf_comment_day_name">Name of day of the week</string>
|
||||
<string name="cwf_comment_day">Day (DD)</string>
|
||||
<string name="cwf_comment_week_number">Week number (ww)</string>
|
||||
<string name="cwf_comment_month">Month name (short)</string>
|
||||
<string name="cwf_comment_loop">Loop status and ago</string>
|
||||
<string name="cwf_comment_direction">Direction arrow</string>
|
||||
<string name="cwf_comment_timestamp">Mintutes ago for last received BG</string>
|
||||
<string name="cwf_comment_sgv">BG value</string>
|
||||
<string name="cwf_comment_cover_plate">Cover image in front of text (dials...)</string>
|
||||
<string name="cwf_comment_cover_plate">Cover image in front of text (dials…)</string>
|
||||
<string name="cwf_comment_hour_hand">Image of hour hand (Analog Watch)</string>
|
||||
<string name="cwf_comment_minute_hand">Image of minute hand (Analog Watch)</string>
|
||||
<string name="cwf_comment_second_hand">Image of second hand (Analog Watch)</string>
|
||||
|
|
|
@ -164,8 +164,8 @@ class CustomWatchface : BaseWatchFace() {
|
|||
.takeIf { it.matches(Regex("E{1,4}")) } ?: "E"
|
||||
monthFormat = json.optString(MONTHFORMAT.key, "MMM")
|
||||
.takeIf { it.matches(Regex("M{1,4}")) } ?: "MMM"
|
||||
binding.dayName.text = dateUtil.dayNameString(dayNameFormat) // Update daynName and month according to format on cwf loading
|
||||
binding.month.text = dateUtil.monthString(monthFormat)
|
||||
binding.dayName.text = dateUtil.dayNameString(dayNameFormat).substringBeforeLast(".") // Update daynName and month according to format on cwf loading
|
||||
binding.month.text = dateUtil.monthString(monthFormat).substringBeforeLast(".")
|
||||
bgColor = when (singleBg.sgvLevel) {
|
||||
1L -> highColor
|
||||
0L -> midColor
|
||||
|
@ -196,6 +196,7 @@ class CustomWatchface : BaseWatchFace() {
|
|||
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)
|
||||
}
|
||||
|
||||
is ImageView -> {
|
||||
|
@ -437,6 +438,7 @@ class CustomWatchface : BaseWatchFace() {
|
|||
TIMEPERIOD(ViewKeys.TIMEPERIOD.key, R.id.timePeriod, null, null, null, null, null),
|
||||
DAY_NAME(ViewKeys.DAY_NAME.key, R.id.day_name, null, null, null, null, null),
|
||||
DAY(ViewKeys.DAY.key, R.id.day, null, null, null, null, null),
|
||||
WEEKNUMBER(ViewKeys.WEEKNUMBER.key, R.id.week_number, R.string.key_show_week_number, null, null, null, null),
|
||||
MONTH(ViewKeys.MONTH.key, R.id.month, null, null, null, null, null),
|
||||
LOOP(ViewKeys.LOOP.key, R.id.loop, R.string.key_show_external_status, null, null, null, null),
|
||||
DIRECTION(ViewKeys.DIRECTION.key, R.id.direction2, R.string.key_show_direction, null, null, null, null),
|
||||
|
@ -594,7 +596,8 @@ private enum class PrefMap(val key: String, @StringRes val prefKey: Int) {
|
|||
SHOW_AGO(CwfMetadataKey.CWF_PREF_WATCH_SHOW_AGO.key, R.string.key_show_ago),
|
||||
SHOW_BG(CwfMetadataKey.CWF_PREF_WATCH_SHOW_BG.key, R.string.key_show_bg),
|
||||
SHOW_BGI(CwfMetadataKey.CWF_PREF_WATCH_SHOW_BGI.key, R.string.key_show_bgi),
|
||||
SHOW_LOOP_STATUS(CwfMetadataKey.CWF_PREF_WATCH_SHOW_LOOP_STATUS.key, R.string.key_show_external_status)
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -113,11 +113,6 @@ class DigitalStyleWatchface : BaseWatchFace() {
|
|||
binding.minute.textSize = 26f
|
||||
binding.hour.letterSpacing = 0.toFloat()
|
||||
binding.minute.letterSpacing = 0.toFloat()
|
||||
|
||||
/* display week number */
|
||||
val mWeekNumber = layoutView?.findViewById<TextView>(R.id.week_number)
|
||||
mWeekNumber?.visibility = sp.getBoolean(R.string.key_show_week_number, false).toVisibility()
|
||||
mWeekNumber?.text = "(" + dateUtil.weekString() + ")"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -373,11 +373,13 @@ abstract class BaseWatchFace : WatchFace() {
|
|||
binding.hour?.text = dateUtil.hourString()
|
||||
binding.minute?.text = dateUtil.minuteString()
|
||||
binding.dateTime?.visibility = sp.getBoolean(R.string.key_show_date, false).toVisibility()
|
||||
binding.dayName?.text = dateUtil.dayNameString(dayNameFormat)
|
||||
binding.dayName?.text = dateUtil.dayNameString(dayNameFormat).substringBeforeLast(".")
|
||||
binding.day?.text = dateUtil.dayString()
|
||||
binding.month?.text = dateUtil.monthString(monthFormat)
|
||||
binding.month?.text = dateUtil.monthString(monthFormat).substringBeforeLast(".")
|
||||
binding.timePeriod?.visibility = android.text.format.DateFormat.is24HourFormat(this).not().toVisibility()
|
||||
binding.timePeriod?.text = dateUtil.amPm()
|
||||
binding.weekNumber?.visibility = sp.getBoolean(R.string.key_show_week_number, false).toVisibility()
|
||||
binding.weekNumber?.text = "(" + dateUtil.weekString() + ")"
|
||||
if (showSecond)
|
||||
setSecond()
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ class WatchfaceViewAdapter(
|
|||
val mainMenuTap = ds?.mainMenuTap ?: sP?.mainMenuTap
|
||||
val chartZoomTap = ds?.chartZoomTap ?: sP?.chartZoomTap
|
||||
val dateTime = ds?.dateTime ?: a2?.dateTime
|
||||
val weekNumber = ds?.weekNumber ?: cU?.weekNumber
|
||||
// val minuteHand = sP?.minuteHand
|
||||
// val secondaryLayout = aL?.secondaryLayout ?: a2?.secondaryLayout ?: aa?.secondaryLayout ?: ds?.secondaryLayout ?: sP?.secondaryLayout
|
||||
// val tertiaryLayout = a2?.tertiaryLayout ?: sP?.tertiaryLayout
|
||||
|
|
|
@ -282,7 +282,7 @@
|
|||
android:textStyle="bold"
|
||||
android:textColor="@color/white"
|
||||
android:visibility="visible"
|
||||
tools:text="day." />
|
||||
tools:text="day" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day"
|
||||
|
@ -296,6 +296,19 @@
|
|||
android:textColor="@color/white"
|
||||
tools:text="01" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/week_number"
|
||||
android:layout_width="0px"
|
||||
android:layout_height="0px"
|
||||
android:layout_marginTop="0px"
|
||||
android:layout_marginLeft="0px"
|
||||
android:gravity="center"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="24px"
|
||||
android:visibility="gone"
|
||||
tools:text="ww" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/month"
|
||||
android:layout_width="50px"
|
||||
|
|
|
@ -9,6 +9,13 @@
|
|||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/key_show_week_number"
|
||||
android:title="@string/pref_show_weeknumber"
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/key_vibrate_hourly"
|
||||
|
|
Loading…
Reference in a new issue