Android Question Rotary knob view and gesture detector

SeaBee

Member
Licensed User
I am not looking for code, more an approach to the problem.

I wrote an app that uses the rotary knob view for some people over here in sunny Cyprus, where the knob is used to dial in a specific variable over up to five full turns covering 0 to 500 - 3.6 degrees per step. I have now been asked to a) save the last setting (easy) and b) to set the dial to that setting so that the user does not have to dial all the way up to the previous setting to make a small change (not so much!)

I thought the best way to do this would be to simulate either a touch or a rotation that stops each time the RKV increments one step, and then repeat this until the knob is set to the previously set number. The gesture detector would appear to be suited to this, using CreateMotionEvent and PassTouchEvent. I presume that X As float, Y As float refers to the position of the first touch with relation to the activity, as I cannot point to a specific view - i.e. the RKV.

My problem is that I can see no way the set the direction of the touch - if it is vertical, then nothing will happen! If I use a two-finger touch to rotate then I can set the view to the RKV, but again, how to control the direction.

It is possible (probable?) that I am taking entirely the wrong approach, in which case I would be very grateful to be pointed in the right direction. If, however, my approach is workable then I would appreciate some further information on how to proceed.

Thanks very much,

Chris C-B
 

SeaBee

Member
Licensed User
I seem to have made some progress - backwards!

The following code works - sort of - if you pre-set a value on the RKV, then each time the sub is run, the RKV decrements instead of incrementing.



B4X:
Sub CreateRKVMotionEvent
   
Dim MEv As Object
   
MEv = GD.CreateMotionEvent(0, DateTime.Now, GD.ACTION_MOVE, rkv1.Left + (rkv1.Width/2), rkv1.Top + (rkv1.Height/2))

GD.PassTouchEventTo(MEv, rkv1)
   
End Sub

Back to the drawing board...
 
Upvote 0

SeaBee

Member
Licensed User
I have a work-around - not a solution, because it relies on making a correction somewhere else to fix a problem that I don't understand in the first place, for something that was pretty nebulous right from the start. That is to say, it is dreadful code - what to do...

B4X:
Sub CreateRKVMotionEvent
   
Dim MEv As Object
Dim OKreturn As Boolean
Dim loopCount As Int = 0

rkv1.adjustmentStep = -3.6 'Reverse step direction to make it work!

    Do Until rkv1Value = 50
       
        loopCount = loopCount + 1
       
        MEv = GD.CreateMotionEvent(0, DateTime.Now , GD.ACTION_MOVE, 0, 0)
        OKreturn = GD.PassTouchEventTo(MEv, rkv1)
        Log(OKreturn & ", " & loopCount) 'loopCount matches the number of RKV steps to reach the set limit.
       
        Sleep(0)
           
    Loop
   
    rkv1.adjustmentStep = 3.6 'Put the step direction back to positive.
       
End Sub

Since the TouchEvent was going backwards, contrary to what I expected, I... er... reversed the direction of the steps on the RKV. If you have ever seen a worse bit of coding, do let me know. :eek:

I don't think I can use this in production, so if anyone has a more elegant solution, or a rational explanation of why the move was always backwards, I would love to see it.

Ps. Just in case I do use it in the end, I had better make a quick bung to Informatix!
 
Last edited:
Upvote 0
Top