Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ashok Kumar - WRITING APPS FOR WEAR OS

Ashok Kumar - WRITING APPS FOR WEAR OS

droidcon Berlin

July 12, 2018
Tweet

More Decks by droidcon Berlin

Other Decks in Programming

Transcript

  1. WHY AM I HERE ? Targetting your application to wear

    devices. Understanding wear application development Best Practices and more
  2. WHY WEAR APP ? ๏ WEAR OS and Devices are

    getting powerful. ๏ Easy access to notifications. ๏ Stand-Alone applications. ๏ Fitness applications. ๏ Watch face development. ๏ And more.
  3. POP QUIZ • Do you have wear device ? •

    Tried developing wear apps ?
  4. Gotchas of Wear 1.x Average Battery efficiency Pairing issues Complex

    user experience And limited scope for developers
  5. Wear 2.0 •Revamped UI with Material Design, darker colors, •and

    a more circular user interface for round watches. •Standalone apps with Google Play Store on watch •Complications for watch faces •Built-in keyboard •Handwriting recognition •Stackable notifications •Smarter notifications •Cellular Support •
  6. Building Blocks of Wear Application • Defining layouts • Creating

    lists • Showing confirmations • Exiting Full Screen Activities • Wear navigation and actions • Multifunction buttons
  7. CREATING LISTS Lists let the user select an item from

    a set of items. In the legacy Wear, 1.x API WearableListView helped programmers to build lists and custom lists. Wearable UI library now has WearableRecyclerView with curvedLayout support and has the best implementation experience in Wear devices.
  8. public class WearActivity extends Activity implements CircularProgressLayout.OnTimerFinishedListener, View.OnClickListener { private

    CircularProgressLayout mCircularProgress; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_wear_activity); mCircularProgress = (CircularProgressLayout) findViewById(R.id.circular_progress); mCircularProgress.setOnTimerFinishedListener(this); mCircularProgress.setOnClickListener(this); } @Override public void onTimerFinished(CircularProgressLayout layout) { // User didn't cancel, perform the action } @Override public void onClick(View view) { if (view.equals(mCircularProgress)) { // User canceled, abort the action mCircularProgress.stopTimer(); } } }
  9. EXITING FULL SCREEN ACTIVITIES <android.support.wear.widget.SwipeDismissFrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/swipe_dismiss_root"

    > <TextView android:id="@+id/test_content" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="Swipe me to dismiss me." /> </android.support.wear.widget.SwipeDismissFrameLayout>
  10. WEAR NAVIGATIONS AND ACTIONS In the new release of Android

    Wear OS, the Material design library adds the following two interactive drawers • Navigation drawer • Action drawer
  11. MULTIFUNCTION BUTTONS “In addition to the power button, Android Wear

    supports another button called the multifunction button on the device. The Wearable support library provides API for determining the multifunction buttons included by the manufacturer:”
  12. INPUT METHOD EDITORS ON WEAR Wear OS by Google adds

    support for input methods beyond voice by extending the Android input method editor (IME) framework. The IME framework provides support for virtual, on-screen keyboards that allow users to input texts in the form of keyclicks, handwriting or gestures.
  13. Gesture KeyEvent Description Flick wrist out KEYCODE_NAVIGATE_NEXT This key code

    goes to the next item. Flick wrist in KEYCODE_NAVIGATE_PREVIOU S This key code goes to the previous item. WRIST GESTURES
  14. WRIST GESTURES BEST PRACTICES • Review the KeyEvent and KeyEvent.Callback

    pages for the delivery of key events to your view • Have a touch parallel for a gesture • Provide visual feedback • Don't reinterpret repeated flick gestures into your own new gesture. It may conflict with the system's Shaking the wrist gesture. • Use requestFocus() and clearFocus() carefully
  15. SEAMLESS DATA COMMUNICATION Wear OS by Google, a watch can

    communicate with a network directly, without access to an Android or iOS phone
  16. Deprecated component Replacement component CapabilityApi CapabilityClient Channel ChannelClient.Channel ChannelApi ChannelClient

    DataApi DataClient MessageApi MessageClient NodeApi NodeClient MIGRATING WEAR APPS TO GOOGLE API
  17. ADVERTISE CAPABILITY To launch an activity on a handheld device

    from a wearable device, use the MessageAPI class to send the request. Multiple wearables can be associated with the handheld Android device; the wearable application needs to determine that an associated node is fit to launch the activity from a handheld device application. To advertise the capability of the handheld application.
  18. ADVERTISE CAPABILITY • Create an XML configuration file in the

    res/ xml/ directory of your project and name it wear.xml • Add a resource named android_wear_capabilities to wear.xml • Define the capabilities that the device provides
  19. RETRIEVE THE NODES WITH THE REQUIRED CAPABILITY Initially, we can

    detect the capable nodes by calling the CapabilityAPI.getCapability() method. Let’s understand how to manually retrieve the results of reachable nodes with the voice_transcription capability.
  20. RETRIEVE THE NODES WITH THE REQUIRED CAPABILITY Initially, we can

    detect the capable nodes by calling the CapabilityAPI.getCapability() method. Let’s understand how to manually retrieve the results of reachable nodes with the voice_transcription capability.
  21. private static final String VOICE_TRANSCRIPTION_CAPABILITY_NAME = "voice_transcription"; private GoogleApiClient mGoogleApiClient;

    private void setupVoiceTranscription() { CapabilityApi.GetCapabilityResult result = Wearable.CapabilityApi.getCapability( mGoogleApiClient, VOICE_TRANSCRIPTION_CAPABILITY_NAME, CapabilityApi.FILTER_REACHABLE).await(); updateTranscriptionCapability(result.getCapability()); }
  22. To detect the capable nodes as they connect to a

    wearable device, register a CapabilityAPI.capabilityListner() instance to googleAPIclient. 
 The following example shows how to register the listener and retrieve the results of reachable nodes with the voice_transcription capability
  23. private void setupVoiceTranscription() { … CapabilityApi.CapabilityListener capabilityListener = new CapabilityApi.CapabilityListener()

    { @Override public void onCapabilityChanged(CapabilityInfo capabilityInfo) { updateTranscriptionCapability(capabilityInfo); } }; Wearable.CapabilityApi.addCapabilityListener( mGoogleApiClient, capabilityListener, VOICE_TRANSCRIPTION_CAPABILITY_NAME); }
  24. On the off chance that you create a service that

    extends WearableListenerService to identify capability changes, you might need to override the onConnectedNodes() method to listen in to finer-grained connectivity details, for example, when a wearable device changes from Wi-Fi to a Bluetooth connection with the handset. For more data on the most proficient method to listen for important events, read Data Layer Events. Heads up
  25. Guiding user to install a phone Application Use the CapabilityApi

    to check whether your phone application is installed on the paired phone. For more data, see the Google samples. In the event that your phone application isn't installed on the phone, use PlayStoreAvailability.getPlayStoreAvailabilityOnPhone() to check what platform the wear is trying to reach.
  26. Guiding user to install a phone Application “If PlayStoreAvailability.PLAY_STORE_ON_PHONE_AVAILABLE is

    returned valid, it implies the phone is an Android phone with the Play store installed. Call RemoteIntent.startRemoteActivity() on the wear device to open the Play Store on the phone. Use the market URI for your telephone application (which might not be the same as your phone URI). For instance, use a market URI: market://details?id=com.example.android.wearable.wear.find devices. In the event that PlayStoreAvailability.PLAY_STORE_ON_PHONE_UNAVAILABLE is returned, it implies the phone is likely an iOS phone (with no Play Store accessible). Open the App Store on the iPhone by calling RemoteIntent.startRemoteActivity() on the wear device. You can indicate your application's iTunes URL, for instance, https://itunes.apple.com/us/application/yourappname. Likewise, observe opening a URL from a watch. On an iPhone, from Android Wear, you can’t programmatically determine whether your phone application is installed. As a best practice, give a mechanism to the user (for example, a button) to manually trigger the opening of the App Store.”
  27. In Wear OS, standalone applications are powerful feature of the

    wear ecosystem. How cool it will be using wear apps without your phone nearby! There are various scenarios in which Wear devices used to be phone dependent, for example, to receive new e-mail notifications, Wear needed to be connected to the phone for Internet services. Now, wear devices can independently connect to Wi-Fi and can sync all apps for new updates. The user can now complete more tasks with wear apps without a phone paired to it.
  28. Inside the application tag <application>, the </application> metadata element is

    placed with com.google.android.wearable.standalone with the value true or false. The new metadata element indicates whether the wear app is a standalone app and doesn't require the phone to be paired to operate. When the metadata element is set to true, the app a can also be available for wear devices working with iPhone. • Completely independent of the phone app. • Semi-independent (without phone pairing, wear app will have limited
 functionality) • Dependent on the phone app
  29. To make a Wear app completely independent or semi- independent,

    set the value of the metadata to true, as follows: <application> ... <meta-data android:name="com.google.android.wearable.standalone" android:value="true" /> ... </application>”
  30. Regardless of the possibility that the value is false, the

    watch application can be installed before the corresponding phone application is installed. In this way, if a watch application identifies that a companion phone does not have a necessary phone application, the watch application ought to incite the user to install the phone application. Heads up:
  31. WATCH FACE “Android Wear watch faces are services that are

    packaged inside a wearable app.” “The CanvasWatchFaceService class and registering your watch face The CanvasWatchFaceService.Engine and Callback methods
  32. WATCH FACE CONTROLS “Generally, analog watch face is the combination

    of three essential components, as follows: HOUR_STROKE MINUTE_STROKE SECOND_TICK_STROKE”
  33. COMMON ISSUES • Different form factors • Battery efficacy •

    UI accommodation • Too much of animations • Assets we use to build the Wear watch face • Watch face depending on hardware
  34. COMPLICATIONS API Complications are surely just the same old thing

    for watches. The internet says the first pocket watch with complications was revealed in the sixteenth century. Smart watches are the ideal place for all the components that we consider for complications.
  35. COMPLICATIONS API onComplicationActivated): This callback method is called when complication

    is activated. (onComplicationDeactivated): This callback method is called when complication is deactivated. (onComplicationUpdate): This callback is called when the complication has updated.
  36. DISTRIBUTING WEAR APPS • Visit https://play.google.com/apps/publish/: • Click on Create

    application and give your app a title. • Thereafter, you will be shown a form to fill in the description and other details, which include screenshots of the app and icons and promo graphics. • In store listing, fill in all the correct information about the app. • Now, upload the signed wear apk. • Answer the questionnaire for content ratings, get a rating, and apply the rating to your app. • In pricing and distribution, you need to have a merchant account to distribute your app in the pricing model. Now, wear note app is a free the Wear app and it lets you select free.
  37. DISTRIBUTING WEAR APPS • Select all the countries on the

    list and choose wear device apk: • Google will review the wear binary and approve to distribute it in the Wear Play store when it is ready.
  38. Q&A