This pull request represents a functional and presentable phone/companion/handheld app. There is still a lot of improvements to be made to the look and function of the app, but this version is functional and pretty enough.
Features
All available settings can be loaded from and applied to the watch
In-app preview of all available settings
Detection of watch connectivity (phone app pings the watch every 5 seconds, 15 seconds since last ping results in a disconnect and initiates handshake attempts)
Added settings for show complications in active/ambient
Adds showing the selected setting for preferences like Date order, date separator, language, etc.
Some preferences have been temporarily removed from the phone app to fit with working features:
Starting complication config activities
Font selection for top text (not yet implemented on the watch side)
The "New" button on the home screen now says "Edit" as multiple preference sets haven't been implemented yet
The phone initiates a transfer of preferences by sending a DataRequest with the boolean "rokas-twelveish-dr" set to true. The watch app then loops through all preferences, adding each key and value to a string array, with each value directly following its key. The array is then returned to the phone in a DataRequest with "rokas-twelveish-dr2"=true.
Upon reception of the array, the phone app loops through all entries and checks for a matching key in each SettingsManager hashmap, adding the value to the corresponding map. The entire SettingsManager is then converted to JSON and saved to a the file test.json. This is partially done because of a difficulty with sharing a SettingsManager between HomeScreen and CustomizationScreen.
Phone loops through each SettingsManager hashmap, adding every key/value pair to a string array, along with the value type. Every preference is added to the array in this format:
String key
String value
String type (String, Integer, or Boolean)
The string array is sent in a DataRequest with boolean rokas-twelveish-dr2 set to true. The watch loops through the string array, converting the second string in each triplet to the appropriate variable type before adding it to preferences.
Pinging
Communicator.ping()
After a connection to the watch has been established through Communicator.initiateHandshake(), a postDelayed Handler is created, running every 5000 milliseconds. This handler calls ping(), sending a DataRequest with rokas-twelveish-fire = true. This request is answered with rokas-twelveish-ice=true and a timestamp (the current system time in milliseconds on the watch) stored in rokas-twelveish-timestamp. This timestamp is stored as lastPing, which is then compared to the current system time of the phone.
If the difference between the current time and the last received timestamp is greater than 15000 milliseconds (15 seconds), the watch is considered disconnected, isWatchConnected is set to false, and handshake initiation is restarted.
When created from the HomeScreen activity, WatchPreviewView tells the communicator to request all preferences from the watch, as described in Communicator.requestPreferences. If the request was succesful, the preferences are saved to the local JSON file as a cache. This file is then loaded by the CustomizationScreen activity. If no such file exists, a new SettingsManageris initiated and saved to the file.
This request includes the changes found in PR #22.
This pull request represents a functional and presentable phone/companion/handheld app. There is still a lot of improvements to be made to the look and function of the app, but this version is functional and pretty enough.
Features
Some preferences have been temporarily removed from the phone app to fit with working features:
Communicator implementation
Loading preferences from watch to phone
Communicator.requestPreferences(Context context, WeakReference<WatchPreviewView> listenerActivity)
The phone initiates a transfer of preferences by sending a
DataRequest
with the boolean"rokas-twelveish-dr"
set to true. The watch app then loops through all preferences, adding each key and value to a string array, with each value directly following its key. The array is then returned to the phone in aDataRequest
with"rokas-twelveish-dr2"=true
.Upon reception of the array, the phone app loops through all entries and checks for a matching key in each
SettingsManager
hashmap, adding the value to the corresponding map. The entire SettingsManager is then converted to JSON and saved to a the filetest.json
. This is partially done because of a difficulty with sharing aSettingsManager
betweenHomeScreen
andCustomizationScreen
.Saving (all) preferences to watch from phone
Communicator.sendWatchFace(SettingsManager settingsManager, Context context)
Phone loops through each
SettingsManager
hashmap, adding every key/value pair to a string array, along with the value type. Every preference is added to the array in this format:The string array is sent in a
DataRequest
with booleanrokas-twelveish-dr2
set to true. The watch loops through the string array, converting the second string in each triplet to the appropriate variable type before adding it to preferences.Pinging
Communicator.ping()
After a connection to the watch has been established through
Communicator.initiateHandshake()
, a postDelayedHandler
is created, running every 5000 milliseconds. This handler callsping()
, sending aDataRequest
withrokas-twelveish-fire = true
. This request is answered withrokas-twelveish-ice=true
and a timestamp (the current system time in milliseconds on the watch) stored inrokas-twelveish-timestamp
. This timestamp is stored aslastPing
, which is then compared to the current system time of the phone.If the difference between the current time and the last received timestamp is greater than 15000 milliseconds (15 seconds), the watch is considered disconnected,
isWatchConnected
is set to false, and handshake initiation is restarted.Loading preferences
WatchPreviewView.WatchPreviewView(Context context, @Nullable AttributeSet attrs)
When created from the
HomeScreen
activity,WatchPreviewView
tells the communicator to request all preferences from the watch, as described inCommunicator.requestPreferences
. If the request was succesful, the preferences are saved to the local JSON file as a cache. This file is then loaded by theCustomizationScreen
activity. If no such file exists, a newSettingsManager
is initiated and saved to the file.This request includes the changes found in PR #22.