In this article we will learn about some of the frequently asked Kotlin programming questions in technical like “android vertical seekbar” Code Answer. When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks. Error or stack handling on kotlin was simple and easy. An error message with filename, line number and a message describing the error is sent to the browser. This tutorial contains some of the most common error checking methods in Kotlin. Below are some solution about “android vertical seekbar” Code Answer.
android vertical seekbar
xxxxxxxxxx
1
import android.content.Context
2
import android.graphics.Canvas
3
import android.util.AttributeSet
4
import android.view.MotionEvent
5
6
7
class VerticalSeekBar : androidx.appcompat.widget.AppCompatSeekBar {
8
private var changeListener: OnSeekBarChangeListener? = null
9
private var x = 0
10
private var y = 0
11
private var z = 0
12
private var w = 0
13
14
constructor(context: Context) : super(context) {}
15
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
16
context,
17
attrs,
18
defStyle
19
) {
20
}
21
22
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
23
24
@Synchronized
25
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
26
super.onSizeChanged(h, w, oldh, oldw)
27
x = w
28
y = h
29
z = oldw
30
this.w = oldh
31
}
32
33
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
34
super.onMeasure(heightMeasureSpec, widthMeasureSpec)
35
setMeasuredDimension(measuredHeight, measuredWidth)
36
}
37
38
override fun onDraw(c: Canvas) {
39
c.rotate(-90f)
40
c.translate(-height.toFloat(), 0f)
41
super.onDraw(c)
42
}
43
44
override fun onTouchEvent(event: MotionEvent): Boolean {
45
if (!isEnabled) {
46
return false
47
}
48
when (event.action) {
49
MotionEvent.ACTION_DOWN -> {
50
isSelected = true
51
isPressed = true
52
if (changeListener != null) changeListener!!.onStartTrackingTouch(this)
53
}
54
MotionEvent.ACTION_UP -> {
55
isSelected = false
56
isPressed = false
57
if (changeListener != null) changeListener!!.onStopTrackingTouch(this)
58
}
59
MotionEvent.ACTION_MOVE -> {
60
val progress = (max
61
- (max * event.y / height).toInt())
62
setProgress(progress)
63
onSizeChanged(width, height, 0, 0)
64
if (changeListener != null) changeListener!!.onProgressChanged(this, progress, true)
65
}
66
MotionEvent.ACTION_CANCEL -> {
67
}
68
}
69
return true
70
}
71
72
@Synchronized
73
override fun setOnSeekBarChangeListener(
74
listener: OnSeekBarChangeListener
75
) {
76
changeListener = listener
77
}
78
79
@Synchronized
80
override fun setProgress(progress: Int) {
81
if (progress >= 0) super.setProgress(progress) else super.setProgress(0)
82
onSizeChanged(x, y, z, w)
83
if (changeListener != null) changeListener!!.onProgressChanged(this, progress, false)
84
}
85
}