mirror of
https://github.com/googlemaps/android-samples.git
synced 2025-12-08 18:02:20 +00:00
Add Ambient mode support to AndroidWearMap sample.
Change-Id: I7bfdfdff6855234d81a1518ce5c10901d16cfa85
This commit is contained in:
parent
e602f8f67f
commit
f0ffb21ef5
@ -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
|
||||
|
||||
@ -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'
|
||||
}
|
||||
|
||||
@ -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"
|
||||
@ -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"
|
||||
|
||||
@ -23,8 +23,8 @@ import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
|
||||
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;
|
||||
@ -33,7 +33,7 @@ import android.widget.FrameLayout;
|
||||
/**
|
||||
* 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);
|
||||
@ -51,12 +51,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);
|
||||
@ -90,12 +97,33 @@ public class MainActivity extends Activity implements OnMapReadyCallback,
|
||||
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
|
||||
public void onMapReady(GoogleMap googleMap) {
|
||||
// Map is ready to be used.
|
||||
|
||||
@ -17,28 +17,28 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:map="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/root_container"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent">
|
||||
<FrameLayout android:id="@+id/root_container"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:map="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/map_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:id="@+id/map_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/map"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:name="com.google.android.gms.maps.MapFragment"/>
|
||||
android:id="@+id/map"
|
||||
android:name="com.google.android.gms.maps.MapFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
map:ambientEnabled="true" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<android.support.wearable.view.DismissOverlayView
|
||||
android:id="@+id/dismiss_overlay"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"/>
|
||||
android:id="@+id/dismiss_overlay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</FrameLayout>
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user