This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] - add bottom sheet into test app to catch regressions
- Loading branch information
Showing
5 changed files
with
184 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...pp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/BottomSheetActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_bottom_sheet.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters