Type=Activity
Version=4.3
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
#Region Module Attributes
	#FullScreen: True
	#IncludeTitle: False
#End Region
'در این قسمت کودک میتواند با جدول ضرب کار کند
 'Activity module
Sub Process_Globals
Dim defaultLang As String
End Sub

Sub Globals
Dim imgBG As ImageView
Dim btnNumber(11) As  Button 
Dim myColor(11) As ColorDrawable
Dim lblTitle,lblResult,lblMenu,lblAbout,lblSetting,lblSound As Label
Dim num1 As Int
Dim blnNumber1 As Boolean
Dim tmr As Timer
Dim res,num1,num2 As Int
Dim media As MediaPlayer
Dim arrInt(11) As String
Dim lblExpersion As Label
Dim bgMedia As MediaPlayer 
Dim spinner1 As Spinner
Dim x1,y1 As Int
Dim lv As LayoutValues
Dim ck2 As CheckBox
Dim sResults As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
lv = GetDeviceLayoutValues
loadColor
Activity.RemoveAllViews
blnNumber1 = False
For i=0 To 10
	arrInt(i) = i
Next
'If loadSetting("Random") = True Then
 ShuffleArray(arrInt)
'End If
 defaultLang = "fa"
initializeComponent
LoadButton
media.Initialize2("mp2")
loadMenu
End Sub
Sub loadMenu
Activity.AddMenuItem2("تنظیمات","btnsetting",LoadBitmap(File.DirAssets,"setting.png"))
Activity.AddMenuItem2("درباره ما","btnabout",LoadBitmap(File.DirAssets,"about.png"))
Activity.AddMenuItem2("خروج","exit1",LoadBitmap(File.DirAssets,"exit.png"))
End Sub
Sub btnsetting_Click
Activity.Finish
StartActivity(setting)
End Sub
Sub btnabout_Click
Activity.Finish
StartActivity(frmabout)
End Sub
Sub exit1_Click
Dim i As Int
i = Msgbox2("آیا مایل به خروج هستید؟","خروج","آری","خیر","",Null)
If i = DialogResponse.POSITIVE Then
 ExitApplication
End If
End Sub
Sub ShuffleArray(arr() As String)
Dim n As Int = arr.Length-1
Dim r As Int
Dim t As String
For i = 0 To n - 1
    r = Rnd(i, n)
    t = arr(i)
    arr(i) = arr(r)
    arr(r) = t
Next
Return arr
End Sub
Sub ShuffleColor(arr() As ColorDrawable)
Dim n As Int = arr.Length-1
Dim r As Int
Dim t As ColorDrawable
For i = 0 To n - 1
    r = Rnd(i, n)
    t = arr(i)
    arr(i) = arr(r)
    arr(r) = t
Next
Return arr
End Sub
Sub loadColor
Dim map1 As Map
Dim R,G,B As Int
Dim sColor,sKey As String
map1.Initialize
Reset_Setting
map1 = File.ReadMap(File.DirInternal,"setting.map")
For i = 0 To 10
 sKey = i
 If map1.Get(sKey) <> Null Then
   sColor = map1.Get(sKey)
 Else
   sColor = "255239254" 
 End If
 If sColor.Length = 8 Then
  sColor = sColor & "0"
 Else If sColor.Length = 7 Then
  sColor = sColor & "00"
 End If
 R = sColor.SubString2(0,3)
 G = sColor.SubString2(3,6)
 B = sColor.SubString2(6,9)
 myColor(i).Initialize(Colors.RGB(R,G,B),8)
Next
End Sub
Sub loadCheckbox
ck2.Initialize("chk1")
ck2.Text = "خودم به سوال پاسخ میدهم"
ck2.TextSize = ck2.TextSize + 5
ck2.TextColor = Colors.Black
Activity.AddView(ck2,5%x,69%y,90%x,50dip)
End Sub
Sub ck2_CheckedChange(Checked As Boolean)
 If Checked = True Then

 End If
End Sub
Sub initializeComponent
Dim gc As GradientDrawable
Dim clr(4),fontAdjust As Int
clr(0) = Colors.RGB(245,212,243)
clr(1) = Colors.RGB(205,45,197)
clr(2) = Colors.RGB(243,229,242)
clr(3) = Colors.RGB(224,161,221)
gc.Initialize("TOP_BOTTOM",clr)
gc.CornerRadius = 20dip
Activity.Background = gc
Activity.Color = Colors.RGB(231,231,231)
Activity.SetBackgroundImage(LoadBitmap(File.DirAssets,"login.jpg"))
'-------------------------------------
'Load Label Title
lblTitle.Initialize("")
lblTitle.Text = "·I¨j¼¨ Jo† Ï»k]"
fontAdjust = ((100%x + 100%y) / (320dip + 480dip) - 1) * 3
lblTitle.TextSize = lblTitle.TextSize + 5
lblTitle.TextColor = Colors.Black
lblTitle.Gravity = Gravity.RIGHT
lblTitle.Typeface = Typeface.LoadFromAssets("nj_nazani.ttf")
Activity.AddView(lblTitle,0dip,15dip,88%x,115dip)
'-------------------------------------
'Load Label Result
lblExpersion.Initialize("")
lblExpersion.TextSize = lblExpersion.TextSize + fontAdjust + 6dip
lblExpersion.TextColor = Colors.Black
If defaultLang = "fa" Then
  lblExpersion.Gravity = Gravity.RIGHT
  lblExpersion.Typeface = Typeface.LoadFromAssets("nj_nazani.ttf")
  Activity.AddView(lblExpersion,1%x,56dip,80%x,40dip)
 Else
  lblExpersion.Gravity = Gravity.LEFT
  Activity.AddView(lblExpersion,28%x,56dip,80%x,40dip)
End If
'-------------------------------------
'Load Label Expersion
lblResult.Initialize("")
lblResult.TextColor = Colors.Blue
lblResult.TextSize = lblResult.TextSize + fontAdjust + 5dip
If defaultLang = "fa" Then
  lblResult.Text = ": ¾\ÃTº"
  lblResult.Typeface = Typeface.LoadFromAssets("nj_nazani.ttf")
  Activity.AddView(lblResult,82%x,56dip,140dip,50dip)
Else
  lblResult.Text = "Result: "
  Activity.AddView(lblResult,4%x,56dip,140dip,50dip)
End If  
'-------------------------------------
End Sub
Sub LoadButton
'Load Button
Dim iLeft As Double 
Dim iTop As Double
Dim res,fontAdjust As Int 
Dim i As Int 
iLeft = 10%x
iTop  = 19%y
fontAdjust = ((100%x + 100%y) / (320dip + 480dip) - 1) * 3
loadColor
For i = 0 To 10
 btnNumber(i).Initialize("btnNumber")
 btnNumber(i).Background = myColor(i)
 btnNumber(i).TextColor = Colors.Black
 btnNumber(i).TextSize = btnNumber(i).TextSize + 11
 If defaultLang = "fa" Then
   btnNumber(i).Typeface =  Typeface.LoadFromAssets("nj_nazani.ttf")
 End If
 res = arrInt(i) + 1
 btnNumber(i).Tag  = res
 btnNumber(i).Text = res
 If i <> 0 Then 
	 If i Mod 3 = 0 Then
	  iLeft = 10%x
	  iTop  = iTop + 14%y
	 End If
 End If
 Activity.AddView(btnNumber(i),iLeft,iTop,20%x,12%y)
  iLeft = iLeft + 29%x
Next
btnNumber(10).Text = "0"
btnNumber(10).Tag = "0"
End Sub
Sub RemoveButton
For i=0 To 10
btnNumber(i).RemoveView
Next
End Sub
Sub btnNumber_Click
Dim button1 As Button
Dim thr As Thread
button1 = Sender
button1.Color = Colors.Blue
playAudio(button1.Tag)
If blnNumber1 = False Then
 lblExpersion.Text = ""
 lblExpersion.TextColor = Colors.Black
    If defaultLang = "fa" Then
      lblExpersion.Text = " nkMo† " & button1.Text
	Else
	  lblExpersion.Text = button1.Text & " Plus "
	End If	
 num1 = button1.Text
 blnNumber1 = True
Else
 If defaultLang = "fa" Then
   lblExpersion.Text =  " j¼zÃ¶ " & button1.Tag & lblExpersion.Text 
 Else
   lblExpersion.Text =  lblExpersion.Text  & button1.Tag & " Is "
 End If
 tmr.Initialize("tmr",800)
 num2 = button1.Tag
 res = num1 * button1.Tag
 tmr.Enabled = True
 blnNumber1 = False
End If
End Sub
Sub tmr_Tick
 lblExpersion.Text =  res & lblExpersion.Text
 playAudio(res)
 res = 0
If loadSetting("Random") = True Then 
 ShuffleArray(arrInt)
 ShuffleColor(myColor)
End If
 RemoveButton
 LoadButton
 ProgressDialogHide
 tmr.Enabled = False
End Sub
Sub playAudio(sNumber As String)
Dim sFilename As String
Dim threat1 As Thread
Dim i,j As Int
Try
	If (sNumber Mod 10 = 0) Then
	 sFilename = sNumber & ".mp3"
	 media.Load(File.DirAssets,defaultLang & "_" &sFilename)
	 media.Play
	Return
	End If
	If sNumber > 19 Then
		 i = sNumber Mod 10
		 j = Floor((sNumber / 10)) * 10
		 sFilename = j & "_.mp3"
		 media.Load(File.DirAssets,defaultLang & "_" & sFilename)
		 media.Play
		 threat1.Sleep(700)
		 sFilename = i & ".mp3"
		 media.Load(File.DirAssets,defaultLang & "_" & sFilename)
		 media.Play 
	Else
		 sFilename = sNumber & ".mp3"
		 media.Load(File.DirAssets,defaultLang & "_" & sFilename)
		 media.Play
	End If
Catch
Msgbox("این قابلیت در نسخه بعدی فعال خواهد شد","خطا")
End Try
End Sub
Sub lblMenu_Click
 Dim i As Int
 i = Msgbox2("آیا مایل به خروج هستید؟","خروج","بله متاسفانه","نه خوشبختانه","",Null)
 If i = DialogResponse.POSITIVE Then
  Activity.Finish
 End If
End Sub
Sub btnLanguage_Click
defaultLang = "en"
RemoveButton
initializeComponent
LoadButton
End Sub
Sub loadSetting(key As String)
Dim map1 As Map
Reset_Setting
map1.Initialize
map1 = File.ReadMap(File.DirInternal,"setting.map")
Return map1.Get(key)
End Sub
Sub Reset_Setting
Dim map1 As Map
If Not (File.Exists(File.DirInternal,"setting.map")) Then
 map1.Initialize
 map1.Put("bgSound","off")
 map1.Put("Random","false")
 map1.Put("Language","fa")
 map1.Put("1","151217255")
 map1.Put("2","251243158")
 map1.Put("3","195150215")
 map1.Put("4","240143178")
 map1.Put("5","215155055")
 map1.Put("6","000255246")
 map1.Put("7","151217255")
 map1.Put("8","129247190")
 map1.Put("9","247212129")
 map1.Put("10","221129247")
 map1.Put("0","129247240")
 'map1.Put("bgSound","on")
 'map1.Put("Random","false")
 'map1.Put("Language","fa")
 'map1.Put("1", "255239254")
 'map1.Put("2", "255239254")
 'map1.Put("3", "255239254")
 'map1.Put("4", "255239254")
 'map1.Put("5", "255239254")
 'map1.Put("6", "255239254")
 'map1.Put("7", "255239254")
 'map1.Put("8", "255239254")
 'map1.Put("9", "255239254")
 'map1.Put("10","255239254")
 'map1.Put("0", "255239254")
 File.WriteMap(File.DirInternal,"setting.map",map1)
End If
End Sub
Sub Activity_Resume
Activity_Create(False)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
  If KeyCode = KeyCodes.KEYCODE_BACK Then
   Activity.Finish
   StartActivity(Main)
  End If
  If KeyCode = KeyCodes.KEYCODE_MENU Then
   Activity.OpenMenu
  End If
End Sub