public void synchronize ( final Context context ) { SportsState previousState = this . previousState ; boolean firstMessage = false ; if ( previousState == null ) { previousState = this . previousState = new SportsState ( ) ; firstMessage = true ; } PebbleDictionary message = new PebbleDictionary ( ) ; if ( getTimeInSec ( ) != previousState . getTimeInSec ( ) || firstMessage ) { previousState . setTimeInSec ( getTimeInSec ( ) ) ; message . addString ( Constants . SPORTS_TIME_KEY , convertSecondsToString ( getTimeInSec ( ) ) ) ; } if ( getDistance ( ) != previousState . getDistance ( ) || firstMessage ) { previousState . setDistance ( getDistance ( ) ) ; message . addString ( Constants . SPORTS_DISTANCE_KEY , convertDistanceToString ( getDistance ( ) ) ) ; } if ( this . paceInSec != null ) { message . addUint8 ( Constants . SPORTS_LABEL_KEY , ( byte ) Constants . SPORTS_DATA_PACE ) ; if ( getPaceInSec ( ) != previousState . getPaceInSec ( ) ) { previousState . setPaceInSec ( getPaceInSec ( ) ) ; message . addString ( Constants . SPORTS_DATA_KEY , convertSecondsToString ( getPaceInSec ( ) ) ) ; } } if ( this . speed != null ) { message . addUint8 ( Constants . SPORTS_LABEL_KEY , ( byte ) Constants . SPORTS_DATA_SPEED ) ; if ( getSpeed ( ) != previousState . getSpeed ( ) ) { previousState . setSpeed ( getSpeed ( ) ) ; message . addString ( Constants . SPORTS_DATA_KEY , convertDistanceToString ( getSpeed ( ) ) ) ; } } if ( this . heartBPM != null ) { if ( getHeartBPM ( ) != previousState . getHeartBPM ( ) ) { previousState . setHeartBPM ( getHeartBPM ( ) ) ; message . addUint8 ( Constants . SPORTS_HR_BPM_KEY , getHeartBPM ( ) ) ; } } if ( getCustomLabel ( ) != null && getCustomValue ( ) != null ) { if ( ! getCustomLabel ( ) . equals ( previousState . getCustomLabel ( ) ) ) { previousState . setCustomLabel ( getCustomLabel ( ) ) ; message . addString ( Constants . SPORTS_CUSTOM_LABEL_KEY , getCustomLabel ( ) ) ; } if ( ! getCustomValue ( ) . equals ( previousState . getCustomValue ( ) ) ) { previousState . setCustomValue ( getCustomValue ( ) ) ; message . addString ( Constants . SPORTS_CUSTOM_VALUE_KEY , getCustomValue ( ) ) ; } } PebbleKit . sendDataToPebble ( context , Constants . SPORTS_UUID , message ) ; }
Synchronizes the current state of the Sports App to the connected watch .