Java 类android.view.OrientationEventListener 实例源码

项目:droidCam    文件:DisplayOrientationDetector.java   
public DisplayOrientationDetector(Context context) {
    mOrientationEventListener = new OrientationEventListener(context) {

        /** This is either Surface.Rotation_0, _90, _180, _270, or -1 (invalid). */
        private int mLastKnownRotation = -1;

        @Override
        public void onOrientationChanged(int orientation) {
            if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN ||
                    mDisplay == null) {
                return;
            }
            final int rotation = mDisplay.getRotation();
            if (mLastKnownRotation != rotation) {
                mLastKnownRotation = rotation;
                dispatchOnDisplayOrientationChanged(DISPLAY_ORIENTATIONS.get(rotation));
            }
        }
    };
}
项目:PXLSRT    文件:DisplayOrientationDetector.java   
public DisplayOrientationDetector(Context context) {
    mOrientationEventListener = new OrientationEventListener(context) {

        /** This is either Surface.Rotation_0, _90, _180, _270, or -1 (invalid). */
        private int mLastKnownRotation = -1;

        @Override
        public void onOrientationChanged(int orientation) {
            if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN ||
                    mDisplay == null) {
                return;
            }
            final int rotation = mDisplay.getRotation();
            if (mLastKnownRotation != rotation) {
                mLastKnownRotation = rotation;
                dispatchOnDisplayOrientationChanged(DISPLAY_ORIENTATIONS.get(rotation));
            }
        }
    };
}
项目:react-native-camera    文件:RCTCameraView.java   
public RCTCameraView(Context context) {
    super(context);
    this._context = context;
    RCTCamera.createInstance(getDeviceOrientation(context));

    _orientationListener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_NORMAL) {
        @Override
        public void onOrientationChanged(int orientation) {
            if (setActualDeviceOrientation(_context)) {
                layoutViewFinder();
            }
        }
    };

    if (_orientationListener.canDetectOrientation()) {
        _orientationListener.enable();
    } else {
        _orientationListener.disable();
    }
}
项目:OkayCamera-Android    文件:Camera2RawFragment.java   
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
    view.findViewById(R.id.picture).setOnClickListener(this);
    mTextureView = (AutoFitTextureView) view.findViewById(R.id.texture);

    // Setup a new OrientationEventListener.  This is used to handle rotation events like a
    // 180 degree rotation that do not normally trigger a call to onCreate to do view re-layout
    // or otherwise cause the preview TextureView's size to change.
    mOrientationListener = new OrientationEventListener(getActivity(),
            SensorManager.SENSOR_DELAY_NORMAL) {
        @Override
        public void onOrientationChanged(int orientation) {
            if (mTextureView != null && mTextureView.isAvailable()) {
                configureTransform(mTextureView.getWidth(), mTextureView.getHeight());
            }
        }
    };
}
项目:LongImageCamera    文件:DisplayOrientationDetector.java   
public DisplayOrientationDetector(Context context) {
    mOrientationEventListener = new OrientationEventListener(context) {

        /** This is either Surface.Rotation_0, _90, _180, _270, or -1 (invalid). */
        private int mLastKnownRotation = -1;

        @Override
        public void onOrientationChanged(int orientation) {
            if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN ||
                    mDisplay == null) {
                return;
            }
            final int rotation = mDisplay.getRotation();
            if (mLastKnownRotation != rotation) {
                mLastKnownRotation = rotation;
                dispatchOnDisplayOrientationChanged(DISPLAY_ORIENTATIONS.get(rotation));
            }
        }
    };
}
项目:react-native-camera-face-detector    文件:RCTCameraView.java   
public RCTCameraView(Context context) {
    super(context);
    this._context = context;
    RCTCamera.createInstance(getDeviceOrientation(context));

    _orientationListener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_NORMAL) {
        @Override
        public void onOrientationChanged(int orientation) {
            if (setActualDeviceOrientation(_context)) {
                layoutViewFinder();
            }
        }
    };

    if (_orientationListener.canDetectOrientation()) {
        _orientationListener.enable();
    } else {
        _orientationListener.disable();
    }
}
项目:LLApp    文件:CameraView.java   
/**
 *   启动屏幕朝向改变监听函数 用于在屏幕横竖屏切换时改变保存的图片的方向
 */
private  void startOrientationChangeListener() {
    OrientationEventListener mOrEventListener = new OrientationEventListener(getContext()) {
        @Override
        public void onOrientationChanged(int rotation) {

            if (((rotation >= 0) && (rotation <= 45)) || (rotation > 315)){
                rotation=0;
            }else if ((rotation > 45) && (rotation <= 135))  {
                rotation=90;
            }
            else if ((rotation > 135) && (rotation <= 225)) {
                rotation=180;
            }
            else if((rotation > 225) && (rotation <= 315)) {
                rotation=270;
            }else {
                rotation=0;
            }
            if(rotation==mOrientation)
                return;
            mOrientation=rotation;
            updateCameraOrientation();
        }
    };
    mOrEventListener.enable();
}
项目:android-camera    文件:DisplayOrientationDetector.java   
public DisplayOrientationDetector(Context context) {
    mOrientationEventListener = new OrientationEventListener(context) {

        /** This is either Surface.Rotation_0, _90, _180, _270, or -1 (invalid). */
        private int mLastKnownRotation = -1;

        @Override
        public void onOrientationChanged(int orientation) {
            if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN ||
                    mDisplay == null) {
                return;
            }
            final int rotation = mDisplay.getRotation();
            if (mLastKnownRotation != rotation) {
                mLastKnownRotation = rotation;
                dispatchOnDisplayOrientationChanged(DISPLAY_ORIENTATIONS.get(rotation));
            }
        }
    };
}
项目:SimpleCamera    文件:DisplayOrientationDetector.java   
public DisplayOrientationDetector(Context context) {
    mOrientationEventListener = new OrientationEventListener(context) {

        /** This is either Surface.Rotation_0, _90, _180, _270, or -1 (invalid). */
        private int mLastKnownRotation = -1;

        @Override
        public void onOrientationChanged(int orientation) {
            if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN ||
                    mDisplay == null) {
                return;
            }
            final int rotation = mDisplay.getRotation();
            if (mLastKnownRotation != rotation) {
                mLastKnownRotation = rotation;
                dispatchOnDisplayOrientationChanged(DISPLAY_ORIENTATIONS.get(rotation));
            }
        }
    };
}
项目:FacerecognitionFlowpilots    文件:OrientationPlugin.java   
public OrientationPlugin(Context ctxt) {
  this.ctxt=ctxt.getApplicationContext();

  orientationEventListener=new OrientationEventListener(ctxt) {
    @Override
    public void onOrientationChanged(int orientation) {
      lastOrientation=orientation;
    }
  };

  if (orientationEventListener.canDetectOrientation()) {
    orientationEventListener.enable();
  }
  else {
    orientationEventListener.disable();
    orientationEventListener=null;
  }
}
项目:FacerecognitionFlowpilots    文件:OrientationPlugin.java   
/**
 * {@inheritDoc}
 */
@Override
public void addToCaptureRequest(CameraCharacteristics cc,
                                boolean facingFront,
                                CaptureRequest.Builder captureBuilder) {
  // based on https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html#JPEG_ORIENTATION

  int pictureOrientation=0;

  if (lastOrientation!=android.view.OrientationEventListener.ORIENTATION_UNKNOWN) {
    int sensorOrientation=cc.get(CameraCharacteristics.SENSOR_ORIENTATION);
    int deviceOrientation=(lastOrientation + 45) / 90 * 90;

    if (facingFront) {
      deviceOrientation = -deviceOrientation;
    }

    pictureOrientation=(sensorOrientation + deviceOrientation + 360) % 360;
  }

  captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, pictureOrientation);
}
项目:cameraview    文件:DisplayOrientationDetector.java   
public DisplayOrientationDetector(Context context) {
    mOrientationEventListener = new OrientationEventListener(context) {

        /** This is either Surface.Rotation_0, _90, _180, _270, or -1 (invalid). */
        private int mLastKnownRotation = -1;

        @Override
        public void onOrientationChanged(int orientation) {
            if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN ||
                    mDisplay == null) {
                return;
            }
            final int rotation = mDisplay.getRotation();
            if (mLastKnownRotation != rotation) {
                mLastKnownRotation = rotation;
                dispatchOnDisplayOrientationChanged(DISPLAY_ORIENTATIONS.get(rotation));
            }
        }
    };
}
项目:WiCamera3D    文件:Util.java   
public static void setRotationParameter(Parameters parameters,
            int cameraId, int orientation) {
        // See android.hardware.Camera.Parameters.setRotation for
        // documentation.
        int rotation = 0;
        if (orientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
             CameraInfo info =
             CameraHolder.instance().getCameraInfo()[cameraId];
//          CameraInfo info = new CameraInfo();
//          Camera.getCameraInfo(cameraId, info);
            if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
                rotation = (info.orientation - orientation + 360) % 360;
            } else { // back-facing camera
                rotation = (info.orientation + orientation) % 360;
            }
        }
        parameters.setRotation(rotation);
    }
项目:WiCamera3D    文件:VideoSurfaceView2D.java   
@Override
public void setOrientationHint() {

    // Util.setRotationParameter(camera_parameters, m_cameraIndex,
    // WiCameraActivity.mOrientation);
    // // System.out.println("拍照时的mOrientation="
    // // + WiCameraActivity.mOrientation + "m_cameraIndex="
    // // + m_cameraIndex);
    // cameras.setParameters(camera_parameters);

    if (cameras != null) {
        int rotation = 0;
        if (WiCameraActivity.mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
            CameraInfo info = CameraHolder.instance().getCameraInfo()[m_cameraIndex];
            if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
                rotation = (info.orientation
                        - WiCameraActivity.mOrientation + 360) % 360;
            } else { // back-facing camera
                rotation = (info.orientation + WiCameraActivity.mOrientation) % 360;
            }
        }
        m_recorder.setOrientationHint(rotation);
    }
}
项目:WiCamera3D    文件:VideoSurfaceView.java   
@Override
public void setOrientationHint() {

    // Util.setRotationParameter(camera_parameters, m_cameraIndex,
    // WiCameraActivity.mOrientation);
    // // System.out.println("拍照时的mOrientation="
    // // + WiCameraActivity.mOrientation + "m_cameraIndex="
    // // + m_cameraIndex);
    // cameras.setParameters(camera_parameters);

    if (cameras != null) {
        int rotation = 0;
        if (WiCameraActivity.mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
            CameraInfo info = CameraHolder.instance().getCameraInfo()[m_cameraIndex];
            if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
                rotation = (info.orientation
                        - WiCameraActivity.mOrientation + 360) % 360;
            } else { // back-facing camera
                rotation = (info.orientation + WiCameraActivity.mOrientation) % 360;
            }
        }
        m_recorder.setOrientationHint(rotation);
    }
}
项目:Camera2    文件:VideoModule.java   
@Override
public void onOrientationChanged(int orientation) {
    // We keep the last known orientation. So if the user first orient
    // the camera then point the camera to floor or sky, we still have
    // the correct orientation.
    if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
        return;
    }
    int newOrientation = CameraUtil.roundOrientation(orientation, mOrientation);

    if (mOrientation != newOrientation) {
        mOrientation = newOrientation;
    }
    mUI.onOrientationChanged(orientation);

}
项目:Camera2    文件:VideoRecordingHints.java   
/**
 * Handles orientation change by starting/stopping the video hint based on the
 * new orientation.
 */
public void onOrientationChanged(int orientation) {
    if (mLastOrientation == orientation) {
        return;
    }
    mLastOrientation = orientation;
    if (mLastOrientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
        return;
    }

    mIsInLandscape = isInLandscape();
    if (getVisibility() == VISIBLE) {
        if (mIsInLandscape) {
            // Landscape.
            mRotationAnimation.cancel();
            // Start fading out.
            if (mAlphaAnimator.isRunning()) {
                return;
            }
            mAlphaAnimator.start();
        } else {
            // Portrait.
            continueRotationAnimation();
        }
    }
}
项目:cwac-cam2    文件:FocusModePlugin.java   
public FocusModePlugin(Context ctxt,
                       FocusMode focusMode,
                       boolean isVideo) {
  this.ctxt=ctxt.getApplicationContext();
  this.focusMode=focusMode;
  this.isVideo=isVideo;

  orientationEventListener=new OrientationEventListener(ctxt) {
    @Override
    public void onOrientationChanged(int orientation) {
      lastOrientation=orientation;
    }
  };

  if (orientationEventListener.canDetectOrientation()) {
    orientationEventListener.enable();
  }
  else {
    orientationEventListener.disable();
    orientationEventListener=null;
  }
}
项目:cwac-cam2    文件:OrientationPlugin.java   
public OrientationPlugin(Context ctxt) {
  this.ctxt=ctxt.getApplicationContext();

  orientationEventListener=new OrientationEventListener(ctxt) {
    @Override
    public void onOrientationChanged(int orientation) {
      if (lastOrientation!=orientation) {
        AbstractCameraActivity.BUS
          .post(new CameraEngine.OrientationChangedEvent());
      }

      lastOrientation=orientation;
    }
  };

  if (orientationEventListener.canDetectOrientation()) {
    orientationEventListener.enable();
  }
  else {
    orientationEventListener.disable();
    orientationEventListener=null;
  }
}
项目:cwac-cam2    文件:OrientationPlugin.java   
/**
 * {@inheritDoc}
 */
@Override
public void addToCaptureRequest(CameraSession session,
                                CameraCharacteristics cc,
                                boolean facingFront,
                                CaptureRequest.Builder captureBuilder) {
  // based on https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html#JPEG_ORIENTATION

  int pictureOrientation=0;

  if (lastOrientation!=android.view.OrientationEventListener.ORIENTATION_UNKNOWN) {
    int sensorOrientation=cc.get(CameraCharacteristics.SENSOR_ORIENTATION);
    int deviceOrientation=(lastOrientation + 45) / 90 * 90;

    if (facingFront) {
      deviceOrientation = -deviceOrientation;
    }

    pictureOrientation=(sensorOrientation + deviceOrientation + 360) % 360;
  }

  captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, pictureOrientation);
}
项目:mc_backup    文件:GeckoApp.java   
@Override
public void enableCameraView() {
    // Start listening for orientation events
    mCameraOrientationEventListener = new OrientationEventListener(this) {
        @Override
        public void onOrientationChanged(int orientation) {
            if (mAppStateListeners != null) {
                for (GeckoAppShell.AppStateListener listener: mAppStateListeners) {
                    listener.onOrientationChanged();
                }
            }
        }
    };
    mCameraOrientationEventListener.enable();

    // Try to make it fully transparent.
    if (mCameraView instanceof SurfaceView) {
        if (Versions.feature11Plus) {
            mCameraView.setAlpha(0.0f);
        }
        ViewGroup mCameraLayout = (ViewGroup) findViewById(R.id.camera_layout);
        // Some phones (eg. nexus S) need at least a 8x16 preview size
        mCameraLayout.addView(mCameraView,
                              new AbsoluteLayout.LayoutParams(8, 16, 0, 0));
    }
}
项目:nexus-camera    文件:VideoModule.java   
@Override
public void onOrientationChanged(int orientation) {
    // We keep the last known orientation. So if the user first orient
    // the camera then point the camera to floor or sky, we still have
    // the correct orientation.
    if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) return;
    int newOrientation = CameraUtil.roundOrientation(orientation, mOrientation);

    if (mOrientation != newOrientation) {
        mOrientation = newOrientation;
    }

    // Show the toast after getting the first orientation changed.
    if (mHandler.hasMessages(SHOW_TAP_TO_SNAPSHOT_TOAST)) {
        mHandler.removeMessages(SHOW_TAP_TO_SNAPSHOT_TOAST);
        showTapToSnapshotToast();
    }
}
项目:io2015-codelabs    文件:CameraFragment.java   
/**
 * Translates from the device orientation given by the Android sensor APIs to the
 * orientation for a JPEG image.
 */
private int getJpegOrientation(CameraCharacteristics c, int deviceOrientation) {
    Log.d(TAG, "getJpegOrientation: ");
    if (deviceOrientation == android.view.OrientationEventListener.ORIENTATION_UNKNOWN)
        return 0;
    int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);

    // Round device orientation to a multiple of 90
    deviceOrientation = (deviceOrientation + 45) / 90 * 90;

    // Reverse device orientation for front-facing cameras
    boolean facingFront = c.get(CameraCharacteristics.LENS_FACING) ==
            CameraCharacteristics.LENS_FACING_FRONT;
    if (facingFront) deviceOrientation = -deviceOrientation;

    // Calculate desired JPEG orientation relative to camera orientation to make
    // the image upright relative to the device orientation
    int jpegOrientation = (sensorOrientation + deviceOrientation + 360) % 360;

    return jpegOrientation;
}
项目:io2015-codelabs    文件:CameraFragment.java   
/**
 * Translates from the device orientation given by the Android sensor APIs to the
 * orientation for a JPEG image.
 */
private int getJpegOrientation(CameraCharacteristics c, int deviceOrientation) {
    Log.d(TAG, "getJpegOrientation: ");
    if (deviceOrientation == android.view.OrientationEventListener.ORIENTATION_UNKNOWN)
        return 0;
    int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);

    // Round device orientation to a multiple of 90
    deviceOrientation = (deviceOrientation + 45) / 90 * 90;

    // Reverse device orientation for front-facing cameras
    boolean facingFront = c.get(CameraCharacteristics.LENS_FACING) ==
            CameraCharacteristics.LENS_FACING_FRONT;
    if (facingFront) deviceOrientation = -deviceOrientation;

    // Calculate desired JPEG orientation relative to camera orientation to make
    // the image upright relative to the device orientation
    int jpegOrientation = (sensorOrientation + deviceOrientation + 360) % 360;

    return jpegOrientation;
}
项目:MapEver    文件:CornerDetectionView.java   
private void updateOrientation()
{
    if(mCamera == null || device_orientation == OrientationEventListener.ORIENTATION_UNKNOWN)
        return;
    CameraInfo info = new CameraInfo();
    Camera.getCameraInfo(getCameraId(),info);
    int rotation = 0;
    if(info.facing == CameraInfo.CAMERA_FACING_FRONT)
    {
        rotation = (info.orientation - device_orientation +360) % 360;
    }
    else
    {
        rotation = (info.orientation + device_orientation) % 360;
    }
    Parameters params = mCamera.getParameters();
    params.setRotation(rotation);
    mCamera.setParameters(params);
}
项目:Selfie-Camera    文件:MainActivity.java   
private void onOrientationChanged(int orientation) {
    /*
     * if( MyDebug.LOG ) { Log.d(TAG, "onOrientationChanged()"); Log.d(TAG,
     * "orientation: " + orientation); Log.d(TAG, "current_orientation: " +
     * current_orientation); }
     */
    if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN)
        return;
    int diff = Math.abs(orientation - current_orientation);
    if (diff > 180)
        diff = 360 - diff;
    // only change orientation when sufficiently changed
    if (diff > 60) {
        orientation = (orientation + 45) / 90 * 90;
        orientation = orientation % 360;
        if (orientation != current_orientation) {
            this.current_orientation = orientation;
            if (MyDebug.LOG) {
                Log.d(TAG, "current_orientation is now: "
                        + current_orientation);
            }
            layoutUI();
        }
    }
}
项目:droidkit-webrtc    文件:VideoCaptureAndroid.java   
public VideoCaptureAndroid(int id, long native_capturer) {
  this.id = id;
  this.native_capturer = native_capturer;
  this.info = new Camera.CameraInfo();
  Camera.getCameraInfo(id, info);

  // Must be the last thing in the ctor since we pass a reference to |this|!
  final VideoCaptureAndroid self = this;
  orientationListener = new OrientationEventListener(GetContext()) {
      @Override public void onOrientationChanged(int degrees) {
        if (degrees == OrientationEventListener.ORIENTATION_UNKNOWN) {
          return;
        }
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
          degrees = (info.orientation - degrees + 360) % 360;
        } else {  // back-facing
          degrees = (info.orientation + degrees) % 360;
        }
        self.OnOrientationChanged(self.native_capturer, degrees);
      }
    };
  // Don't add any code here; see the comment above |self| above!
}
项目:fanfouapp-opensource    文件:ImageHelper.java   
public static int roundOrientation(final int orientationInput) {
    // landscape mode
    int orientation = orientationInput;

    if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
        orientation = 0;
    }

    orientation = orientation % 360;
    int retVal;
    if (orientation < ((0 * 90) + 45)) {
        retVal = 0;
    } else if (orientation < ((1 * 90) + 45)) {
        retVal = 90;
    } else if (orientation < ((2 * 90) + 45)) {
        retVal = 180;
    } else if (orientation < ((3 * 90) + 45)) {
        retVal = 270;
    } else {
        retVal = 0;
    }

    return retVal;
}
项目:HallMonitor    文件:CameraPreview.java   
public CameraPreview(Context ctx, AttributeSet as) {
    super(ctx, as);

    Log.d("hm-cam", "context/attributeset constructor");

    mHolder = getHolder();
    mHolder.addCallback(this);

    mOrientationListener = new OrientationEventListener(ctx, SensorManager.SENSOR_DELAY_NORMAL) {

@Override
public void onOrientationChanged(int angle) {
    mOrientation = ((int)(Math.round(angle/90.0)*90) + 90) % 360;
}

    };
 }
项目:GitHub    文件:IjkPlayerView.java   
/**
 * 初始化
 */
private void _initMediaPlayer() {
    // 加载 IjkMediaPlayer 库
    IjkMediaPlayer.loadLibrariesOnce(null);
    IjkMediaPlayer.native_profileBegin("libijkplayer.so");
    // 声音
    mAudioManager = (AudioManager) mAttachActivity.getSystemService(Context.AUDIO_SERVICE);
    mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    // 亮度
    try {
        int e = Settings.System.getInt(mAttachActivity.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
        float progress = 1.0F * (float) e / 255.0F;
        WindowManager.LayoutParams layout = mAttachActivity.getWindow().getAttributes();
        layout.screenBrightness = progress;
        mAttachActivity.getWindow().setAttributes(layout);
    } catch (Settings.SettingNotFoundException var7) {
        var7.printStackTrace();
    }
    // 进度
    mPlayerSeek.setMax(MAX_VIDEO_SEEK);
    mPlayerSeek.setOnSeekBarChangeListener(mSeekListener);
    // 视频监听
    mVideoView.setOnInfoListener(mInfoListener);
    // 触摸控制
    mGestureDetector = new GestureDetector(mAttachActivity, mPlayerGestureListener);
    mFlVideoBox.setClickable(true);
    mFlVideoBox.setOnTouchListener(mPlayerTouchListener);
    // 屏幕翻转控制
    mOrientationListener = new OrientationEventListener(mAttachActivity) {
        @Override
        public void onOrientationChanged(int orientation) {
            _handleOrientation(orientation);
        }
    };
    if (mIsForbidOrientation) {
        // 禁止翻转
        mOrientationListener.disable();
    }
}
项目:Linphone4Android    文件:LinphoneActivity.java   
@Override
public void onOrientationChanged(final int o) {
    if (o == OrientationEventListener.ORIENTATION_UNKNOWN) {
        return;
    }

    int degrees = 270;
    if (o < 45 || o > 315)
        degrees = 0;
    else if (o < 135)
        degrees = 90;
    else if (o < 225)
        degrees = 180;

    if (mAlwaysChangingPhoneAngle == degrees) {
        return;
    }
    mAlwaysChangingPhoneAngle = degrees;

    Log.d("Phone orientation changed to ", degrees);
    int rotation = (360 - degrees) % 360;
    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
        lc.setDeviceRotation(rotation);
        LinphoneCall currentCall = lc.getCurrentCall();
        if (currentCall != null && currentCall.cameraEnabled() && currentCall.getCurrentParamsCopy().getVideoEnabled()) {
            lc.updateCall(currentCall, null);
        }
    }
}
项目:ZxingForAndroid    文件:RotationListener.java   
public void listen(Context context, RotationCallback callback) {
    // Stop to make sure we're not registering the listening twice.
    stop();

    // Only use the ApplicationContext. In case of a memory leak (e.g. from a framework bug),
    // this will result in less being leaked.
    context = context.getApplicationContext();

    this.callback = callback;

    this.windowManager = (WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE);

    this.orientationEventListener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_NORMAL) {
        @Override
        public void onOrientationChanged(int orientation) {
            WindowManager localWindowManager = windowManager;
            RotationCallback localCallback = RotationListener.this.callback;
            if(windowManager != null && localCallback != null) {
                int newRotation = localWindowManager.getDefaultDisplay().getRotation();
                if (newRotation != lastRotation) {
                    lastRotation = newRotation;
                    localCallback.onRotationChanged(newRotation);
                }
            }
        }
    };
    this.orientationEventListener.enable();

    lastRotation = windowManager.getDefaultDisplay().getRotation();
}
项目:polling-station-app    文件:CameraFragment.java   
/**
 * Handles the setup that can start when the fragment is created.
 * @param savedInstanceState
 */
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    orientationListener = new OrientationEventListener(this.getActivity()) {
        public void onOrientationChanged(int orientation) {
            configureTransform(mTextureView.getWidth(), mTextureView.getHeight());
        }
    };
    int threadsToStart = Runtime.getRuntime().availableProcessors() / 2;
    createOCRThreads(threadsToStart);
    mCameraHandler = new CameraHandler(this);
}
项目:KrGallery    文件:CameraSession.java   
public CameraSession(CameraInfo info, Size preview, Size picture, int format) {
    previewSize = preview;
    pictureSize = picture;
    pictureFormat = format;
   cameraInfo = info;

    SharedPreferences sharedPreferences = Gallery.applicationContext.getSharedPreferences("camera", Activity.MODE_PRIVATE);
    currentFlashMode = sharedPreferences.getString(cameraInfo.frontCamera != 0 ? "flashMode_front" : "flashMode", Camera.Parameters.FLASH_MODE_OFF);

    orientationEventListener = new OrientationEventListener(Gallery.applicationContext) {
        @Override
        public void onOrientationChanged(int orientation) {
            if (orientationEventListener == null || !initied || orientation == ORIENTATION_UNKNOWN) {
                return;
            }
            jpegOrientation = roundOrientation(orientation, jpegOrientation);
            WindowManager mgr = (WindowManager)Gallery.applicationContext.getSystemService(Context.WINDOW_SERVICE);
            int rotation = mgr.getDefaultDisplay().getRotation();
            if (lastOrientation != jpegOrientation || rotation != lastDisplayOrientation) {
                if (!isVideo) {
                    configurePhotoCamera();
                }
                lastDisplayOrientation = rotation;
                lastOrientation = jpegOrientation;
            }
        }
    };

    if (orientationEventListener.canDetectOrientation()) {
        orientationEventListener.enable();
    } else {
        orientationEventListener.disable();
        orientationEventListener = null;
    }
}
项目:KrGallery    文件:CameraSession.java   
private int roundOrientation(int orientation, int orientationHistory) {
    boolean changeOrientation;
    if (orientationHistory == OrientationEventListener.ORIENTATION_UNKNOWN) {
        changeOrientation = true;
    } else {
        int dist = Math.abs(orientation - orientationHistory);
        dist = Math.min( dist, 360 - dist );
        changeOrientation = ( dist >= 45 + ORIENTATION_HYSTERESIS );
    }
    if (changeOrientation) {
        return ((orientation + 45) / 90 * 90) % 360;
    }
    return orientationHistory;
}
项目:PlusGram    文件:CameraSession.java   
public CameraSession(CameraInfo info, Size preview, Size picture, int format) {
    previewSize = preview;
    pictureSize = picture;
    pictureFormat = format;
    cameraInfo = info;

    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("camera", Activity.MODE_PRIVATE);
    currentFlashMode = sharedPreferences.getString(cameraInfo.frontCamera != 0 ? "flashMode_front" : "flashMode", Camera.Parameters.FLASH_MODE_OFF);

    orientationEventListener = new OrientationEventListener(ApplicationLoader.applicationContext) {
        @Override
        public void onOrientationChanged(int orientation) {
            if (orientationEventListener == null || !initied) {
                return;
            }
            WindowManager mgr = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
            int rotation = mgr.getDefaultDisplay().getRotation();
            if (lastOrientation != rotation) {
                if (!isVideo) {
                    configurePhotoCamera();
                }
                lastOrientation = rotation;
            }
        }
    };

    if (orientationEventListener.canDetectOrientation()) {
        orientationEventListener.enable();
    } else {
        orientationEventListener.disable();
        orientationEventListener = null;
    }
}
项目:EZFilter    文件:CameraFilterActivity.java   
private int roundOrientation(int orientation, int orientationHistory) {
    boolean changeOrientation;
    if (orientationHistory == OrientationEventListener.ORIENTATION_UNKNOWN) {
        changeOrientation = true;
    } else {
        int dist = Math.abs(orientation - orientationHistory);
        dist = Math.min(dist, 360 - dist);
        changeOrientation = (dist >= 45 + ORIENTATION_HYSTERESIS);
    }
    if (changeOrientation) {
        return ((orientation + 45) / 90 * 90) % 360;
    }
    return orientationHistory;
}
项目:EZFilter    文件:Camera2FilterActivity.java   
private int roundOrientation(int orientation, int orientationHistory) {
    boolean changeOrientation;
    if (orientationHistory == OrientationEventListener.ORIENTATION_UNKNOWN) {
        changeOrientation = true;
    } else {
        int dist = Math.abs(orientation - orientationHistory);
        dist = Math.min(dist, 360 - dist);
        changeOrientation = (dist >= 45 + ORIENTATION_HYSTERESIS);
    }
    if (changeOrientation) {
        return ((orientation + 45) / 90 * 90) % 360;
    }
    return orientationHistory;
}
项目:programming    文件:MainActivity.java   
private void addOrientationListener() {
    listener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_UI) {
        public void onOrientationChanged(int orientation) {
            if ((orientation >= 230 && orientation <= 290) || (orientation >= 70 && orientation <= 90)) {
                portrait.setText("True");
            }
        }
    };
    if (listener.canDetectOrientation()) listener.enable();
}
项目:Viewer    文件:RotationListener.java   
public void listen(Context context, RotationCallback callback) {
    // Stop to make sure we're not registering the listening twice.
    stop();

    // Only use the ApplicationContext. In case of a memory leak (e.g. from a framework bug),
    // this will result in less being leaked.
    context = context.getApplicationContext();

    this.callback = callback;

    this.windowManager = (WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE);

    this.orientationEventListener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_NORMAL) {
        @Override
        public void onOrientationChanged(int orientation) {
            WindowManager localWindowManager = windowManager;
            RotationCallback localCallback = RotationListener.this.callback;
            if(windowManager != null && localCallback != null) {
                int newRotation = localWindowManager.getDefaultDisplay().getRotation();
                if (newRotation != lastRotation) {
                    lastRotation = newRotation;
                    localCallback.onRotationChanged(newRotation);
                }
            }
        }
    };
    this.orientationEventListener.enable();

    lastRotation = windowManager.getDefaultDisplay().getRotation();
}