﻿B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=6.5
@EndOfDesignText@
'Custom View class 
#Event: ChangeValue
#DesignerProperty: Key: Min, DisplayName: Min Value, FieldType: int, DefaultValue: 0, Description: Min value
#DesignerProperty: Key: Max, DisplayName: Max Value, FieldType: Int, DefaultValue: 9, Description: Max Value
#DesignerProperty: Key: Value, DisplayName: Actual Value, FieldType: int, DefaultValue: 0, Description: Get o Set valute
#DesignerProperty: Key: StepIncremental, DisplayName: Step incremental or decremental, FieldType: int, DefaultValue: 1,MinRange: 1, Description: Get o Set valute

Sub Class_Globals
	Private mEventName As String 'ignore
	Private mCallBack As Object 'ignore
	Private mBase As Panel
	Private Const DefaultColorConstant As Int = -984833 'ignore
	Private Lab As Label
	
	Private Valore As Int
	Public MinValue,MaxValue,StepIncremental As Int
	Public Tag As Object
	
End Sub

'Initialize Custom View - Used by Designer and by code via AddToParent
'Initialize(Me,"Name")
'#Event: NameClass_ChangeValue
Public Sub Initialize (Callback As Object, EventName As String)
	mEventName = EventName
	mCallBack = Callback
End Sub

Sub Corner(Colore As Int) As ColorDrawable
	Dim cdb As ColorDrawable
	cdb.Initialize(Colore, 20dip)
	Return cdb
End Sub

'Don't call on code 
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
	Dim q As Int 
	Dim Bm,Bm2 As Bitmap
	Dim Bp,Bn As Button
	Dim Can,Can2 As Canvas
	Dim Raggio As Double
	Dim Spessore As Double = 6dip
	Dim Space As Double = 16dip
	Dim offX, offY As Int 
	
	mBase = Base
	Base.Color=Colors.Transparent
	
	If Props.ContainsKey("Min") Then MinValue=Props.Get("Min") Else MinValue=1
	If Props.ContainsKey("Max") Then MaxValue=Props.Get("Max") Else MaxValue=10
	If Props.ContainsKey("Value") Then Valore = Props.Get("Value") Else Valore = 1
	If Props.ContainsKey("StepIncremental") Then StepIncremental=Props.Get("StepIncremental") Else StepIncremental=1
	
	If Base.Height / 3 > Base.Width Then
		q = Base.Width 
		offX = 0
		'offY = (Base.Height - (q * 3)) / 2
		offY = 0
	Else 
		q = Base.Height / 3
		offX = 0 ' (Base.Width - q) / 2
		offY = 0
		'Base.Width = q
	End If
	
	Raggio = q - (Spessore/2)
	Bm.InitializeMutable(q * 2, q * 2)
	Can.Initialize2(Bm)
	Can.DrawCircle(q, q, Raggio, Colors.RGB(188,185,185), True, Spessore)
	Can.DrawCircle(q, q, Raggio, Colors.RGB(60,60,60), False, Spessore)
	Can.DrawLine(Space, q, (q * 2) - Space, q, Colors.Black, Spessore * 2)
	Bn.Initialize("Bn")
	Bn.SetBackgroundImage(Can.Bitmap)
	
	Bm2.InitializeMutable(q * 2, q * 2)
	Can2.Initialize2(Bm2)
	Can2.DrawCircle(q, q, Raggio, Colors.RGB(188,185,185), True, Spessore)
	Can2.DrawCircle(q, q, Raggio, Colors.RGB(60,60,60), False, Spessore)
	Can2.DrawLine(Space, q, (q * 2) - Space, q, Colors.Black, Spessore * 2)
	Can2.DrawLine(q, Space, q, (q * 2) - Space, Colors.Black, Spessore * 2)
	Bp.Initialize("Bp")
	Bp.SetBackgroundImage(Can2.Bitmap)
		
	Lab.Initialize("")
	Lab.Text=Valore
	'Lab.Color=Colors.RGB(188,185,185)
	Lab.Background=Corner(Colors.RGB(188,185,185))
	Lab.TextColor=Colors.Black
	Lab.Gravity=Gravity.CENTER
	Lab.TextSize = q / 2dip
	Base.AddView(Lab, offX, offY + q, q, q)
				
	Base.AddView(Bp, offX, offY, q, q)
	Base.AddView(Bn, offX, offY + (q * 2), q, q)
End Sub

Public Sub GetBase As Panel
	Return mBase
End Sub

Public Sub setValue(NewValue As Int)
	Valore=NewValue
	Lab.Text=Valore
End Sub

Public Sub getValue As Int
	Return Valore
End Sub

Private Sub Bp_Click
	If Valore+StepIncremental<=MaxValue Then
		Valore=Valore+StepIncremental
		Lab.Text=Valore
		If SubExists(mCallBack,mEventName & "_ChangeValue") Then CallSub(mCallBack,mEventName & "_ChangeValue")
	End If
End Sub

Private Sub Bn_Click
	If Valore-StepIncremental>=MinValue Then
		Valore=Valore-StepIncremental
		Lab.Text=Valore
		If SubExists(mCallBack,mEventName & "_ChangeValue") Then CallSub(mCallBack,mEventName & "_ChangeValue")
	End If
End Sub