Build1=Default,com.shaderyan.neo.wifi.fix
File1=1.bal
File10=forward_play.png
File11=glassback1.png
File12=t1.png
File13=t2.png
File14=t3.png
File15=t4.png
File2=1.png
File3=2.png
File4=3.png
File5=back_play.png
File6=btn.png
File7=btn2.png
File8=caviardreams.ttf
File9=colors.png
FileGroup1=Default Group
FileGroup10=Default Group
FileGroup11=Default Group
FileGroup12=Default Group
FileGroup13=Default Group
FileGroup14=Default Group
FileGroup15=Default Group
FileGroup2=Default Group
FileGroup3=Default Group
FileGroup4=Default Group
FileGroup5=Default Group
FileGroup6=Default Group
FileGroup7=Default Group
FileGroup8=Default Group
FileGroup9=Default Group
Group=Default Group
Library1=core
Library2=network
Library3=phone
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>~\n~<supports-screens android:largeScreens="true" ~\n~    android:normalScreens="true" ~\n~    android:smallScreens="true" ~\n~    android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~'End of default text.~\n~
Module1=Starter
NumberOfFiles=15
NumberOfLibraries=3
NumberOfModules=1
Version=9.9
@EndOfDesignText@
#Region  Project Attributes 
	#ApplicationLabel: رقص نور وایفای
	#VersionCode: 1
	#VersionName: 
	'SupportedOrientations possible values: unspecified, landscape or portrait.
	#SupportedOrientations: portrait
	#CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: False
#End Region

Sub Process_Globals
	Dim number_effect As Int:number_effect=1
	Dim number_led As Int:number_led=16
	
	Dim auto_effect_1 As Int:auto_effect_1 = 1
	Dim auto_effect_2 As Int:auto_effect_2 = 1
	Dim auto_effect_3 As Int:auto_effect_3 = 1
	
End Sub

Sub Globals
	
	Dim viber As PhoneVibrate
	
	Dim S1 As String
	Dim S2 As String
	Dim S3 As String
	
	Dim state1 As Int
	Dim state2 As Int
	Dim state3 As Int
	
	
	Private cvsColors As Canvas
	Private cvsOverlay As Canvas
	Private pnlColors As Panel
	Private pnlOverlay As Panel
	Private etRed As EditText
	Private etGreen As EditText
	Private etBlue As EditText
	Private btnDo As Button
	
	Public UdpS As UDPSocket
	Public UdpP As UDPPacket

	Public ShrIP, ShrPort As String
	
	ShrIP = "192.168.4.1"
	ShrPort = "2000"
	
	Dim strCmd As String
	Dim strReceive As String
	
	Private imgeffect1 As ImageView
	Private imgEffect2 As ImageView
	Private imgEffect3 As ImageView
	
	Private etEffect1 As EditText
	Private etEffect2 As EditText
	Private etEffect3 As EditText
	Private btnAuto As Button
	Private SeekBarSpeed As SeekBar
	
	Private lblSpeed As Label
	Private etSpeed As EditText
	Private btnSpeed As Button
	Private sp_e1 As Spinner
	Private sp_e2 As Spinner
	Private sp_e3 As Spinner
	Private sp_count As Spinner
	Private sp_effect As Spinner
	'-------------------------------------
	Private lbl_e1 As Label
	Private lbl_e2 As Label
	Private lbl_e3 As Label
	
	Private lbl_count As Label
	Private lbl_effect As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("1")
	cvsColors.Initialize(pnlColors)
	cvsOverlay.Initialize(pnlOverlay)
	'-------------------------------------
	
	'++++++++++++
	sp_e1.AddAll(Array As String("Mode 1", "Mode 2", "Mode 3","Mode 4","Mode 5","Mode 6","Mode 7", "Mode 8", "Mode 9","Mode 10","Mode 11","Mode 12", "Mode 13", "Mode 14","Mode 15","Mode 16","Mode 17","Mode 18", "Mode 19", "Mode 20"))
	sp_e1.TextSize=14
	'sp_e1.TextColor=Colors.Black
	sp_e1.DropdownBackgroundColor=Colors.RGB(136,78,160)
	sp_e1.DropdownTextColor=Colors.White
	'------------
	sp_e2.AddAll(Array As String("Mode 1", "Mode 2", "Mode 3","Mode 4","Mode 5","Mode 6","Mode 7", "Mode 8", "Mode 9","Mode 10","Mode 11","Mode 12", "Mode 13", "Mode 14","Mode 15","Mode 16","Mode 17","Mode 18", "Mode 19", "Mode 20"))
	sp_e2.TextSize=14
	'sp_e2.TextColor=Colors.Black
	sp_e2.DropdownBackgroundColor=Colors.RGB(136,78,160)
	sp_e2.DropdownTextColor=Colors.White
	'------------
	sp_e3.AddAll(Array As String("Mode 1", "Mode 2", "Mode 3","Mode 4","Mode 5","Mode 6","Mode 7", "Mode 8", "Mode 9","Mode 10","Mode 11","Mode 12", "Mode 13", "Mode 14","Mode 15","Mode 16","Mode 17","Mode 18", "Mode 19", "Mode 20"))
	sp_e3.TextSize=14
	'sp_e3.TextColor=Colors.Black
	sp_e3.DropdownBackgroundColor=Colors.RGB(136,78,160)
	sp_e3.DropdownTextColor=Colors.White
	'------------
	sp_effect.AddAll(Array As String("Mode 1", "Mode 2", "Mode 3","Mode 4","Mode 5","Mode 6","Mode 7", "Mode 8", "Mode 9","Mode 10","Mode 11","Mode 12", "Mode 13", "Mode 14","Mode 15","Mode 16","Mode 17","Mode 18", "Mode 19", "Mode 20"))
	sp_effect.TextSize=14
	'sp_effect.TextColor=Colors.Black
	sp_effect.DropdownBackgroundColor=Colors.RGB(136,78,160)
	sp_effect.DropdownTextColor=Colors.White
	'------------
'	Dim list_number As List
'	list_number.Initialize
'	For i = 1 To 100
'		Dim l As List
'		l.Initialize
'		l.Add(i)
'		list_number.Add(l)
'	Next
'	
'	sp_count.AddAll(list_number)

	For i = 1 To 101
		sp_count.Add(i)
	Next

	sp_count.TextSize=14
	'sp_count.TextColor=Colors.Black
	sp_count.DropdownBackgroundColor=Colors.RGB(136,78,160)
	sp_count.DropdownTextColor=Colors.White
	'++++++++++++
	
	sp_e1.SelectedIndex = 0
	sp_e2.SelectedIndex = 0
	sp_e3.SelectedIndex = 0
	sp_effect.SelectedIndex = 0
	sp_count.SelectedIndex = 24
	
End Sub

Sub pnlColors_Touch (Action As Int, X As Float, Y As Float)
	Try
		Dim cx = pnlColors.Width / 2, cy = pnlColors.Height / 2 As Float
		If Sqrt(Power(x - cx, 2) + Power(y - cy, 2)) > pnlColors.Width / 2 Then Return
		Dim clr As Int = cvsColors.Bitmap.GetPixel(X, Y)
		'Activity.Color = clr
		'pnlColors.Color = clr
		'pnlOverlay.Color = clr
		
	
		Dim argb() As Int
		argb = GetARGB(clr)
		'Log("A = " & argb(0))
		'Log("R = " & argb(1))
		'Log("G = " & argb(2))
		'Log("B = " & argb(3))
	
		'ToastMessageShow("red = "&argb(1) &"green = "&argb(2) &"blue = "&argb(3),True)
		etRed.Text = argb(1)
		etGreen.Text = argb(2)
		etBlue.Text = argb(3)
	
		strCmd = argb(1) & ","&argb(2)&","&argb(3)
	
		cvsOverlay.DrawColor(Colors.Transparent)
		cvsOverlay.DrawCircle(X, Y, 20dip, Colors.Black, False, 3dip)
		pnlOverlay.Invalidate
	
		UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
		UdpS.Send(UdpP)
	Catch
		Log("error")
	End Try
	
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
	If KeyCode = KeyCodes.KEYCODE_BACK Then
		If Msgbox2("Do you want to close?", "", "Yes", "Cancel", "No", Null) = DialogResponse.POSITIVE Then
			Return False
		Else
			Return True
		End If
	End If
End Sub


Sub GetARGB(Color As Int) As Int()
	Dim res(4) As Int
	res(0) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff000000), 24)
	res(1) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff0000), 16)
	res(2) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff00), 8)
	res(3) = Bit.And(Color, 0xff)
	Return res
End Sub


Sub btnConnect_Click
	viber.Vibrate(50)
	
	UdpS.Initialize("UdpSEvent",2000,1024)
	ToastMessageShow("با موفقیت متصل شد",True)
End Sub

Sub btnDo_Click
	viber.Vibrate(50)
	
	Try
		strCmd = etRed.Text & ","&etGreen.Text&","&etBlue.Text
		UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
		UdpS.Send(UdpP)
	Catch
		
	End Try
End Sub

Sub btnAuto_Click
'	viber.Vibrate(50)
'	
'	S1 = etEffect1.Text
'	S2 = etEffect2.Text
'	S3 = etEffect3.Text
'	
'	strCmd = "st1"
'	UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
'	UdpS.Send(UdpP)

	viber.Vibrate(50)
	Try
		S1 = etEffect1.Text
		S2 = etEffect2.Text
		S3 = etEffect3.Text
	
		strCmd = "auto,"&auto_effect_1&"x"&S1&"@"&auto_effect_2&"y"&S2&"&"&auto_effect_3&"z"&S3&"#"
		UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
		UdpS.Send(UdpP)
	Catch
		
	End Try	
End Sub

Sub UdpSEvent_PacketArrived (Packet As UDPPacket)
	strReceive = BytesToString(Packet.Data, Packet.Offset,Packet.Length,"ASCII")
	
	Dim str As String
	str = BytesToString(Packet.Data, Packet.Offset,Packet.Length,"ASCII")
	
	If (str.CharAt(0) = "1" And str.CharAt(1) = "0" And str.CharAt(2) = "0") Then
		state1 = CInt(str) - 100000
		If (state1 = CInt(S1)) Then
			strCmd = "st2"
			Log(state1)
			UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
			UdpS.Send(UdpP)
		Else
			strCmd = "st1"
			Log(state1)
			UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
			UdpS.Send(UdpP)
		End If
	Else If (str.CharAt(0) = "2" And str.CharAt(1) = "0" And str.CharAt(2) = "0") Then
		state2 = CInt(str) - 200000
		If (state2 = CInt(S2)) Then
			strCmd = "st3"
			Log(state2)
			UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
			UdpS.Send(UdpP)
		Else
			strCmd = "st2"
			Log(state2)
			UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
			UdpS.Send(UdpP)
		End If
	Else If (str.CharAt(0) = "3" And str.CharAt(1) = "0" And str.CharAt(2) = "0") Then
		state3 = CInt(str) - 300000
		If (state3 = CInt(S3)) Then
			strCmd = "st4"
			Log(state3)
			UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
			UdpS.Send(UdpP)
		Else
			strCmd = "st3"
			Log(state3)
			UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
			UdpS.Send(UdpP)
		End If
	End If
End Sub

Sub imgeffect1_Click
	viber.Vibrate(50)
	
	number_effect=1
	strCmd = "1"
	UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
	UdpS.Send(UdpP)
End Sub

Sub imgEffect2_Click
	viber.Vibrate(50)
	
	number_effect=2
	strCmd = "2"
	UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
	UdpS.Send(UdpP)
End Sub

Sub imgEffect3_Click
	viber.Vibrate(50)
	
	number_effect=3
	strCmd = "3"
	UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
	UdpS.Send(UdpP)
End Sub

Sub SeekBarSpeed_ValueChanged (Value As Int, UserChanged As Boolean)
	Try
		If Value<10 Then
			strCmd = "000"&CStr(Value)
		Else if Value<100 Then
			strCmd = "00"&CStr(Value)
		else if Value<1000 Then
			strCmd = "0"&CStr(Value)
		Else
			strCmd = CStr(Value)
		End If
	
		lblSpeed.Text = CStr(Value)
		etSpeed.Text = CStr(Value)
		UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
		UdpS.Send(UdpP)
	Catch
		
	End Try
End Sub

Sub CStr(o As Object) As String
	Return "" & o
End Sub

Sub CInt(o As Object) As Int
	Return Floor(o)
End Sub

Sub CLng(o As Object) As Long
	Return Floor(o)
End Sub

Sub imgBack_Click
	viber.Vibrate(50)

	Dim num As Int
	num = number_effect
	num = num - 1
	If (num = 0) Then
		num = 1
	End If
	number_effect = num
	
	strCmd = CStr(number_effect)
	
	UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
	UdpS.Send(UdpP)
End Sub

Sub imgForward_Click
	viber.Vibrate(50)

	Dim num As Int
	num = number_effect
	num = num + 1
	If (num = 10) Then
		num = 9
	End If
	number_effect = num
	
	strCmd = CStr(number_effect)
	
	UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
	UdpS.Send(UdpP)
End Sub


Sub btnSpeed_Click
	Try
		Dim val As Int
		val = CInt(etSpeed.Text)
		If val<10 Then
			strCmd = "000"&CStr(val)
		Else if val<100 Then
			strCmd = "00"&CStr(val)
		else if val<1000 Then
			strCmd = "0"&CStr(val)
		Else
			strCmd = CStr(val)
		End If
	
		SeekBarSpeed.Value = val
		lblSpeed.Text = val

		UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
		UdpS.Send(UdpP)
	Catch
	End Try
End Sub

'-------------------------------------------------------------

Sub sp_e1_ItemClick (Position As Int, Value As Object)
	viber.Vibrate(50)
	
	Dim effect1 As String
	effect1 = sp_e1.GetItem(Position)
	lbl_e1.Text = effect1
	
	Dim effect_number_1 As String
	effect_number_1 = effect1.SubString(4)
	'ToastMessageShow(effect_number_1 , True)
	'-----------------------
	auto_effect_1 = CInt(effect_number_1)
	'-----------------------
End Sub

Sub sp_e2_ItemClick (Position As Int, Value As Object)
	viber.Vibrate(50)
	
	Dim effect2 As String
	effect2 = sp_e2.GetItem(Position)
	lbl_e2.Text = effect2
	
	Dim effect_number_2 As String
	effect_number_2 = effect2.SubString(4)
	'ToastMessageShow(effect_number_2 , True)
	'-----------------------
	auto_effect_2 = CInt(effect_number_2)
	'-----------------------
End Sub

Sub sp_e3_ItemClick (Position As Int, Value As Object)
	viber.Vibrate(50)
	
	Dim effect3 As String
	effect3 = sp_e3.GetItem(Position)
	lbl_e3.Text = effect3
	
	Dim effect_number_3 As String
	effect_number_3 = effect3.SubString(4)
	'ToastMessageShow(effect_number_3 , True)
	'-----------------------
	auto_effect_3 = CInt(effect_number_3)
	'-----------------------
End Sub

Sub sp_count_ItemClick (Position As Int, Value As Object)
	viber.Vibrate(50)
	
	Dim count As String
	count = sp_count.GetItem (Position)
	lbl_count.Text = count
	'-----------------------
	number_led = CInt(count)
	'-----------------------
	strCmd = "count,"&CStr(number_led)
	UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
	UdpS.Send(UdpP)
End Sub

Sub sp_effect_ItemClick (Position As Int, Value As Object)
	viber.Vibrate(50)
	
	Dim effect As String
	effect = sp_effect.GetItem(Position)
	lbl_effect.Text = effect
	
	Dim effect_number As String
	effect_number = effect.SubString(4)
	'ToastMessageShow(effect_number , True)
	'-----------------------
	number_effect = CInt(effect_number)
	'-----------------------
	strCmd = number_effect
	UdpP.Initialize(strCmd.GetBytes("ASCII"), ShrIP,ShrPort)
	UdpS.Send(UdpP)
End Sub