use of android.view.OrientationEventListener in project GwellDemo by dxsdyhm.
the class MonitoerActivity method initData.
private void initData() {
// 此处是一种并不常见的横竖屏监听,客户可自行修改实现
mOrientationEventListener = new OrientationEventListener(this) {
@Override
public void onOrientationChanged(int rotation) {
// 设置横屏
if (((rotation >= 0) && (rotation <= 30)) || (rotation >= 330)) {
if (mIsLand) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mIsLand = false;
setHalfScreen(true);
}
} else if (((rotation >= 230) && (rotation <= 310))) {
if (!mIsLand) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mIsLand = true;
setHalfScreen(false);
}
}
}
};
mOrientationEventListener.enable();
}
Aggregations