Add map to FrameLayout and add margins based on wearable window insets.

Change-Id: Ibc882dd56f975f52549e2c28fd2c43934e0f356e
This commit is contained in:
Jan-Felix Schmakeit 2015-05-27 13:23:17 +10:00
parent 0b1d056a56
commit eae63f9561
14 changed files with 48 additions and 8 deletions

View File

@ -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'
}

View File

@ -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);

View File

@ -19,15 +19,24 @@
<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/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"

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -14,4 +14,4 @@
* limitations under the License.
*/
include ':app'
include ':Wearable'