NoChartWatchface: based on BaseWatchFace
This commit is contained in:
parent
db4b1d261b
commit
2b00ea745a
17 changed files with 48 additions and 300 deletions
|
@ -1,13 +1,14 @@
|
||||||
package info.nightscout.androidaps.watchfaces
|
package info.nightscout.androidaps.watchfaces
|
||||||
|
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
import androidx.annotation.LayoutRes
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import com.ustwo.clockwise.common.WatchMode
|
import com.ustwo.clockwise.common.WatchMode
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
|
||||||
class AapsLargeWatchface : BaseWatchFace() {
|
class AapsLargeWatchface : BaseWatchFace() {
|
||||||
|
|
||||||
override fun layoutResource(): Int = R.layout.activity_home_large
|
@LayoutRes override fun layoutResource(): Int = R.layout.activity_home_large
|
||||||
|
|
||||||
override fun setColorDark() {
|
override fun setColorDark() {
|
||||||
mLinearLayout?.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_mLinearLayout))
|
mLinearLayout?.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_mLinearLayout))
|
||||||
|
|
|
@ -2,13 +2,14 @@ package info.nightscout.androidaps.watchfaces
|
||||||
|
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
|
import androidx.annotation.LayoutRes
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import com.ustwo.clockwise.common.WatchMode
|
import com.ustwo.clockwise.common.WatchMode
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
|
||||||
class AapsV2Watchface : BaseWatchFace() {
|
class AapsV2Watchface : BaseWatchFace() {
|
||||||
|
|
||||||
override fun layoutResource(): Int = R.layout.activity_home_2
|
@LayoutRes override fun layoutResource(): Int = R.layout.activity_home_2
|
||||||
|
|
||||||
override fun setColorDark() {
|
override fun setColorDark() {
|
||||||
@ColorInt val dividerTxtColor = if (dividerMatchesBg) ContextCompat.getColor(this, R.color.dark_midColor) else Color.BLACK
|
@ColorInt val dividerTxtColor = if (dividerMatchesBg) ContextCompat.getColor(this, R.color.dark_midColor) else Color.BLACK
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package info.nightscout.androidaps.watchfaces
|
package info.nightscout.androidaps.watchfaces
|
||||||
|
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
import androidx.annotation.LayoutRes
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import com.ustwo.clockwise.common.WatchMode
|
import com.ustwo.clockwise.common.WatchMode
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
|
||||||
class AapsWatchface : BaseWatchFace() {
|
class AapsWatchface : BaseWatchFace() {
|
||||||
|
|
||||||
override fun layoutResource(): Int = R.layout.activity_home
|
@LayoutRes override fun layoutResource(): Int = R.layout.activity_home
|
||||||
|
|
||||||
override fun setColorDark() {
|
override fun setColorDark() {
|
||||||
mLinearLayout?.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_statusView))
|
mLinearLayout?.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_statusView))
|
||||||
|
|
|
@ -337,11 +337,8 @@ abstract class BaseWatchFace : WatchFace() {
|
||||||
missedReadingAlert()
|
missedReadingAlert()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ageLevel(): Int {
|
fun ageLevel(): Int =
|
||||||
return if (timeSince() <= 1000 * 60 * 12) {
|
if (timeSince() <= 1000 * 60 * 12) 1 else 0
|
||||||
1
|
|
||||||
} else 0
|
|
||||||
}
|
|
||||||
|
|
||||||
fun timeSince(): Double {
|
fun timeSince(): Double {
|
||||||
return (System.currentTimeMillis() - singleBg.timeStamp).toDouble()
|
return (System.currentTimeMillis() - singleBg.timeStamp).toDouble()
|
||||||
|
@ -414,13 +411,9 @@ abstract class BaseWatchFace : WatchFace() {
|
||||||
|
|
||||||
override fun onTimeChanged(oldTime: WatchFaceTime, newTime: WatchFaceTime) {
|
override fun onTimeChanged(oldTime: WatchFaceTime, newTime: WatchFaceTime) {
|
||||||
if (layoutSet && (newTime.hasHourChanged(oldTime) || newTime.hasMinuteChanged(oldTime))) {
|
if (layoutSet && (newTime.hasHourChanged(oldTime) || newTime.hasMinuteChanged(oldTime))) {
|
||||||
val wl = wearUtil.getWakeLock("readingPrefs", 50)
|
|
||||||
missedReadingAlert()
|
missedReadingAlert()
|
||||||
checkVibrateHourly(oldTime, newTime)
|
checkVibrateHourly(oldTime, newTime)
|
||||||
if (!isSimpleUi) {
|
if (!isSimpleUi) setDataFields()
|
||||||
setDataFields()
|
|
||||||
}
|
|
||||||
wearUtil.releaseWakeLock(wl)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,7 +435,8 @@ abstract class BaseWatchFace : WatchFace() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n") fun setDataFields() {
|
@SuppressLint("SetTextI18n")
|
||||||
|
fun setDataFields() {
|
||||||
setDateAndTime()
|
setDateAndTime()
|
||||||
mSgv?.text = singleBg.sgvString
|
mSgv?.text = singleBg.sgvString
|
||||||
mSgv?.visibility = sp.getBoolean(R.string.key_show_bg, true).toVisibilityKeepSpace()
|
mSgv?.visibility = sp.getBoolean(R.string.key_show_bg, true).toVisibilityKeepSpace()
|
||||||
|
@ -531,11 +525,8 @@ abstract class BaseWatchFace : WatchFace() {
|
||||||
|
|
||||||
override fun onWatchModeChanged(watchMode: WatchMode) {
|
override fun onWatchModeChanged(watchMode: WatchMode) {
|
||||||
lowResMode = isLowRes(watchMode)
|
lowResMode = isLowRes(watchMode)
|
||||||
if (isSimpleUi) {
|
if (isSimpleUi) setSimpleUiAntiAlias()
|
||||||
setSimpleUiAntiAlias()
|
else setDataFields()
|
||||||
} else {
|
|
||||||
setDataFields()
|
|
||||||
}
|
|
||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,5 +596,6 @@ abstract class BaseWatchFace : WatchFace() {
|
||||||
var iFilter = IntentFilter(Intent.ACTION_BATTERY_CHANGED)
|
var iFilter = IntentFilter(Intent.ACTION_BATTERY_CHANGED)
|
||||||
val NORMAL_TYPEFACE: Typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL)
|
val NORMAL_TYPEFACE: Typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL)
|
||||||
val BOLD_TYPEFACE: Typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)
|
val BOLD_TYPEFACE: Typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)
|
||||||
|
const val SCREEN_SIZE_SMALL = 280
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -82,7 +82,7 @@ class BigChartWatchface : WatchFace() {
|
||||||
private val displaySize = Point()
|
private val displaySize = Point()
|
||||||
private var specW = 0
|
private var specW = 0
|
||||||
private var specH = 0
|
private var specH = 0
|
||||||
private var statusView: TextView? = null
|
private var mStatus: TextView? = null
|
||||||
private var chartTapTime = 0L
|
private var chartTapTime = 0L
|
||||||
private var sgvTapTime = 0L
|
private var sgvTapTime = 0L
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ class BigChartWatchface : WatchFace() {
|
||||||
mAvgDelta = layoutView?.findViewById(R.id.avgdelta)
|
mAvgDelta = layoutView?.findViewById(R.id.avgdelta)
|
||||||
mRelativeLayout = layoutView?.findViewById(R.id.main_layout)
|
mRelativeLayout = layoutView?.findViewById(R.id.main_layout)
|
||||||
chart = layoutView?.findViewById(R.id.chart)
|
chart = layoutView?.findViewById(R.id.chart)
|
||||||
statusView = layoutView?.findViewById(R.id.aps_status)
|
mStatus = layoutView?.findViewById(R.id.externaltstatus)
|
||||||
layoutSet = true
|
layoutSet = true
|
||||||
showAgeAndStatus()
|
showAgeAndStatus()
|
||||||
mRelativeLayout?.measure(specW, specH)
|
mRelativeLayout?.measure(specW, specH)
|
||||||
|
@ -271,8 +271,8 @@ class BigChartWatchface : WatchFace() {
|
||||||
private fun showAgeAndStatus() {
|
private fun showAgeAndStatus() {
|
||||||
mTimestamp?.text = readingAge()
|
mTimestamp?.text = readingAge()
|
||||||
mAvgDelta?.visibility = sp.getBoolean(R.string.key_show_external_status, true).toVisibility()
|
mAvgDelta?.visibility = sp.getBoolean(R.string.key_show_external_status, true).toVisibility()
|
||||||
statusView?.visibility = sp.getBoolean(R.string.key_show_external_status, true).toVisibility()
|
mStatus?.visibility = sp.getBoolean(R.string.key_show_external_status, true).toVisibility()
|
||||||
statusView?.text = status.externalStatus + if (sp.getBoolean(R.string.key_show_cob, true)) (" " + this.status.cob) else ""
|
mStatus?.text = status.externalStatus + if (sp.getBoolean(R.string.key_show_cob, true)) (" " + this.status.cob) else ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setColor() {
|
private fun setColor() {
|
||||||
|
@ -285,7 +285,7 @@ class BigChartWatchface : WatchFace() {
|
||||||
|
|
||||||
private fun setColorLowRes() {
|
private fun setColorLowRes() {
|
||||||
mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime))
|
mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime))
|
||||||
statusView?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView))
|
mStatus?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView))
|
||||||
mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background))
|
mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background))
|
||||||
mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor))
|
mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor))
|
||||||
mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor))
|
mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor))
|
||||||
|
@ -305,7 +305,7 @@ class BigChartWatchface : WatchFace() {
|
||||||
|
|
||||||
private fun setColorDark() {
|
private fun setColorDark() {
|
||||||
mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime))
|
mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime))
|
||||||
statusView?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView))
|
mStatus?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView))
|
||||||
mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background))
|
mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background))
|
||||||
when (singleBg.sgvLevel) {
|
when (singleBg.sgvLevel) {
|
||||||
1L -> {
|
1L -> {
|
||||||
|
@ -346,7 +346,7 @@ class BigChartWatchface : WatchFace() {
|
||||||
private fun setColorBright() {
|
private fun setColorBright() {
|
||||||
if (currentWatchMode == WatchMode.INTERACTIVE) {
|
if (currentWatchMode == WatchMode.INTERACTIVE) {
|
||||||
mTime?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_time))
|
mTime?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_time))
|
||||||
statusView?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_status))
|
mStatus?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_status))
|
||||||
mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background))
|
mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background))
|
||||||
when (singleBg.sgvLevel) {
|
when (singleBg.sgvLevel) {
|
||||||
1L -> {
|
1L -> {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package info.nightscout.androidaps.watchfaces
|
package info.nightscout.androidaps.watchfaces
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.annotation.LayoutRes
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,7 +10,7 @@ import info.nightscout.androidaps.R
|
||||||
*/
|
*/
|
||||||
class CockpitWatchface : BaseWatchFace() {
|
class CockpitWatchface : BaseWatchFace() {
|
||||||
|
|
||||||
override fun layoutResource(): Int = R.layout.activity_cockpit
|
@LayoutRes override fun layoutResource(): Int = R.layout.activity_cockpit
|
||||||
|
|
||||||
override fun setColorDark() {
|
override fun setColorDark() {
|
||||||
mRelativeLayout?.setBackgroundResource(R.drawable.airplane_cockpit_outside_clouds)
|
mRelativeLayout?.setBackgroundResource(R.drawable.airplane_cockpit_outside_clouds)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.support.wearable.watchface.WatchFaceStyle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.annotation.LayoutRes
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.extensions.toVisibility
|
import info.nightscout.androidaps.extensions.toVisibility
|
||||||
|
@ -14,7 +15,7 @@ import info.nightscout.shared.logging.LTag
|
||||||
|
|
||||||
class DigitalStyleWatchface : BaseWatchFace() {
|
class DigitalStyleWatchface : BaseWatchFace() {
|
||||||
|
|
||||||
override fun layoutResource(): Int = R.layout.activity_digitalstyle
|
@LayoutRes override fun layoutResource(): Int = R.layout.activity_digitalstyle
|
||||||
|
|
||||||
override fun getWatchFaceStyle(): WatchFaceStyle {
|
override fun getWatchFaceStyle(): WatchFaceStyle {
|
||||||
return WatchFaceStyle.Builder(this)
|
return WatchFaceStyle.Builder(this)
|
||||||
|
|
|
@ -1,240 +1,19 @@
|
||||||
@file:Suppress("DEPRECATION")
|
|
||||||
|
|
||||||
package info.nightscout.androidaps.watchfaces
|
package info.nightscout.androidaps.watchfaces
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import androidx.annotation.LayoutRes
|
||||||
import android.content.Intent
|
|
||||||
import android.graphics.Canvas
|
|
||||||
import android.graphics.Paint
|
|
||||||
import android.graphics.Point
|
|
||||||
import android.graphics.Rect
|
|
||||||
import android.os.PowerManager
|
|
||||||
import android.support.wearable.watchface.WatchFaceStyle
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.WindowInsets
|
|
||||||
import android.view.WindowManager
|
|
||||||
import android.widget.RelativeLayout
|
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import com.ustwo.clockwise.common.WatchFaceTime
|
|
||||||
import com.ustwo.clockwise.common.WatchMode
|
import com.ustwo.clockwise.common.WatchMode
|
||||||
import com.ustwo.clockwise.common.WatchShape
|
|
||||||
import com.ustwo.clockwise.wearable.WatchFace
|
|
||||||
import dagger.android.AndroidInjection
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.events.EventWearToMobile
|
|
||||||
import info.nightscout.androidaps.extensions.toVisibility
|
|
||||||
import info.nightscout.androidaps.interaction.menus.MainMenuActivity
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
|
||||||
import info.nightscout.shared.logging.AAPSLogger
|
|
||||||
import info.nightscout.shared.logging.LTag
|
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
|
||||||
import info.nightscout.shared.weardata.EventData
|
|
||||||
import info.nightscout.shared.weardata.EventData.ActionResendData
|
|
||||||
import info.nightscout.shared.weardata.EventData.SingleBg
|
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
|
||||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlin.math.floor
|
|
||||||
|
|
||||||
class NoChartWatchface : WatchFace() {
|
class NoChartWatchface : BaseWatchFace() {
|
||||||
|
|
||||||
@Inject lateinit var rxBus: RxBus
|
@LayoutRes override fun layoutResource(): Int =
|
||||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
if (resources.displayMetrics.widthPixels < SCREEN_SIZE_SMALL || resources.displayMetrics.heightPixels < SCREEN_SIZE_SMALL) R.layout.activity_nochart_small
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
else R.layout.activity_nochart
|
||||||
@Inject lateinit var sp: SP
|
|
||||||
@Inject lateinit var dateUtil: DateUtil
|
|
||||||
|
|
||||||
private var disposable = CompositeDisposable()
|
override fun setColorLowRes() {
|
||||||
|
|
||||||
private var singleBg = SingleBg(0, "---", "-", "--", "--", "--", 0, 0.0, 0.0, 0.0, 0)
|
|
||||||
private var status = EventData.Status("no status", "IOB", "-.--", false, "--g", "-.--U/h", "--", "--", -1, "--", false, 1)
|
|
||||||
|
|
||||||
private var mTime: TextView? = null
|
|
||||||
private var mSgv: TextView? = null
|
|
||||||
private var mTimestamp: TextView? = null
|
|
||||||
private var mDelta: TextView? = null
|
|
||||||
private var mAvgDelta: TextView? = null
|
|
||||||
private var mRelativeLayout: RelativeLayout? = null
|
|
||||||
private var sgvLevel: Long = 0
|
|
||||||
private var ageLevel = 1
|
|
||||||
private var lowResMode = false
|
|
||||||
private var layoutSet = false
|
|
||||||
private var wakeLock: PowerManager.WakeLock? = null
|
|
||||||
private var layoutView: View? = null
|
|
||||||
private val displaySize = Point()
|
|
||||||
private var specW = 0
|
|
||||||
private var specH = 0
|
|
||||||
private var statusView: TextView? = null
|
|
||||||
private var sgvTapTime = 0L
|
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
|
||||||
override fun onCreate() {
|
|
||||||
AndroidInjection.inject(this)
|
|
||||||
super.onCreate()
|
|
||||||
val display = (getSystemService(WINDOW_SERVICE) as WindowManager).defaultDisplay
|
|
||||||
display.getSize(displaySize)
|
|
||||||
wakeLock = (getSystemService(POWER_SERVICE) as PowerManager).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:NOChart")
|
|
||||||
specW = View.MeasureSpec.makeMeasureSpec(displaySize.x, View.MeasureSpec.EXACTLY)
|
|
||||||
specH = View.MeasureSpec.makeMeasureSpec(displaySize.y, View.MeasureSpec.EXACTLY)
|
|
||||||
val inflater = getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
|
||||||
val metrics = resources.displayMetrics
|
|
||||||
layoutView = if (metrics.widthPixels < SCREEN_SIZE_SMALL || metrics.heightPixels < SCREEN_SIZE_SMALL) {
|
|
||||||
inflater.inflate(R.layout.activity_nochart_small, null)
|
|
||||||
} else {
|
|
||||||
inflater.inflate(R.layout.activity_nochart, null)
|
|
||||||
}
|
|
||||||
disposable += rxBus
|
|
||||||
.toObservable(SingleBg::class.java)
|
|
||||||
.observeOn(aapsSchedulers.main)
|
|
||||||
.subscribe { event: SingleBg ->
|
|
||||||
aapsLogger.debug(LTag.WEAR, "SingleBg received")
|
|
||||||
singleBg = event
|
|
||||||
mSgv?.let { sgv ->
|
|
||||||
sgv.text = singleBg.sgvString
|
|
||||||
if (ageLevel() <= 0) sgv.paintFlags = sgv.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
|
|
||||||
else sgv.paintFlags = sgv.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
|
||||||
}
|
|
||||||
mTime?.text = dateUtil.timeString()
|
|
||||||
mDelta?.text = singleBg.delta
|
|
||||||
mAvgDelta?.text = singleBg.avgDelta
|
|
||||||
}
|
|
||||||
disposable += rxBus
|
|
||||||
.toObservable(EventData.Status::class.java)
|
|
||||||
.observeOn(aapsSchedulers.main)
|
|
||||||
.subscribe { event: EventData.Status ->
|
|
||||||
// this event is received as last batch of data
|
|
||||||
aapsLogger.debug(LTag.WEAR, "Status received")
|
|
||||||
status = event
|
|
||||||
showAgeAndStatus()
|
|
||||||
mRelativeLayout?.measure(specW, specH)
|
|
||||||
mRelativeLayout?.layout(0, 0, mRelativeLayout?.measuredWidth ?: 0, mRelativeLayout?.measuredHeight ?: 0)
|
|
||||||
invalidate()
|
|
||||||
setColor()
|
|
||||||
}
|
|
||||||
disposable += rxBus
|
|
||||||
.toObservable(EventData.Preferences::class.java)
|
|
||||||
.observeOn(aapsSchedulers.main)
|
|
||||||
.subscribe {
|
|
||||||
setColor()
|
|
||||||
if (layoutSet) {
|
|
||||||
showAgeAndStatus()
|
|
||||||
mRelativeLayout?.measure(specW, specH)
|
|
||||||
mRelativeLayout?.layout(0, 0, mRelativeLayout?.measuredWidth ?: 0, mRelativeLayout?.measuredHeight ?: 0)
|
|
||||||
}
|
|
||||||
invalidate()
|
|
||||||
}
|
|
||||||
performViewSetup()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLayout(shape: WatchShape, screenBounds: Rect, screenInsets: WindowInsets) {
|
|
||||||
super.onLayout(shape, screenBounds, screenInsets)
|
|
||||||
layoutView?.onApplyWindowInsets(screenInsets)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun performViewSetup() {
|
|
||||||
mTime = layoutView?.findViewById(R.id.watch_time)
|
|
||||||
mSgv = layoutView?.findViewById(R.id.sgv)
|
|
||||||
mTimestamp = layoutView?.findViewById(R.id.timestamp)
|
|
||||||
mDelta = layoutView?.findViewById(R.id.delta)
|
|
||||||
mAvgDelta = layoutView?.findViewById(R.id.avgdelta)
|
|
||||||
mRelativeLayout = layoutView?.findViewById(R.id.main_layout)
|
|
||||||
statusView = layoutView?.findViewById(R.id.aps_status)
|
|
||||||
layoutSet = true
|
|
||||||
showAgeAndStatus()
|
|
||||||
mRelativeLayout?.measure(specW, specH)
|
|
||||||
mRelativeLayout?.layout(0, 0, mRelativeLayout?.measuredWidth ?: 0, mRelativeLayout?.measuredHeight ?: 0)
|
|
||||||
rxBus.send(EventWearToMobile(ActionResendData("NOChart:performViewSetup")))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onTapCommand(tapType: Int, x: Int, y: Int, eventTime: Long) {
|
|
||||||
mSgv?.let { mSgv ->
|
|
||||||
val extra = (mSgv.right - mSgv.left) / 2
|
|
||||||
if (tapType == TAP_TYPE_TAP && x + extra >= mSgv.left && x - extra <= mSgv.right && y >= mSgv.top && y <= mSgv.bottom) {
|
|
||||||
if (eventTime - sgvTapTime < 800) {
|
|
||||||
startActivity(Intent(this, MainMenuActivity::class.java).also { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
|
|
||||||
}
|
|
||||||
sgvTapTime = eventTime
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onWatchModeChanged(watchMode: WatchMode) {
|
|
||||||
if (lowResMode xor isLowRes(watchMode)) { //if there was a change in lowResMode
|
|
||||||
lowResMode = isLowRes(watchMode)
|
|
||||||
setColor()
|
|
||||||
} else if (!sp.getBoolean("dark", true)) {
|
|
||||||
//in bright mode: different colours if active:
|
|
||||||
setColor()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isLowRes(watchMode: WatchMode): Boolean {
|
|
||||||
return watchMode == WatchMode.LOW_BIT || watchMode == WatchMode.LOW_BIT_BURN_IN
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getWatchFaceStyle(): WatchFaceStyle {
|
|
||||||
return WatchFaceStyle.Builder(this).setAcceptsTapEvents(true).build()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun ageLevel(): Int = if (timeSince() <= 1000 * 60 * 12) 1 else 0
|
|
||||||
|
|
||||||
fun timeSince(): Double = (System.currentTimeMillis() - singleBg.timeStamp).toDouble()
|
|
||||||
|
|
||||||
private fun readingAge(): String =
|
|
||||||
if (singleBg.timeStamp == 0L) "--'"
|
|
||||||
else "${floor(timeSince() / (1000 * 60)).toInt()}'"
|
|
||||||
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
|
||||||
disposable.clear()
|
|
||||||
super.onDestroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDraw(canvas: Canvas) {
|
|
||||||
if (layoutSet) {
|
|
||||||
mRelativeLayout?.draw(canvas)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onTimeChanged(oldTime: WatchFaceTime, newTime: WatchFaceTime) {
|
|
||||||
if (layoutSet && (newTime.hasHourChanged(oldTime) || newTime.hasMinuteChanged(oldTime))) {
|
|
||||||
mTime?.text = dateUtil.timeString()
|
|
||||||
showAgeAndStatus()
|
|
||||||
mSgv?.let { sgv ->
|
|
||||||
if (ageLevel() <= 0) {
|
|
||||||
sgv.paintFlags = sgv.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
|
|
||||||
} else {
|
|
||||||
sgv.paintFlags = sgv.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
missedReadingAlert()
|
|
||||||
mRelativeLayout?.measure(specW, specH)
|
|
||||||
mRelativeLayout?.layout(0, 0, mRelativeLayout?.measuredWidth ?: 0, mRelativeLayout?.measuredHeight ?: 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showAgeAndStatus() {
|
|
||||||
mTimestamp?.text = readingAge()
|
|
||||||
mAvgDelta?.visibility = sp.getBoolean(R.string.key_show_avg_delta, true).toVisibility()
|
|
||||||
statusView?.text = status.externalStatus
|
|
||||||
statusView?.visibility = View.VISIBLE
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setColor() {
|
|
||||||
when {
|
|
||||||
lowResMode -> setColorLowRes()
|
|
||||||
sp.getBoolean("dark", true) -> setColorDark()
|
|
||||||
else -> setColorBright()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setColorLowRes() {
|
|
||||||
mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime))
|
mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime))
|
||||||
statusView?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView))
|
mStatus?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView))
|
||||||
mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background))
|
mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background))
|
||||||
mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor))
|
mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor))
|
||||||
mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor))
|
mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_midColor))
|
||||||
|
@ -242,11 +21,11 @@ class NoChartWatchface : WatchFace() {
|
||||||
mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_Timestamp))
|
mTimestamp?.setTextColor(ContextCompat.getColor(this, R.color.dark_Timestamp))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setColorDark() {
|
override fun setColorDark() {
|
||||||
mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime))
|
mTime?.setTextColor(ContextCompat.getColor(this, R.color.dark_mTime))
|
||||||
statusView?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView))
|
mStatus?.setTextColor(ContextCompat.getColor(this, R.color.dark_statusView))
|
||||||
mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background))
|
mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background))
|
||||||
when (sgvLevel) {
|
when (singleBg.sgvLevel) {
|
||||||
1L -> {
|
1L -> {
|
||||||
mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor))
|
mSgv?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor))
|
||||||
mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor))
|
mDelta?.setTextColor(ContextCompat.getColor(this, R.color.dark_highColor))
|
||||||
|
@ -272,12 +51,12 @@ class NoChartWatchface : WatchFace() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setColorBright() {
|
override fun setColorBright() {
|
||||||
if (currentWatchMode == WatchMode.INTERACTIVE) {
|
if (currentWatchMode == WatchMode.INTERACTIVE) {
|
||||||
mTime?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_time))
|
mTime?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_time))
|
||||||
statusView?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_status))
|
mStatus?.setTextColor(ContextCompat.getColor(this, R.color.light_bigchart_status))
|
||||||
mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background))
|
mRelativeLayout?.setBackgroundColor(ContextCompat.getColor(this, R.color.light_background))
|
||||||
when (sgvLevel) {
|
when (singleBg.sgvLevel) {
|
||||||
1L -> {
|
1L -> {
|
||||||
mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor))
|
mSgv?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor))
|
||||||
mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor))
|
mDelta?.setTextColor(ContextCompat.getColor(this, R.color.light_highColor))
|
||||||
|
@ -305,17 +84,4 @@ class NoChartWatchface : WatchFace() {
|
||||||
setColorDark()
|
setColorDark()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun missedReadingAlert() {
|
|
||||||
val minutesSince = floor(timeSince() / (1000 * 60)).toInt()
|
|
||||||
if (minutesSince >= 16 && (minutesSince - 16) % 5 == 0) {
|
|
||||||
// attempt endTime recover missing data
|
|
||||||
rxBus.send(EventWearToMobile(ActionResendData("NOChart::missedReadingAlert")))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
const val SCREEN_SIZE_SMALL = 280
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.watchfaces
|
||||||
import android.view.animation.Animation
|
import android.view.animation.Animation
|
||||||
import android.view.animation.LinearInterpolator
|
import android.view.animation.LinearInterpolator
|
||||||
import android.view.animation.RotateAnimation
|
import android.view.animation.RotateAnimation
|
||||||
|
import androidx.annotation.LayoutRes
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.shared.SafeParse.stringToFloat
|
import info.nightscout.shared.SafeParse.stringToFloat
|
||||||
|
@ -17,7 +18,7 @@ class SteampunkWatchface : BaseWatchFace() {
|
||||||
private var lastEndDegrees = 0f
|
private var lastEndDegrees = 0f
|
||||||
private var deltaRotationAngle = 0f
|
private var deltaRotationAngle = 0f
|
||||||
|
|
||||||
override fun layoutResource(): Int = R.layout.activity_steampunk
|
@LayoutRes override fun layoutResource(): Int = R.layout.activity_steampunk
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
forceSquareCanvas = true
|
forceSquareCanvas = true
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
android:gravity="center_horizontal" />
|
android:gravity="center_horizontal" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/aps_status"
|
android:id="@+id/externaltstatus"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:text="E xU/h IOB: x (x+x)"
|
android:text="E xU/h IOB: x (x+x)"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/aps_status"
|
android:id="@+id/externaltstatus"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/aps_status"
|
android:id="@+id/externaltstatus"
|
||||||
android:textSize="24sp"
|
android:textSize="24sp"
|
||||||
android:text="E xU/h IOB: x (x+x)"
|
android:text="E xU/h IOB: x (x+x)"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -66,14 +66,6 @@
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<View
|
|
||||||
android:id="@+id/chart"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="center_horizontal" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
android:gravity="center_horizontal" />
|
android:gravity="center_horizontal" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/aps_status"
|
android:id="@+id/externaltstatus"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
android:gravity="center_horizontal" />
|
android:gravity="center_horizontal" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/aps_status"
|
android:id="@+id/externaltstatus"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:text="E xU/h IOB: x (x+x)"
|
android:text="E xU/h IOB: x (x+x)"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/aps_status"
|
android:id="@+id/externaltstatus"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/aps_status"
|
android:id="@+id/externaltstatus"
|
||||||
android:textSize="24sp"
|
android:textSize="24sp"
|
||||||
android:text="E xU/h IOB: x (x+x)"
|
android:text="E xU/h IOB: x (x+x)"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -66,14 +66,6 @@
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<View
|
|
||||||
android:id="@+id/chart"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="center_horizontal" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
android:gravity="center_horizontal" />
|
android:gravity="center_horizontal" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/aps_status"
|
android:id="@+id/externaltstatus"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
|
Loading…
Reference in a new issue