Sub Process_Globals
End Sub
Sub Globals
Private moButton As Button
Private moSlider As SeekBar
Private moActCan As Canvas
End Sub
Sub Activity_Create(FirstTime As Boolean)
moButton.Initialize("btnExit")
Activity.AddView(moButton, Activity.Width - 105dip, Activity.Height - 55dip, 100dip, 50dip)
moButton.Text = "EXIT"
moSlider.Initialize("skbValue")
Activity.AddView(moSlider, 30dip, (moButton.Top - 55dip), (Activity.Width - 60dip), 50dip)
moSlider.Visible = True
moSlider.Max = 100
moSlider.Value = 0
moActCan.Initialize(Activity)
moActCan.DrawColor(Colors.Black)
End Sub
Sub Activity_Resume
skbValue_ValueChanged(moSlider.Value, False)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Private Sub btnExit_Click
Activity.Finish
End Sub
private Sub skbValue_ValueChanged(Value As Int, UserChanged As Boolean)
Dim poRect As Rect
poRect.Initialize(20dip, 20dip, Activity.Width - 40dip, 60dip)
DrawLEDMeter(moActCan, poRect, Value)
' do this so the changes we drew are updated, if you're using a panel or whatever change from "activity" to that.
Activity.Invalidate
End Sub
' Draws LED Meter. CurrValue is percent value, 0 to 100.
Sub DrawLEDMeter(oCan As Canvas, ControlPosition As Rect, CurrValue As Int)
Dim poBorderGD As GradientDrawable
Dim piBorderCol(3) As Int = Array As Int(Colors.RGB(239, 239, 239), Colors.RGB(126, 126, 126), Colors.RGB(126, 126, 126))
Dim poHighlightGD As GradientDrawable
Dim piHighlightCol(2) As Int = Array As Int(Colors.ARGB(83, 250, 250, 250), Colors.ARGB(63, 250, 250, 250))
Dim poRect1 As Rect
Dim piX As Int
Dim piY As Int
Dim piBaseX As Int
Dim piBaseY As Int
Dim piWidth As Int
Dim piHeight As Int
Dim piSegWidth As Int
Dim piRight As Int
Dim piBottom As Int
Dim piBorderWidth As Int = 5dip
Dim piGlassOffset As Int = 8dip
Dim piLEDOffset As Int = 5dip
' how much to round each bar segment
Dim piCornerRad As Int = 3dip
' number of bar segments
Dim piSegments As Int = 25
Dim piGreenOn(3) As Int = Array As Int(Colors.RGB(0, 161, 0), Colors.RGB(0, 255, 0), Colors.RGB(0, 161, 0))
Dim piGreenOff(3) As Int = Array As Int(Colors.RGB(0, 81, 0), Colors.RGB(0, 81, 0), Colors.RGB(0, 81, 0))
Dim piRedOn(3) As Int = Array As Int(Colors.RGB(161, 0, 0), Colors.RGB(255, 0, 0), Colors.RGB(161, 0, 0))
Dim piRedOff(3) As Int = Array As Int(Colors.RGB(81, 0, 0), Colors.RGB(81, 0, 0), Colors.RGB(81, 0, 0))
Dim piYellowOn(3) As Int = Array As Int(Colors.RGB(161, 161, 0), Colors.RGB(255, 250, 0), Colors.RGB(161, 161, 0))
Dim piYellowOff(3) As Int = Array As Int(Colors.RGB(81, 81, 0), Colors.RGB(81, 81, 0), Colors.RGB(81, 81, 0))
Dim piLed As Int
Dim piCurrVal As Int
Dim piDrawVal As Int
Dim poGD As GradientDrawable
Dim piDrawWidth As Int = ControlPosition.Right - ControlPosition.Left + 1
Dim piDrawHeight As Int = ControlPosition.Bottom - ControlPosition.Top + 1
' Color bar percentages
Dim piGreenMax As Int = 60
Dim piYellowMax As Int = 80
Dim piDrawPercent As Int
' Color to draw in loop
Dim piDrawColors() As Int
' draw gray color gradient to serve as border
poBorderGD.Initialize("TOP_BOTTOM", piBorderCol)
poBorderGD.CornerRadius = 5dip
oCan.DrawDrawable(poBorderGD, ControlPosition)
' black out "intierior" of control
poRect1.Initialize((ControlPosition.Left + piBorderWidth), (ControlPosition.Top + piBorderWidth), (ControlPosition.Left + piDrawWidth - piBorderWidth), (ControlPosition.Top + piDrawHeight - piBorderWidth))
oCan.DrawRect(poRect1, Colors.Black, True, 1dip)
' validate percentage parameter
If CurrValue < 0 Then
piCurrVal = 0
Else
If CurrValue > 100 Then
piCurrVal = 100
Else
piCurrVal = CurrValue
End If
End If
' calculate LED poisition
piBaseX = ControlPosition.Left + piBorderWidth + piLEDOffset
piBaseY = ControlPosition.Top + piBorderWidth + (piLEDOffset / 2)
piWidth = piDrawWidth - ((piBorderWidth + piLEDOffset) * 2)
piHeight = piDrawHeight - ((piBorderWidth + (piLEDOffset / 2)) * 2)
piSegWidth = (piWidth / piSegments) + 0.5
piBaseX = piBaseX + ((piWidth + 3dip - (piSegWidth * piSegments)) / 2)
' draw LEDs
For piLed = 0 To piSegments - 1
piDrawPercent = (piLed / (piSegments - 1)) * 100
If piDrawPercent <= piGreenMax Then
' GREEN BAR
If piCurrVal > piDrawPercent Then
piDrawColors = piGreenOn
Else
piDrawColors = piGreenOff
End If
Else
If piDrawPercent <= piYellowMax Then
' YELLOW BAR
If piCurrVal > piDrawPercent Then
piDrawColors = piYellowOn
Else
piDrawColors = piYellowOff
End If
Else
' RED BAR
If piCurrVal >= piDrawPercent Then
piDrawColors = piRedOn
Else
piDrawColors = piRedOff
End If
End If
End If
poGD.Initialize("TOP_BOTTOM", piDrawColors)
poGD.CornerRadius = piCornerRad
piX = piBaseX + (piLed * piSegWidth)
piY = piBaseY
piRight = piX + piSegWidth - 3dip
piBottom = piY + piHeight
poRect1.Initialize(piX, piY, piRight, piBottom)
oCan.DrawDrawable(poGD, poRect1)
piDrawVal = piDrawVal + 1
Next
' draw "glass reflection" on top of image
poHighlightGD.Initialize("TOP_BOTTOM", piHighlightCol)
poHighlightGD.CornerRadius = 5dip
piX = ControlPosition.Left + piGlassOffset
piY = ControlPosition.Top + piGlassOffset
piRight = piX + piDrawWidth - (piGlassOffset * 2)
piBottom = piY + ((piDrawHeight - (piGlassOffset * 2)) * 0.33) ' 1/3 area reflection
poRect1.Initialize(piX, piY, piRight, piBottom)
oCan.DrawDrawable(poHighlightGD, poRect1)
End Sub