Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private pMain As Page
Private pnlRoot As Panel
Public OrientationModus As String = "Portrait"
Private IsSetOrientation As Boolean
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
pMain.Initialize("pMain")
pMain.RootPanel.LoadLayout("Main")
pnlRoot.LoadLayout("Page1")
NavControl.ShowPage(pMain)
IsSetOrientation = False
End Sub
Private Sub pMain_Resize (Width As Float, Height As Float)
'Log("pMain_Resize")
Dim r As Rect = pMain.SafeAreaInsets
pnlRoot.SetLayoutAnimated(0, 1, r.Left, r.Top, Width - r.Right - r.Left, Height - r.Bottom - r.Top)
End Sub
Private Sub pnlRoot_Resize (Width As Float, Height As Float)
End Sub
Private Sub pMain_Appear
Log("Page1_Appear")
If OrientationModus = "Portrait" Then
SetOrientation(1)
Else
SetOrientation(3)
End If
IsSetOrientation = True
End Sub
Sub btnSettings_Click
'Here the variable "OrientationMode" is changed for the orientation.
mSettings.Show
End Sub
Sub Main_ShouldAutoRotate As Boolean
Log("Main_ShouldAutoRotate")
If IsSetOrientation Then
If DeviceOrientation = "Portrait" And OrientationModus = "Landscape" Then
Return False
else If DeviceOrientation <> "Portrait" And OrientationModus = "Portrait" Then
Return False
Else
Return True
End If
Else
Return False
End If
End Sub
#region Orientation
'0 = "Unknown"
'1 = "Portrait"
'2 = "PortraitUpsideDown"
'3 = "LandscapeLeft"
'4 = "LandscapeRight"
'5 = "FaceUp"
'6 = "FaceDown"
Public Sub SetOrientation(landscape As Int)
Dim no As NativeObject
no.Initialize("UIDevice").RunMethod("currentDevice", Null).SetField("orientation", landscape)
'Log("SetOrientation")
End Sub
Public Sub DeviceOrientation As String
Dim no As NativeObject
Dim o As Int = no.Initialize("UIDevice").RunMethod("currentDevice", Null).RunMethod("orientation", Null).AsNumber
Select o
Case 0
Return "Unknown"
Case 1
Return "Portrait"
Case 2
Return "PortraitUpsideDown"
Case 3
Return "LandscapeLeft"
Case 4
Return "LandscapeRight"
Case 5
Return "FaceUp"
Case 6
Return "FaceDown"
Case Else
Return "Unknown"
End Select
End Sub
#End Region
#Region NavigationController
#if OBJC
@end
@interface UINavigationController (B4IResize)
@end
@implementation UINavigationController (B4IResize)
- (BOOL)shouldAutorotate
{
return [(NSNumber*)[B4IObjectWrapper raiseEvent:self :@"_shouldautorotate" :nil] boolValue];
}
#End If
#End Region