android.content.pm.ActivityInfo#SCREEN_ORIENTATION_REVERSE_LANDSCAPE源码实例Demo

下面列出了android.content.pm.ActivityInfo#SCREEN_ORIENTATION_REVERSE_LANDSCAPE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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;
    }
  }
}
 
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;
		}
	}
}
 
源代码3 项目: fullscreen-video-view   文件: CustomChecks.java
@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;
    }
}
 
源代码4 项目: DKVideoPlayer   文件: TitleView.java
@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);
        }
    }
}
 
源代码5 项目: AndroidHttpCapture   文件: QrCodeScanActivity.java
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;
    }
}
 
源代码6 项目: Android-Applications-Info   文件: Utils.java
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";
    }
}
 
源代码7 项目: TurboLauncher   文件: Launcher.java
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];
}
 
源代码8 项目: zxingfragmentlib   文件: BarCodeScannerFragment.java
@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;
  }
}
 
源代码9 项目: simpleSDL   文件: SDLActivity.java
/**
 * 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);
    }
}
 
源代码10 项目: android-port   文件: SDLActivity.java
/**
 * 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);
    }
}
 
@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);
        }
    }
}
 
源代码12 项目: MD   文件: CustomMediaContoller.java
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;
}
 
源代码13 项目: TVRemoteIME   文件: XLVideoPlayActivity.java
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;
}
 
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;
}
 
源代码15 项目: GiraffePlayer2   文件: UIHelper.java
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;
}
 
@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);
        }
    }
}
 
源代码17 项目: MKVideoPlayer   文件: MKPlayer.java
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;
}
 
源代码18 项目: DMusic   文件: Util.java
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;
}
 
源代码19 项目: GiraffePlayer   文件: GiraffePlayer.java
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;
}
 
源代码20 项目: osmdroid   文件: WeathForceActivity.java
@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);

}