Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Android Wear Projects
Android Wear Projects

Android Wear Projects: Create smart Android Apps for Wearables

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

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Jul 31, 2017
Length 416 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781787123229
Vendor :
Google
Category :
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

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

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
Getting You Ready to Fly - Setting Up Your Development Environment Chevron down icon Chevron up icon
Let us Help Capture What is on Your Mind - WearRecyclerView and More Chevron down icon Chevron up icon
Let us Help Capture What is on Your Mind - Saving Data and Customizing the UI Chevron down icon Chevron up icon
Measure Your Wellness - Sensors Chevron down icon Chevron up icon
Measuring Your Wellness and Syncing Collected Sensor Data Chevron down icon Chevron up icon
Ways to Get Around Anywhere - WearMap and the GoogleAPIclient Chevron down icon Chevron up icon
Ways to Get Around Anywhere - UI controls and More Chevron down icon Chevron up icon
Let us Chat in a Smart Way - Messaging API and More Chevron down icon Chevron up icon
Let us Chat in a Smart Way - Notifications and More Chevron down icon Chevron up icon
Just a Face for Your Time - WatchFace and Services Chevron down icon Chevron up icon
More About Wear 2.0 Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
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%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.