It wraps this posting. Attached the following:
1. B4A project demonstrating the library
2. B4A library files for RotraryKnobView
3. B4A library files for the StringFunctions library (by @margret)
4. The Java Code
Turn the knob with your finger to adjust the value.
Sample code:
The library:
RotaryKnobView
Author: Author: Thomas, Wrapped by: Johan Schoeman
Version: 1
1. B4A project demonstrating the library
2. B4A library files for RotraryKnobView
3. B4A library files for the StringFunctions library (by @margret)
4. The Java Code
Turn the knob with your finger to adjust the value.
Sample code:
B4X:
#Region Project Attributes
#ApplicationLabel: RotaryKnobView
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private rkv1 As RotaryKnobView
Private steps As Float = 3.6 'step 3.6 degrees at a time
Private numberofturns As Int = 2 'final angle will be 720 degrees
Private maxvalue As Int = 100
Private iv1 As ImageView
Private iv2 As ImageView
Private iv3 As ImageView
Dim mbm(10) As Bitmap
Dim sf As StringFunctions
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
sf.Initialize
mbm(0).Initialize(File.DirAssets, "zero.png")
mbm(1).Initialize(File.DirAssets, "one.png")
mbm(2).Initialize(File.DirAssets, "two.png")
mbm(3).Initialize(File.DirAssets, "three.png")
mbm(4).Initialize(File.DirAssets, "four.png")
mbm(5).Initialize(File.DirAssets, "five.png")
mbm(6).Initialize(File.DirAssets, "six.png")
mbm(7).Initialize(File.DirAssets, "seven.png")
mbm(8).Initialize(File.DirAssets, "eight.png")
mbm(9).Initialize(File.DirAssets, "nine.png")
iv1.Bitmap = mbm(0)
iv2.Bitmap = mbm(0)
iv3.Bitmap = mbm(0)
rkv1.adjustmentStep = steps
rkv1.numberOfTurns = numberofturns
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub rkv1_value_changed(direction As Int, angle As Float)
'direction: +1 => CW; -1 => ACW
'angle: max => 360 * numberOfTurns
Dim value As Int = maxvalue * (angle / (numberofturns * 360))
Dim display As String = value
display = sf.Trim(display)
If sf.Len(display) = 1 Then
display = "00" & display
End If
If sf.Len(display) = 2 Then
display = "0" & display
End If
If sf.Left(display,1) = "0" Then iv1.Bitmap = mbm(0)
If sf.Left(display,1) = "1" Then iv1.Bitmap = mbm(1)
If sf.Left(display,1) = "2" Then iv1.Bitmap = mbm(2)
If sf.Left(display,1) = "3" Then iv1.Bitmap = mbm(3)
If sf.Left(display,1) = "4" Then iv1.Bitmap = mbm(4)
If sf.Left(display,1) = "5" Then iv1.Bitmap = mbm(5)
If sf.Left(display,1) = "6" Then iv1.Bitmap = mbm(6)
If sf.Left(display,1) = "7" Then iv1.Bitmap = mbm(7)
If sf.Left(display,1) = "8" Then iv1.Bitmap = mbm(8)
If sf.Left(display,1) = "9" Then iv1.Bitmap = mbm(9)
If sf.mid(display,2,1) = "0" Then iv2.Bitmap = mbm(0)
If sf.mid(display,2,1) = "1" Then iv2.Bitmap = mbm(1)
If sf.mid(display,2,1) = "2" Then iv2.Bitmap = mbm(2)
If sf.mid(display,2,1) = "3" Then iv2.Bitmap = mbm(3)
If sf.mid(display,2,1) = "4" Then iv2.Bitmap = mbm(4)
If sf.mid(display,2,1) = "5" Then iv2.Bitmap = mbm(5)
If sf.mid(display,2,1) = "6" Then iv2.Bitmap = mbm(6)
If sf.mid(display,2,1) = "7" Then iv2.Bitmap = mbm(7)
If sf.mid(display,2,1) = "8" Then iv2.Bitmap = mbm(8)
If sf.mid(display,2,1) = "9" Then iv2.Bitmap = mbm(9)
If sf.mid(display,3,1) = "0" Then iv3.Bitmap = mbm(0)
If sf.mid(display,3,1) = "1" Then iv3.Bitmap = mbm(1)
If sf.mid(display,3,1) = "2" Then iv3.Bitmap = mbm(2)
If sf.mid(display,3,1) = "3" Then iv3.Bitmap = mbm(3)
If sf.mid(display,3,1) = "4" Then iv3.Bitmap = mbm(4)
If sf.mid(display,3,1) = "5" Then iv3.Bitmap = mbm(5)
If sf.mid(display,3,1) = "6" Then iv3.Bitmap = mbm(6)
If sf.mid(display,3,1) = "7" Then iv3.Bitmap = mbm(7)
If sf.mid(display,3,1) = "8" Then iv3.Bitmap = mbm(8)
If sf.mid(display,3,1) = "9" Then iv3.Bitmap = mbm(9)
End Sub
The library:
RotaryKnobView
Author: Author: Thomas, Wrapped by: Johan Schoeman
Version: 1
- RotaryKnobView
Events:- value_changed (direction As Int, angle As Float)
- ba As BA
- BringToFront
- DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
- Initialize (EventName As String)
- Invalidate
- Invalidate2 (arg0 As Rect)
- Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
- IsInitialized As Boolean
- RemoveView
- RequestFocus As Boolean
- SendToBack
- SetBackgroundImage (arg0 As Bitmap)
- SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
- SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
- SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
- SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
- Background As Drawable
- Color As Int [write only]
- Enabled As Boolean
- Height As Int
- Left As Int
- Parent As Object [read only]
- Tag As Object
- Top As Int
- Visible As Boolean
- Width As Int
- adjustmentStep As Float [write only]
- numberOfTurns As Int [write only]