Skip to content

Commit

Permalink
add route overview
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek1508 committed Mar 17, 2021
1 parent 70377be commit b965b46
Show file tree
Hide file tree
Showing 15 changed files with 389 additions and 0 deletions.
35 changes: 35 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,12 @@ License: [The Apache Software License, Version 2.0](http://www.apache.org/licens

===========================================================================

Mapbox Navigation uses portions of the Android Support Library Coordinator Layout (The Support Library is a static library that you can add to your Android application in order to use APIs that are either not available for older platform versions or utility APIs that aren't a part of the framework APIs. Compatible on devices running API 14 or later.).
URL: [https://developer.android.com/jetpack/androidx](https://developer.android.com/jetpack/androidx)
License: [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)

===========================================================================

Mapbox Navigation uses portions of the Android Support Library core utils (The Support Library is a static library that you can add to your Android application in order to use APIs that are either not available for older platform versions or utility APIs that aren't a part of the framework APIs. Compatible on devices running API 14 or later.).
URL: [http://developer.android.com/tools/extras/support-library.html](http://developer.android.com/tools/extras/support-library.html)
License: [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)
Expand Down Expand Up @@ -1013,6 +1019,12 @@ License: [The Apache Software License, Version 2.0](http://www.apache.org/licens

===========================================================================

Mapbox Navigation uses portions of the Android Support RecyclerView v7.
URL: [https://developer.android.com/jetpack/androidx](https://developer.android.com/jetpack/androidx)
License: [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)

===========================================================================

Mapbox Navigation uses portions of the Android Support VectorDrawable.
URL: [https://developer.android.com/jetpack/androidx](https://developer.android.com/jetpack/androidx)
License: [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)
Expand All @@ -1025,6 +1037,18 @@ License: [The Apache Software License, Version 2.0](http://www.apache.org/licens

===========================================================================

Mapbox Navigation uses portions of the Android Transition Support Library.
URL: [https://developer.android.com/jetpack/androidx](https://developer.android.com/jetpack/androidx)
License: [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)

===========================================================================

Mapbox Navigation uses portions of the AndroidX Widget ViewPager2.
URL: [https://developer.android.com/jetpack/androidx](https://developer.android.com/jetpack/androidx)
License: [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)

===========================================================================

Mapbox Navigation uses portions of the Core Kotlin Extensions (Kotlin extensions for 'core' artifact).
URL: [https://developer.android.com/jetpack/androidx](https://developer.android.com/jetpack/androidx)
License: [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)
Expand Down Expand Up @@ -1162,6 +1186,12 @@ License: [BSD](https://opensource.org/licenses/BSD-2-Clause)

===========================================================================

Mapbox Navigation uses portions of the Material Components for Android (Material Components for Android is a static library that you can add to your Android application in order to use APIs that provide implementations of the Material Design specification. Compatible on devices running API 14 or later.).
URL: [http://developer.android.com/tools/extras/support-library.html](http://developer.android.com/tools/extras/support-library.html)
License: [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)

===========================================================================

Mapbox Navigation uses portions of the OkHttp.
License: [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)

Expand Down Expand Up @@ -1256,6 +1286,11 @@ License: [The Apache Software License, Version 2.0](http://www.apache.org/licens

===========================================================================

Mapbox Navigation uses portions of the viewbinding.
License: [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)

===========================================================================



#### Navigation UI Util SDK module
Expand Down
14 changes: 14 additions & 0 deletions libnavui-maps/api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,20 @@ package com.mapbox.navigation.ui.maps.camera.utils {

}

package com.mapbox.navigation.ui.maps.camera.view {

public final class MapboxRouteOverviewButton extends androidx.constraintlayout.widget.ConstraintLayout {
ctor public MapboxRouteOverviewButton(android.content.Context context);
ctor public MapboxRouteOverviewButton(android.content.Context context, android.util.AttributeSet? attrs);
ctor public MapboxRouteOverviewButton(android.content.Context context, android.util.AttributeSet? attrs, int defStyleAttr);
method public void showTextAndExtend(long duration);
method public void updateStyle(@StyleRes int style);
field public static final int EXTEND_TO_WIDTH = 175; // 0xaf
field public static final long SLIDE_DURATION = 300L; // 0x12cL
}

}

package com.mapbox.navigation.ui.maps.internal.route.line {

public final class MapboxRouteLineUtils {
Expand Down
6 changes: 6 additions & 0 deletions libnavui-maps/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ android {
consumerProguardFiles 'proguard-rules.pro', "${rootDir}/proguard/proguard-project.pro"
}

buildFeatures {
viewBinding true
}

testOptions {
unitTests.returnDefaultValues = true
unitTests.includeAndroidResources = true
Expand All @@ -35,13 +39,15 @@ android {

dependencies {
api project(":libnavui-base")
api project(":libnavui-resources")

api dependenciesList.mapboxMapSdk
api dependenciesList.mapboxSdkTurf

implementation dependenciesList.androidXAppCompat
implementation dependenciesList.androidXCardView
implementation dependenciesList.androidXConstraintLayout
implementation dependenciesList.materialDesign
implementation dependenciesList.kotlinStdLib

implementation dependenciesList.timber
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
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.
*/
class MapboxRouteOverviewButton : ConstraintLayout {

private var textWidth = 0
private var isAnimationRunning = false
private val binding = MapboxRouteOverviewLayoutBinding.inflate(
LayoutInflater.from(context),
this
)

/**
*
* @param context Context
* @constructor
*/
constructor(context: Context) : super(context)

/**
*
* @param context Context
* @param attrs AttributeSet?
* @constructor
*/
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
initAttributes(attrs)
}

/**
*
* @param context Context
* @param attrs AttributeSet?
* @param defStyleAttr Int
* @constructor
*/
constructor(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int
) : super(context, attrs, defStyleAttr) {
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) {
if (!isAnimationRunning) {
isAnimationRunning = true
val extendToWidth = EXTEND_TO_WIDTH * context.resources.displayMetrics.density
val animator = getAnimator(textWidth, extendToWidth.toInt())
binding.routeOverviewText.extend(animator) {
binding.routeOverviewText.text = context.getString(R.string.mapbox_route_overview)
postDelayed(
{
val endAnimator = getAnimator(extendToWidth.toInt(), textWidth)
binding.routeOverviewText.shrink(endAnimator) {
binding.routeOverviewText.text = ""
isAnimationRunning = false
}
},
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 = 175
}
}
19 changes: 19 additions & 0 deletions libnavui-maps/src/main/res/drawable/mapbox_ic_route_overview.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="14dp"
android:viewportWidth="16"
android:viewportHeight="14">

<group>
<group>
<group>
<clip-path
android:pathData="M14,4 C13.263,4,12.625,3.595,12.278,3 L3.5,3 C2.673,3,2,3.673,2,4.5 C2,5.327,2.673,6,3.5,6 L12.5,6 C14.43,6,16,7.57,16,9.5 C16,11.43,14.43,13,12.5,13 L3.722,13 C3.375,13.595,2.737,14,2,14 C0.897,14,0,13.103,0,12 C0,10.897,0.897,10,2,10 C2.737,10,3.375,10.405,3.722,11 L12.5,11 C13.327,11,14,10.327,14,9.5 C14,8.673,13.327,8,12.5,8 L3.5,8 C1.57,8,0,6.43,0,4.5 C0,2.57,1.57,1,3.5,1 L12.278,1 C12.625,0.405,13.263,0,14,0 C15.103,0,16,0.897,16,2 C16,3.103,15.103,4,14,4 Z" />
<path
android:fillColor="@color/mapbox_route_overview_drawable_color"
android:pathData="M-5,-5 L21,-5 L21,19 L-5,19 Z" />
</group>
</group>
</group>
</vector>
37 changes: 37 additions & 0 deletions libnavui-maps/src/main/res/layout/mapbox_route_overview_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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"
app:rippleColor="@android:color/transparent"
app:backgroundTint="@color/colorSurface"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</merge>
7 changes: 7 additions & 0 deletions libnavui-maps/src/main/res/values/attrs.xml
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>
4 changes: 4 additions & 0 deletions libnavui-maps/src/main/res/values/colors.xml
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>
4 changes: 4 additions & 0 deletions libnavui-maps/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="mapbox_route_overview">Overview</string>
</resources>
6 changes: 6 additions & 0 deletions libnavui-maps/src/main/res/values/styles.xml
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 libnavui-resources/src/main/res/drawable/mapbox_bg_circle.xml
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>
1 change: 1 addition & 0 deletions libnavui-resources/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<dimen name="mapbox_dimen_36dp">36dp</dimen>
<dimen name="mapbox_dimen_48dp">48dp</dimen>
<dimen name="mapbox_dimen_54dp">54dp</dimen>
<dimen name="mapbox_dimen_56dp">56dp</dimen>
<dimen name="mapbox_dimen_64dp">64dp</dimen>
<dimen name="mapbox_dimen_72dp">72dp</dimen>
<dimen name="mapbox_dimen_96dp">96dp</dimen>
Expand Down
Loading

0 comments on commit b965b46

Please sign in to comment.