Android 中 OrientationEventListener 的使用

 class MyOrientationEventListener extends OrientationEventListener {
        public MyOrientationEventListener(Context ctx, int rate) {
            super(ctx, rate);
        }

        @Override
        public void onOrientationChanged(int orientation) {
            if (orientation == 0 || orientation == 90 || orientation == 270) {
                Log.d("NotificationPanelView", "onOrientationChanged");
            }
        }
    }

 boolean mCanDetectOrientation;
 MyOrientationEventListener myOrientationEventLister;

 myOrientationEventLister = new MyOrientationEventListener(
                getContext(), SensorManager.SENSOR_DELAY_FASTEST);
        if (myOrientationEventLister.canDetectOrientation()) {
            mCanDetectOrientation = true;
        } else {
            mCanDetectOrientation = false;
        }

  if (mCanDetectOrientation)
                myOrientationEventLister.enable();

  if (mCanDetectOrientation)
                myOrientationEventLister.disable();