Courtesy: GitHub

Android XYZTouristAttractions Sample

This sample aims to be as close to a real world example of a mobile and Wear app combination as possible. It has a more refined design and also provides a practical example of how a mobile app would interact and communicate with its wear counterpart.

The app itself is modeled after a hypothetical tourist attractions app that notifies the user when they are in close proximity to notable points of interest.

The Wear component shows tourist attraction images and summary information, and provides quick actions for nearby tourist attractions in a GridViewPager UI component.

Introduction

Steps for trying out this sample:

  • Compile and install the mobile app onto your mobile device or emulator.
  • Compile and install the wearable app onto your Wear device or emulator. (Note: wearable apps are not automatically pushed from your mobile device unless you build a production release, see here for more info).
  • Start the mobile app and use the overflow menu options to test either a notification enhanced for Wear, or the full wearable application (unless you're physically in Sydney in which case the geofence should trigger automatically). Note that the first time you trigger either the notification or the wearable app it may take 20-30 seconds to show up as it needs to transfer the image assets to the wearable (in practice this delay won't be noticeable to users as they will only be notified once the data has been sent).

This sample aims to demonstrate a number of different Android APIs and concepts relating to Android Wear and location using Google Play Services:

The sample also focuses on providing a simple, yet clean design and UI for both mobile and wearable apps with an extra level of visual polish compared to a traditional code sample.

Some of the UI widgets and design patterns used in the mobile app include:

  • Use of Material theme including definition of primary and accent colors
  • AppCompat usage for Material theme backward compatibility
  • Metrics and keylines based on the Material guidelines
  • Window content and activity transitions based on the Material guidelines
  • Use of the RecyclerView widget
  • CoordinatorLayout23 and FloatingActionButton24 from the Design Support library25
  • Material animations such as activity and shared element transitions

The wearable app uses a number of techniques and UI widgets as well:

Pre-requisites

  • Android SDK 26
  • Android Build Tools v26.0.1
  • Android Support Repository

Screenshots

Screenshot

Getting Started

This sample uses the Gradle build system. To build this project, use the "gradlew build" command or use "Import Project" in Android Studio.

Support

If you've found an error in this sample, please file an issue: https://github.com/googlesamples/android-XYZTouristAttractions

Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.

License

Copyright 2017 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

compile 'com.google.android.gms:play-services-location:11.4.0'

compile 'com.google.maps.android:android-maps-utils:0.3.4'

compile 'com.github.bumptech.glide:glide:3.6.1'

compile 'com.android.support:appcompat-v7:25.3.1'

compile 'com.android.support:recyclerview-v7:25.3.1'

compile 'com.android.support:design:25.3.1'

compile 'com.google.android.gms:play-services-wearable:11.4.0'

compile 'com.android.support:support-v13:26.1.0'

compile project(':Shared')

compileSdkVersion 26

minSdkVersion 18

targetSdkVersion 26

versionCode 1

versionName "1.0"

compile 'com.android.support:support-v13:25.3.1'

compile 'com.google.android.gms:play-services-wearable:11.4.0'

compile 'com.google.android.gms:play-services-maps:11.4.0'

compile 'com.google.maps.android:android-maps-utils:0.3.4'

compileSdkVersion 26

minSdkVersion 18

targetSdkVersion 26

compile 'com.google.android.gms:play-services-maps:11.4.0'

compile 'com.google.android.gms:play-services-wearable:11.4.0'

compile 'com.android.support:support-v13:26.1.0'

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

compile project(':Shared')

compileSdkVersion 26

versionCode 1

versionName "1.0"

minSdkVersion 18

targetSdkVersion 25

package com.example.android.xyztouristattractions

uses-permission

  • android.permission.INTERNET
  • android.permission.ACCESS_FINE_LOCATION
  • android.permission.WAKE_LOCK
  • android.permission.READ_EXTERNAL_STORAGE
  • android.permission.WRITE_EXTERNAL_STORAGE

package com.example.android.xyztouristattractions.common

package com.example.android.xyztouristattractions

uses-permission

  • android.permission.READ_EXTERNAL_STORAGE
  • android.permission.WRITE_EXTERNAL_STORAGE

AttractionsActivity

ConfirmationActivity

AttractionsActivity

ConfirmationActivity

AttractionsActivity

The main Wear activity that displays nearby attractions in a {@link android.support.wearable.view.GridViewPager}. Each row shows one attraction and each column shows information or actions for that particular attraction.

A background task to load the attraction data via the Wear DataApi. This can take a second or two sometimes as several images need to be loaded.

ConfirmationActivity

ListenerService

A Wear listener service, used to receive inbound messages from the Wear device.

UtilityService

A utility IntentService, used for a variety of asynchronous background operations that do not necessarily need to be tied to a UI.

Add geofences using Play Services

Called when a geofence is triggered

Called when a location update is requested

Called when the location has been updated

Clears the local device notification

Clears remote device notifications using the Wearable message API

Show the notification. Either the regular notification with wearable features added to enhance, or trigger the full micro app on the wearable. * @param cityId The city to trigger the notification for @param microApp If the micro app should be triggered or just enhanced notifications

Transfer the required data over to the wearable @param attractions list of attraction data to transfer over

ListenerService

UtilityService

ListenerService

A Wear listener service, used to receive inbound messages from other devices.

UtilityService

A utility IntentService, used for a variety of asynchronous background operations that do not necessarily need to be tied to a UI.

Trigger a message that asks the master device to start an activity. * @param context the context @param path the path that will be sent via the wearable message API @param name the tourist attraction name @param city the tourist attraction city

Clear the local notifications

Trigger a message to ask other devices to clear their notifications

Sends the actual message to ask other devices that are capable of showing "details" to start the appropriate activity * @param path the path to pass to the wearable message API @param extraInfo extra info that varies based on the path being sent