diff --git a/app/src/main/java/eu/ztsh/garmin/UI.kt b/app/src/main/java/eu/ztsh/garmin/UI.kt index c16bae5..0277486 100644 --- a/app/src/main/java/eu/ztsh/garmin/UI.kt +++ b/app/src/main/java/eu/ztsh/garmin/UI.kt @@ -59,4 +59,6 @@ class UI(b: ActivityMainBinding) { val searchResultsView = b.searchResults val searchPlaceView = b.searchPlaces val queryEditText = b.query + + val reconnect = b.reconnect } \ No newline at end of file diff --git a/app/src/main/java/eu/ztsh/garmin/view/ExtendableButton.kt b/app/src/main/java/eu/ztsh/garmin/view/ExtendableButton.kt new file mode 100644 index 0000000..7ada0b3 --- /dev/null +++ b/app/src/main/java/eu/ztsh/garmin/view/ExtendableButton.kt @@ -0,0 +1,119 @@ +package eu.ztsh.garmin.view + +import android.content.Context +import android.content.res.TypedArray +import android.util.AttributeSet +import android.view.LayoutInflater +import androidx.annotation.StyleRes +import androidx.annotation.UiThread +import androidx.constraintlayout.widget.ConstraintLayout +import com.mapbox.navigation.ui.components.R +import eu.ztsh.garmin.R.styleable.* +import com.mapbox.navigation.ui.components.databinding.ExtendableButtonLayoutBinding +import com.mapbox.navigation.ui.utils.internal.ExtendableButtonHelper + +/** + * Mapbox extendable generic. + */ +@UiThread +class ExtendableButton : ConstraintLayout { + + private val binding = ExtendableButtonLayoutBinding.inflate(LayoutInflater.from(context), this) + private val helper = ExtendableButtonHelper( + binding.buttonText, + context.resources.getDimensionPixelSize(R.dimen.mapbox_button_size), + context.resources.getDimension(R.dimen.mapbox_recenterButton_minExtendedWidth), + ) + private lateinit var expandedText: String + + /** + * + * @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) + } + + /** + * Allows you to change the style of [ExtendableButton]. + * @param style Int + */ + fun updateStyle(@StyleRes style: Int) { + val typedArray = context.obtainStyledAttributes( + style, + ExtendableButton + ) + 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. + * @param text for the view to show in the extended mode. + */ + @JvmOverloads + fun showTextAndExtend( + duration: Long, + text: String = expandedText, + ) { + if (!helper.isAnimationRunning) { + helper.showTextAndExtend(text, duration) + } + } + + private fun initAttributes(attrs: AttributeSet?) { + val typedArray = context.obtainStyledAttributes( + attrs, + ExtendableButton, + 0, + 0 + ) + applyAttributes(typedArray) + typedArray.recycle() + } + + private fun applyAttributes(typedArray: TypedArray) { + typedArray.getDrawable(ExtendableButton_btn_icon) + .also { binding.buttonIcon.setImageDrawable(it) } + + typedArray.getDrawable( + R.styleable.MapboxRecenterButton_recenterButtonBackground, + )?.let { background -> + binding.buttonIcon.background = background + binding.buttonText.background = background + } + + typedArray.getColorStateList( + R.styleable.MapboxRecenterButton_recenterButtonTextColor, + )?.let { binding.buttonText.setTextColor(it) } + + typedArray.apply { + expandedText = getString(ExtendableButton_expanded_text) ?: "DUNNO" + } + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index bfea266..83cf4b1 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -127,4 +127,15 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/routeOverview" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml new file mode 100644 index 0000000..ef249b8 --- /dev/null +++ b/app/src/main/res/values/attrs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 774ae0a..b845fca 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -7,4 +7,6 @@ Error happened during request Not implemented yet + Reconnect +