-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example to toggle info panel styles at runtime
- Loading branch information
1 parent
95b97f0
commit 3c36847
Showing
10 changed files
with
152 additions
and
1 deletion.
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
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
76 changes: 76 additions & 0 deletions
76
...java/com/mapbox/navigation/examples/preview/dropinui/CustomInfoPanelAttributesActivity.kt
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 @@ | ||
package com.mapbox.navigation.examples.preview.dropinui | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI | ||
import com.mapbox.navigation.dropin.ViewStyleCustomization | ||
import com.mapbox.navigation.dropin.ViewStyleCustomization.Companion.defaultInfoPanelBackground | ||
import com.mapbox.navigation.dropin.ViewStyleCustomization.Companion.defaultInfoPanelMarginEnd | ||
import com.mapbox.navigation.dropin.ViewStyleCustomization.Companion.defaultInfoPanelMarginStart | ||
import com.mapbox.navigation.dropin.ViewStyleCustomization.Companion.defaultInfoPanelPeekHeight | ||
import com.mapbox.navigation.examples.preview.R | ||
import com.mapbox.navigation.examples.preview.databinding.MapboxActivityCustomizeInfopanelOptionsBinding | ||
|
||
/** | ||
* The example demonstrates how to use [ViewStyleCustomization] to customize the peek height, | ||
* margins and background for the default info panel supplied by Drop-In UI. | ||
* | ||
* Before running the example make sure you have put your access_token in the correct place | ||
* inside [app-preview/src/main/res/values/mapbox_access_token.xml]. If not present then add | ||
* this file at the location mentioned above and add the following content to it | ||
* | ||
* <?xml version="1.0" encoding="utf-8"?> | ||
* <resources xmlns:tools="http://schemas.android.com/tools"> | ||
* <string name="mapbox_access_token"><PUT_YOUR_ACCESS_TOKEN_HERE></string> | ||
* </resources> | ||
* | ||
* The example uses replay location engine to facilitate navigation without physically moving. | ||
* | ||
* How to use the example: | ||
* - Start the example | ||
* - Grant the location permissions if not already granted | ||
* - Press on the floating button in the bottom right to apply custom styles | ||
*/ | ||
@OptIn(ExperimentalPreviewMapboxNavigationAPI::class) | ||
class CustomInfoPanelAttributesActivity : AppCompatActivity() { | ||
|
||
private lateinit var binding: MapboxActivityCustomizeInfopanelOptionsBinding | ||
private var toggleInfoPanelStyles = false | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = MapboxActivityCustomizeInfopanelOptionsBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
binding.navigationView.api.enableReplaySession() | ||
|
||
binding.toggleInfoPanelStyles.setOnClickListener { | ||
customizeInfoPanelStyles(toggleInfoPanelStyles) | ||
toggleInfoPanelStyles = !toggleInfoPanelStyles | ||
} | ||
} | ||
|
||
private fun customizeInfoPanelStyles(enabled: Boolean) { | ||
binding.navigationView.customizeViewStyles { | ||
if (enabled) { | ||
infoPanelBackground = defaultInfoPanelBackground() | ||
infoPanelPeekHeight = defaultInfoPanelPeekHeight( | ||
this@CustomInfoPanelAttributesActivity | ||
) | ||
infoPanelMarginEnd = defaultInfoPanelMarginEnd() | ||
infoPanelMarginStart = defaultInfoPanelMarginStart() | ||
} else { | ||
infoPanelBackground = R.drawable.mapbox_bg_custom_info_panel | ||
infoPanelPeekHeight = this@CustomInfoPanelAttributesActivity | ||
.resources | ||
.getDimensionPixelSize(R.dimen.mapbox_custom_infopanel_peekheight) | ||
infoPanelMarginEnd = this@CustomInfoPanelAttributesActivity | ||
.resources | ||
.getDimensionPixelSize(R.dimen.mapbox_custom_infopanel_marginEnd) | ||
infoPanelMarginStart = this@CustomInfoPanelAttributesActivity | ||
.resources | ||
.getDimensionPixelSize(R.dimen.mapbox_custom_infopanel_marginStart) | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
.../mapbox/navigation/examples/preview/dropinui/res/drawable/mapbox_bg_custom_info_panel.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,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> | ||
<solid android:color="@color/onPrimary" /> | ||
<corners android:radius="5dp" /> | ||
</shape> |
Binary file added
BIN
+28 KB
.../examples/preview/dropinui/res/drawable/mapbox_screenshot_custom_info_panel.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.2 KB
...les/preview/dropinui/res/drawable/mapbox_screenshot_custom_info_panel_style.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions
25
...tion/examples/preview/dropinui/res/layout/mapbox_activity_customize_infopanel_options.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,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<com.mapbox.navigation.dropin.NavigationView | ||
android:id="@+id/navigationView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:accessToken="@string/mapbox_access_token" /> | ||
|
||
<com.google.android.material.floatingactionbutton.FloatingActionButton | ||
android:id="@+id/toggleInfoPanelStyles" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginEnd="16dp" | ||
android:layout_marginBottom="120dp" | ||
android:src="@drawable/mapbox_ic_customize" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
tools:ignore="ContentDescription" | ||
/> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
6 changes: 6 additions & 0 deletions
6
...eview/src/main/java/com/mapbox/navigation/examples/preview/dropinui/res/values/dimens.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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<dimen name="mapbox_custom_infopanel_marginEnd">10dp</dimen> | ||
<dimen name="mapbox_custom_infopanel_marginStart">10dp</dimen> | ||
<dimen name="mapbox_custom_infopanel_peekheight">90dp</dimen> | ||
</resources> |
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