Android Question RoundSlider change event

Josias

Member
Licensed User
Hi Guys,

Been playing with Erel's RoundSlider implementation. Works great!

Instead of using the 'Public Sub getValue As Int' to get the value, how can I implement an on_change event to get notified when the user made a change. It should preferably the raised when the user releases the slider.
 

LucaMs

Expert
Licensed User
Add these lines:

(below: "#DesignerProperty: Key: Max, DisplayName..."):
B4X:
#Event: ValueChanged(NewValue As Int)
(below: "Draw" in Sub pnl_Touch, line 105):
B4X:
If SubExists(mCallBack, mEventName & "_ValueChanged") Then
    CallSub2(mCallBack, mEventName & "_ValueChanged", mValue)
End If
 

Josias

Member
Licensed User
Thx for the quick reply. Works like a charm.

How can I trigger only when the user releases the touch?
 

klaus

Expert
Licensed User
You can change the pnl_Touch routine in the CustomView module like this:
B4X:
Private Sub pnl_Touch (Action As Int, X As Float, Y As Float)
    Select Action
        Case pnl.TOUCH_ACTION_DOWN, pnl.TOUCH_ACTION_MOVE
            Dim dx As Int = x - CircleRect.CenterX
            Dim dy As Int = y - CircleRect.CenterY
            Dim dist As Float = Sqrt(Power(dx, 2) + Power(dy, 2))
            If dist > CircleRect.Width / 2 Then
                Dim angle As Int = Round(ATan2D(dy, dx))
                angle = angle + 90
                angle = (angle + 360) Mod 360
                mValue = mMin + angle / 360 * (mMax - mMin)
                mValue = Max(mMin, Min(mMax, mValue))
                Draw
            End If
        Case pnl.TOUCH_ACTION_DOWN, pnl.TOUCH_ACTION_UP
            If SubExists(mCallBack, mEventName & "_ValueChanged") Then
                CallSub2(mCallBack, mEventName & "_ValueChanged", mValue)
            End If
    End Select
End Sub
And in the calling module:
B4X:
Private Sub RoundSlider1_ValueChanged(Value As Int)
    Log(Value)
End Sub
 
Top