Add map to FrameLayout and add margins based on wearable window insets.
Change-Id: Ibc882dd56f975f52549e2c28fd2c43934e0f356e
@ -45,5 +45,5 @@ dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
compile 'com.google.android.support:wearable:1.1.0'
|
||||
compile 'com.google.android.gms:play-services:7.3.0'
|
||||
compile 'com.google.android.gms:play-services:7.5.0'
|
||||
}
|
||||
@ -26,6 +26,9 @@ import com.google.android.gms.maps.model.MarkerOptions;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.wearable.view.DismissOverlayView;
|
||||
import android.view.View;
|
||||
import android.view.WindowInsets;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
/**
|
||||
* Sample that shows how to set up a basic Google Map on Android Wear.
|
||||
@ -43,6 +46,7 @@ public class MainActivity extends FragmentActivity implements OnMapReadyCallback
|
||||
|
||||
/**
|
||||
* The map. It is initialized when the map has been fully loaded and is ready to be used.
|
||||
*
|
||||
* @see #onMapReady(com.google.android.gms.maps.GoogleMap)
|
||||
*/
|
||||
private GoogleMap mMap;
|
||||
@ -53,6 +57,33 @@ public class MainActivity extends FragmentActivity implements OnMapReadyCallback
|
||||
// Set the layout. It only contains a SupportMapFragment and a DismissOverlay.
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
// 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);
|
||||
final FrameLayout mapFrameLayout = (FrameLayout) findViewById(R.id.map_container);
|
||||
|
||||
// Set the system view insets on the containers when they become available.
|
||||
topFrameLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
|
||||
@Override
|
||||
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
|
||||
// Call through to super implementation and apply insets
|
||||
insets = topFrameLayout.onApplyWindowInsets(insets);
|
||||
|
||||
FrameLayout.LayoutParams params =
|
||||
(FrameLayout.LayoutParams) mapFrameLayout.getLayoutParams();
|
||||
|
||||
// Add Wearable insets to FrameLayout container holding map as margins
|
||||
params.setMargins(
|
||||
insets.getSystemWindowInsetLeft(),
|
||||
insets.getSystemWindowInsetTop(),
|
||||
insets.getSystemWindowInsetRight(),
|
||||
insets.getSystemWindowInsetBottom());
|
||||
mapFrameLayout.setLayoutParams(params);
|
||||
|
||||
return insets;
|
||||
}
|
||||
});
|
||||
|
||||
// Obtain the DismissOverlayView and display the intro help text.
|
||||
mDismissOverlay = (DismissOverlayView) findViewById(R.id.dismiss_overlay);
|
||||
mDismissOverlay.setIntroText(R.string.intro_text);
|
||||
@ -19,17 +19,26 @@
|
||||
|
||||
<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">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/map"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:name="com.google.android.gms.maps.SupportMapFragment" />
|
||||
<FrameLayout
|
||||
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.SupportMapFragment"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<android.support.wearable.view.DismissOverlayView
|
||||
android:id="@+id/dismiss_overlay"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"/>
|
||||
</FrameLayout>
|
||||
</FrameLayout>
|
||||
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
@ -14,4 +14,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
include ':app'
|
||||
include ':Wearable'
|
||||
|
||||