← All extensions

Native extension

KlugLayout

com.klug.layout

Landscape on both sides for Android tablets: the app turns with the device, whichever way it is held.

Android In production

Overview

Some apps are designed for landscape only, for example a camera station on a tablet. Users still expect the picture to be the right way up however they place the device: with the buttons on the left or on the right.

KlugLayout sets the Android screen orientation to landscape on both sides. The app stays in landscape, but turns by 180 degrees with the device. It also reports the current display rotation, so an app can adapt its own content, such as a camera picture, to how the device is held.

KlugLayout is in daily use in the PetCam App on Android tablets, our proof of concept.

Features

  • Landscape on both sides, turning with the device
  • No switch to portrait
  • Current display rotation: 0, 90, 180 or 270 degrees
  • Active from the start of the app
  • Does nothing on other platforms, so the code can stay in a cross-platform app

Supported platforms

Android arm64 · armv7

Getting started

Add the extension to your application descriptor:

app.xml
<extensions>
    <extensionID>com.klug.layout</extensionID>
</extensions>

Apps targeting Android 16 should also allow a fixed orientation on large screens with this property inside <application> of the manifest additions:

app.xml
<property android:name="android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY"
          android:value="true"/>

Quick example

Main.as
import com.klug.layout.KlugLayout;

stage.autoOrients = true;
if ( KlugLayout.getInstance().isSupported )
    KlugLayout.getInstance().setSensorLandscape();   // both landscape sides
else
    stage.setAspectRatio( StageAspectRatio.LANDSCAPE );

var rotation:int = KlugLayout.getInstance().displayRotation;

API overview

KlugLayout.getInstance()Returns the single instance.
isSupportedTrue on Android.
setSensorLandscape()Landscape on both sides, turning with the device.
displayRotationThe current display rotation in degrees (0, 90, 180, 270), or -1.

Requirements

AIR SDK51.x (HARMAN)
AndroidAndroid 6.0 (API 23) or later
PermissionsNone