Search icon CANCEL
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
€8.99 | ALL EBOOKS & VIDEOS
Save more on purchases! Buy 2 and save 10%, Buy 3 and save 15%, Buy 5 and save 20%
Android Wear Projects
Android Wear Projects

Android Wear Projects: Create smart Android Apps for Wearables

By Ashok Kumar S
€14.99 per month
Book Jul 2017 416 pages 1st Edition
eBook
€28.99 €8.99
Print
€37.99 €25.99
Subscription
€14.99 Monthly
eBook
€28.99 €8.99
Print
€37.99 €25.99
Subscription
€14.99 Monthly

What do you get with a Packt Subscription?

Free for first 7 days. $15.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Android Wear Projects

Chapter 1. Getting You Ready to Fly - Setting Up Your Development Environment

The culture of Wearing a utility that helps us to perform certain actions has always been part of a modern civilization. Wrist watches for human beings have become an augmented tool for checking the time and date. Wearing a watch lets you check the time with just a glance. Technology has taken this watch-wearing experience to the next level. The first modern Wearable watch was a combination of a calculator and a watch, introduced to the world in 1970. Over the decades, advancements in microprocessors and wireless technology have led to the introduction of a concept called ubiquitous computing. During this time, most leading electronics industry start-ups started to work on their ideas, which has made Wearable devices very popular.

Tech giant companies, such as Google, Apple, Samsung, and Sony, have joined the force of the Wearable devices era. They have introduced their competitive Wearable products, which are extremely successful in the Wearable device market. More interestingly, Google's Android Wear is powerful, follows the same Android smartphone development practices, and has a very good developer community compared to Apple Watch OS and Samsung's Tizen OS developer community.

Google announced Android Wear in March 2014. Since then, Android Wear as a smartwatch and Wearable software platform has evolved. Google's continuous advancement in designing and user experience have resulted in a new generation of the Android Wear operating system, which has the ability to handle biometric sensors like never before with more features in the platform; Google calls it Android Wear 2.0.

Android Wear 2.0 will cause a lot of excitement in app development with remarkably competitive features to develop. Android Wear 2.0 allows a developer to build and carve his idea specific to Android Wear; there is no need to pair a watch and mobile app. Google calls it a standalone application. Android Wear 2.0 introduces a new way to input within the Android watch: a new application programming interface called Complications, which allows watch faces to display vital information from biometrics and other sensors. New updated notifications support for Android Wear 2.0 will help users and developers to present notifications in a more comprehensive manner.

In this chapter, we will explore the following:

  • Android Wear design principles
  • Exploring essential UI components specific to Wear apps
  • Setting up a development environment for Wear apps development
  • Creating your first Android Wear application

Android Wear design principles


Designing a Wear is different than a mobile or tablet application. The Wear operating system is very lightweight and has a specific set of jobs to accomplish by sharing the right information with the Wearer.

General Wear principles are Timely, Glanceable, Easy to Tap, Time-Saving.

Timely

Giving the right information at the right time.

Glanceable

Keeping the Wear application user interface clean and uncluttered.

Easy to Tap

The actions users will click on should have the right spacing and size of the picture.

Time-Saving

Creating the best application flows that do tasks quickly.

For any Wear application, we need the proper building blocks to control the business logic of the application and other architectural implementation. The following are the scenarios for developing a Wear application to help us to carve the wear application better:

  • Defining layouts
  • Creating lists
  • Showing confirmations
  • Wear navigation and actions
  • Multifunction buttons

Defining layouts

Wearable can use the same layouts that we use in handheld Android device programming but with specific constraints for Wear applications. We should not do heavy processing actions similar to handheld Android devices in Wear applications and expect a good user experience.

An application designed for a round screen will not look great on square Wear devices. To resolve this, the Android Wear support library comes with the following two solutions:

  • BoxInsetLayout
  • Curved Layout

We can provide different resources to allow Android to detect the shape of the Android Wear at runtime.

Creating lists

Lists let the user 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.

We can add gestures and other magnificent functionalities:

Exploring UI components for Wear devices


In this subchapter, let's explore the used Wear-specific UI components. In Wear application programming, we can use all the components that we use in mobile app programming, but how we accommodate the visual appearance of components in the Wear device needs to be well thought of before using it.

WatchViewStub: WatchViewStub helps in rendering the views for different form factors of Wearable devices. If your application is being installed on a round watch device, WatchViewStub will load the specific layout configuration for round watches. If it is square, it will load the square layout configuration:

<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.WatchViewStub xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/watch_view_stub"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:rectLayout="@layout/rect_activity_main"
    app:roundLayout="@layout/round_activity_main"
    tools:context="com.ashokslsk.wearapp.MainActivity"
    tools:deviceIds="wear"></android.support.wearable.view.WatchViewStub>

WearableRecyclerView: WearableRecyclerView is the implementation of recyclerview specific to wearable devices. It provides a flexible view for datasets in the Wearable device viewport. We will explore WearbaleRecyclerView in detail in the coming chapters:

 <android.support.wearable.view.WearableRecyclerView
   android:id="@+id/recycler_launcher_view"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:scrollbars="vertical" /> 

Note

Note:WearableListView is deprecated; the Android community recommends using WearableRecyclerView.

CircledImageVIew: An Imageview surrounded by a circle. A very handy component for presenting the image in round form factor Wearable devices:

<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.CircledImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/circledimageview"
    app:circle_color="#2878ff"
    app:circle_radius="50dp"
    app:circle_radius_pressed="50dp"
    app:circle_border_width="5dip"
    app:circle_border_color="#26ce61"
    android:layout_marginTop="15dp"
    android:src="@drawable/skholinguaicon"
    android:layout_gravity="center_horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

BoxInsetLayout: This Layout directly to Framelayout and it has the ability to recognize the form factor of the Wearable device. Shape-aware FrameLayout can box its children in the center square of the screen:

<android.support.wearable.view.BoxInsetLayout    xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ranjan.androidwearuicomponents.BoxInsetLayoutDemo">

<TextView
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_box="all" />

</android.support.wearable.view.BoxInsetLayout>

After the Wear 2.0 release, a few components were deprecated for an immersive activity experience and Google strictly prohibits using them; we can still use all the components that we know in Android programming.

Showing confirmations

Compared to in handheld Android devices, in Wear applications, confirmations should occupy the whole screen or more than what handheld devices show as a dialogue box. This ensures users can see these confirmations at one glance. The Wearable UI library helps in displaying confirmation timers and animated timers in Android Wear.

DelayedConfirmationView

A DelayedConfirmationView is an confirmation view based on the timer:

<android.support.wearable.view.DelayedConfirmationView
android:id="@+id/delayed_confirm"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/cancel_circle"
app:circle_border_color="@color/lightblue"
app:circle_border_width="4dp"
app:circle_radius="16dp">
</android.support.wearable.view.DelayedConfirmationView>

Wear navigation and actions

In the new of Android Wear, the Material design library the following two interactive drawers:

  • Navigation drawer
  • Action drawer

Navigation drawer

Lets user switch between in the application. Developers can allow the drawer to be opened anywhere within the scrolling parent's content by setting the setShouldOnlyOpenWhenAtTop() method to false:

<android.support.wearable.view.drawer.WearableNavigationDrawer
android:id="@+id/top_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_red_light"
app:navigation_style="single_page"/>

Action drawer

The action drawer gives to easy and common actions in your application. By default, action drawer appears at the bottom of the screen and provides specific actions to users:

<android.support.wearable.view.drawer.WearableActionDrawer
android:id="@+id/bottom_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_dark"
app:show_overflow_in_peek="true"/>

Multifunction buttons

In addition to the power button, Android Wear supports another button called the multifunction button on the device. The Wearable library provides API for determining the multifunction buttons included by the manufacturer:

@Override
// Activity
publicboolean onKeyDown(int keyCode,KeyEventevent){
if(event.getRepeatCount()==0){
if(keyCode ==KeyEvent.KEYCODE_STEM_1){
// Do stuff
returntrue;
}elseif(keyCode ==KeyEvent.KEYCODE_STEM_2){
// Do stuff
returntrue;
}elseif(keyCode ==KeyEvent.KEYCODE_STEM_3){
// Do stuff
returntrue;
}
}
returnsuper.onKeyDown(keyCode,event);
}

Visit https://developer.android.com/training/wearables/ui/index.html for any sort of query that you might have on design guidelines for Wear device programming.

Setting up a development environment for Wear development


In this section, we set up a development environment for Wear development.

Prerequisites

  1. Your favorite operating system (Windows, macOS, or Linux)
  2. Determine whether you have the latest JRE installed on your operating system
  3. Install the latest version of JDK or Open JDK
  4. Install the latest version of Android Studio (at the time of writing this book, the latest version is 2.2.3 and any newer version should be fine)

Installing Android Studio

Visit https://developer.android.com/studio/index.html to download the latest version of Android Studio. Google highly recommends using Android Studio for all Android application development, since Android Studio has tight with and useful Android APIs:

After the Android Studio installation, it's now time to download the necessary SDK in the SDK Platforms tab in SDK Manager. Install one complete version of Android; for the scope of this book, we will install Android 7.1.1 API level 25:

After the successful installation of the SDK of Nougat 7.1.1 API level 25, under the SDK Tools tab, make sure you have the components, as shown in the following screenshot:

  • Android Support Library
  • Google Play services
  • Google Repository
  • Android Support Repository

Google releases updates on IDE and SDK Tools frequently; keep your development environment up-to-date.

Note

Note: if you plan to make your application available in China, then you must use the special release version 7.8.87 of the Google Play services client library to handle communication between a phone and watch: https://developer.android.com/training/wearables/apps/creating-app-china.html

Visit the following link to check the Release Notes on SDK Tools: https://developer.android.com/studio/releases/sdk-tools.html.

Updating your IDE from the stable channel is highly recommended. Updates for Android Studio are available on four different channels:

  • Canary channel
  • Dev channel
  • Beta channel
  • Stable channel

Canary channel: The Android Studio team works continuously to make Android Studio better. In this channel, every week there will be an update release, and it will include new functionality changes and improvements; you can check those changes in the release notes. But updates from this channel are not recommended for application production.

Dev Channel: On this channel, a happens after a complete round of internal testing from the Android Studio team.

Beta channel: On this channel, updates are based on stable Canary builds. Before publishing these builds to a stable channel, Google releases them in the beta channel to get developer feedback.

Stable Channel: Are the official stable releases of the Android Studio and will be available to download on Google's page http://developer.android.com/studio.

By default, Android Studio receives from a stable channel.

Creating your first Android Wear application


In this section, let's understand the steps required to create your first Wear project.

Note

Before you continue to create your application, ensure you have one complete version of Android installed with a Wear system image and you have the latest version of Android Studio.

The following picture is the initial interface of Android Studio. In this window, one can import legacy ADT Android projects, configure the Android SDK, and update Android Studio.

Android Studio welcome window with basic controls for getting started:

Creating your first Wear project

Click on the Start a new Android Studio project option in the Android Studio window. You will be prompted by another with project details.

The following screenshot shows the window that allows users to configure their project details, such as project name, Package name, and whether the project needs native C++ support:

You can name your project as you wish. After you have chosen your project name and your project local system location, you can press the Next button in the window, which brings up another window with a few queries, as shown in the following screenshot:

In this window, you can choose to write a standalone Wear application if you uncheck the Phone and Tablet option. In way, you will see only Wear application templates:

Now, Android Studio templates prompt only Android Wear activity templates with the following set of options:

  • Add No Activity
  • Always On Wear Activity
  • Blank Wear Activity
  • Display Notification
  • Google Maps Wear Activity
  • Watch Face

The activity template helps you to access the default boilerplate codes, which are already templatized and can be used directly in projects:

To create the first project, we will choose Blank Wear Activity and click on the Next button in the window. Android Studio will prompt another window for creating the name of the activity and layout file. In this template, the two form factors of Android Wearable devices, which are mostly round and square shapes, are with the boilerplate code stub:

When your project is ready to be created, click on the Finish button. After clicking on Finish, Android Studio will take a few moments to create the project for us.

Way to go! You have now created a working boilerplate code for the Android Wear standalone application without the phone companion application. When successfully created, you will see the following files and codes to your project by default:

If your SDK is not updated with API level 25, you might see the Wear option in the Android Studio project creating prompts with Android Wear support library 1.x; you can update this in the Wear module Gradle file with the following dependency:

compile 'com.google.android.support:wearable:2.0.0'

Creating a Wear emulator

The process of a Wear emulator is very to creating a phone emulator.

In the AVD manager, click on the Create Virtual Device... button:

Choose the required form factor emulator according to your application needs. Now, let's create the Android Wear square emulator:

After selecting the right emulator for your Wear, you will get another prompt to choose the Wear operating system. Let's the API Level 25Nougat emulator, as in the following screenshot:

The last prompt asks for the emulator name and other orientation configurations based on your needs:

Way to go! Now, we have successfully created a square form emulator for the project. Let's run the project that we have in the emulator:

Google recommends developing Wear apps in the actual hardware device to have the best user experience. However, working on emulators has the benefit of creating different screen form factors to check the application's rendering.

Working with actual Wear device
  1. Open the settings on the Wear device
  2. Go to About device
  3. Click on the build number seven times to enable developer mode
  4. Now enable ADB debugging on the watch

You can now connect the Wear device directly to your machine with the USB cable. You can debug your applications over Wi-Fi and Bluetooth with the following setups.

Debugging over Wi-Fi

Make sure your watch has the options enabled. Debugging over Wi-Fi is possible only when the Wear device and machine are connected to the same network.

  • In the Wear device developer option, tap on Debug over Wi-Fi
  • The watch will display its IP address (for example, 192.168.1.100). Keep a reference; we need this for the next step.
  • Connect the debugger to the device
  • Using the following command, we can attach the actual device to the ADB debugger:
adb connect 192.168.1.100
Enable Bluetooth debugging

We need to ensure debugging is in developer options, as follows:

adb forward tcp:4444 localabstract:/adb-hub
adb connect 127.0.0.1:4444

In your Android Wear, just allow ADB Debugging when it asks.

Now that we have a working setup of our development environment, let's understand the basic Android Wear-specific UI components.

Summary


In this chapter, we have looked at the initial setup for Wear application development. We have understood the necessary components to download, setting up a Wear emulator, connecting the Wear emulator to the ADB bridge, debugging over Wi-Fi, and essential user interface components specific to Wear development. In the next chapter, we will explore how to build a note-taking application which persists the data that users enter.

 

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Create real-time Android Wear apps from scratch and become a pro Android Wear Developer
  • Learn to create apps specially dedicated to the Android Wear platform
  • Design custom Wear UIs and create interactive Watch faces

Description

Android Wear Projects is your opportunity to step into the exciting new world of Android Wear app development. This book will help you to master the skills in Android Wear programming and give you a complete insight on wear app development. You will create five different Android Wear apps just like the most popular Android Wear apps. You will create a To-do list, a city maps app, a Wear messenger, Wear fitness tracker and Watch face. While you create these apps you will learn to create custom notifications, receive voice inputs in notifications, add pages to notifications and stack notifications. You will see how to create custom wear app layouts, the custom UIs specially designed for Wear. You will learn to handle and manage data and syncing data with other devices, create interactive Watch faces and also ensure the safety and security of your Wear apps by testing and securing your apps before you deploy them on the app store.

What you will learn

Design and build Wear apps. Learn how to use offline storage in Wear apps. Understand sensors and how to work with them Work with standalone applications of the wear 2.0 API. Create a map application for Android Wear devices Write a watch face and understand more about Wear 2.0 Work with firebase realtime database and firebase functions Create a chatting application that has wear companion app

Product Details

Country selected

Publication date : Jul 31, 2017
Length 416 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781787123229
Vendor :
Google
Category :

What do you get with a Packt Subscription?

Free for first 7 days. $15.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details


Publication date : Jul 31, 2017
Length 416 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781787123229
Vendor :
Google
Category :

Table of Contents

18 Chapters
Title Page Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Author Chevron down icon Chevron up icon
About the Reviewers Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Customer Feedback Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
1. Getting You Ready to Fly - Setting Up Your Development Environment Chevron down icon Chevron up icon
2. Let us Help Capture What is on Your Mind - WearRecyclerView and More Chevron down icon Chevron up icon
3. Let us Help Capture What is on Your Mind - Saving Data and Customizing the UI Chevron down icon Chevron up icon
4. Measure Your Wellness - Sensors Chevron down icon Chevron up icon
5. Measuring Your Wellness and Syncing Collected Sensor Data Chevron down icon Chevron up icon
6. Ways to Get Around Anywhere - WearMap and the GoogleAPIclient Chevron down icon Chevron up icon
7. Ways to Get Around Anywhere - UI controls and More Chevron down icon Chevron up icon
8. Let us Chat in a Smart Way - Messaging API and More Chevron down icon Chevron up icon
9. Let us Chat in a Smart Way - Notifications and More Chevron down icon Chevron up icon
10. Just a Face for Your Time - WatchFace and Services Chevron down icon Chevron up icon
11. More About Wear 2.0 Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Top Reviews
No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.