Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - add bottom sheet into test app to catch regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jul 25, 2017
1 parent a282280 commit b303216
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,16 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>

<activity android:name=".activity.maplayout.BottomSheetActivity"
android:description="@string/description_bottom_sheet"
android:label="@string/activity_bottom_sheet">
<meta-data
android:name="@string/category"
android:value="@string/category_maplayout"/>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>

<!-- For Instrumentation tests -->
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected void onCreate(Bundle savedInstanceState) {
.zoom(11)
.build());

mapFragment = SupportMapFragment.newInstance();
mapFragment = SupportMapFragment.newInstance(options);

transaction.add(R.id.fragment_container, mapFragment, "com.mapbox.map");
transaction.commit();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.mapbox.mapboxsdk.testapp.activity.maplayout;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.mapbox.mapboxsdk.maps.SupportMapFragment;
import com.mapbox.mapboxsdk.testapp.R;

public class BottomSheetActivity extends AppCompatActivity {

private final static String TAG_MAIN_FRAGMENT = "com.mapbox.mapboxsdk.fragment.tag.main";
private final static String TAG_BOTTOM_FRAGMENT = "com.mapbox.mapboxsdk.fragment.tag.bottom";

private BottomSheetBehavior bottomSheetBehavior;
private boolean bottomSheetFragmentAdded;
private boolean mainFragmentAdded;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bottom_sheet);

bottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.bottom_sheet));
bottomSheetBehavior.setPeekHeight((int) (64 * getResources().getDisplayMetrics().density));
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

findViewById(R.id.fabFragment).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleMainMapFragment();
}
});

findViewById(R.id.fabBottomSheet).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleBottomSheetMapFragment();
}
});
}

private void toggleMainMapFragment() {
if (!mainFragmentAdded) {
addMainMapFragment();
} else {
removeMainMapFragment();
}
mainFragmentAdded = !mainFragmentAdded;
}

private void toggleBottomSheetMapFragment() {
if (!bottomSheetFragmentAdded) {
addBottomSheetMapFragment();
} else {
removeBottomSheetFragment();
}
bottomSheetFragmentAdded = !bottomSheetFragmentAdded;
}

private void addMainMapFragment() {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
Fragment fragment = getSupportFragmentManager().findFragmentByTag(TAG_MAIN_FRAGMENT);
if (fragment == null) {
fragmentTransaction.add(R.id.fragment_container, SupportMapFragment.newInstance(), TAG_MAIN_FRAGMENT);
} else {
fragmentTransaction.show(fragment);
}
fragmentTransaction.commit();
}

private void removeMainMapFragment() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(TAG_MAIN_FRAGMENT);
if (fragment != null) {
getSupportFragmentManager().beginTransaction().remove(fragment).commit();
}
}

private void addBottomSheetMapFragment() {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.fragment_container_bottom, SupportMapFragment.newInstance(), TAG_BOTTOM_FRAGMENT);
fragmentTransaction.commit();
}

private void removeBottomSheetFragment() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(TAG_BOTTOM_FRAGMENT);
if (fragment != null) {
getSupportFragmentManager().beginTransaction().remove(fragment).commit();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:padding="24dp"
android:text="Press Floating Action Button to toggle MapView"
android:textSize="22sp"/>

<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fabFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginBottom="82dp"
android:layout_marginRight="@dimen/fab_margin"
android:src="@drawable/ic_refresh"
app:backgroundTint="@color/accent"
app:layout_anchorGravity="top"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fabBottomSheet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_layers"
app:backgroundTint="@color/primary"/>

<android.support.v4.widget.NestedScrollView
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="@android:color/holo_orange_light"
android:clipToPadding="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_gravity="center"
android:gravity="center"
android:text="^"
android:textSize="22sp"/>

<FrameLayout
android:id="@+id/fragment_container_bottom"
android:layout_width="match_parent"
android:layout_height="186dp"/>

</LinearLayout>

</android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<string name="activity_fill_extrusion_layer">Fill extrusions</string>
<string name="activity_building_fill_extrusion_layer">Building layer</string>
<string name="activity_animated_image_source">Animated Image Source</string>
<string name="activity_bottom_sheet">Bottom sheet</string>

<!--Description-->
<string name="description_user_location_tracking">Tracks the location of the user</string>
Expand Down Expand Up @@ -123,6 +124,7 @@
<string name="description_fill_extrusion_layer">Shows how to add 3D extruded shapes</string>
<string name="description_building_fill_extrusion_layer">Shows how to show 3D extruded buildings</string>
<string name="description_animated_image_source">Shows how to animate georeferenced images</string>
<string name="description_bottom_sheet">Show 2 MapView on screen with a bottom sheet</string>

<!--Categories-->
<string name="category">category</string>
Expand Down

0 comments on commit b303216

Please sign in to comment.