Java Code Examples for android.content.pm.ActivityInfo#SCREEN_ORIENTATION_PORTRAIT
The following examples show how to use
android.content.pm.ActivityInfo#SCREEN_ORIENTATION_PORTRAIT .
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: PreviewActivity.java From APDE with GNU General Public License v2.0 | 6 votes |
private void setOrientation(String orientation) { // Set correct orientation int orientationConst; switch (orientation) { case "portrait": orientationConst = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; case "landscape": orientationConst = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case "reverseLandscape": orientationConst = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; case "unspecified": default: orientationConst = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; break; } setRequestedOrientation(orientationConst); }
Example 2
Source File: VideoImpl.java From AgentWebX5 with Apache License 2.0 | 6 votes |
@Override public void onHideCustomView() { LogUtils.i("Info", "onHideCustomView:" + moiveView); if (moiveView == null) return; if (mActivity!=null&&mActivity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); moiveView.setVisibility(View.GONE); if (moiveParentView != null && moiveView != null) { moiveParentView.removeView(moiveView); } if (moiveParentView != null) moiveParentView.setVisibility(View.GONE); if(this.mCallback!=null) mCallback.onCustomViewHidden(); this.moiveView = null; if (mWebView != null) mWebView.setVisibility(View.VISIBLE); }
Example 3
Source File: CaptureActivity.java From CodeScaner with MIT License | 6 votes |
private int getCurrentOrientation() { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_90: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } } else { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_270: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } } }
Example 4
Source File: CaptureActivity.java From weex with Apache License 2.0 | 6 votes |
private int getCurrentOrientation() { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_90: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; } } else { switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_270: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; default: return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } } }
Example 5
Source File: StreamActivity.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 6 votes |
@Override public void onSensorChanged(SensorEvent event) { try { if (event.sensor == mRotationSensor && getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { if (event.values.length > 4) { float[] truncatedRotationVector = new float[4]; System.arraycopy(event.values, 0, truncatedRotationVector, 0, 4); update(truncatedRotationVector); } else { update(event.values); } } } catch (Exception e) { e.printStackTrace(); } }
Example 6
Source File: GosBaseActivity.java From GOpenSource_AppKit_Android_AS with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /** * 设置为竖屏 */ if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } spf = getSharedPreferences(SPF_Name, Context.MODE_PRIVATE); MessageCenter.getInstance(this); // 初始化 setProgressDialog(); }
Example 7
Source File: Utils.java From AndroidBlueprints with Apache License 2.0 | 6 votes |
/** * Locks the device window in actual screen mode */ public static void lockOrientation(Activity activity) { Display display = ((WindowManager) activity. getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int rotation = display.getRotation(); int orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; switch (activity.getResources().getConfiguration().orientation) { case Configuration.ORIENTATION_LANDSCAPE: if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; else orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; case Configuration.ORIENTATION_PORTRAIT: if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270) orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; else orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; } //noinspection ResourceType activity.setRequestedOrientation(orientation); }
Example 8
Source File: MainActivity.java From Android-BLE-Terminal with MIT License | 6 votes |
@Override protected void onResume() { super.onResume(); // set the screen to portrait if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } // if the bluetooth adatper is not support and enabled BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { finish(); } // request to open the bluetooth adapter if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } }
Example 9
Source File: PreviewFrameLayout.java From retroboy with MIT License | 5 votes |
public void setAspectRatio(double ratio) { if (ratio <= 0.0) { throw new IllegalArgumentException(); } if (isInEditMode() || ((Activity)getContext()).getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { ratio = 1 / ratio; } if (mAspectRatio != ratio) { mAspectRatio = ratio; requestLayout(); } }
Example 10
Source File: PIPListActivity.java From DKVideoPlayer with Apache License 2.0 | 5 votes |
private void releaseVideoView() { mVideoView.release(); if (mVideoView.isFullScreen()) { mVideoView.stopFullScreen(); } if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } mPIPManager.setPlayingPosition(-1); }
Example 11
Source File: TinyScreenActivity.java From DKVideoPlayer with Apache License 2.0 | 5 votes |
private void releaseVideoView() { mVideoView.release(); if (mVideoView.isFullScreen()) { mVideoView.stopFullScreen(); } if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } mCurPos = -1; }
Example 12
Source File: BaseActivity.java From phphub-android with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { injectorPresenter(); super.onCreate(savedInstanceState); Icepick.restoreInstanceState(this, savedInstanceState); if(getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } setContentView(getLayoutResId()); initializeToolbar(); navigator = getAppComponent().navigator(); }
Example 13
Source File: CameraConfigurationManager.java From AndroidWebServ with Apache License 2.0 | 5 votes |
/** * Reads, one time, values from the camera that are needed by the app. */ @SuppressWarnings("deprecation") void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); // We're landscape-only, and have apparently seen issues with display thinking it's portrait // when waking from sleep. If it's not landscape, assume it's mistaken and reverse them: /* Modified for portrait by join */ /*if (width < height) { Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect"); int temp = width; width = height; height = temp; }*/ screenResolution = new Point(width, height); Log.i(TAG, "Screen resolution: " + screenResolution); /* Modified for portrait by join */ if (CaptureActivity.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { Point screenResolutionForCamera = new Point(); screenResolutionForCamera.x = screenResolution.x; screenResolutionForCamera.y = screenResolution.y; // preview size is always something like 480*320, other 320*480 if (screenResolution.x < screenResolution.y) { screenResolutionForCamera.x = screenResolution.y; screenResolutionForCamera.y = screenResolution.x; } cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera); } else { cameraResolution = findBestPreviewSizeValue(parameters, screenResolution); } Log.i(TAG, "Camera resolution: " + cameraResolution); }
Example 14
Source File: CameraStreamerActivity.java From media-for-mobile with Apache License 2.0 | 5 votes |
private void createPreview() { surfaceView = new GLSurfaceView(getApplicationContext()); ((RelativeLayout)findViewById(R.id.streamer_layout)).addView(surfaceView, 0); preview = capture.createPreview(surfaceView, camera); if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { capture.setOrientation(90); } else if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ){ capture.setOrientation(0); } preview.start(); }
Example 15
Source File: RecyclerViewFragment.java From DKVideoPlayer with Apache License 2.0 | 5 votes |
private void releaseVideoView() { mVideoView.release(); if (mVideoView.isFullScreen()) { mVideoView.stopFullScreen(); } if(getActivity().getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } mCurPos = -1; }
Example 16
Source File: OrientationChangeAction.java From graphhopper-navigation-android with MIT License | 4 votes |
public static ViewAction orientationPortrait() { return new OrientationChangeAction(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }
Example 17
Source File: FaceRecognitionAppActivity.java From FaceRecognitionApp with GNU General Public License v2.0 | 4 votes |
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) { Mat mGrayTmp = inputFrame.gray(); Mat mRgbaTmp = inputFrame.rgba(); // Flip image to get mirror effect int orientation = mOpenCvCameraView.getScreenOrientation(); if (mOpenCvCameraView.isEmulator()) // Treat emulators as a special case Core.flip(mRgbaTmp, mRgbaTmp, 1); // Flip along y-axis else { switch (orientation) { // RGB image case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: if (mOpenCvCameraView.mCameraIndex == CameraBridgeViewBase.CAMERA_ID_FRONT) Core.flip(mRgbaTmp, mRgbaTmp, 0); // Flip along x-axis else Core.flip(mRgbaTmp, mRgbaTmp, -1); // Flip along both axis break; case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: if (mOpenCvCameraView.mCameraIndex == CameraBridgeViewBase.CAMERA_ID_FRONT) Core.flip(mRgbaTmp, mRgbaTmp, 1); // Flip along y-axis break; } switch (orientation) { // Grayscale image case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: Core.transpose(mGrayTmp, mGrayTmp); // Rotate image if (mOpenCvCameraView.mCameraIndex == CameraBridgeViewBase.CAMERA_ID_FRONT) Core.flip(mGrayTmp, mGrayTmp, -1); // Flip along both axis else Core.flip(mGrayTmp, mGrayTmp, 1); // Flip along y-axis break; case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: Core.transpose(mGrayTmp, mGrayTmp); // Rotate image if (mOpenCvCameraView.mCameraIndex == CameraBridgeViewBase.CAMERA_ID_BACK) Core.flip(mGrayTmp, mGrayTmp, 0); // Flip along x-axis break; case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: if (mOpenCvCameraView.mCameraIndex == CameraBridgeViewBase.CAMERA_ID_FRONT) Core.flip(mGrayTmp, mGrayTmp, 1); // Flip along y-axis break; case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: Core.flip(mGrayTmp, mGrayTmp, 0); // Flip along x-axis if (mOpenCvCameraView.mCameraIndex == CameraBridgeViewBase.CAMERA_ID_BACK) Core.flip(mGrayTmp, mGrayTmp, 1); // Flip along y-axis break; } } mGray = mGrayTmp; mRgba = mRgbaTmp; return mRgba; }
Example 18
Source File: CameraBridgeViewBase.java From FaceRecognitionApp with GNU General Public License v2.0 | 4 votes |
/** * This method shall be called by the subclasses when they have valid * object and want it to be delivered to external client (via callback) and * then displayed on the screen. * @param frame - the current frame to be delivered */ protected void deliverAndDrawFrame(CvCameraViewFrame frame) { Mat modified; if (mListener != null) { modified = mListener.onCameraFrame(frame); } else { modified = frame.rgba(); } boolean bmpValid = true; if (modified != null) { try { Utils.matToBitmap(modified, mCacheBitmap); } catch(Exception e) { Log.e(TAG, "Mat type: " + modified); Log.e(TAG, "Bitmap type: " + mCacheBitmap.getWidth() + "*" + mCacheBitmap.getHeight()); Log.e(TAG, "Utils.matToBitmap() throws an exception: " + e.getMessage()); bmpValid = false; } } if (bmpValid && mCacheBitmap != null) { Canvas canvas = getHolder().lockCanvas(); if (canvas != null) { canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR); int degrees = 0; if (!isEmulator()) { // Rotation is always reported as portrait on the emulator for some reason int orientation = getScreenOrientation(); switch (orientation) { case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: degrees = -90; break; case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: break; case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: degrees = 90; break; case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: degrees = 180; break; } } Matrix matrix = new Matrix(); matrix.postRotate(degrees); Bitmap outputBitmap = Bitmap.createBitmap(mCacheBitmap, 0, 0, mCacheBitmap.getWidth(), mCacheBitmap.getHeight(), matrix, true); if (outputBitmap.getWidth() <= canvas.getWidth()) { mScale = getRatio(outputBitmap.getWidth(), outputBitmap.getHeight(), canvas.getWidth(), canvas.getHeight()); } else { mScale = getRatio(canvas.getWidth(), canvas.getHeight(), outputBitmap.getWidth(), outputBitmap.getHeight()); } if (mScale != 0) { canvas.scale(mScale, mScale, 0, 0); } if (BuildConfig.DEBUG) Log.v(TAG, "mStretch value: " + mScale); canvas.drawBitmap(outputBitmap, 0, 0, null); if (mFpsMeter != null) { mFpsMeter.measure(); mFpsMeter.draw(canvas, 20, 30); } getHolder().unlockCanvasAndPost(canvas); } } }
Example 19
Source File: CameraConfigurationManager.java From zxingfragmentlib with Apache License 2.0 | 4 votes |
private int getScreenOrientation() { int rotation; if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.GINGERBREAD) { rotation = ((Activity) context).getWindowManager().getDefaultDisplay().getRotation(); } else { rotation = ((Activity) context).getWindowManager().getDefaultDisplay().getOrientation(); } DisplayMetrics dm = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm); int width = dm.widthPixels; int height = dm.heightPixels; int orientation; // if the device's natural orientation is portrait: if ((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) && height > width || (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) && width > height) { switch(rotation) { case Surface.ROTATION_0: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; case Surface.ROTATION_90: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_180: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; case Surface.ROTATION_270: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; default: Log.e(TAG, "Unknown screen orientation. Defaulting to " + "portrait."); orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; } } // if the device's natural orientation is landscape or if the device // is square: else { switch(rotation) { case Surface.ROTATION_0: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_90: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; case Surface.ROTATION_180: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; case Surface.ROTATION_270: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; default: Log.e(TAG, "Unknown screen orientation. Defaulting to " + "landscape."); orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; } } Log.v(TAG, "Orientation: " + orientation); return orientation; }
Example 20
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(); }