Skip to content

Commit

Permalink
Merge branch 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
markmcd committed Sep 24, 2015
2 parents ab79c2a + f0ffb21 commit a9dde5b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 22 deletions.
4 changes: 2 additions & 2 deletions AndroidWearMap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ Android Wear Maps Sample

This sample uses the [Google Maps Android API v2](https://developers.google.com/maps/documentation/android/)
to display a map on Android Wear. It shows the basic setup required for a
gradle-based Android Studio project.
gradle-based Android Studio project that [supports ambient mode](https://developer.android.com/training/wearables/apps/always-on.html).

Pre-requisites
--------------

- Android SDK v21
- Android SDK v22
- Latest Android Build Tools
- Android Support Repository
- Android Wear emulator or device
Expand Down
11 changes: 8 additions & 3 deletions AndroidWearMap/Wearable/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ repositories {
jcenter()
}


dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.google.android.support:wearable:1.1.0'
compile 'com.google.android.gms:play-services:7.8.0'
// Required for DismissOverlayView to exit full screen wearable app.
compile 'com.google.android.support:wearable:1.2.0'

// Required to support ambient mode.
provided 'com.google.android.wearable:wearable:1.0.0'

// Include the Google Maps Android API from Google Play Services.
compile 'com.google.android.gms:play-services-maps:8.1.0'
}
16 changes: 4 additions & 12 deletions AndroidWearMap/Wearable/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@
<!-- Mark this app as an Android Wear app. -->
<uses-feature android:name="android.hardware.type.watch" />

<!-- Permissions and features required for the Android Maps API v2 -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<!-- Permission required for ambient mode to keep the application running. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application
android:allowBackup="true"
Expand All @@ -40,10 +34,8 @@
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key"/>

<!-- Meta data required for Google Play Services -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- Reference the wearable shared library required to support ambient mode. -->
<uses-library android:name="com.google.android.wearable" android:required="false" />

<activity
android:name=".MainActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import android.app.Activity;
import android.os.Bundle;
import android.support.wearable.activity.WearableActivity;
import android.support.wearable.view.DismissOverlayView;
import android.view.View;
import android.view.WindowInsets;
Expand All @@ -33,7 +34,7 @@
/**
* Sample that shows how to set up a basic Google Map on Android Wear.
*/
public class MainActivity extends Activity implements OnMapReadyCallback,
public class MainActivity extends WearableActivity implements OnMapReadyCallback,
GoogleMap.OnMapLongClickListener {

private static final LatLng SYDNEY = new LatLng(-33.85704, 151.21522);
Expand All @@ -51,12 +52,19 @@ public class MainActivity extends Activity implements OnMapReadyCallback,
*/
private GoogleMap mMap;

private MapFragment mMapFragment;

public void onCreate(Bundle savedState) {
super.onCreate(savedState);

// Set the layout. It only contains a SupportMapFragment and a DismissOverlay.
setContentView(R.layout.activity_main);

// Enable ambient support, so the map remains visible in simplified, low-color display
// when the user is no longer actively using the app but the app is still visible on the
// watch face.
setAmbientEnabled();

// Retrieve the containers for the root of the layout and the map. Margins will need to be
// set on them to account for the system window insets.
final FrameLayout topFrameLayout = (FrameLayout) findViewById(R.id.root_container);
Expand Down Expand Up @@ -90,10 +98,31 @@ public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
mDismissOverlay.showIntroIfNecessary();

// Obtain the MapFragment and set the async listener to be notified when the map is ready.
MapFragment mapFragment =
(MapFragment) getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
mMapFragment = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
mMapFragment.getMapAsync(this);

}

/**
* Starts ambient mode on the map.
* The API swaps to a non-interactive and low-color rendering of the map when the user is no
* longer actively using the app.
*/
@Override
public void onEnterAmbient(Bundle ambientDetails) {
super.onEnterAmbient(ambientDetails);
mMapFragment.onEnterAmbient(ambientDetails);
}

/**
* Exits ambient mode on the map.
* The API swaps to the normal rendering of the map when the user starts actively using the app.
*/
@Override
public void onExitAmbient() {
super.onExitAmbient();
mMapFragment.onExitAmbient();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion AndroidWearMap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.android.tools.build:gradle:1.3.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit a9dde5b

Please sign in to comment.