List of usage examples for android.content.res Configuration ORIENTATION_LANDSCAPE
int ORIENTATION_LANDSCAPE
To view the source code for android.content.res Configuration ORIENTATION_LANDSCAPE.
Click Source Link
From source file:com.pvjunkies.fieldcam.CameraFragment.java
/** * Tries to open a {@link CameraDevice}. The result is listened by `mStateCallback`. *//* w w w .ja va 2s . com*/ @SuppressWarnings("MissingPermission") private void openCamera(int width, int height) { if (!hasPermissionsGranted(VIDEO_PERMISSIONS)) { requestVideoPermissions(); return; } final Activity activity = getActivity(); if (null == activity || activity.isFinishing()) { return; } CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { Log.d(TAG, "tryAcquire"); if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } String cameraId = manager.getCameraIdList()[0]; // Choose the sizes for camera preview and video recording CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); if (map == null) { throw new RuntimeException("Cannot get available preview/video sizes"); } mVideoSize = chooseVideoSize(map.getOutputSizes(MediaRecorder.class)); mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height, mVideoSize); int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); } else { mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); } configureTransform(width, height); mMediaRecorder = new MediaRecorder(); manager.openCamera(cameraId, mStateCallback, null); } catch (CameraAccessException e) { Toast.makeText(activity, "Cannot access the camera.", Toast.LENGTH_SHORT).show(); activity.finish(); } catch (NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(), FRAGMENT_DIALOG); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening."); } }
From source file:com.google.appinventor.components.runtime.Form.java
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); final int newOrientation = newConfig.orientation; if (newOrientation == Configuration.ORIENTATION_LANDSCAPE || newOrientation == Configuration.ORIENTATION_PORTRAIT) { // At this point, the screen has not be resized to match the new orientation. // We use Handler.post so that we'll dispatch the ScreenOrientationChanged event after the // screen has been resized to match the new orientation. androidUIHandler.post(new Runnable() { public void run() { boolean dispatchEventNow = false; if (frameLayout != null) { if (newOrientation == Configuration.ORIENTATION_LANDSCAPE) { if (frameLayout.getWidth() >= frameLayout.getHeight()) { dispatchEventNow = true; }//from w ww.j ava2 s . c om } else { // Portrait if (frameLayout.getHeight() >= frameLayout.getWidth()) { dispatchEventNow = true; } } } if (dispatchEventNow) { ScreenOrientationChanged(); } else { // Try again later. androidUIHandler.post(this); } } }); } }
From source file:com.sociablue.nanodegree_p1.MovieListFragment.java
private void setGridColumns() { int currentOrientation = getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { mMovieListGridView.setNumColumns(4); } else {//from ww w. ja v a 2 s. co m mMovieListGridView.setNumColumns(2); } }
From source file:com.mebene.ACHud.Camera2VideoFragment2.java
/** * Tries to open a {@link CameraDevice}. The result is listened by `mStateCallback`. *///from www .j a v a2 s . co m @SuppressWarnings("MissingPermission") private void openCamera(int width, int height) { if (!hasPermissionsGranted(VIDEO_PERMISSIONS)) { requestVideoPermissions(); return; } final Activity activity = getActivity(); if (null == activity || activity.isFinishing()) { return; } CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { Log.d(TAG, "tryAcquire"); if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } String cameraId = manager.getCameraIdList()[0]; // Choose the sizes for camera preview and video recording CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); if (map == null) { throw new RuntimeException("Cannot get available preview/video sizes"); } mVideoSize = chooseVideoSize(map.getOutputSizes(MediaRecorder.class)); mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height, mVideoSize); int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); } else { mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); } configureTransform(width, height); mMediaRecorder = new MediaRecorder(); manager.openCamera(cameraId, mStateCallback, null); } catch (CameraAccessException e) { Toast.makeText(activity, "Cannot access the camera.", Toast.LENGTH_SHORT).show(); activity.finish(); } catch (NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. ErrorDialog.newInstance("getString(R.string.camera_error)").show(getChildFragmentManager(), FRAGMENT_DIALOG); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening."); } }
From source file:com.example.testcamera.Camera2BasicFragmentGoogle.java
/** * Sets up member variables related to camera. * * @param width The width of available size for camera preview * @param height The height of available size for camera preview *//* w ww. j a v a 2s .c o m*/ private void setUpCameraOutputs(int width, int height) { Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); // We don't use a front facing camera in this sample. if (characteristics .get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) { continue; } StreamConfigurationMap map = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); // For still image captures, we use the largest available size. Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2); mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); // Danger, W.R.! Attempting to use too large a preview size could exceed the camera // bus' bandwidth limitation, resulting in gorgeous previews but the storage of // garbage capture data. mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height, largest); // We fit the aspect ratio of TextureView to the size of preview we picked. int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); } else { mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); } mCameraId = cameraId; return; } } catch (CameraAccessException e) { e.printStackTrace(); } catch (NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. new ErrorDialog().show(getFragmentManager(), "dialog"); } }
From source file:com.thomasokken.free42.Free42Activity.java
@Override public void onConfigurationChanged(Configuration newConf) { super.onConfigurationChanged(newConf); orientation = newConf.orientation == Configuration.ORIENTATION_LANDSCAPE ? 1 : 0; boolean[] ann_state = skin.getAnnunciators(); SkinLayout newSkin = null;/*ww w . j a v a2s .com*/ if (skinName[orientation].length() == 0 && externalSkinName[orientation].length() > 0) { try { newSkin = new SkinLayout(externalSkinName[orientation], skinSmoothing[orientation], displaySmoothing[orientation], ann_state); } catch (IllegalArgumentException e) { } } if (newSkin == null) { try { newSkin = new SkinLayout(skinName[orientation], skinSmoothing[orientation], displaySmoothing[orientation], ann_state); } catch (IllegalArgumentException e) { } } if (newSkin == null) { try { newSkin = new SkinLayout(builtinSkinNames[0], skinSmoothing[orientation], displaySmoothing[orientation], ann_state); } catch (IllegalArgumentException e) { // This one should never fail; we're loading a built-in skin. } } if (newSkin != null) skin = newSkin; calcView.invalidate(); core_repaint_display(); }
From source file:augsburg.se.alltagsguide.overview.OverviewActivity.java
private boolean shouldUseMultipleColumns() { boolean useMultiple = false; if (getResources() != null) { android.content.res.Configuration config = getResources().getConfiguration(); if (config != null) { switch (config.orientation) { case android.content.res.Configuration.ORIENTATION_LANDSCAPE: useMultiple = mPrefUtilities.useMultipleColumnsLandscape(); break; case android.content.res.Configuration.ORIENTATION_PORTRAIT: useMultiple = mPrefUtilities.useMultipleColumnsPortrait(); break; }/*w w w . j av a 2 s . c o m*/ } } else { useMultiple = mPrefUtilities.useMultipleColumnsPortrait(); } return useMultiple; }
From source file:com.android.music.MusicBrowserActivity.java
/** * M: Create fake menu.// ww w . ja v a 2 s. c om */ private void createFakeMenu() { if (mPermissionReqProcessed == true) { if (mHasMenukey) { MusicLogUtils.d(TAG, "createFakeMenu Quit when there has Menu Key"); return; } if (mOrientaiton == Configuration.ORIENTATION_LANDSCAPE) { mOverflowMenuButtonId = R.id.overflow_menu; mOverflowMenuButton = findViewById(R.id.overflow_menu); } else { mOverflowMenuButtonId = R.id.overflow_menu_nowplaying; mOverflowMenuButton = findViewById(R.id.overflow_menu_nowplaying); View parent = (View) mOverflowMenuButton.getParent(); if (parent != null) { parent.setVisibility(View.VISIBLE); } } mOverflowMenuButton.setVisibility(View.VISIBLE); mOverflowMenuButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { MusicLogUtils.d(TAG, "createFakeMenu:onClick()"); if (v.getId() == mOverflowMenuButtonId) { final PopupMenu popupMenu = new PopupMenu(MusicBrowserActivity.this, mOverflowMenuButton); mPopupMenu = popupMenu; final Menu menu = popupMenu.getMenu(); onCreateOptionsMenu(menu); popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { return onOptionsItemSelected(item); } }); popupMenu.setOnDismissListener(new OnDismissListener() { public void onDismiss(PopupMenu menu) { mPopupMenuShowing = false; MusicLogUtils.d(TAG, "createFakeMenu:onDismiss() called"); return; } }); onPrepareOptionsMenu(menu); mPopupMenuShowing = true; if (popupMenu != null) { MusicLogUtils.d(TAG, "createFakeMenu:popupMenu.show()"); popupMenu.show(); } } } }); } }
From source file:com.example.anna_maria.myapplication.Camera2VideoFragment.java
/** * Tries to open a {@link CameraDevice}. The result is listened by `mStateCallback`. *///w w w . j a va2 s .c o m private void openCamera(int width, int height) { if (!hasPermissionsGranted(VIDEO_PERMISSIONS)) { requestVideoPermissions(); return; } final Activity activity = getActivity(); if (null == activity || activity.isFinishing()) { return; } CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { Log.d(TAG, "tryAcquire"); if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) { throw new RuntimeException("Time out waiting to lock camera opening."); } String cameraId = manager.getCameraIdList()[1]; if (cameraId == null) { throw new RuntimeException("Lulz no camera"); } // Choose the sizes for camera preview and video recording CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); mVideoSize = chooseVideoSize(map.getOutputSizes(MediaRecorder.class)); mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height, mVideoSize); int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); } else { mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); } configureTransform(width, height); mMediaRecorder = new MediaRecorder(); manager.openCamera(cameraId, mStateCallback, null); } catch (CameraAccessException e) { Toast.makeText(activity, "Cannot access the camera.", Toast.LENGTH_SHORT).show(); activity.finish(); } catch (NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(), FRAGMENT_DIALOG); } catch (InterruptedException e) { throw new RuntimeException("Interrupted while trying to lock camera opening."); } }
From source file:com.example.android.tflitecamerademo.Camera2BasicFragment.java
/** * Sets up member variables related to camera. * * @param width The width of available size for camera preview * @param height The height of available size for camera preview *//*from w w w . j a v a2s.com*/ private void setUpCameraOutputs(int width, int height) { Activity activity = getActivity(); CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); // We don't use a front facing camera in this sample. Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING); if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) { continue; } StreamConfigurationMap map = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (map == null) { continue; } // // For still image captures, we use the largest available size. Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); imageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/ 2); // Find out if we need to swap dimension to get the preview size relative to sensor // coordinate. int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); // noinspection ConstantConditions /* Orientation of the camera sensor */ int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); boolean swappedDimensions = false; switch (displayRotation) { case Surface.ROTATION_0: case Surface.ROTATION_180: if (sensorOrientation == 90 || sensorOrientation == 270) { swappedDimensions = true; } break; case Surface.ROTATION_90: case Surface.ROTATION_270: if (sensorOrientation == 0 || sensorOrientation == 180) { swappedDimensions = true; } break; default: Log.e(TAG, "Display rotation is invalid: " + displayRotation); } Point displaySize = new Point(); activity.getWindowManager().getDefaultDisplay().getSize(displaySize); int rotatedPreviewWidth = width; int rotatedPreviewHeight = height; int maxPreviewWidth = displaySize.x; int maxPreviewHeight = displaySize.y; if (swappedDimensions) { rotatedPreviewWidth = height; rotatedPreviewHeight = width; maxPreviewWidth = displaySize.y; maxPreviewHeight = displaySize.x; } if (maxPreviewWidth > MAX_PREVIEW_WIDTH) { maxPreviewWidth = MAX_PREVIEW_WIDTH; } if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) { maxPreviewHeight = MAX_PREVIEW_HEIGHT; } previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest); // We fit the aspect ratio of TextureView to the size of preview we picked. int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { textureView.setAspectRatio(previewSize.getWidth(), previewSize.getHeight()); } else { textureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth()); } this.cameraId = cameraId; return; } } catch (CameraAccessException e) { Log.e(TAG, "Failed to access Camera", e); } catch (NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(), FRAGMENT_DIALOG); } }