11// Tea Timer Application for Bangle.js 2 using sched library
22
3- let appRect = Bangle . appRect ;
4- let centerY = appRect . y + appRect . w / 2 ;
5- let centerX = appRect . x + appRect . h / 2 ;
6- let middleRect = { x :appRect . x , y :centerY - 20 , w :appRect . w , h :40 }
7- let GREEN = g . theme . dark ?0x07E0 :0x03E0 ;
3+ const APP_RECT = Bangle . appRect ;
4+ const CENTER_Y = APP_RECT . y + APP_RECT . w / 2 ;
5+ const CENTER_X = APP_RECT . x + APP_RECT . h / 2 ;
86
97let timerDuration = ( ( ) => {
108 let file = require ( "Storage" ) . open ( "ateatimer.data" , "r" ) ;
@@ -20,7 +18,8 @@ function saveDefaultDuration() {
2018}
2119
2220function drawTime ( ) {
23- g . clearRect ( middleRect ) ;
21+ const TIME_RECT = { x :APP_RECT . x , y :CENTER_Y - 20 , w :APP_RECT . w , h :40 }
22+ g . clearRect ( TIME_RECT ) ;
2423 g . setFont ( "Vector" , 40 ) ;
2524 g . setFontAlign ( 0 , 0 ) ; // Center align
2625
@@ -29,24 +28,24 @@ function drawTime() {
2928 const sign = timeRemaining < 0 ? "-" : "" ;
3029 const timeStr = `${ sign } ${ minutes } :${ seconds . toString ( ) . padStart ( 2 , '0' ) } ` ;
3130
32- g . drawString ( timeStr , centerX , centerY ) ;
31+ g . drawString ( timeStr , CENTER_X , CENTER_Y ) ;
3332
3433 g . flip ( ) ;
3534}
3635
3736function drawButtons ( ) {
3837 // Draw Increase button (triangle pointing up)
3938 g . fillPoly ( [
40- centerX , centerY - 80 , // Top vertex
41- centerX - 20 , centerY - 60 , // Bottom-left vertex
42- centerX + 20 , centerY - 60 // Bottom-right vertex
39+ CENTER_X , CENTER_Y - 80 , // Top vertex
40+ CENTER_X - 20 , CENTER_Y - 60 , // Bottom-left vertex
41+ CENTER_X + 20 , CENTER_Y - 60 // Bottom-right vertex
4342 ] ) ;
4443
4544 // Draw Decrease button (triangle pointing down)
4645 g . fillPoly ( [
47- centerX , centerY + 80 , // Bottom vertex
48- centerX - 20 , centerY + 60 , // Top-left vertex
49- centerX + 20 , centerY + 60 // Top-right vertex
46+ CENTER_X , CENTER_Y + 80 , // Bottom vertex
47+ CENTER_X - 20 , CENTER_Y + 60 , // Top-left vertex
48+ CENTER_X + 20 , CENTER_Y + 60 // Top-right vertex
5049 ] ) ;
5150
5251 g . flip ( ) ;
@@ -75,6 +74,7 @@ function startTimer() {
7574 scheduleTimer ( ) ;
7675
7776 // Flash the time in green to indicate the timer started
77+ const GREEN = g . theme . dark ?0x07E0 :0x03E0 ;
7878 g . setColor ( GREEN ) ;
7979 drawTime ( ) ;
8080 g . reset ( ) ;
@@ -130,10 +130,10 @@ function adjustTime(amount) {
130130
131131function handleTouch ( x , y ) {
132132
133- if ( y < centerY - 40 ) {
133+ if ( y < CENTER_Y - 40 ) {
134134 // Increase button area
135135 adjustTime ( 60 ) ;
136- } else if ( y > centerY + 40 ) {
136+ } else if ( y > CENTER_Y + 40 ) {
137137 // Decrease button area
138138 adjustTime ( - 60 ) ;
139139 } else {
0 commit comments