11// Tea Timer Application for Bangle.js 2 using sched library
22
3- let appRect = Bangle . appRect ;
4- let middleY = appRect . y + appRect . w / 2 ;
5- let middleRect = { x :appRect . x , y :middleY - 20 , w :appRect . w , h :40 }
6- 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 ;
76
87let timerDuration = ( ( ) => {
98 let file = require ( "Storage" ) . open ( "ateatimer.data" , "r" ) ;
@@ -19,7 +18,8 @@ function saveDefaultDuration() {
1918}
2019
2120function drawTime ( ) {
22- 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 ) ;
2323 g . setFont ( "Vector" , 40 ) ;
2424 g . setFontAlign ( 0 , 0 ) ; // Center align
2525
@@ -28,24 +28,24 @@ function drawTime() {
2828 const sign = timeRemaining < 0 ? "-" : "" ;
2929 const timeStr = `${ sign } ${ minutes } :${ seconds . toString ( ) . padStart ( 2 , '0' ) } ` ;
3030
31- g . drawString ( timeStr , g . getWidth ( ) / 2 , g . getHeight ( ) / 2 ) ;
31+ g . drawString ( timeStr , CENTER_X , CENTER_Y ) ;
3232
3333 g . flip ( ) ;
3434}
3535
3636function drawButtons ( ) {
3737 // Draw Increase button (triangle pointing up)
3838 g . fillPoly ( [
39- g . getWidth ( ) / 2 , g . getHeight ( ) / 2 - 80 , // Top vertex
40- g . getWidth ( ) / 2 - 20 , g . getHeight ( ) / 2 - 60 , // Bottom-left vertex
41- g . getWidth ( ) / 2 + 20 , g . getHeight ( ) / 2 - 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
4242 ] ) ;
4343
4444 // Draw Decrease button (triangle pointing down)
4545 g . fillPoly ( [
46- g . getWidth ( ) / 2 , g . getHeight ( ) / 2 + 80 , // Bottom vertex
47- g . getWidth ( ) / 2 - 20 , g . getHeight ( ) / 2 + 60 , // Top-left vertex
48- g . getWidth ( ) / 2 + 20 , g . getHeight ( ) / 2 + 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
4949 ] ) ;
5050
5151 g . flip ( ) ;
@@ -74,6 +74,7 @@ function startTimer() {
7474 scheduleTimer ( ) ;
7575
7676 // Flash the time in green to indicate the timer started
77+ const GREEN = g . theme . dark ?0x07E0 :0x03E0 ;
7778 g . setColor ( GREEN ) ;
7879 drawTime ( ) ;
7980 g . reset ( ) ;
@@ -128,12 +129,11 @@ function adjustTime(amount) {
128129}
129130
130131function handleTouch ( x , y ) {
131- const centerY = g . getHeight ( ) / 2 ;
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