B4A Library WindowView

Johan Schoeman

Expert
Licensed User
The attached project wraps this Github project. Change the pitch / roll of your device and see the pics pan to the left / right (london_wide) or up / down (singapore_tall). Touch the pics to centre them.

Posting the following:
1. B4A project
2. B4A library files
3. london_wide.jpg & singapore_tall.jpg --> copy these two files to the /Objects/res/drawable folder of the B4A project and make sure they are set to Read Only.
4. The Java code

I would suggest reading the "Configuration" section of the Github project to understand some of the methods in use/available in the B4A library.

1.png


Some sample code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: WindowView
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private wv1 As WindowView
    Private wv2 As WindowView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
 
    wv1.DrawableName = "london_wide"
    wv1.MaxRoll = 20
    wv1.OrientationMode = wv1.Orientation_Relative                'or wv1.OrientationMode = wv1.Orientation_Absolute
    wv1.MaxConstantTranslation = 100                              ' default value is 150
    wv1.TranslateMode = wv1.TranslateMode_Constant
 
    wv2.DrawableName = "singapore_tall"
    wv2.MaxPitch = 90
    wv2.MaxConstantTranslation = 100                              ' default value is 150
    wv2.TranslateMode = wv1.TranslateMode_Constant 
 
 

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

WindowView
Author:
Johan Schoeman
Version: 1
  • WindowView
    Fields:
    • Orientation_Absolute As String
    • Orientation_Relative As String
    • TranslateMode_Constant As String
    • TranslateMode_Proportional As String
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • resetOrientationOrigin (immediate As Boolean)
      Manually resets the orientation origin. Has no effect unless {@link #getOrientationMode()}
      is {@link OrientationMode#RELATIVE}.
      immediate: if false, the sensor values smoothly interpolate to the new origin.
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • DrawableName As String [write only]
    • Enabled As Boolean
    • Height As Int
    • HorizontalOrigin As Float
      Horizontal origin (in degrees). When {@link #latestRoll} equals this value, the image
      is centered horizontally.
    • Left As Int
    • MaxConstantTranslation As Float [write only]
      translate_mode - Constant or Proportional (default).
      Specifies how much the image is translated in response to device tilt.
      If Proportional , the image moves within the full range defined
      by max_pitch / max_roll , with the extremities of the image visible
      when device pitch / roll is at those angles. If Constant , the image moves
      a constant amount per unit of tilt which is defined by max_constant_translation,
      achieved when pitch / roll are at max_pitch / max_roll.
    • MaxPitch As Float
      Maximum angle (in degrees) from origin for vertical tilts.
    • MaxRoll As Float
      Maximum angle (in degrees) from origin for horizontal tilts.
    • OrientationMode As String [write only]
      Determines the mapping of orientation to image offset.
      orientation_mode - Absolute or Relative (default).
      Specifies whether device tilt should be tracked with respect
      to Absolute world coordinates (i.e. pitch, roll w.r.t. ground plane)
      or with respect to the device orientation when WindowView is
      created, which WindowView refers to as the 'orientation origin'.
      If using the latter, i.e. Relative , you may use resetOrientationOrigin(boolean)
      to set the orientation origin to that of the device when the method is called.
    • SensorSamplingPeriod As Int
    • Tag As Object
    • Top As Int
    • TranslateMode As String [write only]
      translate_mode - Constant or Proportional (default).
      Specifies how much the image is translated in response to device tilt.
      If Proportional , the image moves within the full range defined
      by max_pitch / max_roll , with the extremities of the image visible
      when device pitch / roll is at those angles. If Constant , the image moves
      a constant amount per unit of tilt which is defined by max_constant_translation,
      achieved when pitch / roll are at max_pitch / max_roll.
    • VerticalOrigin As Float
      Vertical origin (in degrees). When {@link #latestPitch} equals this value, the image
      is centered vertically.
    • Visible As Boolean
    • Width As Int
 

Attachments

Last edited:
Top