Simple native extension offering several utility methods for Android platform:
- Getting full screen width & height of the device
- Getting DisplayMetrics
- Getting system version
- Setting UI visibility flags
- Setting brightness
- Setting status bar color
Just copy the extension from the bin
directory over to your project and modify your app descriptor XML with the extension's ID:
<extensions>
<extensionID>com.marpies.ane.androidutils</extensionID>
</extensions>
// If desired, enable logging before calling any API
AIRAndroidUtils.logEnabled = true;
trace( AIRAndroidUtils.screenWidth );
trace( AIRAndroidUtils.screenHeight );
const dm:AIRAndroidUtilsDisplayMetrics = AIRAndroidUtils.displayMetrics;
trace( dm.density );
trace( dm.densityDpi );
trace( dm.widthPixels );
trace( dm.heightPixels );
trace( dm.xdpi );
trace( dm.ydpi );
if( AIRAndroidUtils.systemVersion >= AIRAndroidUtilsVersionCodes.KITKAT ) {
// Use KITKAT's API
}
// Immersive full screen
if( AIRAndroidUtils.isImmersiveFullScreenSupported ) {
AIRAndroidUtils.setUIVisibility(
AIRAndroidUtilsUIFlags.SYSTEM_UI_FLAG_HIDE_NAVIGATION | // Hides software buttons
AIRAndroidUtilsUIFlags.SYSTEM_UI_FLAG_FULLSCREEN | // Hides status bar
AIRAndroidUtilsUIFlags.SYSTEM_UI_FLAG_IMMERSIVE_STICKY // Enters immersive full screen
);
}
// Temporarily hide the software buttons (appear on touch)
AIRAndroidUtils.setUIVisibility( AIRAndroidUtilsUIFlags.SYSTEM_UI_FLAG_HIDE_NAVIGATION );
See the class AIRAndroidUtilsUIFlags.as for available UI flags.
// Use values from 0.0 to 1.0
AIRAndroidUtils.setBrightness( Math.random() );
// Use user's preferences
AIRAndroidUtils.setBrightness( -1 );
if( AIRAndroidUtils.isStatusBarColorSupported ) {
// Color in the format #RRGGBB or #AARRGGBB, or one of the following values: red, blue, green, black, white, gray, cyan, magenta, yellow, lightgray, darkgray.
AIRAndroidUtils.setStatusBarColor( "#FF0000" );
}
ANT build scripts are available in the build directory. Edit build.properties to correspond with your local setup.
The ANE has been written by Marcel Piestansky and is distributed under Apache License, version 2.0.
- Public release