[Q][Solved] How to detect the orientation on program start and redraw controls
Hello all,
I am starting my adventure with Basic4PPC by trying to develop a simple application which is supposed to show a fulscreen set of 24 ImageButtons (each with different function) on a 480x800 device.
The problem is that the arrangement of the ImageButtons must be different for Portrait and for Landscape mode. For fullscreen and resize options I tried to use the FormLib library.
Now I've faced a first question: How to detect what Orientation my device has at very program start. I want to do it yet before the Form1 is showed, but on the other hand the only condition I can use is "Form1.Width<Form1.Height" which means (unless I am too stupid) that the Form1 has to be showed already.
Assuming that I can retrieve the resolution information somehow (or some of you will help me to do it) I still don't know what can I do later. I think it would be better to use just one Form for both orientations and only redraw it with different ImageButtons arrangement for each Portrait or Landscape.
That is because for each of the controls I have to define 2 events (ButtonUp and Down). Furthermore I can't change the size of the Form in the designer, and the ScreenSize defined in Tools affects all Forms at once. But that's another problem and I've already read why is it like that.
I tried to write a little sample with 4 icons and 4 texts (just for a starter) but trying to run this program gives me lots of errors like "Input string was not in a correct format" in each of the lines inside my "Ifs".
In the designer I created only 1 empty form with black background and no Controls as I have to (or I want to) add the controls according to an orientation.
Can you guys at least tell me if I am going in the right direction? Or my thinking sucks completely?
Here's the sample:
Hello all,
I am starting my adventure with Basic4PPC by trying to develop a simple application which is supposed to show a fulscreen set of 24 ImageButtons (each with different function) on a 480x800 device.
The problem is that the arrangement of the ImageButtons must be different for Portrait and for Landscape mode. For fullscreen and resize options I tried to use the FormLib library.
Now I've faced a first question: How to detect what Orientation my device has at very program start. I want to do it yet before the Form1 is showed, but on the other hand the only condition I can use is "Form1.Width<Form1.Height" which means (unless I am too stupid) that the Form1 has to be showed already.
Assuming that I can retrieve the resolution information somehow (or some of you will help me to do it) I still don't know what can I do later. I think it would be better to use just one Form for both orientations and only redraw it with different ImageButtons arrangement for each Portrait or Landscape.
That is because for each of the controls I have to define 2 events (ButtonUp and Down). Furthermore I can't change the size of the Form in the designer, and the ScreenSize defined in Tools affects all Forms at once. But that's another problem and I've already read why is it like that.
I tried to write a little sample with 4 icons and 4 texts (just for a starter) but trying to run this program gives me lots of errors like "Input string was not in a correct format" in each of the lines inside my "Ifs".
In the designer I created only 1 empty form with black background and no Controls as I have to (or I want to) add the controls according to an orientation.
Can you guys at least tell me if I am going in the right direction? Or my thinking sucks completely?
Here's the sample:
B4X:
Sub Globals
'Declare the global variables here.
End Sub
Sub App_Start
Form1.Show
flb.New1("Form1",B4PObject(1))
flb.FullScreen(cPPC)
If Form1.Width<Form1.Height Then
'Portrait
Form1.Width=480;
Form1.Height=800
Form1.refresh
AddImageButton("Form1","ImageButton8",25,305,115,30,"Contact",0,0,0,215,215,215,"cCenterImage","",False,False,True,11)
AddImageButton("Form1","ImageButton7",20,180,120,120,"",212,208,200,0,0,0,"cCenterImage","Contact.png",False,True,True,9)
AddImageButton("form1","ImageButton6",335,145,115,30,"MMS",0,0,0,215,215,215,"cCenterImage","",False,False,True,11)
AddImageButton("form1","ImageButton5",180,145,115,30,"SMS",0,0,0,215,215,215,"cCenterImage","",False,False,True,11)
AddImageButton("form1","ImageButton4",20,145,115,30,"E-mail",0,0,0,215,215,215,"cCenterImage","",False,False,True,11)
AddImageButton("form1","ImageButton3",335,20,120,120,"",212,208,200,0,0,0,"cCenterImage","MMS.png",False,True,True,9)
AddImageButton("form1","ImageButton2",180,20,120,120,"",212,208,200,0,0,0,"cCenterImage","SMS.png",False,True,True,9)
AddImageButton("form1","ImageButton1",20,20,120,120,"",212,208,200,0,0,0,"cCenterImage","Mail.png",False,True,True,9)
Else
'Landscape
Form1.Width=800
Form1.Height=480
Form1.refresh
AddImageButton("form1","ImageButton8",455,155,120,30,"Contact",212,208,200,215,215,215,"cCenterImage","",True,True,True,11)
AddImageButton("form1","ImageButton6",310,150,120,30,"MMS",212,208,200,215,215,215,"cCenterImage","",True,True,True,11)
AddImageButton("form1","ImageButton5",165,150,120,30,"SMS",212,208,200,215,215,215,"cCenterImage","",True,True,True,11)
AddImageButton("form1","ImageButton4",20,150,120,30,"E-mail",212,208,200,215,215,215,"cCenterImage","",True,True,True,11)
AddImageButton("form1","ImageButton7",455,20,120,120,"",212,208,200,0,0,0,"cCenterImage","Contact.png",False,True,True,9)
AddImageButton("form1","ImageButton3",310,20,120,120,"",212,208,200,0,0,0,"cCenterImage","MMS.png",False,True,True,9)
AddImageButton("form1","ImageButton2",165,20,120,120,"",212,208,200,0,0,0,"cCenterImage","SMS.png",False,True,True,9)
AddImageButton("form1","ImageButton1",20,20,120,120,"",212,208,200,0,0,0,"cCenterImage","Mail.png",False,True,True,9)
End If
End Sub
Sub fl_Resize
If Form1.Width<Form1.Height Then
'Portrait
Form1.Width=480
Form1.Height=800
Form1.refresh
AddImageButton("Form1","ImageButton8",25,305,115,30,"Contact",0,0,0,215,215,215,"cCenterImage","",False,False,True,11)
AddImageButton("Form1","ImageButton7",20,180,120,120,"",212,208,200,0,0,0,"cCenterImage","Contact.png",False,True,True,9)
AddImageButton("form1","ImageButton6",335,145,115,30,"MMS",0,0,0,215,215,215,"cCenterImage","",False,False,True,11)
AddImageButton("form1","ImageButton5",180,145,115,30,"SMS",0,0,0,215,215,215,"cCenterImage","",False,False,True,11)
AddImageButton("form1","ImageButton4",20,145,115,30,"E-mail",0,0,0,215,215,215,"cCenterImage","",False,False,True,11)
AddImageButton("form1","ImageButton3",335,20,120,120,"",212,208,200,0,0,0,"cCenterImage","MMS.png",False,True,True,9)
AddImageButton("form1","ImageButton2",180,20,120,120,"",212,208,200,0,0,0,"cCenterImage","SMS.png",False,True,True,9)
AddImageButton("form1","ImageButton1",20,20,120,120,"",212,208,200,0,0,0,"cCenterImage","Mail.png",False,True,True,9)
Else
'Landscape
Form1.Width=800
Form1.Height=480
Form1.refresh
AddImageButton("form1","ImageButton8",455,155,120,30,"Contact",212,208,200,215,215,215,"cCenterImage","",True,True,True,11)
AddImageButton("form1","ImageButton6",310,150,120,30,"MMS",212,208,200,215,215,215,"cCenterImage","",True,True,True,11)
AddImageButton("form1","ImageButton5",165,150,120,30,"SMS",212,208,200,215,215,215,"cCenterImage","",True,True,True,11)
AddImageButton("form1","ImageButton4",20,150,120,30,"E-mail",212,208,200,215,215,215,"cCenterImage","",True,True,True,11)
AddImageButton("form1","ImageButton7",455,20,120,120,"",212,208,200,0,0,0,"cCenterImage","Contact.png",False,True,True,9)
AddImageButton("form1","ImageButton3",310,20,120,120,"",212,208,200,0,0,0,"cCenterImage","MMS.png",False,True,True,9)
AddImageButton("form1","ImageButton2",165,20,120,120,"",212,208,200,0,0,0,"cCenterImage","SMS.png",False,True,True,9)
AddImageButton("form1","ImageButton1",20,20,120,120,"",212,208,200,0,0,0,"cCenterImage","Mail.png",False,True,True,9)
End If
End Sub
Sub ImageButton1_Click
r = Msgbox("Do you want to exit?", "Test", cMsgboxYesNo)
If r = cYes Then
AppClose
End If
End Sub
Sub ImageButton1_ButtonDown
ImageButton1.image="Mail_Press.png"
End Sub
Sub ImageButton1_ButtonUp
ImageButton1.image="Mail.png"
End Sub
Sub ImageButton2_ButtonDown
ImageButton2.image="SMS_Press.png"
End Sub
Sub ImageButton2_ButtonUp
ImageButton2.image="SMS.png"
End Sub
Sub ImageButton3_ButtonDown
ImageButton3.image="MMS_Press.png"
End Sub
Sub ImageButton3_ButtonUp
ImageButton3.image="MMS.png"
End Sub
Sub ImageButton7_ButtonDown
ImageButton7.image="Contact_Press.png"
End Sub
Sub ImageButton7_ButtonUp
ImageButton7.image="Contact.png"
End Sub
Last edited: