Add translucent navigation and status bar to the MerchantsFragment and adjust the content size so that the map grows below them.

This commit is contained in:
Severiano Jaramillo 2019-01-29 22:33:32 -06:00
parent ba82d50cc6
commit 4d8ed68912
3 changed files with 45 additions and 11 deletions

View file

@ -38,9 +38,13 @@ class HomeFragment : Fragment() {
val toolbar: Toolbar? = activity?.findViewById(R.id.toolbar)
toolbar?.navigationIcon = resources.getDrawable(R.drawable.ic_bitsy_logo_2, null)
toolbar?.setBackgroundResource(if (!nightMode) R.color.colorPrimary else R.color.colorToolbarDark)
toolbar?.visibility = View.VISIBLE
// Sets the status bar background color to a primaryColorDark
// Makes sure the Navigation and Status bar are not translucent after returning from the MerchantsFragment
val window = activity?.window
window?.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
window?.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
// Sets the status bar background color to a primaryColorDark
window?.statusBarColor = ContextCompat.getColor(context!!,
if (!nightMode) R.color.colorPrimaryDark else R.color.colorStatusBarDark)

View file

@ -106,6 +106,12 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio
// Get a reference to the toolbar, to correctly place the merchants and tellers popup menu
mToolbar = activity?.findViewById(R.id.toolbar)
mToolbar?.visibility = View.GONE
// Sets the Navigation and Status bars translucent so that the map can be viewed through them
val window = activity?.window
window?.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
window?.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
return inflater.inflate(R.layout.fragment_merchants, container, false)
}
@ -326,6 +332,10 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
// Add padding to move the controls out of the toolbar/status bar and navigation bar.
// TODO might be necessary to convert dp to pixels
mMap.setPadding(0, 200, 0, 100)
applyMapTheme()
verifyLocationPermission()

View file

@ -1,15 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<fragment
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
map:uiZoomControls="true"
map:uiCompass="true"
map:cameraTargetLat="9.933058"
map:cameraTargetLng="-84.230800"
map:cameraZoom="3.5"
tools:context=".fragments.MerchantsFragment"/>
android:orientation="vertical"
tools:context=".activities.MainActivity">
<!-- TODO get the height of the status bar dynamically instead of hardcoding the 24dp-->
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginTop="24dp"
android:background="@color/semiTransparent"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.MaterialComponents" />
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
map:uiZoomControls="true"
map:uiCompass="true"
map:cameraTargetLat="9.933058"
map:cameraTargetLng="-84.230800"
map:cameraZoom="3.5"
tools:context=".fragments.MerchantsFragment"/>
</RelativeLayout>