[Q] How to detect the orientation on program start and redraw controls accordingly

Skrobel

Member
Licensed User
[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:
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:

derez

Expert
Licensed User
Longtime User
You cannot change the size of the form from the code, that is why you get an error on the lines Form1.width = 480 etc.

Also you double the text in adding the buttons which is also not by the format:

B4X:
AddImageButton("Form1","ImageButton8",25,305,115,30,"Contact",0,0,0,215,215,215,"cCenterImage","",False,False,True,11)

should be
B4X:
AddImageButton("Form1","ImageButton8",25,305,115,30,"Contact")

The way I can think of doing it is to create two applications, one for each case, and to run a small application which will check the registry and launch the proper application accordingly.
 

klaus

Expert
Licensed User
Longtime User
I would suggest you to:
- add all your controls in the form designer in the desktop IDE with the default images.
- in the Resize routine write the code to position the controls acording to the orientation
- put the button images in an ImageList control to avoid loading the image files with each button event

There is a mean to get and set the display orientation with agraham's ControlsExDevice library, but this one is only available for users having bought B4PPC.

In your code, when the Reszie routine is called you add the same controls once more, but they alreay do exist. The resize routine is called when the form is shown. This means that the routine is also called before the form is shown the first time.

The code could look like below, Disp is a Display object from the ControlsExDevice library.
B4X:
[SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff]Sub [/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]App_Start[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]flbMain.New1([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"frmMain"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]B4PObject[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]Disp.New1[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]frmMain.Show[/FONT][/SIZE]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
 
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]flbMain_Resize[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Disp.Orientation=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0 [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton1.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton1.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton2.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton2.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]180[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton3.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton3.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]335[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton4.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]145[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton4.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton5.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]145[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton5.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]180[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton6.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]145[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton6.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]335[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton7.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]180[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton7.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton8.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]305[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton8.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]25[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton1.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton1.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton2.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton2.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]165[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton3.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton3.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]310[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton4.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]150[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton4.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton5.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]150[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton5.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]165[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton6.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]150[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton6.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]310[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton7.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton7.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]455[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton8.Top=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]155[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageButton8.Left=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]455[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT]
[SIZE=2][FONT=Courier New][COLOR=#0000ff]End Sub[/COLOR][/FONT][/SIZE]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
Best regards.
 

Skrobel

Member
Licensed User
If I understand correctly you suggest that the "starting" program should check the orientation in the system registry? And then start appropriate i.e. Landscape.exe or Portrait.exe?

Would it be optimal with regard i.e. to memory usage? To build a program which will run another program?

When the user will tap a certain Button I want the application to close itself. In your idea I would have to close either the (i.e.) Landscape.exe and the "host" program to free up all the memory.

On the other hand I imagine a situation that the user will change the orientation when the Landscape.exe will be running already. In this situation only the Landscape.exe would have to be closed and the host program should immediately start Portrait.exe.

It's all getting a bit complicated. But if you confirm this is a best way to do it, I'll try :)
 

klaus

Expert
Licensed User
Longtime User
My suggestion is having only 1 program !
When starting the program the Resize routine is called before the form is shown and adjusts the button layout.
If you have, in your program, a Button to change the display orientation, the Resize routine will do the work again.
You can memorize the start display oriention when the program starts and set the oriention back to this 'default' value when leaving the program.

Best regards.
 

Skrobel

Member
Licensed User
I would suggest you to:
- add all your controls in the form designer in the desktop IDE with the default images.
- in the Resize routine write the code to position the controls acording to the orientation
- put the button images in an ImageList control to avoid loading the image files with each button event
(...)

Thank you Klaus,

I knew there must be an easier way to handle orientation changes than to create 3 different applications.

The reason why I didn't put all the graphics in the ImageList is that when the user taps a button, the "..._press" image is loaded but only for the actual button that was pressed by the user, then my application is supposed to close leavin whatever program the user started on top. So I didn't want all the "_press" images to be loaded for each program start as I think it's not the fastest way. But on the other hand I can at least try it.

I didn't realize the Resize routine is also called when the Form is shown for the very first time. I guess this will make my job easier without touching the registry.

That's right. I'm not a registered user yet. This is because I'm not going to be a proffessional programmer, only I want to help a friend to put a missing tool to one of his Rhodium ROMs. There is an application called Smaberg's ActionScreen but it works only in Portrait. I thought I could try to learn some programming and by the way do something helpful.
I was looking for some not very complicated (and possibly freeware) programming language, ran into B4PPC and currently I'm "trying before buying" ;) because in the mean time I realized there are no freeware programming interfaces that could be used on PPC, so I will have to buy B4PPC. But at least I can see now this is a simple but very powerfull tool which is worth a dollar or two... ;) Even if I'm not going to use it for commercial purposes. :)

Best Regards
 

Skrobel

Member
Licensed User
My suggestion is having only 1 program !
When starting the program the Resize routine is called before the form is shown and adjusts the button layout.
If you have, in your program, a Button to change the display orientation, the Resize routine will do the work again.
You can memorize the start display oriention when the program starts and set the oriention back to this 'default' value when leaving the program.

Best regards.

No, I'm not going to make a button to change the orientation. But I'm trying to develop a tool for HTC Rhodium which changes the orientation when you slide in/out the hard keyboard. Thats why I have to consider an orientation change during the program running.
 

Skrobel

Member
Licensed User
As promised I want to post my feedback about a method proposed by Klaus.

It works just FINE! :sign0060:

The ControlExDevice library detects the orientation muuuuch faster than the method taken from FormLib. The effect (when I tried to use FormLib) was that when the device was in Landscape, the form was previously showed in default, Portrait arrangement, and then switched over to the Landscape arrangement. It takes 1-2 seconds avg.

Now the form swhows in appropriate order immediately, and the transition is almost unnoticeable! Thanks! :D

Only one small glitch I don't know how to handle.

When the my program starts on the device it fits the screen perfectly and hides the taskbar and the softkeybar without problem. But when I change the orientation (by sliding in/out my hardware keyboard) the SIP symbol appears in on the bottom of the screen. Is this a system matter or I can avoid it somehow?

Please look at my screenshots and a program attached.
 

Attachments

  • ActionScreenForms.sbp
    9.6 KB · Views: 200
  • ScreenShot2.jpg
    ScreenShot2.jpg
    12.5 KB · Views: 195

klaus

Expert
Licensed User
Longtime User
Could you also post the button images, so we could try to run your program.

Why are you using ImageButtons to display the text below the buttons, simple Lables would be OK.
Or do you need or want to use the Button and Click events of those ?
Another way would be to increase the button dimensions and add the texts directly onto the button images. This would need less controls.

With another test program I tried to reproduce your problem, but with a button to change the display orientation.
My htc Touch HD has a different behaviour:
I don't get the SIP button as you do, but after the orientation change the titlebar is displayed.

Try to include in the Resize routine SIP(False), perhaps this would solve your problem.

Best regards.
 

Skrobel

Member
Licensed User
Of course I can! :) Here goes my whole program folder.

MojActionScreen.zip - download

I had to upload it to 4shared 'cause it exceeded the file size limit for attachment.

I'll test your SIP suggestion in the evening.
If you have some more time I would also ask you for a bit of help in Optimizing the program to let it start quicker on the device. On my Rhodium it needs about 3-4 seconds to start. I would like it to be at least a bit faster.
I'm sure my programming is not "optimized", so there's much to improve in this topic.

As for controls I tried to use Labels, but I can't get the text to be aligned to the middle of the control. And the reason why I din't put the texts in pngs is that I want to make a possibility to add text in other languages (i.e. using text file).
 

klaus

Expert
Licensed User
Longtime User
I had a look at your program, very interesting.
I'm afraid that the loading speed is like it is, there is nothing more to do to increase it. On my htc Touch HD it takes about 2 seconds.

I suggest you to modify the size of the green button images to 120/120 pixels to match the button size like the black buttons.

Attached you find a modified program with Labels instead of ImageButtons to dispaly the text below the E-Mail and SMS buttons.
Centering the text and set it to Bold can be done with the Formib library.

Best regards.
 

Attachments

  • ActionScreenForms1.sbp
    9.9 KB · Views: 189

Skrobel

Member
Licensed User
My htc Touch HD has a different behaviour:
I don't get the SIP button as you do, but after the orientation change the titlebar is displayed.

Try to include in the Resize routine SIP(False), perhaps this would solve your problem.

Unfortunately not. The soft keyboard symbol still appears after change of orientation. Seems like this is a system isuue afterall...

I had a look at your program, very interesting.
I'm afraid that the loading speed is like it is, there is nothing more to do to increase it. On my htc Touch HD it takes about 2 seconds.
The original application called Action Screen which is to be found HERE starts itself immediately BUT I've noticed that when it's installed on my PDA there is a process called HTCActionScreen.exe running in background (it starts with the system) and actually when we press an application link it's not started but it's brought to front. The "calling" link is actually a following command:
"\Windows\HTCActionScreen.exe"
I thought of doing similar thing. To put my app in the StartUp folder with a parameter to exist only with a hidden window, and when called it shows up the MainForm, then after the Timer1 ticks hides instead of closing.
The only problem is that the actual HTCActionScreen.exe when running in background takes about 133 kB of memory. My program takes about 2MB of memory. This is definitely too much to put as a resident...


I suggest you to modify the size of the green button images to 120/120 pixels to match the button size like the black buttons.
Believe me, they are 120/120 px. The reason why you see a grey strip on top of the icon when you tap a button is that the form itself also simulates "pushing" a button (it can be clearly seen when no ButtonDown is triggered for an ImageButton). I guess this interferes with a position of this green image. I don't know how to omit that, and honestly I didn't think about it yet :) Perhaps I'll just get rid of the green images (even though I like them) and use only the "built-in" pushing simulation.

Attached you find a modified program with Labels instead of ImageButtons to dispaly the text below the E-Mail and SMS buttons.
Centering the text and set it to Bold can be done with the Formib library.

You are right! In your example the Labels look exactly the same like ImageButtons. I don't know if it changes the memory usage or the speed but I will sure use these instead of my method.

Thank you very much for all your suggestions :)

Best Regards
Luke
 

klaus

Expert
Licensed User
Longtime User
Concerning the green button images they have a size of 160/120 pixels.
They have a black border of 20 pixels on each side.
Mail_press is the only one with 120/120 pixels.
If you set SMSButton from cCenterImage to cStretchImage you'll see it.

Best regards.
 

Skrobel

Member
Licensed User
Oh, I'm dumb! You're perfectly right they are 160/120. Don't know how it happened. I remember I resized them all.
And of course before I wrote yesterday I have checked random one just to be sure and it happened to be... Mail_press.png

I hope resizing these buttons will save some memory, and about the further optimization I think I'll have to put another thread not to make an :sign0006: here. Or I can change the thread Title.

Thank you
Best Regards
Luke
 
Top