Skip to content

Instantly share code, notes, and snippets.

@esDotDev
Last active August 29, 2015 13:56
Show Gist options
  • Save esDotDev/9241796 to your computer and use it in GitHub Desktop.
Save esDotDev/9241796 to your computer and use it in GitHub Desktop.
Fixes Adobe AIR issue with newer Kindle Fire and Kindle HDX devices, where the screen orientation becomes reversed.
if(Capabilities.manufacturer.toLowerCase().indexOf("android") > -1){
var applyRotationFix:Boolean = false;
//Use build.props file to check if we're on a problematic Kindle Device
var file:File = new File("/system/build.prop");
if(file.exists){
var fs: FileStream = new FileStream();
fs.open(file, FileMode.READ);
var props:String = fs.readUTFBytes(fs.bytesAvailable);
fs.close();
var regExp:RegExp = /ro.product.model=(\w+)/;
var model:String = props.match(regExp)? props.match(regExp).pop() : null;
var targetModels:Array = ["KFAPWA", "KFAPWI", "KFTHWA", "KFTHWI", "KFSOWI"];
if(targetModels.indexOf(model) != -1){
applyRotationFix = true;
}
}
//If we are on a problem device, apply fix:
if(applyRotationFix){
var currentOrientation:String;
setInterval(function(){
//If we've already forced this orientation, we don't need to do it again.
if(stage.deviceOrientation == currentOrientation){ return; }
//Force stage orientation to match device
if(stage.deviceOrientation == StageOrientation.ROTATED_LEFT){
stage.setOrientation(StageOrientation.ROTATED_LEFT);
}
else if(stage.deviceOrientation == StageOrientation.ROTATED_RIGHT){
stage.setOrientation(StageOrientation.ROTATED_RIGHT);
}
currentOrientation = stage.deviceOrientation;
}, 1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment