Wednesday, September 30, 2015

Multiple screens/pages အသံုးျပဳ ျခင္း

Multiple screens/pages အသံုးျပဳ ျခင္း

B4A မွာ Activity ေတြ ထပ္ထည့္ၿပီး Multiple screens အေနနဲ႔ သံုးခဲ့ၾကပါတယ္။ အခု BMP APK Creator 2.0 မွာ Main activity တခုပဲ အသံုးျပဳႏိုင္ပါေသးတယ္။ ကိုယ့္ရဲ့ app မွာ Multiple screens/pages သံုးခ်င္ရင္ Panels ေတြကို Base display အေနနဲ႔ Show/Hide လုပ္ၿပီး ဖန္တီးႏိုင္ပါတယ္။ ေအာက္က နမူနာ ပရိုဂရမ္ မွာ Two screens display အေနနဲ႔ သံုးျပထားပါတယ္။ Screen တခုကေန ေနာက္ screen တခုကို ကူးေျပာင္းဖို႔ Button တခုစီ ထည့္ျပထားပါတယ္။ Screen 2 ကေန Screen 1 ကို ေျပာင္းဖို႔ Button ကို ႏွိပ္ႏိုင္သလို ဖုန္းရဲ့ BACK_BUTTON ကိုလဲ ႏွိပ္ႏိုင္ပါတယ္။ Screen 1 မွာ BACK_BUTTON ကို ႏွိပ္ရင္ေတာ့ Activity Finish ျဖစ္သြားမွာ ျဖစ္ပါတယ္။ BACK_BUTTON ႏွိပ္တာကို သိႏိုင္ဖို႔ Events Sub အပိုင္းမွာ Sub Activity_KeyPress(key) နဲ႔ ဖမ္းရပါမယ္။ key=4 က BACK_BUTTON ျဖစ္ပါတယ္။

#######################
Main Code Section တြင္ ေရးရန္
#######################

AddPanel("pnl1", 0,0,100%x,100%y,"")
SetColor("pnl1",0,cGreen)

AddLabel("lbl1",10%x,30%y,80%x,20%y,"pnl1")
SetText("lbl1","This is screen 1")

AddButton("btn1",10%x,60%y,80%x,20%y,"pnl1")
SetText("btn1","Go to screen 2")

REM ********************************

AddPanel("pnl2", 0,0,100%x,100%y,"")
SetColor("pnl2",0,cRed)

AddLabel("lbl2",10%x,30%y,80%x,20%y,"pnl2")
SetText("lbl2","This is screen 2")

AddButton("btn2",10%x,60%y,80%x,20%y,"pnl2")
SetText("btn2","Go to screen 1")

SetVisible("pnl2",false)

current="pnl1"

#####################
Events and Subs Section တြင္ ေရးရန္
#####################

Sub Activity_KeyPress(key)
If key=4 Then
If current="pnl2" Then
current="pnl1"
Button_Click("btn2")
Else
ActivityFinish
End If
End If
End Sub

REM ********************************

Sub Button_Click(who)
Select who
Case "btn1"
SetVisible("pnl1",false)
SetVisible("pnl2",true)
current="pnl2"
Case "btn2"
SetVisible("pnl1",true)
SetVisible("pnl2",false)
current="pnl1"
End Select
End Sub

REM *******************************

သတိျပဳပါရန္
========

Sub Activity_KeyPress(key) ကို ထည့္လိုက္ရင္ BACK_BUTTON (=4) နဲ႔ MENU_BUTTON (=82) ကို code ေတြ ေရးေပးရပါမယ္။ MENU_BUTTON အတြက္ code မေရးခဲ့ ရင္ Menu ကို ေခၚလို႔မရေတာ့ပါဘူး။ ဒါကို ေျဖရွင္းႏိုင္ဖို႔ ေအာက္က code ကိုပါ ထည့္သြင္းေပးပါ။

REM in code section
REM --------------------
menuVisible=false

REM in Events & Subs section
REM --------------------------------

Sub Activity_KeyPress(key)
..
..
If key=82 Then
If menuVisible=false Then
menuVisible=true
OpenMenu
Else
menuVisible=false
CloseMenu
End If
End If
...
...
End Sub

Monday, September 28, 2015

Lesson 4

Lesson4 ListView , . . .
ListView က item တခုခ်င္းဆီ ကို List နဲ႕ျပေပးပီးေတာ့ Click တဲ႕အခါမွာ လည္း Item တခုခ်င္းကို ျပန္ပီး Get လုပ္ႏိုင္မယ္ သူ႕ကို ရိဳးရိဳး Add လုပ္ပီး Item ေတ ထည့္ႏိုင္သလို
FileReadList , FileListFiles ေတကေနလဲ List ေတကို ထည့္ႏိုင္ example မွာကေတာ့ရိဳးရိဳးပဲျပေတာ့မယ္။
-------------------- ဒါက View Panel >>>> -------------
'Add ListView to Activity -----------------------
AddListView("lv1",0,0,100%x,100%y,"")
SetColor("lv1",0, cGray)
'Add some Items to ListView -----------------
Add("lv1", "BMP")
Add("lv1", "IDE")
Add("lv1", "is Simple IDE")
Add("lv1", "For Android Apks.")
------------<<<< ဒါက Event Panel ---------------------
'Get Click Item-----------------------
Sub ListView_ItemClick(who, pos, value)
MsgBox(Value, "")
End Sub
example soucres - http://pc.cd/iz2rtalK



Lesson 3

Lesson 3 Input Functions. . .
lesson 2 မွာေတာ့ Activity ေပၚကို View ေတဘလို ေခၚထည့္ႏိုင္လဲဆိုတာကို ေျပာျပပီးပါပီ
Lesson 3 က ေတာ့ InputBox ေတကေန Value ေတကို ရယူႏိုင္တာကို ေျပာပါမယ္။
ံုပံုမွာ ေတာ့ View Panel မွာ Label တခုရယ္ Button တခုရယ္ကို ထည့္ေပးထားပါတယ္။ Event Panel ကို သြားရင္ Button Click မွာ
InputBox တခုနဲ႕ျပခိုင္းပီးေတာ့ ရလာတဲ႕ GetInput ကို
Label ရဲ႕ စာသားေနရာမွာ လွမ္းသံုးေပးတာကို ျမင္ႏိုင္ပါတယ္။
GetText တို႕နဲ႕
InPutBox အေၾကာင္းေတကို ေတာ့ App ထဲက Guide ေတမွာ ဖတ္ႏိုင္ပါတယ္။
if u need example sources - http://pc.cd/uV2rtalK



---------------------------------------------
Basic4Android Myanmar Programmers

Lesson 2

BMP IDE
Add Views to Activity - Add Buttons ---
---------------------------------------------------------

AddButton(Name, Left, Top, Width, Height, "")

View ေတကို Activity ထဲမွာ ထည့္သြင္းတဲ႕အခါ View ေတရဲ႕ Layout ကို အေပၚမွာ ျပေပးထားတျ႕အတိုင္း သက္မွတ္ရပါတယ္။ View တိုင္း ဒီပံုစံပါပဲ။
left = Screen ကေန View ရဲ႕ ဘယ္ဘက္ႏွခမ္း အကြာအေ၀းး
Top = Screen ကေန View ရဲ႕ အေပၚႏွခမ္း အကြာအေ၀းး
Width = view ရဲ႕ အက်ယ္ နဲ႕
Height = View ရဲ႕ အျမင့္ပါ။
ဒီေတာ့ Button3 ခုကို ေအာက္က အတိုင္းထည့္လိုက္ပါမယ္။

AddButton("btn1", 10%x, 10%y, 80%x, 10%y, "")
AddButton("btn2", 10%x, 20%y, 80%x, 10%y, "")
AddButton("btn3", 10%x, 30%y, 80%x, 10%y, "")
btn1,btn2,btn3 ေတကေတာ့ Button Name ေတပါ။ Top ေတကို 10%y ဆီ တိုးတိုးပီး ခြါသြားတာကို ၾကည့္ပါ။
အခု တိုင္း Run ၾကည့္ရင္ Button 3 ခုကို Screen ေပၚမွာ ျမင္ႏိုင္ပါၿပီ။
ေနာက္ Button ေတအတြက္ စာေလးေတ သက္မွတ္ေပးပါမယ္

SetText("btn1" , "Click Me 1")
SetText("btn2" , "Click Me 2")
SetText("btn3" , "Click Me 3")
SetText က ေရွ႕မွာေတာ့ View ရဲ႕ Name နဲ႕ ေနာက္မွာက မိမိေရးခ်င္းတဲ႕ စာ ဆိုတာ ကို ၾကည့္ပါ့။
အခုအတိုင္း Run ရင္ Button3 ခုမွာ စာေလးေတပါ ပါလာပါၿပီ၊
ေနာက္ Click အတြက္ပဲ က်န္ပါၿပီ။
Event Panel ထဲကို Slide လုပ္ပီးသြားလိုက္ပါ။
------------------------------------------
Sub Button_Click(Who)
End Sub
-------------------- အခုလို ေ၇းထားတဲ႕ event တခုကို ေတြ႕ရပါမယ္။ သူကေတာ့ Button ေတကို Click လုပ္ရင္
လာပီး သက္ေရာကိတဲ႕ ေနရာပါ။(Who) ကေတာ့ မိမိ Click လိုက္တဲ႕ Button Name ကို ျပေပးပါလိမ့္မယ္
အာ့ေတာ့ အာ့ Event ထဲမွာ အခု လိုေရးလိုက္ပါ။

Sub Button_Click(Who)
Select Who
Case "btn1"
MsgBox("Button 1" , "You Clicked")
Case "btn2"
MsgBox("Button 2" , "You Clicked")
Case "btn3"
MsgBox("Button 3" , "You Clicked")
End Select
End Sub
အခုတိုင္းေရးပီး Run လိုက္ရင္ Button ေတကို Click တဲ႕ အခါ ေရၚထားတဲ႕ အတိုင္း Msgbox သံုးခု button အလိုက္ျပေပးမွာပါ။
button ေတကို Click ရင္ ဒီေနရာကို သက္ရာပါတယ္။ Click လိုက္တဲ႕ Button ရဲ႕ Name ဟာ (ၽWho) ဆီကို လာျပပါတယ္။
ဒါေၾကာင့္ Select Who နဲ႕ စစ္လိုက္ပီး btn1 ဆို ဘာျပ btn2 ဆို ဘာျပ ။
ဒီလို တခုခ်င္းခိုင္းလိုက္တာပါပဲ။
Select နဲ႕ စပီးရင္ ေနာက္မွာ End Select နဲ႕ ျပန္ပိတ္ရပါတယ္။
try ၾကည့္လိုက္ပါ။

Example Project - http://pc.cd/REBrtalK



-----------------------------------------------------------------------------------
Basic4Android Myanmar Programmers
www.facebook.com/groups/316136215260862/

Lesson 1

How to Create your First Program with 
BMP IDE ?
ပထမဆံုး Project အတြက္ 
BMP ကို ဖြင့္လိုက္ပါ။ 
This is a View Panel >>>>> 
ဆိုတဲ႕စာေလးေတြ႕ရပါမယ္။ဒါကို ညာဘက္ကို Slide ရင္
<<<<< This is a Event Panel ကိုေရာက္ပါတယ္။
View Panel ထဲမွာပဲေနလိုက္ပါ။အာ့ထဲမွာ အခုလို႕ရိဳက္ထည့္လိုက္ပါ။
Msgbox("Hello All " , "Greeting")
ဒါေလးတေၾကာင္းရိဳက္ထည့္ပီး Run လိုက္ပါ။
မိမိ app မွာ Android MessageBox ေလးကို ျမင္ရပါမယ္။
Msgboxသည္ ("Message" , "Title") 
ဒီပံုစံပါ။ ဒါေလးေရးပီး Run ဖို႕မခက္ခဲေလာက္ပါဘူးေနာ္။
example ကိုလည္း ဒီမွာေဒါင္းႏိုင္ပါတယ္။
lesson1 - http://pc.cd/jKBrtalK
အဲ project ေတ ဘလို ယူစမ္းသံုးရမလဲဆိုရင္ 
Tool >> importProject ႏွိပ္ပါ။ မိမိ import လုပ္ခ်င္တဲ႕ 
Project.src ဖိုင္ကိုေရြးေပးပီး Ok ႏွိပ္ရင္ရပါၿပီ။