2020-09-29 20:58:10 +02:00
package info.nightscout.androidaps.watchfaces ;
2022-04-22 22:19:10 +02:00
import android.annotation.SuppressLint ;
2020-09-29 20:58:10 +02:00
import android.content.Intent ;
2020-10-08 19:48:50 +02:00
import android.content.res.ColorStateList ;
2020-09-29 20:58:10 +02:00
import android.support.wearable.watchface.WatchFaceStyle ;
import android.view.LayoutInflater ;
2020-10-08 21:33:19 +02:00
import android.view.View ;
2020-09-29 20:58:10 +02:00
import android.widget.LinearLayout ;
2020-10-08 21:33:19 +02:00
import android.widget.TextView ;
2020-09-29 20:58:10 +02:00
import androidx.core.content.ContextCompat ;
2020-10-08 19:48:50 +02:00
2020-10-08 22:25:18 +02:00
import java.text.SimpleDateFormat ;
import java.util.Date ;
2020-09-29 20:58:10 +02:00
import info.nightscout.androidaps.R ;
import info.nightscout.androidaps.interaction.menus.MainMenuActivity ;
2022-04-23 16:20:50 +02:00
import info.nightscout.shared.logging.LTag ;
2020-09-29 20:58:10 +02:00
2020-10-31 21:00:46 +01:00
public class DigitalStyle extends BaseWatchFace {
2020-10-26 21:12:33 +01:00
private static final long TIME_TAP_THRESHOLD = 800 ;
2020-09-29 20:58:10 +02:00
private long sgvTapTime = 0 ;
2022-04-22 22:19:10 +02:00
@SuppressLint ( " InflateParams " ) @Override
2020-09-29 20:58:10 +02:00
public void onCreate ( ) {
super . onCreate ( ) ;
LayoutInflater inflater = ( LayoutInflater ) getSystemService ( LAYOUT_INFLATER_SERVICE ) ;
2020-10-31 21:00:46 +01:00
layoutView = inflater . inflate ( R . layout . activity_digitalstyle , null ) ;
2020-09-29 20:58:10 +02:00
performViewSetup ( ) ;
}
@Override
protected void onTapCommand ( int tapType , int x , int y , long eventTime ) {
//tapType = TAP_TYPE_TAP;
2022-04-23 16:20:50 +02:00
aapsLogger . debug ( LTag . WEAR , " onTapCommand: DeviceWidth x DeviceHeight /// x , y, TapType >> " , getWidth ( ) + " x " + getHeight ( ) + " /// " + x + " , " + y + " , " + tapType ) ;
2020-09-29 20:58:10 +02:00
if ( tapType = = TAP_TYPE_TAP ) {
2020-10-26 21:12:33 +01:00
if ( eventTime - sgvTapTime < TIME_TAP_THRESHOLD ) {
2020-09-29 20:58:10 +02:00
Intent intent = new Intent ( this , MainMenuActivity . class ) ;
intent . addFlags ( Intent . FLAG_ACTIVITY_NEW_TASK ) ;
startActivity ( intent ) ;
}
sgvTapTime = eventTime ;
}
}
2022-04-23 15:29:02 +02:00
@SuppressWarnings ( " deprecation " )
2020-09-29 20:58:10 +02:00
@Override
protected WatchFaceStyle getWatchFaceStyle ( ) {
return new WatchFaceStyle . Builder ( this )
. setAcceptsTapEvents ( true )
. setHideNotificationIndicator ( false )
. setShowUnreadCountIndicator ( true )
. build ( ) ;
}
protected void setColorDark ( ) {
2022-04-22 22:19:10 +02:00
if ( singleBg . getSgvLevel ( ) = = 1 ) {
2022-04-23 18:34:04 +02:00
mSgv . setTextColor ( ContextCompat . getColor ( this , R . color . dark_highColor ) ) ;
mDirection . setTextColor ( ContextCompat . getColor ( this , R . color . dark_highColor ) ) ;
2022-04-22 22:19:10 +02:00
} else if ( singleBg . getSgvLevel ( ) = = 0 ) {
2022-04-23 18:34:04 +02:00
mSgv . setTextColor ( ContextCompat . getColor ( this , R . color . dark_midColor ) ) ;
mDirection . setTextColor ( ContextCompat . getColor ( this , R . color . dark_midColor ) ) ;
2022-04-22 22:19:10 +02:00
} else if ( singleBg . getSgvLevel ( ) = = - 1 ) {
2022-04-23 18:34:04 +02:00
mSgv . setTextColor ( ContextCompat . getColor ( this , R . color . dark_lowColor ) ) ;
mDirection . setTextColor ( ContextCompat . getColor ( this , R . color . dark_lowColor ) ) ;
2020-09-29 20:58:10 +02:00
}
if ( ageLevel = = 1 ) {
2022-04-23 18:34:04 +02:00
mTimestamp . setTextColor ( ContextCompat . getColor ( this , R . color . dark_midColor ) ) ;
2020-09-29 20:58:10 +02:00
} else {
2022-04-23 18:34:04 +02:00
mTimestamp . setTextColor ( ContextCompat . getColor ( this , R . color . dark_TimestampOld ) ) ;
2020-09-29 20:58:10 +02:00
}
2022-04-22 22:19:10 +02:00
if ( status . getBatteryLevel ( ) = = 1 ) {
2022-04-23 18:34:04 +02:00
mUploaderBattery . setTextColor ( ContextCompat . getColor ( this , R . color . dark_midColor ) ) ;
2020-09-29 20:58:10 +02:00
} else {
2022-04-23 18:34:04 +02:00
mUploaderBattery . setTextColor ( ContextCompat . getColor ( this , R . color . dark_uploaderBatteryEmpty ) ) ;
2020-09-29 20:58:10 +02:00
}
if ( chart ! = null ) {
2022-04-23 18:34:04 +02:00
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 ) ;
2020-09-29 20:58:10 +02:00
pointSize = 1 ;
setupCharts ( ) ;
2020-10-26 21:12:33 +01:00
setWatchfaceStyle ( ) ;
2020-09-29 20:58:10 +02:00
}
2020-10-26 21:12:33 +01:00
}
2020-09-29 20:58:10 +02:00
2020-10-26 21:12:33 +01:00
private void setWatchfaceStyle ( ) {
2020-09-29 20:58:10 +02:00
/* frame styles*/
LinearLayout mShapesElements = layoutView . findViewById ( R . id . shapes_elements ) ;
if ( mShapesElements ! = null ) {
String displayFormatType = ( mShapesElements . getContentDescription ( ) . toString ( ) . startsWith ( " round " ) ? " round " : " rect " ) ;
2022-04-22 22:19:10 +02:00
String displayStyle = sp . getString ( " digitalstyle_frameStyle " , " full " ) ;
String displayFrameColor = sp . getString ( " digitalstyle_frameColor " , " red " ) ;
String displayFrameColorSaturation = sp . getString ( " digitalstyle_frameColorSaturation " ,
" 500 " ) ;
String displayFrameColorOpacity = sp . getString ( " digitalstyle_frameColorOpacity " , " 1 " ) ;
2020-10-08 19:48:50 +02:00
// Load image with shapes
2020-10-31 21:00:46 +01:00
String styleDrawableName = " digitalstyle_bg_ " + displayStyle + " _ " + displayFormatType ;
2020-09-29 20:58:10 +02:00
try {
2022-04-23 18:34:04 +02:00
mShapesElements . setBackground ( getResources ( ) . getDrawable ( getResources ( ) . getIdentifier ( styleDrawableName , " drawable " , this . getPackageName ( ) ) ) ) ;
2020-09-29 20:58:10 +02:00
} catch ( Exception e ) {
2022-04-23 16:20:50 +02:00
aapsLogger . error ( " digitalstyle_frameStyle " , " RESOURCE NOT FOUND >> " + styleDrawableName ) ;
2020-09-29 20:58:10 +02:00
}
2020-10-08 19:48:50 +02:00
// set background-tint-color
2020-10-09 14:50:41 +02:00
if ( displayFrameColor . equalsIgnoreCase ( " multicolor " ) | | displayStyle . equalsIgnoreCase ( " none " ) ) {
2020-10-08 19:48:50 +02:00
mShapesElements . setBackgroundTintList ( null ) ;
} else {
String strColorName = ( ( displayFrameColor . equals ( " white " ) | | displayFrameColor . equals ( " black " ) ) ? displayFrameColor : displayFrameColor + " _ " + displayFrameColorSaturation ) ;
2022-04-23 16:20:50 +02:00
aapsLogger . debug ( LTag . WEAR , " digitalstyle_strColorName " , strColorName ) ;
2020-10-08 19:48:50 +02:00
try {
2022-04-23 18:34:04 +02:00
ColorStateList colorStateList = ContextCompat . getColorStateList ( this , getResources ( ) . getIdentifier ( strColorName , " color " , this . getPackageName ( ) ) ) ;
2020-10-08 19:48:50 +02:00
mShapesElements . setBackgroundTintList ( colorStateList ) ;
} catch ( Exception e ) {
mShapesElements . setBackgroundTintList ( null ) ;
2022-04-23 16:20:50 +02:00
aapsLogger . error ( " digitalstyle_colorName " , " COLOR NOT FOUND >> " + strColorName ) ;
2020-10-08 19:48:50 +02:00
}
}
2020-09-29 20:58:10 +02:00
2020-10-09 14:50:41 +02:00
// set opacity of shapes
mShapesElements . setAlpha ( Float . parseFloat ( displayFrameColorOpacity ) ) ;
2020-10-08 19:48:50 +02:00
}
2020-10-08 21:33:19 +02:00
/* optimize font-size --> when date is off then increase font-size of time */
2022-04-22 22:19:10 +02:00
Boolean isShowDate = sp . getBoolean ( " show_date " , false ) ;
2020-10-08 21:33:19 +02:00
if ( ! isShowDate ) {
layoutView . findViewById ( R . id . date_time ) . setVisibility ( View . GONE ) ;
mHour . setTextSize ( 62 ) ;
mMinute . setTextSize ( 40 ) ;
mHour . setLetterSpacing ( ( float ) - 0 . 066 ) ;
mMinute . setLetterSpacing ( ( float ) - 0 . 066 ) ;
} else {
layoutView . findViewById ( R . id . date_time ) . setVisibility ( View . VISIBLE ) ;
mHour . setTextSize ( 40 ) ;
mMinute . setTextSize ( 26 ) ;
mHour . setLetterSpacing ( ( float ) 0 ) ;
mMinute . setLetterSpacing ( ( float ) 0 ) ;
2020-10-08 22:25:18 +02:00
/* display week number */
2022-04-22 22:19:10 +02:00
Boolean isShowWeekNumber = sp . getBoolean ( " show_weeknumber " , false ) ;
2022-04-23 16:20:50 +02:00
aapsLogger . info ( LTag . WEAR , " --------------------------------- " , " weeknumber refresh " ) ;
2020-10-08 22:25:18 +02:00
TextView mWeekNumber = layoutView . findViewById ( R . id . weeknumber ) ;
if ( isShowWeekNumber ) {
mWeekNumber . setVisibility ( View . VISIBLE ) ;
mWeekNumber . setText ( " ( " + ( new SimpleDateFormat ( " ww " ) ) . format ( new Date ( ) ) + " ) " ) ;
} else {
mWeekNumber . setVisibility ( View . GONE ) ;
mWeekNumber . setText ( " " ) ;
}
2020-10-08 21:33:19 +02:00
}
2020-10-08 22:25:18 +02:00
2020-09-29 20:58:10 +02:00
}
protected void setColorLowRes ( ) {
setColorDark ( ) ;
}
2020-10-26 21:31:26 +01:00
protected void setColorBright ( ) { setColorDark ( ) ; /* getCurrentWatchMode() == WatchMode.AMBIENT or WatchMode.INTERACTIVE */ }
2020-09-29 20:58:10 +02:00
}