-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetectActivityOrientationChange
More file actions
36 lines (31 loc) · 1.21 KB
/
DetectActivityOrientationChange
File metadata and controls
36 lines (31 loc) · 1.21 KB
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
//detect activity orientation change after Activity.setRequestedOrientation was called
public class Activity {
private OrientationEventListener mOrientationListener;
@Override
public void onCreate(Bundle b) {
mOrientationListener
= new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL){
@Override
public void onOrientationChanged(int degree) {
// TODO Auto-generated method stub
LogFactory.w("onOrientationChanged", degree + "");
if (mIsLandscape) {
if ( 260 <= degree && degree <= 280) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else if (80 <=degree && degree <= 100) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
}
}
}};
if (mOrientationListener.canDetectOrientation()){
mOrientationListener.enable();
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (mOrientationListener != null) {
mOrientationListener.disable();
}
}
}