Thursday, October 29, 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 --------------------
showMenu=true
REM set it to false if you don't want to show menu.

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

Sub Activity_KeyPress(key)
..
..
If key=82 Then
    If showMenu=true Then
        OpenMenu
    End If
End If
...
...
End Sub

Wednesday, October 28, 2015

Text Editor Sample project

Text editor တခု ေရးၾကမယ္

New, Open, Save ၃ မ်ိဳးပါတဲ့ Text editor တခုေရးျပထားပါတယ္။ အလြယ္ကူဆံုး ျဖစ္ေအာင္ txt ဖိုင္ကို FileDirRootExternal directory မွာ ပံုေသ ထားထားပါတယ္။ Code ေတြကို    နားလည္ေအာင္ ဖတ္ပါ။ ထပ္မံ ခ်ဲ႕ထြင္ၾကည့္ပါ။

================
Views Panel
================

dim f(0)
Dir=FileDirRootExternal
fname="Untitled.txt"
Setactivitytitle(fname)

AddPanel("pnlOpen",0,0,100%x,100%y,"")
AddListView("lv",0,0,100%x,100%y,"pnlOpen")
SetVisible("pnlOpen",false)

AddPanel("pnlEditor",0,0,100%x,100%y,"")
AddEditText("et",0,0,100%x,100%y,"pnlEditor")

AddMenuItem("New")
AddMenuItem("Open")
AddMenuItem("Save")

================
Events Panel
================

Sub Activity_Pause(UserClosed)
End Sub

Sub Activity_Resume
End Sub

Sub ListView_ItemClick(who, pos, value)

if StringEndsWith(value,".txt") then
str=FileReadString(Dir,value)
fname=value
SetActivityTitle(fname)
SetText("et",str)
SetVisible("pnlOpen",false)
SetVisible("pnlEditor",true)
end if

End Sub

Sub Menu_Click(Which)
select which

case "New"

SetText("et","")
fname="Untitled.txt"
SetActivityTitle(fname)

case "Open"

clear("lv")
FileListFiles(Dir,"f")
AddAll("lv","f")
SetVisible("pnlOpen",true)
SetVisible("pnlEditor",false)

case "Save"

a=inputBox("Enter File name to be saved.","Save File","OK","Cancel","")
if a=-1 then
fname=GetInput
SetActivityTitle(fname)
FileWriteString(Dir,fname,getText("et"))
ShowToast("File saved successfully",false)
end if
end select

end sub

Sub Edit_Change(Who, Old, New)
End Sub
Sub Edit_enterpressed(who)
End Sub

================

Tuesday, October 27, 2015

Scroll view

ScrollView ထည့္ျခင္း

ScrollView ထဲမွာ 30 buttons ထည့္ျပထားပါတယ္။

1. AddScrollView(scrollViewName,left,top,width,height,parent)

2. GetPanel(scrollViewName,panelName)

3. SetHeight(panelName,heightValue)
ကိုယ္ထည့္မဲ့ view ေတြ အတြက္ လံုေလာက္တဲ့ height ကို သတ္မွတ္ေပးပါ။

4. panelName ထဲကို ကိုယ္ႀကိဳ က္တဲ့ view ေတြ ထည့္ပါ။

=======================

AddscrollView("scr",0,0,100%x,100%y,"")
getPanel("scr","pnl")
Setheight("pnl",30*10%y)

for i=0 to 29
AddButton("btn" & i, 10%x, i*10%y, 80%x, 10%y, "pnl")
SetText("btn" & i,"Button " & i)
next

==============

Wednesday, October 21, 2015

Sliding panel

BMP IDE နဲ႔ Sliding Panel တခု ေရးျပထားပါတယ္။ Drag လုပ္ၾကည့္ႏိုင္ပါတယ္။  :)

===============
Main
===============
in=0-windowwidth/2+50
Visible=50
pwidth=windowwidth/2

AddPanel("pnl1",in,0,pwidth,windowheight,"")
SetColor("pnl1",0,cyellow )

AddLabel("lbl1",10,100,300,100,"pnl1")
SetText("lbl1","Sliding Panel")

AddButton("btn1",10,200,300,100,"pnl1")
SetText("btn1","Click me")

dx=0
dy=0
draggable=false
oldl=in
newl=0

AddLabel("lbl2",287,495,348,217,"")
SetText("lbl2","Label in main activity")

AddButton("btn2",287,205,307,124,"")
SetText("btn2","Click me")

===============
Events
===============
Sub Activity_Pause(UserClosed)
End Sub

Sub Activity_Resume
End Sub

sub activity_touch(action,tx,ty)

select action

case 0
if tx< Visible then
draggable=true
dx=tx
end if

case 1
draggable=false

case 2
if draggable=true then
oldl=getleft("pnl1")
newl=oldl+tx-dx
if newl>0 then
newl=0
end if
if newl<in then
newl=in
end if
Visible=pwidth-newl
Setleft("pnl1",newl)

end if

end select

end sub

Sub Button_Click(Who)
select who
case "btn1"
MsgBox("You clicked the Button in sliding Panel","")
case "btn2"
MsgBox("You clicked the Button in main activity","")
end select
End Sub
==================

Mathematical Flower

BMP IDE ကို အသံုးျပဳ ၿပီး Mathematical Flower ေလး တခု ေရးဆြဲၾကည့္ရေအာင္။  :)

=================
Main
=================

Addimage("img",0,0,windowwidth,windowheight-50,"")

AddLabel("lbl",0,windowheight-50,windowwidth,50,"")
SetText("lbl","Mathematical Flower by Nyi Nyi Lwin")

canvasinit("img")
drawColor(cyellow)

centerx=windowwidth/2
centery=windowheight/2

x=0
y=0
a=0
a2=0
a3=0

b=0
r=0
g=0
col=0

SetTimerInterval(10)
SetTimerEnabled(true)

=============
Events
=============
Sub Activity_Pause(UserClosed)
End Sub

Sub Activity_Resume
End Sub

Sub Timer_Tick

a=a+0.01
a2=a2+0.06
a3=a3+0.09

if a>6.28 then
a=0
end if

if a2>6.28 then
a2=0
end if

if a3>6.28 then
a3=0
end if

x=sin(a)*200+cos(a2)*100+centerx
y=cos(a)*200+sin(a2)*100+centery

r=128+sin(a)*127

g=128+sin(a2)*127

b=128+sin(a3)*127

col=argb(255,r,g,b)

drawcircle(x,y,50,col,true,1)
invalidate("img")

End Sub

==============

Monday, October 19, 2015

Alpha Brainwave

Alpha Brainwave

လူ႔ ဦးေႏွာက္မွာ သူ႔စိတ္အေျခအေန ေပၚ မူတည္ၿပီး လွ်ပ္စစ္ သံလိုက္လိႈင္းေတြ ျဖစ္ေပၚေနပါတယ္။ Frequency က တစကၠန္႔ကို ၃ ႀကိမ္ကေန ၃၀ ေလာက္ထိ အမ်ိဳးမ်ိဳး ျဖစ္ႏိုင္ပါတယ္။ တရားထိုင္ေနစဥ္ ကာလမွာ တစကၠန္႔ကို ၇ ႀကိမ္ေလာက္ရွိၿပီး ဒါကို Alpha Brainwave လို႔ ေခၚပါတယ္။ စိတ္တည္ၿငိမ္ ေအးခ်မ္းေနတဲ့ အေျခအေန ျဖစ္ပါတယ္။ ကြန္ပ်ဴ တာ ၊ android အကူအညီနဲ႔ ဒီလို စိတ္အေျခအေနမ်ိဳ း ျဖစ္ေပၚလာေအာင္ အျမင္အာရံု၊ အၾကားအာရံုနဲ႔ လံႈ႕ေဆာ္လို႔ ရပါတယ္။

7Hz ရွိတဲ့ အေရာင္လိႈင္းနဲ႔ ဦးေႏွာက္ကို train လုပ္ဖို႔  BMP IDE နဲ႔ နမူနာ program တခု ေရးျပလိုက္ပါတယ္။

စိတ္ေအးလက္ေအး စူးစိုက္ၿပီး ၾကည့္ၾကည့္ပါ။ :)

====================
Main
====================
AddPanel("pnl",0,0,windowwidth,windowheight,"")

dim cols(4)
a=0

SetTimerEnabled("true")
SetTimerInterval( 143)

===================
Events
===================

Sub Activity_Pause(UserClosed)
End Sub

Sub Activity_Resume
End Sub

Sub Timer_Tick
a=a+1
if a=4 then
a=0
end if

select a

case 0
cols(0)=cwhite
cols(1)=Cred
cols(2)=Cgreen
cols(3)=Cblue

case 1
cols(0)=cgreen
cols(1)=Cblue
cols(2)=Cwhite
cols(3)=Cred

case 2
cols(0)=cred
cols(1)=Cgreen
cols(2)=cblue
cols(3)=Cwhite

case 3
cols(0)=cwhite
cols(1)=CGreen
cols(2)=CBLUE
cols(3)=Cred

end select
SetBackground( "pnl","TOP_BOTTOM",0,"cols")
invalidate("pnl")

End Sub

======================

မဟာဘုတ္​​ေဗဒင္​ project

ျမန္မာေမြးသကၠရာဇ္ နဲ႔ ေမြးေန႔အရ ဘယ္ မဟာဘုတ္ အဖြားလဲဆိုတာကို BMP IDE နဲ႔ နမူနာ ေရးျပထားပါတယ္။

======================
Views Panel တြင္ ေရးရန္
======================

AddLabel("lbl1",0,100,720,131,"")
SetText("lbl1","Maha Bote" )

AddLabel("lbl2",0,281,348,117,"")
SetText("lbl2","Burmese birth year" )

AddLabel("lbl3",0,434,348,110,"")
SetText("lbl3","Select birth day" )

AddEditText("edt1",376,280,344,120,"")

AddSpinner("spn1",375,436,345,113,"")
Add( "spn1","Sunday")
Add( "spn1","Monday")
Add( "spn1","Tuesday")
Add( "spn1","Wednesday")
Add( "spn1","Thursday")
Add( "spn1","Friday")
Add( "spn1","Saturday")

AddButton("btn1",181,609,387,112,"")
SetText( "btn1","Calculate")

AddLabel("lbl4",0,772,720,284,"")

==========================
Events Panel တြင္ ေရးရန္
==========================

Sub Activity_Pause(UserClosed)
End Sub

Sub Activity_Resume
End Sub

Sub Spinner_ItemClick(who, pos, value)
End Sub

Sub Button_Click(Who)
y=GetText("edt1")

out=y

wh:
y=y-7
if y>7 then
goto wh
end if

if y=0 then
y=7
end if
e=Getselectedindex("spn1")+1

out=out & "/" & getselectEdItem("spn1") & " --> "

if y=e then
h="Binga"
else if y=e+3 or y=e-4 then
h="Adipati"
else if y=e+6 or y=e-1 then
h="Puti"
else if y=e+2 or y=e-5 then
h="Yarza"
else if y=e+5 or y=e-2 then
h="Thike"
else if y=e+1 or y=e-6 then
h="Ahtun"
else if y=e+4 or y=e-3 then
h="Marana"
end if

SetText("lbl4",out & h)
End Sub

Sub Edit_Change(Who, Old, New)
End Sub
Sub Edit_enterpressed(who)
End Sub

=====================

မဟာဘုတ္ ေဗဒင္ apk တခုအျဖစ္ ခ်ဲ႕ထြင္ ဖန္တီးၾကည့္ပါ။ :)