Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Functional phone app #23

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open

Conversation

augustuen
Copy link

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

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 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.

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:

  1. String key
  2. String value
  3. 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.

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 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.

Fixed wrong capitalization by calpilatizing the words in strings.xml and adding toLowerCase on capitalise2's output.
-Fixed: capitalisation for suffixes with non-break spaces
…precated getAdapterPosition() - This seems to have fixed a bug with onItemClickSwitch not being fired in MainTextSettingsFragment

Updated capitalisation of a key string.
Fixed a bug where invalidating the preview wouldn't update the prefixes and suffixes
…le adding options for other types of setting selection with only text.

Refactored MainTextSettingsFragment.onActivityResult to be more readable.

Started implementing handling for font and capitalization settings - Not yet functional.
…ins.

Changed the text of some options to look better. Added helping text to replace integer options (e.g. date order, capitalization)

Refactored TextSelectionActivity slightly to fit with TopSettingsFragment.onItemClick
…ixed broken imports in ComplicationConfigActivity
…eds implementing getting preferences from the wearable to handheld.

Refactored MyWatchFace.Engine.onDataChanged to accept more than one incoming preference at a time. Changed how the wearable fetches preferences to send to handheld.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant