-
Notifications
You must be signed in to change notification settings - Fork 11
/
screen-orientation.android.js
42 lines (35 loc) · 1.38 KB
/
screen-orientation.android.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var application=require("application"),
timer=require("timer");
var callback=null,
orientationConstants={
"landscape":"SCREEN_ORIENTATION_SENSOR_LANDSCAPE",
"portrait":"SCREEN_ORIENTATION_SENSOR_PORTRAIT",
"all":"SCREEN_ORIENTATION_FULL_USER"
};
function setOrientation(type,callback){
var type=type.toLowerCase(),
requestedOrientationConstant=orientationConstants[type],
interval=null;
if(undefined!==requestedOrientationConstant){
if(undefined!==application.android.foregroundActivity){
application.android.foregroundActivity.setRequestedOrientation(android.content.pm.ActivityInfo[requestedOrientationConstant]);
if(callback){
callback();
}
}else {
interval = timer.setInterval(function () {
if (undefined !== application.android.foregroundActivity) {
application.android.foregroundActivity.setRequestedOrientation(android.content.pm.ActivityInfo[requestedOrientationConstant]);
timer.clearInterval(interval);
if(callback){
callback();
}
}
}, 1);
}
}
}
exports.setCurrentOrientation=setOrientation;
exports.orientationCleanup=function(){
setOrientation("all");
};