> Home   > Dynamic orientation changes in the emulator 

Dynamic orientation changes in the emulator
By: Dwayne Lamb

In the on going battle to keep up with the rubbery Windows Mobile platform, you may want to yet again change your applications to support the latest and greatest feature that has been bolted onto the Standard (most of us know it as Smartphone) version of Windows Mobile. As of the release of Windows Mobile 6.0, some Smartphone manufacturers will be releasing new devices that not only support Landscape mode (like the Motorolla Q, Samsung BlackJack) but also devices that have the ability to switch back and forth between Portrait and Landscape to accommodate things like new slide out keyboards (like the HTC S710).

The emulators that came with the first Windows Mobile 6.0 SDK refresh do not support a feature, like Pocket PC emulators have, where you can trigger the emulator to change orientations by clicking on one of the keys on the emulator keypad (typically the Address shortcut key on the PPC emulator). The new Designed for Windows Mobile 6 Standard Application Handbook however, does state that it is a requirement for certification that your application does support “dynamically switching display devices”. However, even if you don’t care about passing certification, you will want to keep your customers and users happy, so you will likely want to at least test how your application behaves on a dynamic orientation switch.

Since the emulators did not support the functionality it was suggested that I write my own simple application to run on the emulator as a work around so that I could at least test an application before my new HTC S710 arrived.

It is a bit of a kludge solution, however it does at least allow you, through a series of steps, to trigger the orientation switching behaviour that you need in order to simulate dynamic orientation changes.

My goal was just to meet the basic requirement with this utility, so I have not spent the time to make the tool or the source fancy or robust.

Here is the basic source: (Project files downloadable further down)
Imports Microsoft.WindowsCE.Forms
Public Class Form1


    Private Sub Form1_Load(ByVal sender As System.Object,
 ByVal e As System.EventArgs)
 Handles MyBase.Load
        Dim o As ScreenOrientation = SystemSettings.ScreenOrientation

        chkPortrait.Checked = False
        chkLandscape90.Checked = False
        chkLandscape270.Checked = False

        Select Case 0
            Case ScreenOrientation.Angle0
                chkPortrait.Checked = True
            Case ScreenOrientation.Angle90
                chkLandscape90.Checked = True
            Case ScreenOrientation.Angle180
                chkPortrait.Checked = True
            Case ScreenOrientation.Angle270
                chkLandscape270.Checked = True
        End Select
        InputModeEditor.SetInputMode(txtDelay, InputMode.Numeric)

    End Sub

    Private Sub chkLandscape90_CheckStateChanged(ByVal sender As System.Object,
 ByVal e As System.EventArgs)
 Handles chkLandscape90.CheckStateChanged

        If chkLandscape90.Checked Then
            chkPortrait.Checked = False
            chkLandscape270.Checked = False
            Timer1.Interval = CInt(txtDelay.Text)
            Timer1.Enabled = True
        End If

    End Sub

    Private Sub chkPortrait_CheckStateChanged(ByVal sender As System.Object,
 ByVal e As System.EventArgs)
 Handles chkPortrait.CheckStateChanged

        If chkPortrait.Checked Then
            chkLandscape270.Checked = False
            chkLandscape90.Checked = False
            Timer1.Interval = CInt(txtDelay.Text)
            Timer1.Enabled = True
        End If
        
    End Sub

    Private Sub chkLandscape270_CheckStateChanged(ByVal sender As System.Object,
 ByVal e As System.EventArgs)
 Handles chkLandscape270.CheckStateChanged

        If chkLandscape270.Checked Then
            chkPortrait.Checked = False
            chkLandscape90.Checked = False
            Timer1.Interval = CInt(txtDelay.Text)
            Timer1.Enabled = True
        End If
        
    End Sub

    Private Sub TriggerOrientationChange()

        If chkLandscape90.Checked Then
            If SystemSettings.ScreenOrientation <> ScreenOrientation.Angle90
 Then SystemSettings.ScreenOrientation = ScreenOrientation.Angle90
        ElseIf chkPortrait.Checked Then
            If SystemSettings.ScreenOrientation <> ScreenOrientation.Angle0
 Then SystemSettings.ScreenOrientation = ScreenOrientation.Angle0
        ElseIf chkLandscape270.Checked Then
            If SystemSettings.ScreenOrientation <> ScreenOrientation.Angle270
 Then SystemSettings.ScreenOrientation = ScreenOrientation.Angle270
        End If

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object,
 ByVal e As System.EventArgs) Handles Timer1.Tick
        TriggerOrientationChange()
        Timer1.Enabled = False
    End Sub
End Class


And here is a zip file with the .exe file in it and another one with the source files inside.

To use the utility, connect and cradle your Windows Mobile 6 emulator image of choice and then copy the ScreenOrientation.exe file into the Windows|Start Menu folder of your emulator. Note: placing it there is an expedient way to get it onto your device and accessible for testing in a dev environment but I am not advocating that you distribute applications that install directly into that folder. Also note that the Windows folder on Windows Mobile 6 devices is now seen as a hidden folder by the file explorer so you will have to make sure that you Show Hidden Files and Folders in the Folders Options from the File Explorer Tools menu.

I set the default value of the timer to 5000 to give myself 5 seconds in order to get back to my application screen before the switch occurs so that I can witness the changes that take place. If you want the switch to happen automatically, just drop the 5 to set the delay to 0 or remove that logic all together if you like.

Note: When you run this utility on any of the Windows Mobile Standard (aka Smartphone) Landscape emulators, (including the Motorolla Q emulator) it exposes what appears to be a bug in the implementation of the SystemSettings.ScreenOrientation api . Those emulators seem to treat the orientation setting as the orientation of the device itself and not the actual screen. The screens on these devices are actually in landscape mode when the device is held upright and portrait when they are held sideways. I have not tested this out on an actual device yet, so I don’t know if the problem is in the emulator or in the devices themselves in which case the emulators may simply be misbehaving like the device they are emulating. If the devices do behave this way, the api will be pretty much useless to developers and they will need to resort back to the manual approach of figuring out the orientation of the device by dividing Screen.PrimaryScreen.Bounds.Width by Screen.PrimaryScreen.Bounds.Height or some similar method. I hope it is just one of the many design flaws of these emulators like the messed up emulator keys. I still have not found a way to enter a numeric through several of these emulator keypads.

See profile of: Dwayne Lamb
Visual Byte Inc.

Infuseweb Web Hosting
>


Google
Web www.mobidogs.com   

Related Links

Designed For WM 6 Handbook
Adapt Your App Homepage
WM 6 SDK Refresh

     
    © 2014 Visual Byte Inc. All rights reserved.

Server: Monday, November 24, 2014 11:58:15 AM