Wear: Watchfaces unify onCreate, onTapCommand
This commit is contained in:
parent
9b064404ac
commit
9c17c075f4
10 changed files with 92 additions and 253 deletions
|
@ -1,46 +1,13 @@
|
|||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package info.nightscout.androidaps.watchfaces
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.support.wearable.watchface.WatchFaceStyle
|
||||
import android.view.LayoutInflater
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.ustwo.clockwise.common.WatchMode
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interaction.menus.MainMenuActivity
|
||||
|
||||
class AapsLargeWatchface : BaseWatchFace() {
|
||||
|
||||
private var sgvTapTime: Long = 0
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
val inflater = getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
layoutView = inflater.inflate(R.layout.activity_home_large, null)
|
||||
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) {
|
||||
val intent = Intent(this, MainMenuActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
startActivity(intent)
|
||||
}
|
||||
sgvTapTime = eventTime
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getWatchFaceStyle(): WatchFaceStyle {
|
||||
return WatchFaceStyle.Builder(this).setAcceptsTapEvents(true).build()
|
||||
}
|
||||
override fun layoutResource(): Int = R.layout.activity_home_large
|
||||
|
||||
override fun setColorDark() {
|
||||
mLinearLayout?.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_mLinearLayout))
|
||||
|
@ -70,7 +37,7 @@ class AapsLargeWatchface : BaseWatchFace() {
|
|||
|
||||
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))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,63 +1,14 @@
|
|||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package info.nightscout.androidaps.watchfaces
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.support.wearable.watchface.WatchFaceStyle
|
||||
import android.view.LayoutInflater
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.ustwo.clockwise.common.WatchMode
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interaction.menus.MainMenuActivity
|
||||
|
||||
class AapsV2Watchface : BaseWatchFace() {
|
||||
|
||||
private var chartTapTime: Long = 0
|
||||
private var sgvTapTime: Long = 0
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
val inflater = getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
layoutView = inflater.inflate(R.layout.activity_home_2, null)
|
||||
performViewSetup()
|
||||
}
|
||||
|
||||
override fun onTapCommand(tapType: Int, x: Int, y: Int, eventTime: Long) {
|
||||
chart?.let { chart ->
|
||||
if (tapType == TAP_TYPE_TAP && x >= chart.left && x <= chart.right && y >= chart.top && y <= chart.bottom) {
|
||||
if (eventTime - chartTapTime < 800) {
|
||||
changeChartTimeframe()
|
||||
}
|
||||
chartTapTime = eventTime
|
||||
return
|
||||
}
|
||||
}
|
||||
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) {
|
||||
val intent = Intent(this, MainMenuActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
startActivity(intent)
|
||||
}
|
||||
sgvTapTime = eventTime
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeChartTimeframe() {
|
||||
var timeframe = sp.getInt(R.string.key_chart_time_frame, 3)
|
||||
timeframe = timeframe % 5 + 1
|
||||
sp.putInt(R.string.key_chart_time_frame, timeframe)
|
||||
}
|
||||
|
||||
override fun getWatchFaceStyle(): WatchFaceStyle {
|
||||
return WatchFaceStyle.Builder(this).setAcceptsTapEvents(true).build()
|
||||
}
|
||||
override fun layoutResource(): Int = R.layout.activity_home_2
|
||||
|
||||
override fun setColorDark() {
|
||||
@ColorInt val dividerTxtColor = if (dividerMatchesBg) ContextCompat.getColor(this, R.color.dark_midColor) else Color.BLACK
|
||||
|
|
|
@ -1,62 +1,13 @@
|
|||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package info.nightscout.androidaps.watchfaces
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.support.wearable.watchface.WatchFaceStyle
|
||||
import android.view.LayoutInflater
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.ustwo.clockwise.common.WatchMode
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interaction.menus.MainMenuActivity
|
||||
|
||||
class AapsWatchface : BaseWatchFace() {
|
||||
|
||||
private var chartTapTime: Long = 0
|
||||
private var sgvTapTime: Long = 0
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
val inflater = getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
layoutView = inflater.inflate(R.layout.activity_home, null)
|
||||
performViewSetup()
|
||||
}
|
||||
|
||||
override fun onTapCommand(tapType: Int, x: Int, y: Int, eventTime: Long) {
|
||||
chart?.let { chart ->
|
||||
if (tapType == TAP_TYPE_TAP && x >= chart.left && x <= chart.right && y >= chart.top && y <= chart.bottom) {
|
||||
if (eventTime - chartTapTime < 800) {
|
||||
changeChartTimeframe()
|
||||
}
|
||||
chartTapTime = eventTime
|
||||
return
|
||||
}
|
||||
}
|
||||
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) {
|
||||
val intent = Intent(this, MainMenuActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
startActivity(intent)
|
||||
}
|
||||
sgvTapTime = eventTime
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeChartTimeframe() {
|
||||
var timeframe = sp.getInt(R.string.key_chart_time_frame, 3)
|
||||
timeframe = timeframe % 5 + 1
|
||||
sp.putInt(R.string.key_chart_time_frame, timeframe)
|
||||
}
|
||||
|
||||
override fun getWatchFaceStyle(): WatchFaceStyle {
|
||||
return WatchFaceStyle.Builder(this).setAcceptsTapEvents(true).build()
|
||||
}
|
||||
override fun layoutResource(): Int = R.layout.activity_home
|
||||
|
||||
override fun setColorDark() {
|
||||
mLinearLayout?.setBackgroundColor(ContextCompat.getColor(this, if (dividerMatchesBg) R.color.dark_background else R.color.dark_statusView))
|
||||
|
|
|
@ -7,8 +7,9 @@ import android.content.Intent
|
|||
import android.content.IntentFilter
|
||||
import android.graphics.*
|
||||
import android.os.BatteryManager
|
||||
import android.os.PowerManager
|
||||
import android.os.Vibrator
|
||||
import android.support.wearable.watchface.WatchFaceStyle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.WindowInsets
|
||||
import android.view.WindowManager
|
||||
|
@ -16,6 +17,7 @@ import android.widget.ImageView
|
|||
import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.ustwo.clockwise.common.WatchFaceTime
|
||||
import com.ustwo.clockwise.common.WatchMode
|
||||
|
@ -27,6 +29,7 @@ import info.nightscout.androidaps.events.EventWearPreferenceChange
|
|||
import info.nightscout.androidaps.events.EventWearToMobile
|
||||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.extensions.toVisibilityKeepSpace
|
||||
import info.nightscout.androidaps.interaction.menus.MainMenuActivity
|
||||
import info.nightscout.androidaps.interaction.utils.Persistence
|
||||
import info.nightscout.androidaps.interaction.utils.WearUtil
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
|
@ -49,6 +52,7 @@ import kotlin.math.floor
|
|||
* Created by emmablack on 12/29/14.
|
||||
* Updated by andrew-warrington on 02-Jan-2018.
|
||||
* Refactored by dlvoy on 2019-11-2019
|
||||
* Refactored by MilosKozak 24/04/2022
|
||||
*/
|
||||
abstract class BaseWatchFace : WatchFace() {
|
||||
|
||||
|
@ -67,6 +71,9 @@ abstract class BaseWatchFace : WatchFace() {
|
|||
protected var treatmentData = TreatmentData(ArrayList(), ArrayList(), ArrayList(), ArrayList())
|
||||
protected var graphData = EventData.GraphData(ArrayList())
|
||||
|
||||
// Layout
|
||||
@LayoutRes abstract fun layoutResource(): Int
|
||||
|
||||
private val displaySize = Point()
|
||||
var mTime: TextView? = null
|
||||
var mHour: TextView? = null
|
||||
|
@ -100,8 +107,10 @@ abstract class BaseWatchFace : WatchFace() {
|
|||
var mLinearLayout: LinearLayout? = null
|
||||
var mLinearLayout2: LinearLayout? = null
|
||||
var mDate: LinearLayout? = null
|
||||
var mChartTap: LinearLayout? = null
|
||||
var mMainMenuTap: LinearLayout? = null
|
||||
var mChartTap: LinearLayout? = null // Steampunk only
|
||||
var mMainMenuTap: LinearLayout? = null // Steampunk,Digital only
|
||||
var chart: LineChartView? = null
|
||||
|
||||
var ageLevel = 1
|
||||
var loopLevel = -1
|
||||
var highColor = Color.YELLOW
|
||||
|
@ -111,13 +120,16 @@ abstract class BaseWatchFace : WatchFace() {
|
|||
var basalBackgroundColor = Color.BLUE
|
||||
var basalCenterColor = Color.BLUE
|
||||
var bolusColor = Color.MAGENTA
|
||||
var lowResMode = false
|
||||
var layoutSet = false
|
||||
private var lowResMode = false
|
||||
private var layoutSet = false
|
||||
var bIsRound = false
|
||||
var dividerMatchesBg = false
|
||||
var pointSize = 2
|
||||
var chart: LineChartView? = null
|
||||
var wakeLock: PowerManager.WakeLock? = null
|
||||
|
||||
// Tapping times
|
||||
private var sgvTapTime: Long = 0
|
||||
private var chartTapTime: Long = 0
|
||||
private var mainMenuTapTime: Long = 0
|
||||
|
||||
// related endTime manual layout
|
||||
var layoutView: View? = null
|
||||
|
@ -146,7 +158,6 @@ abstract class BaseWatchFace : WatchFace() {
|
|||
colorDarkLow = ContextCompat.getColor(this, R.color.dark_lowColor)
|
||||
@Suppress("DEPRECATION")
|
||||
(getSystemService(WINDOW_SERVICE) as WindowManager).defaultDisplay.getSize(displaySize)
|
||||
wakeLock = (getSystemService(POWER_SERVICE) as PowerManager).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:BaseWatchFace")
|
||||
specW = View.MeasureSpec.makeMeasureSpec(displaySize.x, View.MeasureSpec.EXACTLY)
|
||||
specH = if (forceSquareCanvas) specW else View.MeasureSpec.makeMeasureSpec(displaySize.y, View.MeasureSpec.EXACTLY)
|
||||
disposable += rxBus
|
||||
|
@ -185,6 +196,58 @@ abstract class BaseWatchFace : WatchFace() {
|
|||
persistence.turnOff()
|
||||
setupBatteryReceiver()
|
||||
setupSimpleUi()
|
||||
layoutView = (getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater).inflate(layoutResource(), null)
|
||||
performViewSetup()
|
||||
rxBus.send(EventWearToMobile(ActionResendData("BaseWatchFace::onCreate")))
|
||||
}
|
||||
|
||||
override fun onTapCommand(tapType: Int, x: Int, y: Int, eventTime: Long) {
|
||||
chart?.let { chart ->
|
||||
if (tapType == TAP_TYPE_TAP && x >= chart.left && x <= chart.right && y >= chart.top && y <= chart.bottom) {
|
||||
if (eventTime - chartTapTime < 800) {
|
||||
changeChartTimeframe()
|
||||
}
|
||||
chartTapTime = eventTime
|
||||
return
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
mChartTap?.let { mChartTap ->
|
||||
if (tapType == TAP_TYPE_TAP && x >= mChartTap.left && x <= mChartTap.right && y >= mChartTap.top && y <= mChartTap.bottom) {
|
||||
if (eventTime - chartTapTime < 800) {
|
||||
changeChartTimeframe()
|
||||
}
|
||||
chartTapTime = eventTime
|
||||
return
|
||||
}
|
||||
}
|
||||
mMainMenuTap?.let { mMainMenuTap ->
|
||||
if (tapType == TAP_TYPE_TAP && x >= mMainMenuTap.left && x <= mMainMenuTap.right && y >= mMainMenuTap.top && y <= mMainMenuTap.bottom) {
|
||||
if (eventTime - mainMenuTapTime < 800) {
|
||||
startActivity(Intent(this, MainMenuActivity::class.java).also { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
|
||||
}
|
||||
mainMenuTapTime = eventTime
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open fun changeChartTimeframe() {
|
||||
var timeframe = sp.getInt(R.string.key_chart_time_frame, 3)
|
||||
timeframe = timeframe % 5 + 1
|
||||
sp.putInt(R.string.key_chart_time_frame, timeframe)
|
||||
}
|
||||
|
||||
override fun getWatchFaceStyle(): WatchFaceStyle {
|
||||
return WatchFaceStyle.Builder(this).setAcceptsTapEvents(true).build()
|
||||
}
|
||||
|
||||
private fun setupBatteryReceiver() {
|
||||
|
@ -272,7 +335,6 @@ abstract class BaseWatchFace : WatchFace() {
|
|||
setupCharts()
|
||||
setDataFields()
|
||||
missedReadingAlert()
|
||||
wakeLock?.acquire(50)
|
||||
}
|
||||
|
||||
fun ageLevel(): Int {
|
||||
|
|
|
@ -1,14 +1,7 @@
|
|||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package info.nightscout.androidaps.watchfaces
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.support.wearable.watchface.WatchFaceStyle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interaction.menus.MainMenuActivity
|
||||
|
||||
/**
|
||||
* Created by andrew-warrington on 18/11/2017.
|
||||
|
@ -16,30 +9,7 @@ import info.nightscout.androidaps.interaction.menus.MainMenuActivity
|
|||
*/
|
||||
class CockpitWatchface : BaseWatchFace() {
|
||||
|
||||
private var sgvTapTime: Long = 0
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
val inflater = getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
layoutView = inflater.inflate(R.layout.activity_cockpit, null)
|
||||
performViewSetup()
|
||||
}
|
||||
|
||||
override fun onTapCommand(tapType: Int, x: Int, y: Int, eventTime: Long) {
|
||||
if (tapType == TAP_TYPE_TAP) {
|
||||
if (eventTime - sgvTapTime < 800) {
|
||||
val intent = Intent(this, MainMenuActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
startActivity(intent)
|
||||
}
|
||||
sgvTapTime = eventTime
|
||||
}
|
||||
}
|
||||
|
||||
override fun getWatchFaceStyle(): WatchFaceStyle {
|
||||
return WatchFaceStyle.Builder(this).setAcceptsTapEvents(true).build()
|
||||
}
|
||||
override fun layoutResource(): Int = R.layout.activity_cockpit
|
||||
|
||||
override fun setColorDark() {
|
||||
mRelativeLayout?.setBackgroundResource(R.drawable.airplane_cockpit_outside_clouds)
|
||||
|
@ -77,13 +47,13 @@ class CockpitWatchface : BaseWatchFace() {
|
|||
}
|
||||
|
||||
private fun setTextSizes() {
|
||||
if (status.detailedIob) {
|
||||
if (bIsRound) mIOB2?.textSize = 10f
|
||||
else mIOB2?.textSize = 9f
|
||||
} else {
|
||||
if (bIsRound) mIOB2?.textSize = 13f
|
||||
else mIOB2?.textSize = 12f
|
||||
}
|
||||
if (status.detailedIob) {
|
||||
if (bIsRound) mIOB2?.textSize = 10f
|
||||
else mIOB2?.textSize = 9f
|
||||
} else {
|
||||
if (bIsRound) mIOB2?.textSize = 13f
|
||||
else mIOB2?.textSize = 12f
|
||||
}
|
||||
if (mUploaderBattery?.visibility != View.GONE && mRigBattery?.visibility != View.GONE) {
|
||||
if (bIsRound) {
|
||||
mUploaderBattery?.textSize = 12f
|
||||
|
|
|
@ -3,42 +3,18 @@
|
|||
package info.nightscout.androidaps.watchfaces
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.support.wearable.watchface.WatchFaceStyle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.interaction.menus.MainMenuActivity
|
||||
import info.nightscout.shared.logging.LTag
|
||||
|
||||
class DigitalStyleWatchface : BaseWatchFace() {
|
||||
|
||||
private var sgvTapTime: Long = 0
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
val inflater = getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
layoutView = inflater.inflate(R.layout.activity_digitalstyle, null)
|
||||
performViewSetup()
|
||||
}
|
||||
|
||||
override fun onTapCommand(tapType: Int, x: Int, y: Int, eventTime: Long) {
|
||||
//tapType = TAP_TYPE_TAP;
|
||||
aapsLogger.debug(LTag.WEAR, "onTapCommand: DeviceWidth x DeviceHeight /// x , y, TapType >> ", "$width x $height /// $x , $y , $tapType")
|
||||
if (tapType == TAP_TYPE_TAP) {
|
||||
if (eventTime - sgvTapTime < TIME_TAP_THRESHOLD) {
|
||||
val intent = Intent(this, MainMenuActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
startActivity(intent)
|
||||
}
|
||||
sgvTapTime = eventTime
|
||||
}
|
||||
}
|
||||
override fun layoutResource(): Int = R.layout.activity_digitalstyle
|
||||
|
||||
override fun getWatchFaceStyle(): WatchFaceStyle {
|
||||
return WatchFaceStyle.Builder(this)
|
||||
|
|
|
@ -10,7 +10,6 @@ import android.graphics.Point
|
|||
import android.graphics.Rect
|
||||
import android.os.PowerManager
|
||||
import android.support.wearable.watchface.WatchFaceStyle
|
||||
import android.text.format.DateFormat
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.WindowInsets
|
||||
|
|
|
@ -1,17 +1,10 @@
|
|||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package info.nightscout.androidaps.watchfaces
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.support.wearable.watchface.WatchFaceStyle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.LinearInterpolator
|
||||
import android.view.animation.RotateAnimation
|
||||
import androidx.core.content.ContextCompat
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interaction.menus.MainMenuActivity
|
||||
import info.nightscout.shared.SafeParse.stringToFloat
|
||||
import org.joda.time.TimeOfDay
|
||||
|
||||
|
@ -21,43 +14,14 @@ import org.joda.time.TimeOfDay
|
|||
*/
|
||||
class SteampunkWatchface : BaseWatchFace() {
|
||||
|
||||
private var chartTapTime: Long = 0
|
||||
private var mainMenuTapTime: Long = 0
|
||||
private var lastEndDegrees = 0f
|
||||
private var deltaRotationAngle = 0f
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
override fun layoutResource(): Int = R.layout.activity_steampunk
|
||||
|
||||
override fun onCreate() {
|
||||
forceSquareCanvas = true
|
||||
super.onCreate()
|
||||
val inflater = getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
layoutView = inflater.inflate(R.layout.activity_steampunk, null)
|
||||
performViewSetup()
|
||||
}
|
||||
|
||||
override fun onTapCommand(tapType: Int, x: Int, y: Int, eventTime: Long) {
|
||||
mChartTap?.let { mChartTap ->
|
||||
if (tapType == TAP_TYPE_TAP && x >= mChartTap.left && x <= mChartTap.right && y >= mChartTap.top && y <= mChartTap.bottom) {
|
||||
if (eventTime - chartTapTime < 800) {
|
||||
changeChartTimeframe()
|
||||
}
|
||||
chartTapTime = eventTime
|
||||
return
|
||||
}
|
||||
}
|
||||
mMainMenuTap?.let { mMainMenuTap ->
|
||||
if (tapType == TAP_TYPE_TAP && x >= mMainMenuTap.left && x <= mMainMenuTap.right && y >= mMainMenuTap.top && y <= mMainMenuTap.bottom) {
|
||||
if (eventTime - mainMenuTapTime < 800) {
|
||||
startActivity(Intent(this, MainMenuActivity::class.java).also { it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
|
||||
}
|
||||
mainMenuTapTime = eventTime
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getWatchFaceStyle(): WatchFaceStyle {
|
||||
return WatchFaceStyle.Builder(this).setAcceptsTapEvents(true).build()
|
||||
}
|
||||
|
||||
override fun setColorDark() {
|
||||
|
@ -241,15 +205,10 @@ class SteampunkWatchface : BaseWatchFace() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun changeChartTimeframe() {
|
||||
override fun changeChartTimeframe() {
|
||||
var timeframe = sp.getInt(R.string.key_chart_time_frame, 3)
|
||||
timeframe = timeframe % 5 + 1
|
||||
pointSize = if (timeframe < 3) {
|
||||
2
|
||||
} else {
|
||||
1
|
||||
}
|
||||
setupCharts()
|
||||
pointSize = if (timeframe < 3) 2 else 1
|
||||
sp.putInt(R.string.key_chart_time_frame, timeframe)
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
<!-- left side 3/8 width -->
|
||||
<LinearLayout
|
||||
android:id="@+id/main_menu_tap"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="3"
|
||||
|
@ -266,6 +267,7 @@
|
|||
|
||||
<!-- right side 5/8 width -->
|
||||
<LinearLayout
|
||||
android:id="@+id/chart_zoom_tap"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="5"
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
<!-- left side 3/8 width -->
|
||||
<LinearLayout
|
||||
android:id="@+id/main_menu_tap"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="3"
|
||||
|
@ -267,6 +268,7 @@
|
|||
|
||||
<!-- right side 5/8 width -->
|
||||
<LinearLayout
|
||||
android:id="@+id/chart_zoom_tap"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="5"
|
||||
|
|
Loading…
Reference in a new issue