Java Code Examples for android.view.OrientationEventListener#canDetectOrientation()
The following examples show how to use
android.view.OrientationEventListener#canDetectOrientation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdvCamera.java From adv_camera with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void identifyOrientationEvents() { OrientationEventListener myOrientationEventListener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_NORMAL) { @Override public void onOrientationChanged(int iAngle) { final int[] iLookup = {0, 0, 0, 90, 90, 90, 90, 90, 90, 180, 180, 180, 180, 180, 180, 270, 270, 270, 270, 270, 270, 0, 0, 0}; // 15-degree increments if (iAngle != ORIENTATION_UNKNOWN) { int iNewOrientation = iLookup[iAngle / 15]; if (iOrientation != iNewOrientation) { iOrientation = iNewOrientation; } mPhotoAngle = normalize(iAngle); } } }; if (myOrientationEventListener.canDetectOrientation()) { myOrientationEventListener.enable(); } }
Example 2
Source File: RCTCameraView.java From react-native-camera-face-detector with MIT License | 6 votes |
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(); } }
Example 3
Source File: CameraSession.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
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 || orientation == ORIENTATION_UNKNOWN) { return; } jpegOrientation = roundOrientation(orientation, jpegOrientation); WindowManager mgr = (WindowManager) ApplicationLoader.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; } }
Example 4
Source File: CameraSession.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
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 || orientation == ORIENTATION_UNKNOWN) { return; } jpegOrientation = roundOrientation(orientation, jpegOrientation); WindowManager mgr = (WindowManager) ApplicationLoader.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; } }
Example 5
Source File: CameraSession.java From KrGallery with GNU General Public License v2.0 | 5 votes |
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; } }
Example 6
Source File: MainActivity.java From programming with GNU General Public License v3.0 | 5 votes |
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(); }
Example 7
Source File: WhatsappCameraActivity.java From WhatsAppCamera with MIT License | 5 votes |
private void identifyOrientationEvents() { myOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { @Override public void onOrientationChanged(int iAngle) { final int iLookup[] = {0, 0, 0, 90, 90, 90, 90, 90, 90, 180, 180, 180, 180, 180, 180, 270, 270, 270, 270, 270, 270, 0, 0, 0}; // 15-degree increments if (iAngle != ORIENTATION_UNKNOWN) { int iNewOrientation = iLookup[iAngle / 15]; if (iOrientation != iNewOrientation) { iOrientation = iNewOrientation; if (iOrientation == 0) { mOrientation = 90; } else if (iOrientation == 270) { mOrientation = 0; } else if (iOrientation == 90) { mOrientation = 180; } } mPhotoAngle = normalize(iAngle); } } }; if (myOrientationEventListener.canDetectOrientation()) { myOrientationEventListener.enable(); } }
Example 8
Source File: ReactOrientationListenerModule.java From react-native-orientation-listener with MIT License | 5 votes |
public ReactOrientationListenerModule(ReactApplicationContext reactContext) { super(reactContext); this.reactContext = reactContext; final ReactApplicationContext thisContext = reactContext; mOrientationListener = new OrientationEventListener(reactContext, SensorManager.SENSOR_DELAY_NORMAL) { @Override public void onOrientationChanged(int orientation) { WritableNativeMap params = new WritableNativeMap(); String orientationValue = ""; if(orientation == 0) { orientationValue = "PORTRAIT"; } else { orientationValue = "LANDSCAPE"; } params.putString("orientation", orientationValue); params.putString("device", getDeviceName()); if (thisContext.hasActiveCatalystInstance()) { thisContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("orientationDidChange", params); } } }; if (mOrientationListener.canDetectOrientation() == true) { mOrientationListener.enable(); } else { mOrientationListener.disable(); } }
Example 9
Source File: ReactOrientationControllerModule.java From react-native-orientation-controller with MIT License | 5 votes |
public ReactOrientationControllerModule(final ReactApplicationContext reactContext, Activity activity) { super(reactContext); this.reactContext = reactContext; this.mActivity = activity; mApplicationOrientationListener = new OrientationEventListener(reactContext) { @Override public void onOrientationChanged(int orientation) { deviceOrientation = orientation; if(lastDeviceOrientation.compareTo(getDeviceOrientationAsString())!=0){ lastDeviceOrientation = getDeviceOrientationAsString(); WritableNativeMap data = getDataMap(); try{ reactContext .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("orientationDidChange", data); } catch (RuntimeException e) { Log.e("ERROR ", "java.lang.RuntimeException: Trying to invoke JS before CatalystInstance has been set!"); } } } }; if (mApplicationOrientationListener.canDetectOrientation() == true) { mApplicationOrientationListener.enable(); } else { mApplicationOrientationListener.disable(); } }
Example 10
Source File: CameraSession.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
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 || orientation == ORIENTATION_UNKNOWN) { return; } jpegOrientation = roundOrientation(orientation, jpegOrientation); WindowManager mgr = (WindowManager) ApplicationLoader.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; } }
Example 11
Source File: CameraSession.java From Telegram with GNU General Public License v2.0 | 5 votes |
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 || orientation == ORIENTATION_UNKNOWN) { return; } jpegOrientation = roundOrientation(orientation, jpegOrientation); WindowManager mgr = (WindowManager) ApplicationLoader.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; } }
Example 12
Source File: BarcodeCaptureActivity.java From google-authenticator-android with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // On API 19+ devices, we make the status bar become transparent. In older devices, we simply // remove the status bar. if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); // On API 21+ we need to set the status bar color to transparent color instead of using flag // FLAG_TRANSLUCENT_STATUS as in API 19, 20 to make the the status bar transparent. if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { getWindow().setStatusBarColor(Color.TRANSPARENT); } else { getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } } else { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } mStartFromAddAccountActivity = getIntent() .getBooleanExtra(INTENT_EXTRA_START_FROM_ADD_ACCOUNT, false); setContentView(R.layout.barcode_capture_activity); mCameraSourcePreview = (CameraSourcePreview) findViewById(R.id.camera_source_preview); mGraphicOverlay = (GraphicOverlay) findViewById(R.id.graphic_overlay); mCurrentRotation = getWindowManager().getDefaultDisplay().getRotation(); mOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_UI) { @Override public void onOrientationChanged(int i) { if (i == ORIENTATION_UNKNOWN) { return; } int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (mCurrentRotation != rotation) { // Orientation changed, refresh camera. mCurrentRotation = rotation; if (mCameraSourcePreview != null) { mCameraSourcePreview.stop(); mCameraSourcePreview.release(); } createCameraSource(); startCameraSource(); } } }; if (mOrientationEventListener.canDetectOrientation() == true) { mOrientationEventListener.enable(); } else { mOrientationEventListener.disable(); } // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. if (mPermissionRequestor.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) { createCameraSource(); } else { requestCameraPermission(); } }