List of usage examples for android.view Display getRotation
@Surface.Rotation public int getRotation()
From source file:org.puder.trs80.EmulatorActivity.java
private void lockOrientation() { Display display = getWindowManager().getDefaultDisplay(); rotation = display.getRotation(); int height;//w w w . j a va2s .c o m int width; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) { height = display.getHeight(); width = display.getWidth(); } else { Point size = new Point(); display.getSize(size); height = size.y; width = size.x; } switch (rotation) { case Surface.ROTATION_90: if (width > height) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); } break; case Surface.ROTATION_180: if (height > width) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } break; case Surface.ROTATION_270: if (width > height) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } break; default: if (height > width) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } }
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.ColorimetryLiquidActivity.java
private void startTest() { mResults = new ArrayList<>(); mWaitingForStillness = false;// w w w. j a v a 2s .c om mIsFirstResult = true; mShakeDetector.setMinShakeAcceleration(1); mShakeDetector.setMaxShakeDuration(MAX_SHAKE_DURATION_2); mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI); (new AsyncTask<Void, Void, Void>() { @Nullable @Override protected Void doInBackground(Void... params) { return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); mCameraFragment = CameraDialogFragment.newInstance(); mCameraFragment.setPictureTakenObserver(new CameraDialogFragment.PictureTaken() { @Override public void onPictureTaken(@NonNull byte[] bytes, boolean completed) { Bitmap bitmap = ImageUtil.getBitmap(bytes); Display display = getWindowManager().getDefaultDisplay(); int rotation; switch (display.getRotation()) { case Surface.ROTATION_0: rotation = DEGREES_90; break; case Surface.ROTATION_180: rotation = DEGREES_270; break; case Surface.ROTATION_270: rotation = DEGREES_180; break; case Surface.ROTATION_90: default: rotation = 0; break; } bitmap = ImageUtil.rotateImage(bitmap, rotation); TestInfo testInfo = CaddisflyApp.getApp().getCurrentTestInfo(); Bitmap croppedBitmap; if (testInfo.isUseGrayScale()) { croppedBitmap = ImageUtil.getCroppedBitmap(bitmap, ColorimetryLiquidConfig.SAMPLE_CROP_LENGTH_DEFAULT, false); if (croppedBitmap != null) { croppedBitmap = ImageUtil.getGrayscale(croppedBitmap); } } else { croppedBitmap = ImageUtil.getCroppedBitmap(bitmap, ColorimetryLiquidConfig.SAMPLE_CROP_LENGTH_DEFAULT, true); } //Ignore the first result as camera may not have focused correctly if (!mIsFirstResult) { if (croppedBitmap != null) { getAnalyzedResult(croppedBitmap); } else { showError( String.format(TWO_SENTENCE_FORMAT, getString(R.string.chamberNotFound), getString(R.string.checkChamberPlacement)), ImageUtil.getBitmap(bytes)); mCameraFragment.stopCamera(); mCameraFragment.dismiss(); return; } } mIsFirstResult = false; if (completed) { analyzeFinalResult(bytes, croppedBitmap); mCameraFragment.dismiss(); } else { sound.playShortResource(R.raw.beep); } } }); acquireWakeLock(); delayRunnable = new Runnable() { @Override public void run() { final FragmentTransaction ft = getFragmentManager().beginTransaction(); Fragment prev = getFragmentManager().findFragmentByTag("cameraDialog"); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); try { mCameraFragment.show(ft, "cameraDialog"); mCameraFragment.takePictures(AppPreferences.getSamplingTimes(), ColorimetryLiquidConfig.DELAY_BETWEEN_SAMPLING); } catch (Exception e) { Timber.e(e); finish(); } } }; delayHandler.postDelayed(delayRunnable, ColorimetryLiquidConfig.DELAY_BETWEEN_SAMPLING); } }).execute(); }
From source file:org.godotengine.godot.Godot.java
@Override public void onSensorChanged(SensorEvent event) { Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); int displayRotation = display.getRotation(); float[] adjustedValues = new float[3]; final int axisSwap[][] = { { 1, -1, 0, 1 }, // ROTATION_0 { -1, -1, 1, 0 }, // ROTATION_90 { -1, 1, 0, 1 }, // ROTATION_180 { 1, 1, 1, 0 } }; // ROTATION_270 final int[] as = axisSwap[displayRotation]; adjustedValues[0] = (float) as[0] * event.values[as[2]]; adjustedValues[1] = (float) as[1] * event.values[as[3]]; adjustedValues[2] = event.values[2]; final float x = adjustedValues[0]; final float y = adjustedValues[1]; final float z = adjustedValues[2]; final int typeOfSensor = event.sensor.getType(); if (mView != null) { mView.queueEvent(new Runnable() { @Override/*from w w w . j ava 2 s. c o m*/ public void run() { if (typeOfSensor == Sensor.TYPE_ACCELEROMETER) { GodotLib.accelerometer(-x, y, -z); } if (typeOfSensor == Sensor.TYPE_GRAVITY) { GodotLib.gravity(-x, y, -z); } if (typeOfSensor == Sensor.TYPE_MAGNETIC_FIELD) { GodotLib.magnetometer(-x, y, -z); } if (typeOfSensor == Sensor.TYPE_GYROSCOPE) { GodotLib.gyroscope(x, -y, z); } } }); } }
From source file:com.gsma.rcs.ri.sharing.video.OutgoingVideoSharing.java
/** * Start the camera preview/*from w ww . ja va 2s . c o m*/ */ private void startCameraPreview() { if (mCamera == null) { return; } // Camera settings Camera.Parameters p = mCamera.getParameters(); p.setPreviewFormat(PixelFormat.YCbCr_420_SP); // Orientation Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); switch (display.getRotation()) { case Surface.ROTATION_0: if (LogUtils.isActive) { Log.d(LOGTAG, "ROTATION_0"); } if (mOpenedCameraId == CameraOptions.FRONT) { mVideoPlayer.setOrientation(Orientation.ROTATE_90_CCW); } else { mVideoPlayer.setOrientation(Orientation.ROTATE_90_CW); } mCamera.setDisplayOrientation(90); break; case Surface.ROTATION_90: if (LogUtils.isActive) { Log.d(LOGTAG, "ROTATION_90"); } mVideoPlayer.setOrientation(Orientation.NONE); break; case Surface.ROTATION_180: if (LogUtils.isActive) { Log.d(LOGTAG, "ROTATION_180"); } if (mOpenedCameraId == CameraOptions.FRONT) { mVideoPlayer.setOrientation(Orientation.ROTATE_90_CW); } else { mVideoPlayer.setOrientation(Orientation.ROTATE_90_CCW); } mCamera.setDisplayOrientation(270); break; case Surface.ROTATION_270: if (LogUtils.isActive) { Log.d(LOGTAG, "ROTATION_270"); } if (mOpenedCameraId == CameraOptions.FRONT) { mVideoPlayer.setOrientation(Orientation.ROTATE_180); } else { mVideoPlayer.setOrientation(Orientation.ROTATE_180); } mCamera.setDisplayOrientation(180); break; } // Check if preview size is supported if (isPreviewSizeSupported(p, mVideoWidth, mVideoHeight)) { // Use the existing size without resizing p.setPreviewSize(mVideoWidth, mVideoHeight); // TODO videoPlayer.activateResizing(videoWidth, videoHeight); // // same size = no // resizing if (LogUtils.isActive) { Log.d(LOGTAG, "Camera preview initialized with size " + mVideoWidth + "x" + mVideoHeight); } } else { // Check if can use a other known size (QVGA, CIF or VGA) int w = 0; int h = 0; for (Camera.Size size : p.getSupportedPreviewSizes()) { w = size.width; h = size.height; if ((w == H264Config.QVGA_WIDTH && h == H264Config.QVGA_HEIGHT) || (w == H264Config.CIF_WIDTH && h == H264Config.CIF_HEIGHT) || (w == H264Config.VGA_WIDTH && h == H264Config.VGA_HEIGHT)) { break; } } if (w != 0) { p.setPreviewSize(w, h); // TODO does not work if default sizes are not supported like // for Samsung S5 mini // mVideoPlayer.activateResizing(w, h); if (LogUtils.isActive) { Log.d(LOGTAG, "Camera preview initialized with size " + w + "x" + h + " with a resizing to " + mVideoWidth + "x" + mVideoHeight); } } else { // The camera don't have known size, we can't use it if (LogUtils.isActive) { Log.d(LOGTAG, "Camera preview can't be initialized with size " + mVideoWidth + "x" + mVideoHeight); } Toast.makeText(this, getString(R.string.label_session_failed, "Camera is not compatible"), Toast.LENGTH_SHORT).show(); quitSession(); return; } } // Set camera parameters mCamera.setParameters(p); try { mCamera.setPreviewDisplay(mVideoView.getHolder()); mCamera.startPreview(); mCameraPreviewRunning = true; } catch (Exception e) { mCamera = null; } }
From source file:com.example.android.animationsdemo.CameraActivity.java
/** * Convert touch position x:y to {@link android.hardware.Camera.Area} position -1000:-1000 to 1000:1000. *//*from w ww . j a v a 2 s .co m*/ private Rect calculateTapArea(float x, float y) { // define focus area (36dp) Display display = ((WindowManager) getSystemService(Activity.WINDOW_SERVICE)).getDefaultDisplay(); DisplayMetrics metrics = getResources().getDisplayMetrics(); int areaSize = Float.valueOf(36 * metrics.density).intValue(); DKLog.d(TAG, String.format("x=%f, y=%f, areaSize=%d", x, y, areaSize)); int width = mPreview.getWidth(); int height = mPreview.getHeight(); // Convert touch area to new area -1000:-1000 to 1000:1000. float left = ((x - areaSize) / width) * 2000 - 1000; float top = ((y - areaSize) / height) * 2000 - 1000; float right = ((x + areaSize) / width) * 2000 - 1000; float bottom = ((y + areaSize) / height) * 2000 - 1000; // adjust boundary if (left < -1000) { right += ((-1000) - left); left = (-1000); } if (top < -1000) { bottom += ((-1000) - top); top = (-1000); } if (right > 1000) { left -= (right - 1000); right = 1000; } if (bottom > 1000) { top -= (bottom - 1000); bottom = 1000; } // rotate matrix if portrait RectF rectF = new RectF(left, top, right, bottom); Matrix matrix = new Matrix(); int degree = (display.getRotation() == Surface.ROTATION_0) ? (-90) : (0); matrix.setRotate(degree); matrix.mapRect(rectF); return new Rect(Math.round(rectF.left), Math.round(rectF.top), Math.round(rectF.right), Math.round(rectF.bottom)); }
From source file:com.mruddy.devdataviewer.DevDataListFragment.java
/** * @return/*from w ww. ja v a 2 s .com*/ */ @SuppressLint("NewApi") private List<String> getDevDataList() { final List<String> result = new LinkedList<String>(); final Display display = this.getActivity().getWindowManager().getDefaultDisplay(); final DisplayMetrics appAreaDisplayMetrics = new DisplayMetrics(); display.getMetrics(appAreaDisplayMetrics); result.add("API Level: " + Build.VERSION.SDK_INT); result.add("Android Release: " + Build.VERSION.RELEASE); if (Build.VERSION.SDK_INT >= 17) { final DisplayMetrics fullDisplayMetrics = new DisplayMetrics(); display.getRealMetrics(fullDisplayMetrics); result.add("Full Width (px): " + fullDisplayMetrics.widthPixels); result.add("Full Height (px): " + fullDisplayMetrics.heightPixels); result.add("Full Width (dp): " + ((int) (fullDisplayMetrics.widthPixels / fullDisplayMetrics.density))); result.add( "Full Height (dp): " + ((int) (fullDisplayMetrics.heightPixels / fullDisplayMetrics.density))); } result.add("App Area Width (px): " + appAreaDisplayMetrics.widthPixels); result.add("App Area Height (px): " + appAreaDisplayMetrics.heightPixels); result.add("App Area Width (dp): " + ((int) (appAreaDisplayMetrics.widthPixels / appAreaDisplayMetrics.density))); result.add("App Area Height (dp): " + ((int) (appAreaDisplayMetrics.heightPixels / appAreaDisplayMetrics.density))); result.add("dp Scaling Factor: " + appAreaDisplayMetrics.density); final String densityBucket = DevDataListFragment.DENSITY_BUCKETS.get(appAreaDisplayMetrics.densityDpi); result.add("Density Bucket: " + (null != densityBucket ? densityBucket : "other") + " (" + appAreaDisplayMetrics.densityDpi + ")"); result.add("Actual xdpi: " + appAreaDisplayMetrics.xdpi); result.add("Actual ydpi: " + appAreaDisplayMetrics.ydpi); if (Build.VERSION.SDK_INT >= 8) { final String rotation = DevDataListFragment.ROTATION.get(display.getRotation()); result.add("Rotation: " + (null != rotation ? rotation : "other (" + display.getRotation() + ")")); } final String orientation = DevDataListFragment.ORIENTATION .get(this.getResources().getConfiguration().orientation); result.add("Orientation: " + (null != orientation ? orientation : "other (" + this.getResources().getConfiguration().orientation + ")")); final int screenSizeKey = this.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK; final String screenSizeBucket = DevDataListFragment.SCREEN_SIZE_BUCKETS.get(screenSizeKey); result.add( "Size Bucket: " + (null != screenSizeBucket ? screenSizeBucket : "other (" + screenSizeKey + ")")); return result; }
From source file:com.almalence.opencam.ApplicationScreen.java
@Override public void surfaceCreated(SurfaceHolder holder) { // ----- Find 'normal' orientation of the device Display display = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int rotation = display.getRotation(); if ((rotation == Surface.ROTATION_90) || (rotation == Surface.ROTATION_270)) landscapeIsNormal = true; // false; - if landscape view orientation // set for ApplicationScreen else// w w w . j a va2 s .com landscapeIsNormal = false; surfaceCreated = true; mCameraSurface = surfaceHolder.getSurface(); }
From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
public void onRotate() { Display display = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int rotation = display.getRotation(); if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) { orient = "portrait"; } else if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) { orient = "landscape"; }//from w w w . j ava2s . c o m if (orient.equals("portrait")) { if (lang.equals("prilang")) { keyboard = prilang; } else if (lang.equals("seclang")) { keyboard = seclang; } slideAnimation(); kv.setKeyboard(keyboard); doubleUp = 1; screen = 1; caps = true; if (allCaps) { capsLock = false; } kv.invalidateAllKeys(); keyboard.setShifted(caps); kv.invalidateAllKeys(); } else if (orient.equals("landscape")) { switch (screen) { case 1: if (lang.equals("prilang")) { keyboard = prilang_landscape; } else if (lang.equals("seclang")) { keyboard = seclang_landscape; } break; case 2: if (number == 1) { keyboard = new Keyboard(this, R.xml.numeric_landscape); } else if (number == 2) { keyboard = new Keyboard(this, R.xml.symbols_landscape); } break; } slideAnimation(); kv.setKeyboard(keyboard); doubleUp = 1; screen = 1; caps = true; if (allCaps) { capsLock = false; } kv.invalidateAllKeys(); keyboard.setShifted(caps); kv.invalidateAllKeys(); } }
From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java
@TargetApi(Build.VERSION_CODES.FROYO) private boolean handleVolumeButtonEvent(KeyEvent event) { //Disable volume button handling during TTS if (!config.isVolumeKeyNavEnabled() || ttsIsRunning()) { return false; }/*w w w . j a va2 s . c om*/ Activity activity = getActivity(); if (activity == null) { return false; } boolean invert = false; int rotation = Surface.ROTATION_0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { Display display = activity.getWindowManager().getDefaultDisplay(); rotation = display.getRotation(); } switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_90: invert = false; break; case Surface.ROTATION_180: case Surface.ROTATION_270: invert = true; break; } if (event.getAction() != KeyEvent.ACTION_DOWN) { return true; } if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) { if (invert) { pageDown(Orientation.HORIZONTAL); } else { pageUp(Orientation.HORIZONTAL); } } else if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) { if (invert) { pageUp(Orientation.HORIZONTAL); } else { pageDown(Orientation.HORIZONTAL); } } return true; }
From source file:net.zorgblub.typhon.fragment.ReadingFragment.java
@TargetApi(Build.VERSION_CODES.FROYO) private boolean handleVolumeButtonEvent(KeyEvent event) { //Disable volume button handling during TTS if (!config.isVolumeKeyNavEnabled() || ttsIsRunning()) { return false; }/*from w w w .ja va 2 s. c o m*/ Activity activity = getActivity(); if (activity == null) { return false; } boolean invert = false; int rotation = Surface.ROTATION_0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { Display display = activity.getWindowManager().getDefaultDisplay(); rotation = display.getRotation(); } switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_90: invert = false; break; case Surface.ROTATION_180: case Surface.ROTATION_270: invert = true; break; } if (event.getAction() != KeyEvent.ACTION_DOWN) { return true; } if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) { if (config.isVolumeKeyNavChaptersEnabled()) { if (invert) { bookView.navigateForward(); } else { bookView.navigateBack(); } } else { if (invert) { pageDown(Orientation.HORIZONTAL); } else { pageUp(Orientation.HORIZONTAL); } } } else if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) { if (config.isVolumeKeyNavChaptersEnabled()) { if (invert) { bookView.navigateBack(); } else { bookView.navigateForward(); } } else { if (invert) { pageUp(Orientation.HORIZONTAL); } else { pageDown(Orientation.HORIZONTAL); } } } return true; }