Search in sources :

Example 6 with OrientationEventListener

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();
}
Also used : OrientationEventListener(android.view.OrientationEventListener)

Aggregations

OrientationEventListener (android.view.OrientationEventListener)6 Point (android.graphics.Point)2 WindowManager (android.view.WindowManager)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 ActivityManager (android.app.ActivityManager)1 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PackageInfo (android.content.pm.PackageInfo)1 Paint (android.graphics.Paint)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Handler (android.os.Handler)1 RecognizerIntent (android.speech.RecognizerIntent)1 TextToSpeech (android.speech.tts.TextToSpeech)1 GestureDetector (android.view.GestureDetector)1 View (android.view.View)1 RelativeLayout (android.widget.RelativeLayout)1 Preview (net.sourceforge.opencamera.Preview.Preview)1