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.team3061.cheezdroid.SelfieModeFragment.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 w w. ja v a2s.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()) { Log.i("CameraId", cameraId); 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) { Log.w(TAG, "Skipped for facing " + cameraId); continue; } StreamConfigurationMap map = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (map == null) { Log.w(TAG, "Skipped for null map " + cameraId); continue; } // For still image captures, we use the largest available size. Size[] imgSizes = map.getOutputSizes(ImageFormat.YUV_420_888); Size selected = imgSizes[imgSizes.length - 1]; for (Size s : imgSizes) { if (s.getWidth() <= 352) { selected = s; break; } } mImageReader = ImageReader.newInstance(selected.getWidth(), selected.getHeight(), ImageFormat.YUV_420_888, /*maxImages*/3); mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); // Find out if we need to swap dimension to get the preview size relative to sensor // coordinate. int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); 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; } // 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), rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, selected); Log.i(TAG, "Size : " + mPreviewSize); // 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()); } // Check if the flash is supported. Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); mFlashSupported = available == null ? false : available; mCameraId = cameraId; return; } } catch (CameraAccessException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. ErrorDialog.newInstance("Camera error").show(getChildFragmentManager(), FRAGMENT_DIALOG); } }
From source file:com.android.music.MusicBrowserActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MusicUtils.setPartyShuffleMenuIcon(menu); super.onPrepareOptionsMenu(menu); if (mPermissionReqProcessed == true) { if (!mIsSdcardMounted) { MusicLogUtils.w(TAG, "Sdcard is not mounted, don't show option menu!"); return false; }/*from w w w .j a v a 2s . c om*/ /// M: Only show play all in song activity. menu.findItem(PLAY_ALL).setVisible(mCurrentTab == SONG_INDEX); /// M: Show shuffle all in all activity except playlist activity. menu.findItem(SHUFFLE_ALL).setVisible(mCurrentTab != PLAYLIST_INDEX); /// M: Only show effect menu when effect class is enable. MusicUtils.setEffectPanelMenu(getApplicationContext(), menu); /// M: Search button can only show on one of place between ///nowplaying and action bar, when action bar exist, /// it should show on action bar, otherwise show on nowplaying, ///if nowplaying not exist(such as landscape in /// MusicBrowserActivity), show it in option menu. mSearchItem.setVisible(mOrientaiton == Configuration.ORIENTATION_LANDSCAPE); /// M: show the specific extral option menu when plugin need Bundle options = new Bundle(); options.putInt(PluginUtils.TAB_INDEX, mCurrentTab); mMusicPlugin.onPrepareOptionsMenu(menu, ACTIVITY_NAME, options); } return true; }
From source file:com.rbsoftware.pfm.personalfinancemanager.MainActivity.java
/** * Creates navigation drawer//www. j av a2 s .co m * * @param savedInstanceState of activity * @param toolbar of activity * @param intent received after login */ private void setupNavigationDrawer(final Bundle savedInstanceState, Toolbar toolbar, Intent intent) { AccountDocument accountDocument = financeDocumentModel .getAccountDocument(AccountDocument.ACCOUNT_DOCUMENT_ID + getUserId()); if (accountDocument == null) { HashMap<String, List<String>> values = new HashMap<>(); List<String> mainAccount = new ArrayList<>(); mainAccount.add(getString(R.string.main_wallet)); values.put(FinanceDocument.MAIN_ACCOUNT, mainAccount); accountDocument = new AccountDocument(MainActivity.getUserId(), values); MainActivity.financeDocumentModel.createDocument(accountDocument); } final HashMap<String, List<String>> accountsMap = accountDocument.getAccountsMap(); ArrayList<ProfileDrawerItem> profiles = new ArrayList<>(); for (Map.Entry<String, List<String>> entry : accountsMap.entrySet()) { ProfileDrawerItem profileDrawerItem; if (intent.getStringExtra("photoURL") != null) { profileDrawerItem = new ProfileDrawerItem().withName(intent.getStringExtra("name")) .withEmail(entry.getValue().get(0)).withIcon(intent.getStringExtra("photoURL")); } else { profileDrawerItem = new ProfileDrawerItem().withName(intent.getStringExtra("name")) .withEmail(entry.getValue().get(0)); } profiles.add(profileDrawerItem); } //Set up image loading through Picasso DrawerImageLoader.init(new AbstractDrawerImageLoader() { @Override public void set(ImageView imageView, Uri uri, Drawable placeholder) { if (uri != null) { Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView); } } @Override public void cancel(ImageView imageView) { Picasso.with(imageView.getContext()).cancelRequest(imageView); } }); // Create the AccountHeader drawerAccountHeader = new AccountHeaderBuilder().withActivity(this) .withHeaderBackground(R.drawable.account_header_background) .addProfiles(profiles.toArray(new ProfileDrawerItem[profiles.size()])) .withOnlyMainProfileImageVisible(true).withProfileImagesClickable(false) .withSavedInstance(savedInstanceState) .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() { @Override public boolean onProfileChanged(View view, IProfile profile, boolean current) { for (Map.Entry<String, List<String>> entry : getAccountsMap().entrySet()) { if (entry.getValue().get(0).equals(profile.getEmail().toString())) { mActiveAccountId = entry.getKey(); break; } } //checking if orientation has been changed //if not reload data int prevState = orientationState; if (savedInstanceState != null) { prevState = savedInstanceState.getInt("screenOrientation"); savedInstanceState.putInt("screenOrientation", getResources().getConfiguration().orientation); } if (!Utils.isOrientationChanged(getApplicationContext(), prevState)) { reloadFragmentData(); } return false; } }).build(); //Setting default account for (IProfile profile : profiles) { String accountName = getString(R.string.main_wallet); if (savedInstanceState != null) { accountName = savedInstanceState.getString("activeAccountName"); } if (profile.getEmail().getText().equals(accountName)) { drawerAccountHeader.setActiveProfile(profile, true); } } //Build navigation drawer DrawerBuilder drawerBuilder = new DrawerBuilder().withActivity(this).withToolbar(toolbar) .withAccountHeader(drawerAccountHeader).withDelayDrawerClickEvent(0) .addDrawerItems( new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[0]) .withIcon(GoogleMaterial.Icon.gmd_dashboard), new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[1]) .withIcon(GoogleMaterial.Icon.gmd_book), new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[2]) .withIcon(GoogleMaterial.Icon.gmd_monetization_on), new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[3]) .withIcon(GoogleMaterial.Icon.gmd_pie_chart), new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[4]) .withIcon(GoogleMaterial.Icon.gmd_credit_card), new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[5]) .withIcon(GoogleMaterial.Icon.gmd_history), new DividerDrawerItem(), new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[6]) .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star), new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[7]) .withIcon(GoogleMaterial.Icon.gmd_add_circle), new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[8]) .withIcon(GoogleMaterial.Icon.gmd_account_balance_wallet), new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[9]) .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_settings), new PrimaryDrawerItem().withName(getResources().getStringArray(R.array.drawer_menu)[10]) .withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app)) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { if (position == 11) { Intent i = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(i, MainActivity.RESULT_OK); return true; } else if (position == 8) { recommendToFriend(); } else if (position == 12) { signout(); return true; } else { openFragment(position); } return false; } }) .withSavedInstance(savedInstanceState); //make multipane layout for tablets in landscape orientation if (Utils.isTablet(this) && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { drawerBuilder.withTranslucentStatusBar(false).withTranslucentNavigationBar(false); mMaterialDrawer = drawerBuilder.buildView(); ((ViewGroup) findViewById(R.id.nav_tablet)).addView(mMaterialDrawer.getSlider()); } else { mMaterialDrawer = drawerBuilder.build(); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(false); mMaterialDrawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(true); } } }
From source file:de.tlabs.ssr.g1.client.SourcesView.java
public void transformToFitScene() { float xScalingFactor = 0.0f; float yScalingFactor = 0.0f; float xDiff;// w w w. ja v a 2 s . c om float yDiff; float[][] sceneBounds; float minBounds[]; float maxBounds[]; // if size of this view not yet initialized, wait until it is initialized if (!viewSizeInitialized) { transformToFitSceneFlag = true; return; } // get scene bounds in screen coordinates recalculateViewportTransformation(); // just to be sure we are using the latest values sceneBounds = getSceneBounds(viewportTransformation); minBounds = sceneBounds[0]; maxBounds = sceneBounds[1]; // get max x and y distances in pixels xDiff = maxBounds[0] - minBounds[0]; yDiff = maxBounds[1] - minBounds[1]; // recalculate scaling if (xDiff > 0 || yDiff > 0) { // calculate best scaling in x and y direction if (xDiff > 0) { xScalingFactor = ((float) getWidth() - FIT_SCENE_PIXEL_BORDER_2) / xDiff; } else { xScalingFactor = Float.POSITIVE_INFINITY; } if (yDiff > 0) { yScalingFactor = ((float) getHeight() - FIT_SCENE_PIXEL_BORDER_2) / yDiff; } else { yScalingFactor = Float.POSITIVE_INFINITY; } // set best scaling float scalingFactor = Math.min(xScalingFactor, yScalingFactor); zoomView(scalingFactor); recalculateViewportTransformation(newViewportTransformation, currentCenterRotation, currentScaling * scalingFactor, currentTranslation); } else { newViewportTransformation.set(viewportTransformation); } // get scene bounds using new scaling sceneBounds = getSceneBounds(newViewportTransformation); minBounds = sceneBounds[0]; maxBounds = sceneBounds[1]; // get max x and y distances in pixels xDiff = maxBounds[0] - minBounds[0]; yDiff = maxBounds[1] - minBounds[1]; // calculate translation to center the scene float transX = -minBounds[0] + (getWidth() - xDiff) / 2; float transY = -minBounds[1] + (getHeight() - yDiff) / 2; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { translateView(transX, transY); } else if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { translateView(transY, -transX); } }
From source file:com.example.dorothylu.thesisprototype.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 ww .j av a2 s . 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. 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()); mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2); mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); // 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 mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); boolean swappedDimensions = false; switch (displayRotation) { case Surface.ROTATION_0: case Surface.ROTATION_180: if (mSensorOrientation == 90 || mSensorOrientation == 270) { swappedDimensions = true; } break; case Surface.ROTATION_90: case Surface.ROTATION_270: if (mSensorOrientation == 0 || mSensorOrientation == 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; } // 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), 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) { mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); } else { mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); } // Check if the flash is supported. Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); mFlashSupported = available == null ? false : available; 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. ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(), FRAGMENT_DIALOG); } }
From source file:com.example.snackler.snackler.TwoFragment.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 w w . j a va 2 s . 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()); mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2); mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); // 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 mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); boolean swappedDimensions = false; switch (displayRotation) { case Surface.ROTATION_0: case Surface.ROTATION_180: if (mSensorOrientation == 90 || mSensorOrientation == 270) { swappedDimensions = true; } break; case Surface.ROTATION_90: case Surface.ROTATION_270: if (mSensorOrientation == 0 || mSensorOrientation == 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; } // 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), 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) { mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); } else { mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); } // Check if the flash is supported. Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); mFlashSupported = available == null ? false : available; 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. ErrorDialog.newInstance("Camera error").show(getChildFragmentManager(), FRAGMENT_DIALOG); } }
From source file:com.alexstrong.smashing.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 www . ja v a 2s .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()); mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2); mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); // 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 mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); boolean swappedDimensions = false; switch (displayRotation) { case Surface.ROTATION_0: case Surface.ROTATION_180: if (mSensorOrientation == 90 || mSensorOrientation == 270) { swappedDimensions = true; } break; case Surface.ROTATION_90: case Surface.ROTATION_270: if (mSensorOrientation == 0 || mSensorOrientation == 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; } // 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), 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) { mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); } else { mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); } // Check if the flash is supported. Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); mFlashSupported = available == null ? false : available; 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. ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(), FRAGMENT_DIALOG); } }
From source file:de.tlabs.ssr.g1.client.SourcesView.java
public void setOrientation(int newOrientation) { if (currentOrientation == newOrientation) return;// w w w. jav a2 s . c om if (newOrientation == Configuration.ORIENTATION_LANDSCAPE) { // portrait -> landscape centerRotationInterpolator.setStartEndValues(0.0f, -90.0f); } else if (newOrientation == Configuration.ORIENTATION_PORTRAIT) { // landscape -> portrait centerRotationInterpolator.setStartEndValues(-90.0f, 0.0f); } else { // unsupported orientation, this should never happen return; } // save current orientation currentOrientation = newOrientation; setOrientationFlag(true); // start interpolating centerRotationInterpolator.startInterpolating(); }
From source file:camera2basic.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 *//* w ww. jav a 2 s . co 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. 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()); mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2); mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); // Find out if we need to swap dimension to get the preview size relative to sensor // coordinate. int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); 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; } // 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), 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) { mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); } else { mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); } // Check if the flash is supported. Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); mFlashSupported = available == null ? false : available; 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. ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(), FRAGMENT_DIALOG); } }
From source file:com.ttxgps.zoom.GestureImageView.java
/** * Returns true if the image dimensions are aligned with the orientation of * the device.//from w w w . java2 s .com * * @return */ public boolean isOrientationAligned() { if (deviceOrientation == Configuration.ORIENTATION_LANDSCAPE) { return isLandscape(); } else if (deviceOrientation == Configuration.ORIENTATION_PORTRAIT) { return isPortrait(); } return true; }