-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70377be
commit d05ddc9
Showing
14 changed files
with
340 additions
and
0 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
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
107 changes: 107 additions & 0 deletions
107
...maps/src/main/java/com/mapbox/navigation/ui/maps/camera/view/MapboxRouteOverviewButton.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,107 @@ | ||
package com.mapbox.navigation.ui.maps.camera.view | ||
|
||
import android.content.Context | ||
import android.content.res.TypedArray | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import androidx.annotation.StyleRes | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import androidx.core.content.ContextCompat | ||
import com.mapbox.navigation.ui.maps.R | ||
import com.mapbox.navigation.ui.maps.databinding.MapboxRouteOverviewLayoutBinding | ||
import com.mapbox.navigation.ui.utils.internal.extensions.afterMeasured | ||
import com.mapbox.navigation.ui.utils.internal.extensions.extend | ||
import com.mapbox.navigation.ui.utils.internal.extensions.shrink | ||
import com.mapbox.navigation.ui.utils.internal.extensions.slideWidth | ||
|
||
/** | ||
* Default view to allow user to switch to route overview mode. | ||
* @property textWidth Int | ||
* @property binding MapboxRouteOverviewLayoutBinding | ||
* @constructor | ||
*/ | ||
class MapboxRouteOverviewButton @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyleAttr: Int = 0 | ||
) : ConstraintLayout(context, attrs, defStyleAttr) { | ||
|
||
private var textWidth = 0 | ||
private val binding = MapboxRouteOverviewLayoutBinding.inflate( | ||
LayoutInflater.from(context), | ||
this | ||
) | ||
|
||
init { | ||
initAttributes(attrs) | ||
} | ||
|
||
override fun onFinishInflate() { | ||
super.onFinishInflate() | ||
binding.routeOverviewText.afterMeasured { | ||
textWidth = width | ||
} | ||
} | ||
|
||
/** | ||
* Allows you to change the style of [MapboxRouteOverviewButton]. | ||
* @param style Int | ||
*/ | ||
fun updateStyle(@StyleRes style: Int) { | ||
val typedArray = context.obtainStyledAttributes( | ||
style, | ||
R.styleable.MapboxRouteOverviewButton | ||
) | ||
applyAttributes(typedArray) | ||
typedArray.recycle() | ||
} | ||
|
||
/** | ||
* Invoke the function to show optional text associated with the view. | ||
* @param duration for the view to be in the extended mode before it starts to shrink. | ||
*/ | ||
fun showTextAndExtend(duration: Long) { | ||
val animator = getAnimator(textWidth, EXTEND_TO_WIDTH) | ||
binding.routeOverviewText.extend(animator) { | ||
binding.routeOverviewText.text = "Overview" | ||
postDelayed( | ||
{ | ||
val endAnimator = getAnimator(EXTEND_TO_WIDTH, textWidth) | ||
binding.routeOverviewText.shrink(endAnimator) { | ||
binding.routeOverviewText.text = "" | ||
} | ||
}, | ||
duration | ||
) | ||
} | ||
} | ||
|
||
private fun initAttributes(attrs: AttributeSet?) { | ||
val typedArray = context.obtainStyledAttributes( | ||
attrs, | ||
R.styleable.MapboxRouteOverviewButton | ||
) | ||
applyAttributes(typedArray) | ||
typedArray.recycle() | ||
} | ||
|
||
private fun applyAttributes(typedArray: TypedArray) { | ||
ContextCompat.getDrawable( | ||
context, | ||
typedArray.getResourceId( | ||
R.styleable.MapboxRouteOverviewButton_overviewButtonDrawable, | ||
R.drawable.mapbox_ic_route_overview | ||
) | ||
).also { | ||
binding.routeOverviewIcon.setImageDrawable(it) | ||
} | ||
} | ||
|
||
private fun getAnimator(from: Int, to: Int) = | ||
binding.routeOverviewText.slideWidth(from, to, SLIDE_DURATION) | ||
|
||
private companion object { | ||
const val SLIDE_DURATION = 300L | ||
const val EXTEND_TO_WIDTH = 450 | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
libnavui-maps/src/main/res/drawable/mapbox_ic_route_overview.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,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="@color/mapbox_route_overview_drawable_color" | ||
android:pathData="M14,4l2.29,2.29 -2.88,2.88 1.42,1.42 2.88,-2.88L20,10L20,4zM10,4L4,4v6l2.29,-2.29 4.71,4.7L11,20h2v-8.41l-5.29,-5.3z"/> | ||
</vector> |
39 changes: 39 additions & 0 deletions
39
libnavui-maps/src/main/res/layout/mapbox_route_overview_layout.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,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<merge xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout"> | ||
|
||
<androidx.appcompat.widget.AppCompatTextView | ||
android:id="@+id/routeOverviewText" | ||
android:layout_height="@dimen/mapbox_dimen_56dp" | ||
android:layout_width="@dimen/mapbox_dimen_56dp" | ||
android:paddingStart="@dimen/mapbox_dimen_20dp" | ||
android:paddingEnd="@dimen/mapbox_dimen_4dp" | ||
android:elevation="0dp" | ||
android:textSize="@dimen/mapbox_dimen_text_14sp" | ||
android:textAllCaps="true" | ||
android:gravity="start|center_vertical" | ||
app:layout_constraintEnd_toEndOf="@id/routeOverviewIcon" | ||
app:layout_constraintTop_toTopOf="@id/routeOverviewIcon" | ||
app:layout_constraintBottom_toBottomOf="@id/routeOverviewIcon" | ||
android:background="@drawable/mapbox_bg_circle" | ||
android:textColor="@color/colorOnSurface" /> | ||
|
||
<com.google.android.material.floatingactionbutton.FloatingActionButton | ||
android:id="@+id/routeOverviewIcon" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:elevation="0dp" | ||
app:fabSize="normal" | ||
android:layout_marginTop="@dimen/mapbox_dimen_4dp" | ||
android:layout_marginEnd="@dimen/mapbox_dimen_4dp" | ||
android:tint="@color/colorOnSurface" | ||
app:rippleColor="@android:color/transparent" | ||
app:srcCompat="@drawable/mapbox_ic_route_overview" | ||
app:backgroundTint="@color/colorSurface" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" /> | ||
</merge> |
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<declare-styleable name="MapboxRouteOverviewButton"> | ||
<!-- Defines the drawable representing route overview. --> | ||
<attr name="overviewButtonDrawable" format="reference" /> | ||
</declare-styleable> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="mapbox_route_overview_drawable_color">@color/colorOnSurface</color> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<style name="MapboxStyleRouteOverview"> | ||
<item name="overviewButtonDrawable">@drawable/mapbox_ic_route_overview</item> | ||
</style> | ||
</resources> |
5 changes: 5 additions & 0 deletions
5
libnavui-resources/src/main/res/drawable/mapbox_bg_circle.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"> | ||
<solid android:color="@color/colorSurface" /> | ||
<corners android:radius="@dimen/mapbox_dimen_56dp" /> | ||
</shape> |
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
Oops, something went wrong.