Java Code Examples for android.view.OrientationEventListener#enable()
The following examples show how to use
android.view.OrientationEventListener#enable() .
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: CameraView.java From LLApp with Apache License 2.0 | 5 votes |
/** * 启动屏幕朝向改变监听函数 用于在屏幕横竖屏切换时改变保存的图片的方向 */ 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(); }
Example 8
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 9
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 10
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 11
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 12
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 13
Source File: OrientationUtils.java From GSYVideoPlayer with Apache License 2.0 | 4 votes |
protected void init() { mOrientationEventListener = new OrientationEventListener(mActivity.getApplicationContext()) { @SuppressLint("SourceLockedOrientationActivity") @Override public void onOrientationChanged(int rotation) { boolean autoRotateOn = (Settings.System.getInt(mActivity.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1); if (!autoRotateOn && mRotateWithSystem) { if (!mIsOnlyRotateLand || getIsLand() == LAND_TYPE_NULL) { return; } } if (mVideoPlayer != null && mVideoPlayer.isVerticalFullByVideoSize()) { return; } if (mIsPause) { return; } // 设置竖屏 if (((rotation >= 0) && (rotation <= mOrientationOption.getNormalPortraitAngleStart())) || (rotation >= mOrientationOption.getNormalPortraitAngleEnd())) { if (mClick) { if (mIsLand > LAND_TYPE_NULL && !mClickLand) { return; } else { mClickPort = true; mClick = false; mIsLand = LAND_TYPE_NULL; } } else { if (mIsLand > LAND_TYPE_NULL) { if (!mIsOnlyRotateLand) { mScreenType = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); if (mVideoPlayer.getFullscreenButton() != null) { if (mVideoPlayer.isIfCurrentIsFullscreen()) { mVideoPlayer.getFullscreenButton().setImageResource(mVideoPlayer.getShrinkImageRes()); } else { mVideoPlayer.getFullscreenButton().setImageResource(mVideoPlayer.getEnlargeImageRes()); } } mIsLand = LAND_TYPE_NULL; } mClick = false; } } } // 设置横屏 else if (((rotation >= mOrientationOption.getNormalLandAngleStart()) && (rotation <= mOrientationOption.getNormalLandAngleEnd()))) { if (mClick) { if (!(mIsLand == LAND_TYPE_NORMAL) && !mClickPort) { return; } else { mClickLand = true; mClick = false; mIsLand = LAND_TYPE_NORMAL; } } else { if (!(mIsLand == LAND_TYPE_NORMAL)) { mScreenType = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); if (mVideoPlayer.getFullscreenButton() != null) { mVideoPlayer.getFullscreenButton().setImageResource(mVideoPlayer.getShrinkImageRes()); } mIsLand = 1; mClick = false; } } } // 设置反向横屏 else if (rotation > mOrientationOption.getReverseLandAngleStart() && rotation < mOrientationOption.getReverseLandAngleEnd()) { if (mClick) { if (!(mIsLand == LAND_TYPE_REVERSE) && !mClickPort) { return; } else { mClickLand = true; mClick = false; mIsLand = LAND_TYPE_REVERSE; } } else if (!(mIsLand == LAND_TYPE_REVERSE)) { mScreenType = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); if (mVideoPlayer.getFullscreenButton() != null) { mVideoPlayer.getFullscreenButton().setImageResource(mVideoPlayer.getShrinkImageRes()); } mIsLand = LAND_TYPE_REVERSE; mClick = false; } } } }; mOrientationEventListener.enable(); }
Example 14
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(); } }
Example 15
Source File: WebRTCDemo.java From webrtc-app-mono with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { Log.d(TAG, "onCreate"); super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); populateCameraOrientations(); setContentView(R.layout.tabhost); IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().compareTo(Intent.ACTION_HEADSET_PLUG) == 0) { int state = intent.getIntExtra("state", 0); Log.v(TAG, "Intent.ACTION_HEADSET_PLUG state: " + state + " microphone: " + intent.getIntExtra("microphone", 0)); if (voERunning) { routeAudio(state == 0 && cbEnableSpeaker.isChecked()); } } } }; registerReceiver(receiver, receiverFilter); mTabHost = getTabHost(); // Main tab mTabSpecVideo = mTabHost.newTabSpec("tab_video"); mTabSpecVideo.setIndicator("Main"); mTabSpecVideo.setContent(R.id.tab_video); mTabHost.addTab(mTabSpecVideo); // Shared config tab mTabHost = getTabHost(); mTabSpecConfig = mTabHost.newTabSpec("tab_config"); mTabSpecConfig.setIndicator("Settings"); mTabSpecConfig.setContent(R.id.tab_config); mTabHost.addTab(mTabSpecConfig); TabSpec mTabv; mTabv = mTabHost.newTabSpec("tab_vconfig"); mTabv.setIndicator("Video"); mTabv.setContent(R.id.tab_vconfig); mTabHost.addTab(mTabv); TabSpec mTaba; mTaba = mTabHost.newTabSpec("tab_aconfig"); mTaba.setIndicator("Audio"); mTaba.setContent(R.id.tab_aconfig); mTabHost.addTab(mTaba); int childCount = mTabHost.getTabWidget().getChildCount(); for (int i = 0; i < childCount; i++) { mTabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50; } orientationListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_UI) { public void onOrientationChanged (int orientation) { if (orientation != ORIENTATION_UNKNOWN) { currentDeviceOrientation = orientation; compensateCameraRotation(); } } }; orientationListener.enable (); // Create a folder named webrtc in /scard for debugging webrtcDebugDir = Environment.getExternalStorageDirectory().toString() + webrtcName; File webrtcDir = new File(webrtcDebugDir); if (!webrtcDir.exists() && webrtcDir.mkdir() == false) { Log.v(TAG, "Failed to create " + webrtcDebugDir); } else if (!webrtcDir.isDirectory()) { Log.v(TAG, webrtcDebugDir + " exists but not a folder"); webrtcDebugDir = null; } startMain(); if (AUTO_CALL_RESTART_DELAY_MS > 0) startOrStop(); }
Example 16
Source File: CordovaActivity.java From crosswalk-cordova-android with Apache License 2.0 | 4 votes |
/** * Shows the splash screen over the full Activity */ @SuppressWarnings("deprecation") protected void showSplashScreen(final int time) { final CordovaActivity that = this; Runnable runnable = new Runnable() { public void run() { // Create the layout for the dialog splashLayout = getSplashLayout(); // Create and show the dialog splashDialog = new Dialog(that, android.R.style.Theme_Translucent_NoTitleBar); // check to see if the splash screen should be full screen if(getBooleanProperty("FullScreen", false)) { toggleFullscreen(splashDialog.getWindow()); if (isImmersiveMode()) { splashDialog.getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { setSystemUiVisibilityMode(splashDialog.getWindow()); } } }); } } splashDialog.setContentView(splashLayout); splashDialog.setCancelable(false); splashDialog.show(); mCurrentOrientation = getScreenOrientation(); splashOrientationListener = new OrientationEventListener(that, SensorManager.SENSOR_DELAY_NORMAL) { public void onOrientationChanged(int ori) { if (splashDialog == null || !splashDialog.isShowing()) { return; } // Reset contentView of splashDialog when orientation changed. int orientation = getScreenOrientation(); if (orientation != mCurrentOrientation) { splashLayout = getSplashLayout(); splashDialog.setContentView(splashLayout); mCurrentOrientation = orientation; } } }; splashOrientationListener.enable(); // Set Runnable to remove splash screen just in case final Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { removeSplashScreen(); } }, time); } }; this.runOnUiThread(runnable); }