Java Code Examples for android.content.pm.ActivityInfo#SCREEN_ORIENTATION_REVERSE_LANDSCAPE

The following examples show how to use android.content.pm.ActivityInfo#SCREEN_ORIENTATION_REVERSE_LANDSCAPE . 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: CaptureActivity.java    From ZXing-Standalone-library with Apache License 2.0 6 votes vote down vote up
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 2
Source File: CaptureActivity.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
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 3
Source File: CustomChecks.java    From fullscreen-video-view with Apache License 2.0 6 votes vote down vote up
@Override
public void perform(UiController uiController, View view) {
    uiController.loopMainThreadUntilIdle();
    int orientation = getActivityOrientation(view);
    boolean checkOrientation = false;
    switch (orientationType) {
        case PORTRAIT:
            checkOrientation = orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
                    || orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
                    || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
                    || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT;
            break;

        case LANDSCAPE:
            checkOrientation = orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
                    || orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
                    || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
                    || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE;
            break;
    }

    if (checkOrientation) {
        isOrientation[0] = true;
    }
}
 
Example 4
Source File: TitleView.java    From DKVideoPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void onPlayerStateChanged(int playerState) {
    if (playerState == VideoView.PLAYER_FULL_SCREEN) {
        if (mControlWrapper.isShowing() && !mControlWrapper.isLocked()) {
            setVisibility(VISIBLE);
            mSysTime.setText(PlayerUtils.getCurrentSystemTime());
        }
        mTitle.setSelected(true);
    } else {
        setVisibility(GONE);
        mTitle.setSelected(false);
    }

    Activity activity = PlayerUtils.scanForActivity(getContext());
    if (activity != null && mControlWrapper.hasCutout()) {
        int orientation = activity.getRequestedOrientation();
        int cutoutHeight = mControlWrapper.getCutoutHeight();
        if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
            mTitleContainer.setPadding(0, 0, 0, 0);
        } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            mTitleContainer.setPadding(cutoutHeight, 0, 0, 0);
        } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
            mTitleContainer.setPadding(0, 0, cutoutHeight, 0);
        }
    }
}
 
Example 5
Source File: QrCodeScanActivity.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
private int getCurrentOrientation() {
    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    switch (rotation) {
        case Surface.ROTATION_0:
        case Surface.ROTATION_90:
            return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        default:
            return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
    }
}
 
Example 6
Source File: Utils.java    From Android-Applications-Info with Apache License 2.0 5 votes vote down vote up
public static String getOrientationString(int orientation) {
    switch (orientation) {
        case ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED:
            return "Unspecified";
        case ActivityInfo.SCREEN_ORIENTATION_BEHIND:
            return "Behind";
        case ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR:
            return "Full sensor";
        case ActivityInfo.SCREEN_ORIENTATION_FULL_USER:
            return "Full user";
        case ActivityInfo.SCREEN_ORIENTATION_LOCKED:
            return "Locked";
        case ActivityInfo.SCREEN_ORIENTATION_NOSENSOR:
            return "No sensor";
        case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
            return "Landscape";
        case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
            return "Portrait";
        case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
            return "Reverse portrait";
        case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
            return "Reverse landscape";
        case ActivityInfo.SCREEN_ORIENTATION_USER:
            return "User";
        case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
            return "Sensor landscape";
        case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
            return "Sensor portrait";
        case ActivityInfo.SCREEN_ORIENTATION_SENSOR:
            return "Sensor";
        case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
            return "User landscape";
        case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
            return "User portrait";
        default:
            return "null";
    }
}
 
Example 7
Source File: SDLActivity.java    From android-port with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This can be overridden
 */
public void setOrientationBis(int w, int h, boolean resizable, String hint) 
{
    int orientation = -1;

    if (hint.contains("LandscapeRight") && hint.contains("LandscapeLeft")) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
    } else if (hint.contains("LandscapeRight")) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    } else if (hint.contains("LandscapeLeft")) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
    } else if (hint.contains("Portrait") && hint.contains("PortraitUpsideDown")) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
    } else if (hint.contains("Portrait")) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    } else if (hint.contains("PortraitUpsideDown")) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
    }

    /* no valid hint */
    if (orientation == -1) {
        if (resizable) {
            /* no fixed orientation */
        } else {
            if (w > h) {
                orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
            } else {
                orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
            }
        }
    }

    Log.v("SDL", "setOrientation() orientation=" + orientation + " width=" + w +" height="+ h +" resizable=" + resizable + " hint=" + hint);
    if (orientation != -1) {
        mSingleton.setRequestedOrientation(orientation);
    }
}
 
Example 8
Source File: Launcher.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
private int mapConfigurationOriActivityInfoOri(int configOri) {
	final Display d = getWindowManager().getDefaultDisplay();
	int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
	switch (d.getRotation()) {
	case Surface.ROTATION_0:
	case Surface.ROTATION_180:
		// We are currently in the same basic orientation as the natural
		// orientation
		naturalOri = configOri;
		break;
	case Surface.ROTATION_90:
	case Surface.ROTATION_270:
		// We are currently in the other basic orientation to the natural
		// orientation
		naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? Configuration.ORIENTATION_PORTRAIT
				: Configuration.ORIENTATION_LANDSCAPE;
		break;
	}

	int[] oriMap = { ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
			ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
			ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
			ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE };
	// Since the map starts at portrait, we need to offset if this device's
	// natural orientation
	// is landscape.
	int indexOffset = 0;
	if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
		indexOffset = 1;
	}
	return oriMap[(d.getRotation() + indexOffset) % 4];
}
 
Example 9
Source File: SDLActivity.java    From simpleSDL with MIT License 5 votes vote down vote up
/**
 * This can be overridden
 */
public void setOrientationBis(int w, int h, boolean resizable, String hint) 
{
    int orientation = -1;

    if (hint.contains("LandscapeRight") && hint.contains("LandscapeLeft")) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
    } else if (hint.contains("LandscapeRight")) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    } else if (hint.contains("LandscapeLeft")) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
    } else if (hint.contains("Portrait") && hint.contains("PortraitUpsideDown")) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
    } else if (hint.contains("Portrait")) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    } else if (hint.contains("PortraitUpsideDown")) {
        orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
    }

    /* no valid hint */
    if (orientation == -1) {
        if (resizable) {
            /* no fixed orientation */
        } else {
            if (w > h) {
                orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
            } else {
                orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
            }
        }
    }

    Log.v("SDL", "setOrientation() orientation=" + orientation + " width=" + w +" height="+ h +" resizable=" + resizable + " hint=" + hint);
    if (orientation != -1) {
        mSingleton.setRequestedOrientation(orientation);
    }
}
 
Example 10
Source File: BarCodeScannerFragment.java    From zxingfragmentlib with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.FROYO)
private int getCurrentOrientation() {
  int rotation = getActivity().getWindowManager().getDefaultDisplay().getRotation();
  switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_90:
      return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    default:
      return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
  }
}
 
Example 11
Source File: WeathForceActivity.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    //lock the device in current screen orientation
    int orientation;
    int rotation = ((WindowManager) this.getSystemService(
            Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
    switch (rotation) {
        case Surface.ROTATION_0:
            orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            this.deviceOrientation = 0;
            break;
        case Surface.ROTATION_90:
            this.deviceOrientation = 90;
            orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            break;
        case Surface.ROTATION_180:
            this.deviceOrientation = 180;
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
            break;
        default:
            this.deviceOrientation = 270;
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
            break;
    }

    this.setRequestedOrientation(orientation);


    LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    try {
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

            return;
        }
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    } catch (Exception ex) {
    }
    compass = new InternalCompassOrientationProvider(this);
    compass.startOrientationProvider(this);
    mMapView.getController().zoomTo(14);

}
 
Example 12
Source File: GiraffePlayer.java    From GiraffePlayer with Apache License 2.0 4 votes vote down vote up
private int getScreenOrientation() {
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    DisplayMetrics dm = new DisplayMetrics();
    activity.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:
                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:
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
        }
    }

    return orientation;
}
 
Example 13
Source File: Util.java    From DMusic with Apache License 2.0 4 votes vote down vote up
public static int getScreenOrientation(Activity activity) {
    int rotation = activity.getWindowManager().getDefaultDisplay()
            .getRotation();
    DisplayMetrics dm = new DisplayMetrics();
    activity.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:
                orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                break;
        }
    } 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:
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
        }
    }
    return orientation;
}
 
Example 14
Source File: MKPlayer.java    From MKVideoPlayer with MIT License 4 votes vote down vote up
private int getScreenOrientation() {
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    DisplayMetrics dm = new DisplayMetrics();
    activity.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:
                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:
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
        }
    }

    return orientation;
}
 
Example 15
Source File: ScreenOrientationSwitcher.java    From android-jungle-mediaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public void onOrientationChanged(int orientation) {
    if (!mEnableAutoRotation) {
        return;
    }

    Context context = mContextRef.get();
    if (context == null || !(context instanceof Activity)) {
        return;
    }

    long currTimestamp = System.currentTimeMillis();
    if (currTimestamp - mLastCheckTimestamp > MAX_CHECK_INTERVAL) {
        mIsSupportGravity = isScreenAutoRotate();
        mLastCheckTimestamp = currTimestamp;
    }

    if (!mIsSupportGravity) {
        return;
    }

    if (orientation == ORIENTATION_UNKNOWN) {
        return;
    }

    int requestOrientation = ORIENTATION_UNKNOWN;
    if (orientation > 350 || orientation < 10) {
        requestOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    } else if (orientation > 80 && orientation < 100) {
        requestOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
    } else if (orientation > 260 && orientation < 280) {
        requestOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    } else {
        return;
    }

    if (requestOrientation == mCurrOrientation) {
        return;
    }

    boolean needNotify = mCurrOrientation != ORIENTATION_UNKNOWN;
    mCurrOrientation = requestOrientation;

    if (needNotify) {
        if (mChangeListener != null) {
            mChangeListener.onChanged(requestOrientation);
        } else {
            Activity activity = (Activity) context;
            activity.setRequestedOrientation(requestOrientation);
        }
    }
}
 
Example 16
Source File: UIHelper.java    From GiraffePlayer2 with Apache License 2.0 4 votes vote down vote up
private int getScreenOrientation() {
    if (activity == null) {
        return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    DisplayMetrics dm = new DisplayMetrics();
    activity.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:
                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:
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
        }
    }

    return orientation;
}
 
Example 17
Source File: FaceRecognitionAppActivity.java    From FaceRecognitionApp with GNU General Public License v2.0 4 votes vote down vote up
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: XLVideoPlayActivity.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
private int getScreenOrientation() {
    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    DisplayMetrics dm = new DisplayMetrics();
    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:
                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:
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
        }
    }

    return orientation;
}
 
Example 19
Source File: CustomMediaContoller.java    From MD with Apache License 2.0 4 votes vote down vote up
public int getScreenOrientation(Activity activity) {
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    DisplayMetrics dm = new DisplayMetrics();
    activity.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:
                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:
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
        }
    }

    return orientation;
}
 
Example 20
Source File: ScreenOrientationSwitcher.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onOrientationChanged(int orientation) {
    if (!mEnableAutoRotation) {
        return;
    }

    Context context = mContextRef.get();
    if (context == null || !(context instanceof Activity)) {
        return;
    }

    long currTimestamp = System.currentTimeMillis();
    if (currTimestamp - mLastCheckTimestamp > MAX_CHECK_INTERVAL) {
        mIsSupportGravity = isScreenAutoRotate();
        mLastCheckTimestamp = currTimestamp;
    }

    if (!mIsSupportGravity) {
        return;
    }

    if (orientation == ORIENTATION_UNKNOWN) {
        return;
    }

    int requestOrientation = ORIENTATION_UNKNOWN;
    if (orientation > 350 || orientation < 10) {
        requestOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    } else if (orientation > 80 && orientation < 100) {
        requestOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
    } else if (orientation > 260 && orientation < 280) {
        requestOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
    } else {
        return;
    }

    if (requestOrientation == mCurrOrientation) {
        return;
    }

    boolean needNotify = mCurrOrientation != ORIENTATION_UNKNOWN;
    mCurrOrientation = requestOrientation;

    if (needNotify) {
        if (mChangeListener != null) {
            mChangeListener.onChanged(requestOrientation);
        } else {
            Activity activity = (Activity) context;
            activity.setRequestedOrientation(requestOrientation);
        }
    }
}