Skip to content

Instantly share code, notes, and snippets.

View lukelorusso's full-sized avatar
🤖
var droidMood = true

Luke Lorusso lukelorusso

🤖
var droidMood = true
View GitHub Profile
<?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"
@lukelorusso
lukelorusso / VerticalSeekBar.kt
Last active June 28, 2019 15:32
updateViews()
// [...]
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) {
@lukelorusso
lukelorusso / VerticalSeekBar.kt
Last active June 28, 2019 15:31
applyAttributes() -> barCardView.setOnTouchListener
// [...]
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 -> {
@lukelorusso
lukelorusso / VerticalSeekBar.kt
Last active June 28, 2019 15:30
applyAttributes() -> thumb.setOnTouchListener
// [...]
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 -
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
<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">