Add a drag indicator element at the top of LicenceDialog

A new `DragIndicatorView` had been introduced, which draws a small drag handle element. When used inside a `BottomSheetDialog`, this view will add a callback for hiding the indicator when the dialog is fully expanded.
This commit is contained in:
lynxnb 2022-01-25 19:57:52 +01:00 committed by Mark Collins
parent 6848e69638
commit f93d3b78d3
5 changed files with 80 additions and 2 deletions

View File

@ -0,0 +1,62 @@
/*
* SPDX-License-Identifier: MPL-2.0
* Copyright © 2022 Skyline Team and Contributors (https://github.com/skyline-emu/)
*/
package emu.skyline.views
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import androidx.transition.TransitionManager
import com.google.android.material.bottomsheet.BottomSheetBehavior
import emu.skyline.R
class DragIndicatorView : androidx.appcompat.widget.AppCompatImageView {
private val visibilityCallback = DragIndicatorCallback()
private var callbackAttached = false
init {
setImageResource(R.drawable.drag_indicator)
isFocusable = false
isClickable = false
}
constructor(context : Context) : super(context)
constructor(context : Context, attrs : AttributeSet?) : super(context, attrs)
constructor(context : Context, attrs : AttributeSet?, defStyleAttr : Int) : super(context, attrs, defStyleAttr)
override fun onAttachedToWindow() {
super.onAttachedToWindow()
if (callbackAttached)
return
// Check if this view is inside a BottomSheetDialog and attach the visibility callback in that case
var parentView = parent
while (parentView != null) {
try {
val behavior = BottomSheetBehavior.from(parentView as View)
behavior.addBottomSheetCallback(visibilityCallback)
callbackAttached = true
break
} catch (e : IllegalArgumentException) {
parentView = parentView.parent
}
}
}
inner class DragIndicatorCallback : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet : View, newState : Int) {
// Enables animation between visibility states
TransitionManager.beginDelayedTransition(parent as ViewGroup)
visibility = if (newState == BottomSheetBehavior.STATE_EXPANDED && bottomSheet.top == 0)
View.INVISIBLE
else
View.VISIBLE
}
override fun onSlide(bottomSheet : View, slideOffset : Float) {}
}
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="42dp"
android:height="4dp" />
<solid android:color="@color/onBackgroundLight" />
<corners android:radius="4dp" />
</shape>

View File

@ -8,8 +8,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingHorizontal="2.5dp"
android:paddingTop="20dp">
android:paddingHorizontal="2.5dp">
<emu.skyline.views.DragIndicatorView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="8dp" />
<TextView
android:id="@+id/library_title"
@ -29,6 +33,7 @@
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5"
android:textSize="15sp"
tools:ignore="TouchTargetSizeCheck"
tools:text="https://github.com/skyline-emu/skyline" />
<TextView

View File

@ -4,4 +4,5 @@
<color name="backgroundColor">#FF121212</color>
<color name="backgroundColorVariant">#323232</color>
<color name="dividerColor">@android:color/white</color>
<color name="onBackgroundLight">#1AFFFFFF</color>
</resources>

View File

@ -5,6 +5,7 @@
<color name="backgroundColor">@android:color/white</color>
<color name="backgroundColorVariant">#F8F8F8</color>
<color name="dividerColor">@android:color/black</color>
<color name="onBackgroundLight">#1E000000</color>
<color name="colorPerfStatsPrimary">#9FFFFF00</color>
<color name="colorPerfStatsSecondary">#9F00FFFF</color>