Wearable Reply - Android Library

feature

If you have followed any of our work in the past, you know that Jake and I are passionate about open-source work. Check out our GitHubs (klinker24 and klinker41) and it is pretty clear!

Everyone's background and experience is different, and like blogging, open-source work is the perfect way to give back to the Android community and share some of your unique experience. If we make a component in one of our apps that can be re-used, we open-source it! That is just the way we have always done things.

If we make a component in one of our apps that can be re-used, we open-source it!

When I started to make the Android Wear 2.0 app for Pulse, I saw an open-source opportunity again, in the form of text input.

Android Wear 2.0 + Pulse

With Android Wear 2.0, Google decided to allow users to input text via the keyboard. I think that is a great decision, considering how funny people look, when talking into their watches.


notification reply

Notification reply options for Android Wear 2.0.


With Pulse, while implementing replies to conversations, I realized that text input still wasn't that great for Android Wear. While Google now allowed the user to use a keyboard, implementing an EditText on a tiny watch screen, was a horrible UX. I decided that there needed to be an easy way to reply, using activity results, but found that Google did not provide one, other than the method for voice replies, which had been around since Android Wear 1.0:

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);  
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,  
        RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
startActivityForResult(intent, SPEECH_REQUEST_CODE);  

I wanted a similar API that allowed for voice reply, text input, and canned responses, similar to what they did for notifications in Wear 2.0, so I made it myself:

https://github.com/klinker24/wearable-reply

The library allows for quick and easy text input, whether that is from your voice, a keyboard, or canned responses. The missing API is now available!

The missing API is now available!

Using the library

To get started, add the dependency:

dependencies {  
    ...
    compile 'com.klinkerapps:wearable-reply:1.0.0'
}

After adding the dependency, usage is super simple. Start the reply activity with:

WearableReplyActivity.start(activity);  
WearableReplyActivity.start(activity, R.array.reply_options);  
WearableReplyActivity.start(activity, new String[] {"test 1", "test 2" });  

If you omit the String[] or the array resource, the WearableReplyActivity will display the default canned responses: "Yes", "No", "Maybe", "Ok", and "Thanks".

When the user has done the text input, the results will be delivered to your Activity#onActivityResult method, and can be pulled with:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    super.onActivityResult(requestCode, resultCode, data);

    String result = WearableReplyActivity.getResultText(data);
    if (result != null) {
        Toast.makeText(this, result, Toast.LENGTH_SHORT).show();
    }
}

And that is it.

If you are making an app for Android Wear 2.0, you now have an easy text input method! Don't worry about trying to shove an EditText on the tiny screen, or implementing this stuff yourself.

Before making the library, I did consider the possibility that Google had an implicit Intent sitting out there, that I could have plugged into, but there is no guarantee that that would always be around, or that it would work the same for everyone, so I decided to implement it myself instead.

Future Improvements

I would love to improve the layout of the library, to closer resemble Android Wear 2.0's notification reply layout. This will probably come with time, but for now, it is clean, easy to look at, and simple to understand.

I also opened up a few issues in the library that I would like to implement as well, including:

  • Drawing emojis, similar to the notification reply method
  • A countdown timer for voice replies, so the user can see what they spoke, and choose to cancel it.

Let me know if there is anything else you would like to see out of this library, or if you plan on using it in your Android Wear 2.0 app!