From 5c923d4a07750e328869f70b5bc54c78c950dc56 Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Tue, 5 Jul 2022 22:07:38 +0200 Subject: [PATCH] chore: wear watchface use databinding --- .../androidaps/di/WearServicesModule.kt | 1 + .../watchfaces/AapsLargeWatchface.kt | 157 +++++------ .../androidaps/watchfaces/AapsV2Watchface.kt | 259 +++++++++--------- .../androidaps/watchfaces/AapsWatchface.kt | 172 ++++++------ .../watchfaces/BigChartWatchface.kt | 171 ++++++------ .../androidaps/watchfaces/CockpitWatchface.kt | 74 ++--- .../watchfaces/DigitalStyleWatchface.kt | 84 +++--- .../androidaps/watchfaces/NoChartWatchface.kt | 119 ++++---- .../watchfaces/SteampunkWatchface.kt | 140 +++++----- .../watchfaces/utils/WatchfaceViewAdapter.kt | 102 +++++++ .../res/layout-notround/activity_bigchart.xml | 6 +- .../activity_bigchart_small.xml | 6 +- .../res/layout-notround/activity_cockpit.xml | 10 +- .../layout-notround/activity_digitalstyle.xml | 24 +- .../res/layout-notround/activity_home.xml | 4 +- .../res/layout-notround/activity_home_2.xml | 16 +- .../layout-notround/activity_home_large.xml | 4 +- .../res/layout-notround/activity_nochart.xml | 6 +- .../activity_nochart_small.xml | 6 +- .../layout-notround/activity_steampunk.xml | 6 +- .../res/layout-round/activity_bigchart.xml | 6 +- .../layout-round/activity_bigchart_small.xml | 6 +- .../res/layout-round/activity_cockpit.xml | 10 +- .../layout-round/activity_digitalstyle.xml | 18 +- .../main/res/layout-round/activity_home.xml | 4 +- .../main/res/layout-round/activity_home_2.xml | 16 +- .../res/layout-round/activity_home_large.xml | 4 +- .../res/layout-round/activity_nochart.xml | 6 +- .../layout-round/activity_nochart_small.xml | 6 +- .../res/layout-round/activity_steampunk.xml | 6 +- 30 files changed, 743 insertions(+), 706 deletions(-) create mode 100644 wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt diff --git a/wear/src/main/java/info/nightscout/androidaps/di/WearServicesModule.kt b/wear/src/main/java/info/nightscout/androidaps/di/WearServicesModule.kt index 6e318f0e45..93204ba917 100644 --- a/wear/src/main/java/info/nightscout/androidaps/di/WearServicesModule.kt +++ b/wear/src/main/java/info/nightscout/androidaps/di/WearServicesModule.kt @@ -6,6 +6,7 @@ import info.nightscout.androidaps.comm.DataLayerListenerServiceWear import info.nightscout.androidaps.complications.* import info.nightscout.androidaps.tile.* import info.nightscout.androidaps.watchfaces.* +import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace @Module @Suppress("unused") diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsLargeWatchface.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsLargeWatchface.kt index 39e7252498..b8f922f300 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsLargeWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsLargeWatchface.kt @@ -1,116 +1,93 @@ package info.nightscout.androidaps.watchfaces import android.graphics.Color -import androidx.annotation.LayoutRes +import android.view.LayoutInflater import androidx.core.content.ContextCompat +import androidx.viewbinding.ViewBinding import com.ustwo.clockwise.common.WatchMode import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.ActivityHomeLargeBinding +import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace class AapsLargeWatchface : BaseWatchFace() { - @LayoutRes override fun layoutResource(): Int = R.layout.activity_home_large + private lateinit var binding: ActivityHomeLargeBinding + + override fun inflateLayout(inflater: LayoutInflater): ViewBinding { + binding = ActivityHomeLargeBinding.inflate(inflater) + return binding + } override fun setColorDark() { - mLinearLayout?.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_mLinearLayout)) - mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) - when (singleBg.sgvLevel) { - 1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - } - - 0L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - } - - -1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - } + binding.secondaryLayout.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_mLinearLayout)) + binding.time.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) + val color = when (singleBg.sgvLevel) { + 1L -> R.color.dark_highColor + 0L -> R.color.dark_midColor + -1L -> R.color.dark_lowColor + else -> R.color.dark_midColor } - if (ageLevel == 1) mTimestamp?.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_mTimestamp1_home)) - else mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_TimestampOld)) - - if (status.batteryLevel == 1) mUploaderBattery?.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_uploaderBattery)) - else mUploaderBattery?.setTextColor(ContextCompat.getColor(this, R.color.dark_uploaderBatteryEmpty)) - - mStatus?.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_mStatus_home)) + binding.sgv.setTextColor(ContextCompat.getColor(this, color)) + binding.delta.setTextColor(ContextCompat.getColor(this, color)) + binding.direction.setTextColor(ContextCompat.getColor(this, color)) + val colorTime = if (ageLevel == 1) if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_mTimestamp1_home else R.color.dark_TimestampOld + binding.timestamp.setTextColor(ContextCompat.getColor(this, colorTime)) + val colourBat = if (status.batteryLevel == 1) if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_uploaderBattery else R.color.dark_uploaderBatteryEmpty + binding.uploaderBattery.setTextColor(ContextCompat.getColor(this, colourBat)) + binding.status.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_mStatus_home)) } override fun setColorBright() { if (currentWatchMode == WatchMode.INTERACTIVE) { - mLinearLayout?.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.light_background else R.color.light_stripe_background)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background)) - when (singleBg.sgvLevel) { - 1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - } - - 0L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - } - - -1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - } + binding.secondaryLayout.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.light_background else R.color.light_stripe_background)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background)) + val color = when (singleBg.sgvLevel) { + 1L -> R.color.light_highColor + 0L -> R.color.light_midColor + -1L -> R.color.light_lowColor + else -> R.color.light_midColor } - if (ageLevel == 1) mTimestamp?.setTextColor(if (dividerMatchesBg) Color.BLACK else Color.WHITE) - else mTimestamp?.setTextColor(Color.RED) + binding.sgv.setTextColor(ContextCompat.getColor(this, color)) + binding.delta.setTextColor(ContextCompat.getColor(this, color)) + binding.direction.setTextColor(ContextCompat.getColor(this, color)) - if (status.batteryLevel == 1) mUploaderBattery?.setTextColor(if (dividerMatchesBg) Color.BLACK else Color.WHITE) - else mUploaderBattery?.setTextColor(Color.RED) + val colorTime = if (ageLevel == 1) if (dividerMatchesBg) Color.BLACK else Color.WHITE else Color.RED + binding.timestamp.setTextColor(colorTime) + val colourBat = if (status.batteryLevel == 1) if (dividerMatchesBg) Color.BLACK else Color.WHITE else Color.RED + binding.uploaderBattery.setTextColor(colourBat) - mStatus?.setTextColor(if (dividerMatchesBg) Color.BLACK else Color.WHITE) - mTime?.setTextColor(Color.BLACK) + binding.status.setTextColor(if (dividerMatchesBg) Color.BLACK else Color.WHITE) + binding.time.setTextColor(Color.BLACK) } else { - mRelativeLayout?.setBackgroundColor(Color.BLACK) - mLinearLayout?.setBackgroundColor(if (dividerMatchesBg) Color.BLACK else Color.LTGRAY) - when (singleBg.sgvLevel) { - 1L -> { - mSgv?.setTextColor(Color.YELLOW) - mDirection?.setTextColor(Color.YELLOW) - mDelta?.setTextColor(Color.YELLOW) - } - - 0L -> { - mSgv?.setTextColor(Color.WHITE) - mDirection?.setTextColor(Color.WHITE) - mDelta?.setTextColor(Color.WHITE) - } - - -1L -> { - mSgv?.setTextColor(Color.RED) - mDirection?.setTextColor(Color.RED) - mDelta?.setTextColor(Color.RED) - } + binding.mainLayout.setBackgroundColor(Color.BLACK) + binding.secondaryLayout.setBackgroundColor(if (dividerMatchesBg) Color.BLACK else Color.LTGRAY) + val color = when (singleBg.sgvLevel) { + 1L -> Color.YELLOW + 0L -> Color.WHITE + -1L -> Color.RED + else -> Color.WHITE } - mUploaderBattery?.setTextColor(if (dividerMatchesBg) Color.WHITE else Color.BLACK) - mTimestamp?.setTextColor(if (dividerMatchesBg) Color.WHITE else Color.BLACK) - mStatus?.setTextColor(if (dividerMatchesBg) Color.WHITE else Color.BLACK) - mTime?.setTextColor(Color.WHITE) + binding.sgv.setTextColor(ContextCompat.getColor(this, color)) + binding.delta.setTextColor(ContextCompat.getColor(this, color)) + binding.direction.setTextColor(ContextCompat.getColor(this, color)) + + binding.uploaderBattery.setTextColor(if (dividerMatchesBg) Color.WHITE else Color.BLACK) + binding.timestamp.setTextColor(if (dividerMatchesBg) Color.WHITE else Color.BLACK) + binding.status.setTextColor(if (dividerMatchesBg) Color.WHITE else Color.BLACK) + binding.time.setTextColor(Color.WHITE) } } override fun setColorLowRes() { - mLinearLayout?.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_mLinearLayout)) - mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mTimestamp?.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_mTimestamp1_home)) - mUploaderBattery?.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_uploaderBattery)) - mStatus?.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_mStatus_home)) + binding.secondaryLayout.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_mLinearLayout)) + binding.time.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) + binding.sgv.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.delta.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.direction.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.timestamp.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_mTimestamp1_home)) + binding.uploaderBattery.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_uploaderBattery)) + binding.status.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_mStatus_home)) } -} \ No newline at end of file +} diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsV2Watchface.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsV2Watchface.kt index 5665af5c09..887fe53072 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsV2Watchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsV2Watchface.kt @@ -1,110 +1,109 @@ package info.nightscout.androidaps.watchfaces import android.graphics.Color +import android.view.LayoutInflater import androidx.annotation.ColorInt -import androidx.annotation.LayoutRes import androidx.core.content.ContextCompat +import androidx.viewbinding.ViewBinding import com.ustwo.clockwise.common.WatchMode import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.ActivityHome2Binding +import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace class AapsV2Watchface : BaseWatchFace() { - @LayoutRes override fun layoutResource(): Int = R.layout.activity_home_2 + private lateinit var binding: ActivityHome2Binding + + override fun inflateLayout(inflater: LayoutInflater): ViewBinding { + binding = ActivityHome2Binding.inflate(inflater) + return binding + } override fun setColorDark() { @ColorInt val dividerTxtColor = if (dividerMatchesBg) ContextCompat.getColor(this, R.color.dark_midColor) else Color.BLACK @ColorInt val dividerBatteryOkColor = ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_uploaderBattery) @ColorInt val dividerBgColor = ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_statusView) - mLinearLayout?.setBackgroundColor(dividerBgColor) - mLinearLayout2?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) - mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mIOB1?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mIOB2?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mCOB1?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mCOB2?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDay?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mMonth?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mLoop?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.secondaryLayout.setBackgroundColor(dividerBgColor) + binding.tertiaryLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) + binding.time.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.iob1.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.iob2.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.cob1.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.cob2.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.day.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.month.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.loop.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) setTextSizes() - when (singleBg.sgvLevel) { - 1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - } - - 0L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - } - - -1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - } + val color = when (singleBg.sgvLevel) { + 1L -> R.color.dark_highColor + 0L -> R.color.dark_midColor + -1L -> R.color.dark_lowColor + else -> R.color.dark_midColor } - if (ageLevel == 1) mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - else mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_TimestampOld)) + binding.sgv.setTextColor(ContextCompat.getColor(this, color)) + binding.direction.setTextColor(ContextCompat.getColor(this, color)) - if (status.batteryLevel == 1) mUploaderBattery?.setTextColor(dividerBatteryOkColor) - else mUploaderBattery?.setTextColor(ContextCompat.getColor(this, R.color.dark_uploaderBatteryEmpty)) + val colorTime = if (ageLevel == 1) R.color.dark_midColor else R.color.dark_TimestampOld + binding.timestamp.setTextColor(ContextCompat.getColor(this, colorTime)) + val colourBat = if (status.batteryLevel == 1) dividerBatteryOkColor else ContextCompat.getColor(this, R.color.dark_uploaderBatteryEmpty) + binding.uploaderBattery.setTextColor(colourBat) - mRigBattery?.setTextColor(dividerTxtColor) - mDelta?.setTextColor(dividerTxtColor) - mAvgDelta?.setTextColor(dividerTxtColor) - mBasalRate?.setTextColor(dividerTxtColor) - mBgi?.setTextColor(dividerTxtColor) + binding.rigBattery.setTextColor(dividerTxtColor) + binding.delta.setTextColor(dividerTxtColor) + binding.avgDelta.setTextColor(dividerTxtColor) + binding.basalRate?.setTextColor(dividerTxtColor) + binding.bgi.setTextColor(dividerTxtColor) when (loopLevel) { - -1 -> mLoop?.setBackgroundResource(R.drawable.loop_grey_25) - 1 -> mLoop?.setBackgroundResource(R.drawable.loop_green_25) - else -> mLoop?.setBackgroundResource(R.drawable.loop_red_25) - } - if (chart != null) { - highColor = ContextCompat.getColor(this, R.color.dark_highColor) - lowColor = ContextCompat.getColor(this, R.color.dark_lowColor) - midColor = ContextCompat.getColor(this, R.color.dark_midColor) - gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) - basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark) - basalCenterColor = ContextCompat.getColor(this, R.color.basal_light) - pointSize = 2 - setupCharts() + -1 -> binding.loop.setBackgroundResource(R.drawable.loop_grey_25) + 1 -> binding.loop.setBackgroundResource(R.drawable.loop_green_25) + else -> binding.loop.setBackgroundResource(R.drawable.loop_red_25) } + + highColor = ContextCompat.getColor(this, R.color.dark_highColor) + lowColor = ContextCompat.getColor(this, R.color.dark_lowColor) + midColor = ContextCompat.getColor(this, R.color.dark_midColor) + gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) + basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark) + basalCenterColor = ContextCompat.getColor(this, R.color.basal_light) + pointSize = 2 + setupCharts() } override fun setColorLowRes() { @ColorInt val dividerTxtColor = if (dividerMatchesBg) ContextCompat.getColor(this, R.color.dark_midColor) else Color.BLACK @ColorInt val dividerBgColor = ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_statusView) - mLinearLayout?.setBackgroundColor(dividerBgColor) - mLinearLayout2?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) - mLoop?.setBackgroundResource(R.drawable.loop_grey_25) - mLoop?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_Timestamp)) - mDelta?.setTextColor(dividerTxtColor) - mAvgDelta?.setTextColor(dividerTxtColor) - mRigBattery?.setTextColor(dividerTxtColor) - mUploaderBattery?.setTextColor(dividerTxtColor) - mBasalRate?.setTextColor(dividerTxtColor) - mBgi?.setTextColor(dividerTxtColor) - mIOB1?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mIOB2?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mCOB1?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mCOB2?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDay?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mMonth?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) - if (chart != null) { - highColor = ContextCompat.getColor(this, R.color.dark_midColor) - lowColor = ContextCompat.getColor(this, R.color.dark_midColor) - midColor = ContextCompat.getColor(this, R.color.dark_midColor) - gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) - basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark_lowres) - basalCenterColor = ContextCompat.getColor(this, R.color.basal_light_lowres) - pointSize = 2 - setupCharts() - } + binding.secondaryLayout.setBackgroundColor(dividerBgColor) + binding.tertiaryLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) + binding.loop.setBackgroundResource(R.drawable.loop_grey_25) + binding.loop.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.sgv.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.direction.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.timestamp.setTextColor(ContextCompat.getColor(this, R.color.dark_Timestamp)) + binding.delta.setTextColor(dividerTxtColor) + binding.avgDelta.setTextColor(dividerTxtColor) + binding.rigBattery.setTextColor(dividerTxtColor) + binding.uploaderBattery.setTextColor(dividerTxtColor) + binding.basalRate?.setTextColor(dividerTxtColor) + binding.bgi.setTextColor(dividerTxtColor) + binding.iob1.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.iob2.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.cob1.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.cob2.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.day.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.month.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.time.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) + + highColor = ContextCompat.getColor(this, R.color.dark_midColor) + lowColor = ContextCompat.getColor(this, R.color.dark_midColor) + midColor = ContextCompat.getColor(this, R.color.dark_midColor) + gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) + basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark_lowres) + basalCenterColor = ContextCompat.getColor(this, R.color.basal_light_lowres) + pointSize = 2 + setupCharts() + setTextSizes() } @@ -112,58 +111,50 @@ class AapsV2Watchface : BaseWatchFace() { if (currentWatchMode == WatchMode.INTERACTIVE) { @ColorInt val dividerTxtColor = if (dividerMatchesBg) Color.BLACK else ContextCompat.getColor(this, R.color.dark_midColor) @ColorInt val dividerBgColor = ContextCompat.getColor(this, if (dividerMatchesBg) R.color.light_background else R.color.light_stripe_background) - mLinearLayout?.setBackgroundColor(dividerBgColor) - mLinearLayout2?.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background)) - mTime?.setTextColor(Color.BLACK) - mIOB1?.setTextColor(Color.BLACK) - mIOB2?.setTextColor(Color.BLACK) - mCOB1?.setTextColor(Color.BLACK) - mCOB2?.setTextColor(Color.BLACK) - mDay?.setTextColor(Color.BLACK) - mMonth?.setTextColor(Color.BLACK) - mLoop?.setTextColor(Color.BLACK) + binding.secondaryLayout.setBackgroundColor(dividerBgColor) + binding.tertiaryLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background)) + binding.time.setTextColor(Color.BLACK) + binding.iob1.setTextColor(Color.BLACK) + binding.iob2.setTextColor(Color.BLACK) + binding.cob1.setTextColor(Color.BLACK) + binding.cob2.setTextColor(Color.BLACK) + binding.day.setTextColor(Color.BLACK) + binding.month.setTextColor(Color.BLACK) + binding.loop.setTextColor(Color.BLACK) setTextSizes() - when (singleBg.sgvLevel) { - 1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - } - - 0L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - } - - -1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - } + val color = when (singleBg.sgvLevel) { + 1L -> R.color.light_highColor + 0L -> R.color.light_midColor + -1L -> R.color.light_lowColor + else -> R.color.light_midColor } - if (ageLevel == 1) mTimestamp?.setTextColor(Color.BLACK) - else mTimestamp?.setTextColor(Color.RED) - if (status.batteryLevel == 1) mUploaderBattery?.setTextColor(dividerTxtColor) - else mUploaderBattery?.setTextColor(Color.RED) - mRigBattery?.setTextColor(dividerTxtColor) - mDelta?.setTextColor(dividerTxtColor) - mAvgDelta?.setTextColor(dividerTxtColor) - mBasalRate?.setTextColor(dividerTxtColor) - mBgi?.setTextColor(dividerTxtColor) + binding.sgv.setTextColor(ContextCompat.getColor(this, color)) + binding.direction.setTextColor(ContextCompat.getColor(this, color)) + val colorTime = if (ageLevel == 1) Color.BLACK else Color.RED + binding.timestamp.setTextColor(colorTime) + val colourBat = if (status.batteryLevel == 1) dividerTxtColor else Color.RED + binding.uploaderBattery.setTextColor(colourBat) + binding.rigBattery.setTextColor(dividerTxtColor) + binding.delta.setTextColor(dividerTxtColor) + binding.avgDelta.setTextColor(dividerTxtColor) + binding.basalRate?.setTextColor(dividerTxtColor) + binding.bgi.setTextColor(dividerTxtColor) when (loopLevel) { - -1 -> mLoop?.setBackgroundResource(R.drawable.loop_grey_25) - 1 -> mLoop?.setBackgroundResource(R.drawable.loop_green_25) - else -> mLoop?.setBackgroundResource(R.drawable.loop_red_25) - } - if (chart != null) { - highColor = ContextCompat.getColor(this, R.color.light_highColor) - lowColor = ContextCompat.getColor(this, R.color.light_lowColor) - midColor = ContextCompat.getColor(this, R.color.light_midColor) - gridColor = ContextCompat.getColor(this, R.color.light_gridColor) - basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_light) - basalCenterColor = ContextCompat.getColor(this, R.color.basal_dark) - pointSize = 2 - setupCharts() + -1 -> binding.loop.setBackgroundResource(R.drawable.loop_grey_25) + 1 -> binding.loop.setBackgroundResource(R.drawable.loop_green_25) + else -> binding.loop.setBackgroundResource(R.drawable.loop_red_25) } + + highColor = ContextCompat.getColor(this, R.color.light_highColor) + lowColor = ContextCompat.getColor(this, R.color.light_lowColor) + midColor = ContextCompat.getColor(this, R.color.light_midColor) + gridColor = ContextCompat.getColor(this, R.color.light_gridColor) + basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_light) + basalCenterColor = ContextCompat.getColor(this, R.color.basal_dark) + pointSize = 2 + setupCharts() + } else { setColorDark() } @@ -171,11 +162,11 @@ class AapsV2Watchface : BaseWatchFace() { private fun setTextSizes() { if (status.detailedIob) { - mIOB1?.textSize = 14f - mIOB2?.textSize = 10f + binding.iob1.textSize = 14f + binding.iob2.textSize = 10f } else { - mIOB1?.textSize = 10f - mIOB2?.textSize = 14f + binding.iob1.textSize = 10f + binding.iob2.textSize = 14f } } -} \ No newline at end of file +} diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsWatchface.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsWatchface.kt index 48e457a3d1..4086d479ec 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/AapsWatchface.kt @@ -1,114 +1,106 @@ package info.nightscout.androidaps.watchfaces import android.graphics.Color -import androidx.annotation.LayoutRes +import android.view.LayoutInflater import androidx.core.content.ContextCompat +import androidx.viewbinding.ViewBinding import com.ustwo.clockwise.common.WatchMode import info.nightscout.androidaps.R +import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace +import info.nightscout.androidaps.databinding.ActivityHomeBinding class AapsWatchface : BaseWatchFace() { - @LayoutRes override fun layoutResource(): Int = R.layout.activity_home + private lateinit var binding: ActivityHomeBinding + + override fun inflateLayout(inflater: LayoutInflater): ViewBinding { + binding = ActivityHomeBinding.inflate(inflater) + return binding + } override fun setColorDark() { - mLinearLayout?.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_statusView)) - mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) - when (singleBg.sgvLevel) { - 1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - } - - 0L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - } - - -1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - } - } - if (ageLevel == 1) mTimestamp?.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_mTimestamp1_home)) - else mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_TimestampOld)) - if (status.batteryLevel == 1) mUploaderBattery?.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_uploaderBattery)) - else mUploaderBattery?.setTextColor(ContextCompat.getColor(this, R.color.dark_uploaderBatteryEmpty)) - mStatus?.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_mStatus_home)) - if (chart != null) { - highColor = ContextCompat.getColor(this, R.color.dark_highColor) - lowColor = ContextCompat.getColor(this, R.color.dark_lowColor) - midColor = ContextCompat.getColor(this, R.color.dark_midColor) - gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) - basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark) - basalCenterColor = ContextCompat.getColor(this, R.color.basal_light) - pointSize = 2 - setupCharts() + binding.secondaryLayout.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_statusView)) + binding.time.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) + val color = when (singleBg.sgvLevel) { + 1L -> R.color.dark_highColor + 0L -> R.color.dark_midColor + -1L -> R.color.dark_lowColor + else -> R.color.dark_midColor } + binding.sgv.setTextColor(ContextCompat.getColor(this, color)) + binding.delta.setTextColor(ContextCompat.getColor(this, color)) + binding.direction.setTextColor(ContextCompat.getColor(this, color)) + + val colorTime = if (ageLevel == 1) if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_mTimestamp1_home else R.color.dark_TimestampOld + binding.timestamp.setTextColor(ContextCompat.getColor(this, colorTime)) + + val colourBat = if (status.batteryLevel == 1) if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_uploaderBattery else R.color.dark_uploaderBatteryEmpty + binding.uploaderBattery.setTextColor(ContextCompat.getColor(this, colourBat)) + + binding.status.setTextColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_midColor else R.color.dark_mStatus_home)) + + highColor = ContextCompat.getColor(this, R.color.dark_highColor) + lowColor = ContextCompat.getColor(this, R.color.dark_lowColor) + midColor = ContextCompat.getColor(this, R.color.dark_midColor) + gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) + basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark) + basalCenterColor = ContextCompat.getColor(this, R.color.basal_light) + pointSize = 2 + setupCharts() + } override fun setColorLowRes() { - mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_Timestamp)) - if (chart != null) { - highColor = ContextCompat.getColor(this, R.color.dark_midColor) - lowColor = ContextCompat.getColor(this, R.color.dark_midColor) - midColor = ContextCompat.getColor(this, R.color.dark_midColor) - gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) - basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark_lowres) - basalCenterColor = ContextCompat.getColor(this, R.color.basal_light_lowres) - pointSize = 2 - setupCharts() - } + binding.time.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) + binding.sgv.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.delta.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.timestamp.setTextColor(ContextCompat.getColor(this, R.color.dark_Timestamp)) + + highColor = ContextCompat.getColor(this, R.color.dark_midColor) + lowColor = ContextCompat.getColor(this, R.color.dark_midColor) + midColor = ContextCompat.getColor(this, R.color.dark_midColor) + gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) + basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark_lowres) + basalCenterColor = ContextCompat.getColor(this, R.color.basal_light_lowres) + pointSize = 2 + setupCharts() } override fun setColorBright() { if (currentWatchMode == WatchMode.INTERACTIVE) { - mLinearLayout?.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.light_background else R.color.light_stripe_background)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background)) - when (singleBg.sgvLevel) { - 1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - } - - 0L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - } - - -1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - } - } - if (ageLevel == 1) mTimestamp?.setTextColor(if (dividerMatchesBg) Color.BLACK else Color.WHITE) - else mTimestamp?.setTextColor(Color.RED) - if (status.batteryLevel == 1) mUploaderBattery?.setTextColor(if (dividerMatchesBg) Color.BLACK else Color.WHITE) - else mUploaderBattery?.setTextColor(Color.RED) - mStatus?.setTextColor(if (dividerMatchesBg) Color.BLACK else Color.WHITE) - mTime?.setTextColor(Color.BLACK) - if (chart != null) { - highColor = ContextCompat.getColor(this, R.color.light_highColor) - lowColor = ContextCompat.getColor(this, R.color.light_lowColor) - midColor = ContextCompat.getColor(this, R.color.light_midColor) - gridColor = ContextCompat.getColor(this, R.color.light_gridColor) - basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_light) - basalCenterColor = ContextCompat.getColor(this, R.color.basal_dark) - pointSize = 2 - setupCharts() + binding.secondaryLayout.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.light_background else R.color.light_stripe_background)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background)) + val color = when (singleBg.sgvLevel) { + 1L -> R.color.light_highColor + 0L -> R.color.light_midColor + -1L -> R.color.light_lowColor + else -> R.color.light_midColor } + binding.sgv.setTextColor(ContextCompat.getColor(this, color)) + binding.delta.setTextColor(ContextCompat.getColor(this, color)) + binding.direction.setTextColor(ContextCompat.getColor(this, color)) + + val colorTime = if (ageLevel == 1) if (dividerMatchesBg) Color.BLACK else Color.WHITE else Color.RED + binding.timestamp.setTextColor(colorTime) + + val colourBat = if (status.batteryLevel == 1) if (dividerMatchesBg) Color.BLACK else Color.WHITE else Color.RED + binding.uploaderBattery.setTextColor(colourBat) + + binding.status.setTextColor(if (dividerMatchesBg) Color.BLACK else Color.WHITE) + binding.time.setTextColor(Color.BLACK) + + highColor = ContextCompat.getColor(this, R.color.light_highColor) + lowColor = ContextCompat.getColor(this, R.color.light_lowColor) + midColor = ContextCompat.getColor(this, R.color.light_midColor) + gridColor = ContextCompat.getColor(this, R.color.light_gridColor) + basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_light) + basalCenterColor = ContextCompat.getColor(this, R.color.basal_dark) + pointSize = 2 + setupCharts() + } else { setColorDark() } } -} \ No newline at end of file +} diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BigChartWatchface.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BigChartWatchface.kt index 698ce41142..f6b472797b 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BigChartWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BigChartWatchface.kt @@ -3,119 +3,110 @@ package info.nightscout.androidaps.watchfaces import android.annotation.SuppressLint -import androidx.annotation.LayoutRes +import android.view.LayoutInflater import androidx.core.content.ContextCompat +import androidx.viewbinding.ViewBinding import com.ustwo.clockwise.common.WatchMode import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.ActivityBigchartBinding +import info.nightscout.androidaps.databinding.ActivityBigchartSmallBinding +import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace +import info.nightscout.androidaps.watchfaces.utils.WatchfaceViewAdapter class BigChartWatchface : BaseWatchFace() { - @LayoutRes override fun layoutResource(): Int = - if (resources.displayMetrics.widthPixels < SCREEN_SIZE_SMALL || resources.displayMetrics.heightPixels < SCREEN_SIZE_SMALL) R.layout.activity_bigchart_small - else R.layout.activity_bigchart + private lateinit var binding: WatchfaceViewAdapter + + override fun inflateLayout(inflater: LayoutInflater): ViewBinding { + if (resources.displayMetrics.widthPixels < SCREEN_SIZE_SMALL || resources.displayMetrics.heightPixels < SCREEN_SIZE_SMALL) { + val layoutBinding = ActivityBigchartSmallBinding.inflate(inflater) + binding = WatchfaceViewAdapter.getBinding(layoutBinding) + return layoutBinding + } + val layoutBinding = ActivityBigchartBinding.inflate(inflater) + binding = WatchfaceViewAdapter.getBinding(layoutBinding) + return layoutBinding + } @SuppressLint("SetTextI18n") override fun setDataFields() { super.setDataFields() - mStatus?.text = status.externalStatus + if (sp.getBoolean(R.string.key_show_cob, true)) (" " + this.status.cob) else "" + binding.status?.text = status.externalStatus + if (sp.getBoolean(R.string.key_show_cob, true)) (" " + this.status.cob) else "" } override fun setColorLowRes() { - mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) - mStatus?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_Timestamp)) - if (chart != null) { - highColor = ContextCompat.getColor(this, R.color.dark_midColor) - lowColor = ContextCompat.getColor(this, R.color.dark_midColor) - midColor = ContextCompat.getColor(this, R.color.dark_midColor) - gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) - basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark_lowres) - basalCenterColor = ContextCompat.getColor(this, R.color.basal_light_lowres) - pointSize = 2 - setupCharts() - } + binding.time?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) + binding.status?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) + binding.sgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.delta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.avgDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.timestamp.setTextColor(ContextCompat.getColor(this, R.color.dark_Timestamp)) + + highColor = ContextCompat.getColor(this, R.color.dark_midColor) + lowColor = ContextCompat.getColor(this, R.color.dark_midColor) + midColor = ContextCompat.getColor(this, R.color.dark_midColor) + gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) + basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark_lowres) + basalCenterColor = ContextCompat.getColor(this, R.color.basal_light_lowres) + pointSize = 2 + setupCharts() } override fun setColorDark() { - mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) - mStatus?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) - when (singleBg.sgvLevel) { - 1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - } + binding.time?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) + binding.status?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) + val color = when (singleBg.sgvLevel) { + 1L -> R.color.dark_highColor + 0L -> R.color.dark_midColor + -1L -> R.color.dark_lowColor + else -> R.color.dark_midColor + } + binding.sgv?.setTextColor(ContextCompat.getColor(this, color)) + binding.delta?.setTextColor(ContextCompat.getColor(this, color)) + binding.avgDelta?.setTextColor(ContextCompat.getColor(this, color)) - 0L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - } + val colorTime = if (ageLevel == 1) R.color.dark_Timestamp else R.color.dark_TimestampOld + binding.timestamp.setTextColor(ContextCompat.getColor(this, colorTime)) - -1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - } - } - if (ageLevel == 1) { - mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_Timestamp)) - } else { - mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_TimestampOld)) - } - if (chart != null) { - highColor = ContextCompat.getColor(this, R.color.dark_highColor) - lowColor = ContextCompat.getColor(this, R.color.dark_lowColor) - midColor = ContextCompat.getColor(this, R.color.dark_midColor) - gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) - basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark) - basalCenterColor = ContextCompat.getColor(this, R.color.basal_light) - pointSize = 2 - setupCharts() - } + highColor = ContextCompat.getColor(this, R.color.dark_highColor) + lowColor = ContextCompat.getColor(this, R.color.dark_lowColor) + midColor = ContextCompat.getColor(this, R.color.dark_midColor) + gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) + basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark) + basalCenterColor = ContextCompat.getColor(this, R.color.basal_light) + pointSize = 2 + setupCharts() } override fun setColorBright() { if (currentWatchMode == WatchMode.INTERACTIVE) { - mTime?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_time)) - mStatus?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_status)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background)) - when (singleBg.sgvLevel) { - 1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - } - - 0L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - } - - -1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - } - } - if (ageLevel == 1) mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.light_mTimestamp1)) - else mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.light_mTimestamp)) - if (chart != null) { - highColor = ContextCompat.getColor(this, R.color.light_highColor) - lowColor = ContextCompat.getColor(this, R.color.light_lowColor) - midColor = ContextCompat.getColor(this, R.color.light_midColor) - gridColor = ContextCompat.getColor(this, R.color.light_gridColor) - basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_light) - basalCenterColor = ContextCompat.getColor(this, R.color.basal_dark) - pointSize = 2 - setupCharts() + binding.time?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_time)) + binding.status?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_status)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background)) + val color = when (singleBg.sgvLevel) { + 1L -> R.color.light_highColor + 0L -> R.color.light_midColor + -1L -> R.color.light_lowColor + else -> R.color.light_midColor } + binding.sgv?.setTextColor(ContextCompat.getColor(this, color)) + binding.delta?.setTextColor(ContextCompat.getColor(this, color)) + binding.avgDelta?.setTextColor(ContextCompat.getColor(this, color)) + + val colorTime = if (ageLevel == 1) R.color.light_mTimestamp1 else R.color.light_mTimestamp + binding.timestamp.setTextColor(ContextCompat.getColor(this, colorTime)) + + highColor = ContextCompat.getColor(this, R.color.light_highColor) + lowColor = ContextCompat.getColor(this, R.color.light_lowColor) + midColor = ContextCompat.getColor(this, R.color.light_midColor) + gridColor = ContextCompat.getColor(this, R.color.light_gridColor) + basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_light) + basalCenterColor = ContextCompat.getColor(this, R.color.basal_dark) + pointSize = 2 + setupCharts() + } else { setColorDark() } diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CockpitWatchface.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CockpitWatchface.kt index cb15fbc7f9..2736b49e1b 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CockpitWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CockpitWatchface.kt @@ -1,8 +1,11 @@ package info.nightscout.androidaps.watchfaces +import android.view.LayoutInflater import android.view.View -import androidx.annotation.LayoutRes +import androidx.viewbinding.ViewBinding import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.ActivityCockpitBinding +import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace /** * Created by andrew-warrington on 18/11/2017. @@ -10,37 +13,36 @@ import info.nightscout.androidaps.R */ class CockpitWatchface : BaseWatchFace() { - @LayoutRes override fun layoutResource(): Int = R.layout.activity_cockpit + private lateinit var binding: ActivityCockpitBinding + + override fun inflateLayout(inflater: LayoutInflater): ViewBinding { + binding = ActivityCockpitBinding.inflate(inflater) + return binding + } override fun setColorDark() { - mRelativeLayout?.setBackgroundResource(R.drawable.airplane_cockpit_outside_clouds) + binding.mainLayout.setBackgroundResource(R.drawable.airplane_cockpit_outside_clouds) setTextSizes() - when (singleBg.sgvLevel) { - 1L -> { - mHighLight?.setBackgroundResource(R.drawable.airplane_led_yellow_lit) - mLowLight?.setBackgroundResource(R.drawable.airplane_led_grey_unlit) - } - - 0L -> { - mHighLight?.setBackgroundResource(R.drawable.airplane_led_grey_unlit) - mLowLight?.setBackgroundResource(R.drawable.airplane_led_grey_unlit) - } - - -1L -> { - mHighLight?.setBackgroundResource(R.drawable.airplane_led_grey_unlit) - mLowLight?.setBackgroundResource(R.drawable.airplane_led_red_lit) - } + val led = when (singleBg.sgvLevel) { + 1L -> R.drawable.airplane_led_yellow_lit + 0L -> R.drawable.airplane_led_grey_unlit + -1L -> R.drawable.airplane_led_red_lit + else -> R.drawable.airplane_led_grey_unlit } + + binding.highLight.setBackgroundResource(led) + binding.lowLight.setBackgroundResource(led) + when (loopLevel) { - -1 -> mLoop?.setBackgroundResource(R.drawable.loop_grey_25) - 1 -> mLoop?.setBackgroundResource(R.drawable.loop_green_25) - else -> mLoop?.setBackgroundResource(R.drawable.loop_red_25) + -1 -> binding.loop.setBackgroundResource(R.drawable.loop_grey_25) + 1 -> binding.loop.setBackgroundResource(R.drawable.loop_green_25) + else -> binding.loop.setBackgroundResource(R.drawable.loop_red_25) } invalidate() } override fun setColorLowRes() { - mRelativeLayout?.setBackgroundResource(R.drawable.airplane_cockpit_outside_clouds_lowres) + binding.mainLayout.setBackgroundResource(R.drawable.airplane_cockpit_outside_clouds_lowres) } override fun setColorBright() { @@ -49,28 +51,28 @@ class CockpitWatchface : BaseWatchFace() { private fun setTextSizes() { if (status.detailedIob) { - if (bIsRound) mIOB2?.textSize = 10f - else mIOB2?.textSize = 9f + if (bIsRound) binding.iob2.textSize = 10f + else binding.iob2.textSize = 9f } else { - if (bIsRound) mIOB2?.textSize = 13f - else mIOB2?.textSize = 12f + if (bIsRound) binding.iob2.textSize = 13f + else binding.iob2.textSize = 12f } - if (mUploaderBattery?.visibility != View.GONE && mRigBattery?.visibility != View.GONE) { + if (binding.uploaderBattery.visibility != View.GONE && binding.rigBattery.visibility != View.GONE) { if (bIsRound) { - mUploaderBattery?.textSize = 12f - mRigBattery?.textSize = 12f + binding.uploaderBattery.textSize = 12f + binding.rigBattery.textSize = 12f } else { - mUploaderBattery?.textSize = 10f - mRigBattery?.textSize = 10f + binding.uploaderBattery.textSize = 10f + binding.rigBattery.textSize = 10f } } else { if (bIsRound) { - mUploaderBattery?.textSize = 13f - mRigBattery?.textSize = 13f + binding.uploaderBattery.textSize = 13f + binding.rigBattery.textSize = 13f } else { - mUploaderBattery?.textSize = 12f - mRigBattery?.textSize = 12f + binding.uploaderBattery.textSize = 12f + binding.rigBattery.textSize = 12f } } } -} \ No newline at end of file +} diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/DigitalStyleWatchface.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/DigitalStyleWatchface.kt index de808a21be..d2aa2257fa 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/DigitalStyleWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/DigitalStyleWatchface.kt @@ -4,18 +4,26 @@ package info.nightscout.androidaps.watchfaces import android.annotation.SuppressLint import android.support.wearable.watchface.WatchFaceStyle +import android.view.LayoutInflater import android.view.View import android.widget.LinearLayout import android.widget.TextView -import androidx.annotation.LayoutRes import androidx.core.content.ContextCompat +import androidx.viewbinding.ViewBinding import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.ActivityDigitalstyleBinding import info.nightscout.androidaps.extensions.toVisibility +import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace import info.nightscout.shared.logging.LTag class DigitalStyleWatchface : BaseWatchFace() { - @LayoutRes override fun layoutResource(): Int = R.layout.activity_digitalstyle + private lateinit var binding: ActivityDigitalstyleBinding + + override fun inflateLayout(inflater: LayoutInflater): ViewBinding { + binding = ActivityDigitalstyleBinding.inflate(inflater) + return binding + } override fun getWatchFaceStyle(): WatchFaceStyle { return WatchFaceStyle.Builder(this) @@ -26,39 +34,31 @@ class DigitalStyleWatchface : BaseWatchFace() { } override fun setColorDark() { - when (singleBg.sgvLevel) { - 1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - } - - 0L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - } - - -1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - mDirection?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - } + val color = when (singleBg.sgvLevel) { + 1L -> R.color.dark_highColor + 0L -> R.color.dark_midColor + -1L -> R.color.dark_lowColor + else -> R.color.dark_midColor } - if (ageLevel == 1) mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - else mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_TimestampOld)) + binding.sgv.setTextColor(ContextCompat.getColor(this, color)) + binding.direction.setTextColor(ContextCompat.getColor(this, color)) - if (status.batteryLevel == 1) mUploaderBattery?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - else mUploaderBattery?.setTextColor(ContextCompat.getColor(this, R.color.dark_uploaderBatteryEmpty)) + val colorTime = if (ageLevel == 1) R.color.dark_midColor else R.color.dark_TimestampOld + binding.timestamp.setTextColor(ContextCompat.getColor(this, colorTime)) + + val colorBat = if (status.batteryLevel == 1) R.color.dark_midColor else R.color.dark_uploaderBatteryEmpty + binding.uploaderBattery.setTextColor(ContextCompat.getColor(this, colorBat)) + + highColor = ContextCompat.getColor(this, R.color.dark_highColor) + lowColor = ContextCompat.getColor(this, R.color.dark_lowColor) + midColor = ContextCompat.getColor(this, R.color.dark_midColor) + gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) + basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark) + basalCenterColor = ContextCompat.getColor(this, R.color.basal_light) + pointSize = 1 + setupCharts() + setWatchfaceStyle() - if (chart != null) { - highColor = ContextCompat.getColor(this, R.color.dark_highColor) - lowColor = ContextCompat.getColor(this, R.color.dark_lowColor) - midColor = ContextCompat.getColor(this, R.color.dark_midColor) - gridColor = ContextCompat.getColor(this, R.color.dark_gridColor) - basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark) - basalCenterColor = ContextCompat.getColor(this, R.color.basal_light) - pointSize = 1 - setupCharts() - setWatchfaceStyle() - } } @SuppressLint("SetTextI18n") @@ -103,19 +103,19 @@ class DigitalStyleWatchface : BaseWatchFace() { val isShowDate = sp.getBoolean(R.string.key_show_date, false) if (!isShowDate) { layoutView?.findViewById(R.id.date_time)?.visibility = View.GONE - mHour?.textSize = 62f - mMinute?.textSize = 40f - mHour?.letterSpacing = (-0.066).toFloat() - mMinute?.letterSpacing = (-0.066).toFloat() + binding.hour.textSize = 62f + binding.minute.textSize = 40f + binding.hour.letterSpacing = (-0.066).toFloat() + binding.minute.letterSpacing = (-0.066).toFloat() } else { layoutView?.findViewById(R.id.date_time)?.visibility = View.VISIBLE - mHour?.textSize = 40f - mMinute?.textSize = 26f - mHour?.letterSpacing = 0.toFloat() - mMinute?.letterSpacing = 0.toFloat() + binding.hour.textSize = 40f + binding.minute.textSize = 26f + binding.hour.letterSpacing = 0.toFloat() + binding.minute.letterSpacing = 0.toFloat() /* display week number */ - val mWeekNumber = layoutView?.findViewById(R.id.weeknumber) + val mWeekNumber = layoutView?.findViewById(R.id.week_number) mWeekNumber?.visibility = sp.getBoolean(R.string.key_show_week_number, false).toVisibility() mWeekNumber?.text = "(" + dateUtil.weekString() + ")" } @@ -128,4 +128,4 @@ class DigitalStyleWatchface : BaseWatchFace() { override fun setColorBright() { setColorDark() /* getCurrentWatchMode() == WatchMode.AMBIENT or WatchMode.INTERACTIVE */ } -} \ No newline at end of file +} diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/NoChartWatchface.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/NoChartWatchface.kt index bcbb388684..e277945540 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/NoChartWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/NoChartWatchface.kt @@ -1,87 +1,78 @@ package info.nightscout.androidaps.watchfaces -import androidx.annotation.LayoutRes +import android.view.LayoutInflater import androidx.core.content.ContextCompat +import androidx.viewbinding.ViewBinding import com.ustwo.clockwise.common.WatchMode import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.ActivityBigchartBinding +import info.nightscout.androidaps.databinding.ActivityBigchartSmallBinding +import info.nightscout.androidaps.databinding.ActivityNochartBinding +import info.nightscout.androidaps.databinding.ActivityNochartSmallBinding +import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace +import info.nightscout.androidaps.watchfaces.utils.WatchfaceViewAdapter class NoChartWatchface : BaseWatchFace() { - @LayoutRes override fun layoutResource(): Int = - if (resources.displayMetrics.widthPixels < SCREEN_SIZE_SMALL || resources.displayMetrics.heightPixels < SCREEN_SIZE_SMALL) R.layout.activity_nochart_small - else R.layout.activity_nochart + private lateinit var binding: WatchfaceViewAdapter + + override fun inflateLayout(inflater: LayoutInflater): ViewBinding { + if (resources.displayMetrics.widthPixels < SCREEN_SIZE_SMALL || resources.displayMetrics.heightPixels < SCREEN_SIZE_SMALL) { + val layoutBinding = ActivityNochartSmallBinding.inflate(inflater) + binding = WatchfaceViewAdapter.getBinding(layoutBinding) + return layoutBinding + } + val layoutBinding = ActivityNochartBinding.inflate(inflater) + binding = WatchfaceViewAdapter.getBinding(layoutBinding) + return layoutBinding + } override fun setColorLowRes() { - mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) - mStatus?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_Timestamp)) + binding.time?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) + binding.status?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) + binding.sgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.delta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.avgDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) + binding.timestamp.setTextColor(ContextCompat.getColor(this, R.color.dark_Timestamp)) } override fun setColorDark() { - mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) - mStatus?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) - when (singleBg.sgvLevel) { - 1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor)) - } - - 0L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor)) - } - - -1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_lowColor)) - } - } - if (ageLevel == 1) { - mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_Timestamp)) - } else { - mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_TimestampOld)) + binding.time?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime)) + binding.status?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) + val color = when (singleBg.sgvLevel) { + 1L -> R.color.dark_highColor + 0L -> R.color.dark_midColor + -1L -> R.color.dark_lowColor + else -> R.color.dark_midColor } + binding.sgv?.setTextColor(ContextCompat.getColor(this, color)) + binding.delta?.setTextColor(ContextCompat.getColor(this, color)) + binding.avgDelta?.setTextColor(ContextCompat.getColor(this, color)) + val colorTime = if (ageLevel == 1) R.color.dark_Timestamp else R.color.dark_TimestampOld + binding.timestamp.setTextColor(ContextCompat.getColor(this, colorTime)) } override fun setColorBright() { if (currentWatchMode == WatchMode.INTERACTIVE) { - mTime?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_time)) - mStatus?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_status)) - mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background)) - when (singleBg.sgvLevel) { - 1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor)) - } - - 0L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_midColor)) - } - - -1L -> { - mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - mAvgDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_lowColor)) - } - } - if (ageLevel == 1) { - mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.light_mTimestamp1)) - } else { - mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.light_mTimestamp)) + binding.time?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_time)) + binding.status?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_status)) + binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background)) + val color = when (singleBg.sgvLevel) { + 1L -> R.color.light_highColor + 0L -> R.color.light_midColor + -1L -> R.color.light_lowColor + else -> R.color.light_midColor } + binding.sgv?.setTextColor(ContextCompat.getColor(this, color)) + binding.delta?.setTextColor(ContextCompat.getColor(this, color)) + binding.avgDelta?.setTextColor(ContextCompat.getColor(this, color)) + val colorTime = if (ageLevel == 1) R.color.light_mTimestamp1 else R.color.light_mTimestamp + binding.timestamp.setTextColor(ContextCompat.getColor(this, colorTime)) + } else { setColorDark() } } -} \ No newline at end of file +} diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/SteampunkWatchface.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/SteampunkWatchface.kt index eba08790d6..e387062017 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/SteampunkWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/SteampunkWatchface.kt @@ -2,12 +2,15 @@ package info.nightscout.androidaps.watchfaces +import android.view.LayoutInflater import android.view.animation.Animation import android.view.animation.LinearInterpolator import android.view.animation.RotateAnimation -import androidx.annotation.LayoutRes import androidx.core.content.ContextCompat +import androidx.viewbinding.ViewBinding import info.nightscout.androidaps.R +import info.nightscout.androidaps.databinding.ActivitySteampunkBinding +import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace import info.nightscout.shared.SafeParse.stringToFloat import org.joda.time.TimeOfDay @@ -19,8 +22,12 @@ class SteampunkWatchface : BaseWatchFace() { private var lastEndDegrees = 0f private var deltaRotationAngle = 0f + private lateinit var binding: ActivitySteampunkBinding - @LayoutRes override fun layoutResource(): Int = R.layout.activity_steampunk + override fun inflateLayout(inflater: LayoutInflater): ViewBinding { + binding = ActivitySteampunkBinding.inflate(inflater) + return binding + } override fun onCreate() { forceSquareCanvas = true @@ -29,48 +36,48 @@ class SteampunkWatchface : BaseWatchFace() { override fun setColorDark() { if (ageLevel() <= 0 && singleBg.timeStamp != 0L) { - mLinearLayout2?.setBackgroundResource(R.drawable.redline) - mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.red_600)) + binding.tertiaryLayout.setBackgroundResource(R.drawable.redline) + binding.timestamp.setTextColor(ContextCompat.getColor(this, R.color.red_600)) } else { - mLinearLayout2?.setBackgroundResource(0) - mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.black_86p)) + binding.tertiaryLayout.setBackgroundResource(0) + binding.timestamp.setTextColor(ContextCompat.getColor(this, R.color.black_86p)) } - mLoop?.setTextColor(ContextCompat.getColor(this, if (loopLevel == 0) R.color.red_600 else R.color.black_86p)) + binding.loop.setTextColor(ContextCompat.getColor(this, if (loopLevel == 0) R.color.red_600 else R.color.black_86p)) if (singleBg.sgvString != "---") { - var rotationAngle = 0f //by default, show ? on the dial (? is at 0 degrees on the dial) + var rotationAngle = 0f // by default, show ? on the dial (? is at 0 degrees on the dial) if (singleBg.glucoseUnits != "-") { - //ensure the glucose dial is the correct units - mGlucoseDial?.setImageResource(if (singleBg.glucoseUnits == "mmol") R.drawable.steampunk_dial_mmol else R.drawable.steampunk_dial_mgdl) + // ensure the glucose dial is the correct units + binding.glucoseDial.setImageResource(if (singleBg.glucoseUnits == "mmol") R.drawable.steampunk_dial_mmol else R.drawable.steampunk_dial_mgdl) - //convert the Sgv to degrees of rotation + // convert the Sgv to degrees of rotation rotationAngle = if (singleBg.glucoseUnits == "mmol") stringToFloat(singleBg.sgvString) * 18f //convert to mg/dL, which is equivalent to degrees - else stringToFloat(singleBg.sgvString) //if glucose a value is received, use it to determine the amount of rotation of the dial. + else stringToFloat(singleBg.sgvString) // if glucose a value is received, use it to determine the amount of rotation of the dial. } - if (rotationAngle > 330) rotationAngle = 330f //if the glucose value is higher than 330 then show "HIGH" on the dial. ("HIGH" is at 330 degrees on the dial) - if (rotationAngle != 0f && rotationAngle < 30) rotationAngle = 30f //if the glucose value is lower than 30 show "LOW" on the dial. ("LOW" is at 30 degrees on the dial) + if (rotationAngle > 330) rotationAngle = 330f // if the glucose value is higher than 330 then show "HIGH" on the dial. ("HIGH" is at 330 degrees on the dial) + if (rotationAngle != 0f && rotationAngle < 30) rotationAngle = 30f // if the glucose value is lower than 30 show "LOW" on the dial. ("LOW" is at 30 degrees on the dial) if (lastEndDegrees == 0f) lastEndDegrees = rotationAngle - //rotate glucose dial + // rotate glucose dial val rotate = RotateAnimation(lastEndDegrees, rotationAngle - lastEndDegrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f).apply { fillAfter = true interpolator = LinearInterpolator() duration = 1 } - mGlucoseDial?.startAnimation(rotate) + binding.glucoseDial.startAnimation(rotate) lastEndDegrees = rotationAngle //store the final angle as a starting point for the next rotation. } - //set the delta gauge and rotate the delta pointer - var deltaIsNegative = 1f //by default go clockwise - if (singleBg.avgDelta != "--") { //if a legitimate delta value is + // set the delta gauge and rotate the delta pointer + var deltaIsNegative = 1f // by default go clockwise + if (singleBg.avgDelta != "--") { // if a legitimate delta value is // received, // then... if (singleBg.avgDelta[0] == '-') deltaIsNegative = -1f //if the delta is negative, go counter-clockwise val absAvgDelta = stringToFloat(singleBg.avgDelta.substring(1)) //get rid of the sign so it can be converted to float. var autoGranularity = "0" //auto-granularity off - //ensure the delta gauge is the right units and granularity + // ensure the delta gauge is the right units and granularity if (singleBg.glucoseUnits != "-") { if (singleBg.glucoseUnits == "mmol") { if (sp.getString("delta_granularity", "2") == "4") { //Auto granularity @@ -82,15 +89,15 @@ class SteampunkWatchface : BaseWatchFace() { } } if (sp.getString("delta_granularity", "2") == "1" || autoGranularity == "1") { //low - mLinearLayout?.setBackgroundResource(R.drawable.steampunk_gauge_mmol_10) + binding.secondaryLayout.setBackgroundResource(R.drawable.steampunk_gauge_mmol_10) deltaRotationAngle = absAvgDelta * 30f } if (sp.getString("delta_granularity", "2") == "2" || autoGranularity == "2") { //medium - mLinearLayout?.setBackgroundResource(R.drawable.steampunk_gauge_mmol_05) + binding.secondaryLayout.setBackgroundResource(R.drawable.steampunk_gauge_mmol_05) deltaRotationAngle = absAvgDelta * 60f } if (sp.getString("delta_granularity", "2") == "3" || autoGranularity == "3") { //high - mLinearLayout?.setBackgroundResource(R.drawable.steampunk_gauge_mmol_03) + binding.secondaryLayout.setBackgroundResource(R.drawable.steampunk_gauge_mmol_03) deltaRotationAngle = absAvgDelta * 100f } } else { @@ -103,44 +110,40 @@ class SteampunkWatchface : BaseWatchFace() { } } if (sp.getString("delta_granularity", "2") == "1" || autoGranularity == "1") { //low - mLinearLayout?.setBackgroundResource(R.drawable.steampunk_gauge_mgdl_20) + binding.secondaryLayout.setBackgroundResource(R.drawable.steampunk_gauge_mgdl_20) deltaRotationAngle = absAvgDelta * 1.5f } if (sp.getString("delta_granularity", "2") == "2" || autoGranularity == "2") { //medium - mLinearLayout?.setBackgroundResource(R.drawable.steampunk_gauge_mgdl_10) + binding.secondaryLayout.setBackgroundResource(R.drawable.steampunk_gauge_mgdl_10) deltaRotationAngle = absAvgDelta * 3f } if (sp.getString("delta_granularity", "2") == "3" || autoGranularity == "3") { //high - mLinearLayout?.setBackgroundResource(R.drawable.steampunk_gauge_mgdl_5) + binding.secondaryLayout.setBackgroundResource(R.drawable.steampunk_gauge_mgdl_5) deltaRotationAngle = absAvgDelta * 6f } } } if (deltaRotationAngle > 40) deltaRotationAngle = 40f - mDeltaGauge?.rotation = deltaRotationAngle * deltaIsNegative + binding.deltaPointer.rotation = deltaRotationAngle * deltaIsNegative } - //rotate the minute hand. - mMinuteHand?.rotation = TimeOfDay().minuteOfHour * 6f + // rotate the minute hand. + binding.minuteHand.rotation = TimeOfDay().minuteOfHour * 6f - //rotate the hour hand. - mHourHand?.rotation = TimeOfDay().hourOfDay * 30f + TimeOfDay().minuteOfHour * 0.5f + // rotate the hour hand. + binding.hourHand.rotation = TimeOfDay().hourOfDay * 30f + TimeOfDay().minuteOfHour * 0.5f setTextSizes() - mLoop?.setBackgroundResource(0) - if (chart != null) { - highColor = ContextCompat.getColor(this, R.color.black) - lowColor = ContextCompat.getColor(this, R.color.black) - midColor = ContextCompat.getColor(this, R.color.black) - gridColor = ContextCompat.getColor(this, R.color.grey_steampunk) - basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark) - basalCenterColor = ContextCompat.getColor(this, R.color.basal_dark) - pointSize = if (sp.getInt(R.string.key_chart_time_frame, 3) < 3) { - 2 - } else { - 1 - } - setupCharts() - } + binding.loop.setBackgroundResource(0) + + highColor = ContextCompat.getColor(this, R.color.black) + lowColor = ContextCompat.getColor(this, R.color.black) + midColor = ContextCompat.getColor(this, R.color.black) + gridColor = ContextCompat.getColor(this, R.color.grey_steampunk) + basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark) + basalCenterColor = ContextCompat.getColor(this, R.color.basal_dark) + pointSize = if (sp.getInt(R.string.key_chart_time_frame, 3) < 3) 2 else 1 + setupCharts() + invalidate() } @@ -162,36 +165,23 @@ class SteampunkWatchface : BaseWatchFace() { fontLarge = 13f } - //top row. large font unless text too big (i.e. detailedIOB) - mCOB2?.textSize = fontLarge - mBasalRate?.textSize = fontLarge - if (status.iobDetail.length < 7) { - mIOB2?.textSize = fontLarge - } else { - mIOB2?.textSize = fontSmall - } + // top row. large font unless text too big (i.e. detailedIOB) + binding.cob2.textSize = fontLarge + binding.basalRate.textSize = fontLarge + val fontIob = if (status.iobDetail.length < 7) fontLarge else fontSmall + binding.iob2.textSize = fontIob - //bottom row. font medium unless text too long (i.e. longer than 9' timestamp) - mLoop?.let { mLoop -> - mTimestamp?.let { mTimestamp -> - if (mTimestamp.text.length < 3 || mLoop.text.length < 3) { //always resize these fields together, for symmetry. - mTimestamp.textSize = fontMedium - mLoop.textSize = fontMedium - } else { - mTimestamp.textSize = fontSmall - mLoop.textSize = fontSmall - } - } - } + // bottom row. font medium unless text too long (i.e. longer than 9' timestamp) + // always resize these fields together, for symmetry. + val font = if (binding.timestamp.text.length < 3 || binding.loop.text.length < 3) fontMedium else fontSmall + binding.loop.textSize = font + binding.timestamp.textSize = font + + // if both batteries are shown, make them smaller. + val fontBat = if (sp.getBoolean(R.string.key_show_uploader_battery, true) && sp.getBoolean(R.string.key_show_rig_battery, false)) fontSmall else fontMedium + binding.uploaderBattery.textSize = fontBat + binding.rigBattery.textSize = fontBat - //if both batteries are shown, make them smaller. - if (sp.getBoolean(R.string.key_show_uploader_battery, true) && sp.getBoolean(R.string.key_show_rig_battery, false)) { - mUploaderBattery?.textSize = fontSmall - mRigBattery?.textSize = fontSmall - } else { - mUploaderBattery?.textSize = fontMedium - mRigBattery?.textSize = fontMedium - } } override fun changeChartTimeframe() { @@ -200,4 +190,4 @@ class SteampunkWatchface : BaseWatchFace() { pointSize = if (timeframe < 3) 2 else 1 sp.putString(R.string.key_chart_time_frame, timeframe.toString()) } -} \ No newline at end of file +} diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt new file mode 100644 index 0000000000..3b1b8113b8 --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt @@ -0,0 +1,102 @@ +package info.nightscout.androidaps.watchfaces.utils + +import androidx.viewbinding.ViewBinding +import info.nightscout.androidaps.databinding.ActivityHomeLargeBinding +import info.nightscout.androidaps.databinding.ActivityHome2Binding +import info.nightscout.androidaps.databinding.ActivityHomeBinding +import info.nightscout.androidaps.databinding.ActivityBigchartBinding +import info.nightscout.androidaps.databinding.ActivityBigchartSmallBinding +import info.nightscout.androidaps.databinding.ActivityCockpitBinding +import info.nightscout.androidaps.databinding.ActivityDigitalstyleBinding +import info.nightscout.androidaps.databinding.ActivityNochartBinding +import info.nightscout.androidaps.databinding.ActivitySteampunkBinding + +/** + * WatchfaceViewAdapter binds all WatchFace variants shared attributes to one common view adapter. + * Requires at least one of the ViewBinding as a parameter. Recommended to use the factory object to create the binding. + */ +class WatchfaceViewAdapter( + aL: ActivityHomeLargeBinding? = null, + a2: ActivityHome2Binding? = null, + aa: ActivityHomeBinding? = null, + bC: ActivityBigchartBinding? = null, + bCs: ActivityBigchartSmallBinding? = null, + cp: ActivityCockpitBinding? = null, + ds: ActivityDigitalstyleBinding? = null, + nC: ActivityNochartBinding? = null, + sP: ActivitySteampunkBinding? = null +) { + + init { + if (aL == null && a2 == null && aa == null && bC == null && bCs == null && cp == null && ds == null && nC == null && sP == null) { + throw IllegalArgumentException("Require at least on Binding parameter") + } + } + + private val errorMessage = "Missing require View Binding parameter" + // Required attributes + val mainLayout = + aL?.mainLayout ?: a2?.mainLayout ?: aa?.mainLayout ?: bC?.mainLayout ?: bC?.mainLayout ?: cp?.mainLayout ?: ds?.mainLayout ?: nC?.mainLayout ?: sP?.mainLayout + ?: throw IllegalArgumentException(errorMessage) + val timestamp = + aL?.timestamp ?: a2?.timestamp ?: aa?.timestamp ?: bC?.timestamp ?: bC?.timestamp ?: cp?.timestamp ?: ds?.timestamp ?: nC?.timestamp ?: sP?.timestamp + ?: throw IllegalArgumentException(errorMessage) + val root = + aL?.root ?: a2?.root ?: aa?.root ?: bC?.root ?: bC?.root ?: cp?.root ?: ds?.root ?: nC?.root ?: sP?.root + ?: throw IllegalArgumentException(errorMessage) + + // Optional attributes + val sgv = aL?.sgv ?: a2?.sgv ?: aa?.sgv ?: bC?.sgv ?: bC?.sgv ?: cp?.sgv ?: ds?.sgv ?: nC?.sgv + val direction = aL?.direction ?: a2?.direction ?: aa?.direction ?: cp?.direction ?: ds?.direction + val loop = a2?.loop ?: cp?.loop ?: sP?.loop + val delta = aL?.delta ?: a2?.delta ?: aa?.delta ?: bC?.delta ?: bC?.delta ?: cp?.delta ?: ds?.delta ?: nC?.delta + val avgDelta = a2?.avgDelta ?: bC?.avgDelta ?: bC?.avgDelta ?: cp?.avgDelta ?: ds?.avgDelta ?: nC?.avgDelta + val uploaderBattery = aL?.uploaderBattery ?: a2?.uploaderBattery ?: aa?.uploaderBattery ?: cp?.uploaderBattery ?: ds?.uploaderBattery ?: sP?.uploaderBattery + val rigBattery = a2?.rigBattery ?: cp?.rigBattery ?: ds?.rigBattery ?: sP?.rigBattery + val basalRate = a2?.basalRate ?: cp?.basalRate ?: ds?.basalRate ?: sP?.basalRate + val bgi = a2?.bgi ?: ds?.bgi + val AAPSv2 = a2?.AAPSv2 ?: cp?.AAPSv2 ?: ds?.AAPSv2 ?: sP?.AAPSv2 + val cob1 = a2?.cob1 ?: ds?.cob1 + val cob2 = a2?.cob2 ?: cp?.cob2 ?: ds?.cob2 ?: sP?.cob2 + val time = aL?.time ?: a2?.time ?: aa?.time ?: bC?.time ?: bC?.time ?: cp?.time ?: nC?.time + val minute = ds?.minute + val hour = ds?.hour + val day = a2?.day ?: ds?.day + val month = a2?.month ?: ds?.month + val iob1 = a2?.iob1 ?: ds?.iob1 + val iob2 = a2?.iob2 ?: cp?.iob2 ?: ds?.iob2 ?: sP?.iob2 + val chart = a2?.chart ?: aa?.chart ?: bC?.chart ?: bC?.chart ?: ds?.chart ?: sP?.chart + val status = aL?.status ?: aa?.status ?: bC?.status ?: bC?.status ?: nC?.status + val timePeriod = ds?.timePeriod + val dayName = ds?.dayName + val mainMenuTap = ds?.mainMenuTap ?: sP?.mainMenuTap + val chartZoomTap = sP?.chartZoomTap + val dateTime = ds?.dateTime ?: a2?.dateTime + // val minuteHand = sP?.minuteHand + // val secondaryLayout = aL?.secondaryLayout ?: a2?.secondaryLayout ?: aa?.secondaryLayout ?: ds?.secondaryLayout ?: sP?.secondaryLayout + // val tertiaryLayout = a2?.tertiaryLayout ?: sP?.tertiaryLayout + // val highLight = cp?.highLight + // val lowLight = cp?.lowLight + // val deltaGauge = sP?.deltaPointer + // val hourHand = sP?.hourHand + // val glucoseDial = sP?.glucoseDial + + companion object { + + fun getBinding(bindLayout: ViewBinding): WatchfaceViewAdapter { + return when (bindLayout) { + is ActivityHomeLargeBinding -> WatchfaceViewAdapter(bindLayout) + is ActivityHome2Binding -> WatchfaceViewAdapter(null, bindLayout) + is ActivityHomeBinding -> WatchfaceViewAdapter(null, null, bindLayout) + is ActivityBigchartBinding -> WatchfaceViewAdapter(null, null, null, bindLayout) + is ActivityBigchartSmallBinding -> WatchfaceViewAdapter(null, null, null, null, bindLayout) + is ActivityCockpitBinding -> WatchfaceViewAdapter(null, null, null, null, null, bindLayout) + is ActivityDigitalstyleBinding -> WatchfaceViewAdapter(null, null, null, null, null, null, bindLayout) + is ActivityNochartBinding -> WatchfaceViewAdapter(null, null, null, null, null, null, null, bindLayout) + is ActivitySteampunkBinding -> WatchfaceViewAdapter(null, null, null, null, null, null, null, null, bindLayout) + else -> throw IllegalArgumentException("ViewBinding is not implement in WatchfaceViewAdapter") + } + } + } + +} diff --git a/wear/src/main/res/layout-notround/activity_bigchart.xml b/wear/src/main/res/layout-notround/activity_bigchart.xml index 8c3a136e6a..28be3ae4bb 100644 --- a/wear/src/main/res/layout-notround/activity_bigchart.xml +++ b/wear/src/main/res/layout-notround/activity_bigchart.xml @@ -46,7 +46,7 @@ tools:ignore="HardcodedText" /> - + - + - +