This file contains hidden or 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
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/container" | |
...> | |
<androidx.cardview.widget.CardView | |
android:id="@+id/barCardView" | |
... | |
android:layout_gravity="center_horizontal" | |
app:cardElevation="0dp"> |
This file contains hidden or 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
open class VerticalSeekBar constructor(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) { | |
companion object { | |
private const val DEFAULT_MAX_VALUE = 100 | |
private const val DEFAULT_DRAWABLE_BACKGROUND: String = "#f6f6f6" | |
private const val DEFAULT_DRAWABLE_PROGRESS_START: String = "#4D88E1" | |
private const val DEFAULT_DRAWABLE_PROGRESS_END: String = "#7BA1DB" | |
} | |
private var onProgressChangeListener: ((Int) -> Unit)? = null |
This file contains hidden or 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
// [...] | |
private fun applyAttributes() { | |
// [...] | |
// here we intercept the click on the thumb | |
thumb.setOnTouchListener { thumb, event -> | |
val rawY = event.rawY.roundToInt() | |
when (event.action and MotionEvent.ACTION_MASK) { | |
MotionEvent.ACTION_DOWN -> { // here we get the max top y coordinate (yDelta) | |
yDelta = rawY + | |
(barCardView.layoutParams as LayoutParams).topMargin - |
This file contains hidden or 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
// [...] | |
private fun applyAttributes() { | |
// [...] | |
// here we intercept the click on the bar | |
barCardView.setOnTouchListener { drawable, event -> | |
val positionY = event.y.roundToInt() | |
val action = { | |
val fillHeight = bar.measuredHeight | |
when { // here we update progress | |
positionY in 1 until fillHeight -> { |
This file contains hidden or 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
// [...] | |
private fun updateViews() { | |
post { | |
val barCardViewLayoutParams = barCardView.layoutParams as LayoutParams | |
val fillHeight = height - barCardViewLayoutParams.topMargin - barCardViewLayoutParams.bottomMargin | |
val marginByProgress = fillHeight - (progress * fillHeight / maxValue) | |
thumb.layoutParams = (thumb.layoutParams as LayoutParams).apply { | |
topMargin = marginByProgress | |
val thumbCardViewHalfHeight = if (showThumb) thumbCardView.measuredHeight / 2 else 0 | |
if (barCardViewLayoutParams.topMargin > thumbCardViewHalfHeight) { |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content"> | |
<EditText | |
android:id="@+id/editCodeReal" | |
android:layout_width="1dp" | |
android:layout_height="1dp" |
This file contains hidden or 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
var text: Editable = "".toEditable() | |
set(value) { | |
field = value | |
renderCode() // let's keep this for later | |
} | |
... | |
override fun onAttachedToWindow() { | |
super.onAttachedToWindow() | |
... |
This file contains hidden or 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
private fun renderCode() { | |
for (i in 0 until llCodeWrapper.childCount) { | |
val itemContainer = llCodeWrapper.getChildAt(i) | |
itemContainer.findViewById<TextView>(R.id.tvCode).text = | |
if (text.length > i) | |
(if (maskTheCode) codeMaskChar else text[i]) | |
.toString() | |
else "" |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.core.widget.NestedScrollView 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="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"><!-- vertical scrolling purpose --> | |
<LinearLayout | |
android:layout_width="match_parent" |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<dimen name="item_fixed_width">70dp</dimen> | |
</resources> |
OlderNewer