Java Code Examples for android.app.Activity#getRequestedOrientation()

The following examples show how to use android.app.Activity#getRequestedOrientation() . These examples are extracted from open source projects. 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 Project: DKVideoPlayer   File: CompleteView.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onPlayerStateChanged(int playerState) {
    if (playerState == VideoView.PLAYER_FULL_SCREEN) {
        mStopFullscreen.setVisibility(VISIBLE);
    } else if (playerState == VideoView.PLAYER_NORMAL) {
        mStopFullscreen.setVisibility(GONE);
    }

    Activity activity = PlayerUtils.scanForActivity(getContext());
    if (activity != null && mControlWrapper.hasCutout()) {
        int orientation = activity.getRequestedOrientation();
        int cutoutHeight = mControlWrapper.getCutoutHeight();
        LayoutParams sflp = (LayoutParams) mStopFullscreen.getLayoutParams();
        if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
            sflp.setMargins(0, 0, 0, 0);
        } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            sflp.setMargins(cutoutHeight, 0, 0, 0);
        } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
            sflp.setMargins(0, 0, 0, 0);
        }
    }
}
 
Example 2
Source Project: DKVideoPlayer   File: LiveControlView.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onPlayerStateChanged(int playerState) {
    switch (playerState) {
        case VideoView.PLAYER_NORMAL:
            mFullScreen.setSelected(false);
            break;
        case VideoView.PLAYER_FULL_SCREEN:
            mFullScreen.setSelected(true);
            break;
    }

    Activity activity = PlayerUtils.scanForActivity(getContext());
    if (activity != null && mControlWrapper.hasCutout()) {
        int orientation = activity.getRequestedOrientation();
        int cutoutHeight = mControlWrapper.getCutoutHeight();
        if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
            mBottomContainer.setPadding(0, 0, 0, 0);
        } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            mBottomContainer.setPadding(cutoutHeight, 0, 0, 0);
        } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
            mBottomContainer.setPadding(0, 0, cutoutHeight, 0);
        }
    }
}
 
Example 3
Source Project: DKVideoPlayer   File: TitleView.java    License: 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 4
@Override
public void callActivityOnCreate(Activity activity, Bundle icicle) {
       VirtualCore.get().getComponentDelegate().beforeActivityCreate(activity);
	IBinder token = mirror.android.app.Activity.mToken.get(activity);
	ActivityClientRecord r = VActivityManager.get().getActivityRecord(token);
	if (r != null) {
           r.activity = activity;
       }
	ContextFixer.fixContext(activity);
	ActivityFixer.fixActivity(activity);
	ActivityInfo info = null;
	if (r != null) {
           info = r.info;
       }
	if (info != null) {
           if (info.theme != 0) {
               activity.setTheme(info.theme);
           }
           if (activity.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
                   && info.screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
               activity.setRequestedOrientation(info.screenOrientation);
           }
       }
	super.callActivityOnCreate(activity, icicle);
	VirtualCore.get().getComponentDelegate().afterActivityCreate(activity);
}
 
Example 5
private void onActivityCreated(Activity activity) throws RemoteException {
    try {
        Intent targetIntent = activity.getIntent();
        if (targetIntent != null) {
            ActivityInfo targetInfo = targetIntent.getParcelableExtra(Env.EXTRA_TARGET_INFO);
            ActivityInfo stubInfo = targetIntent.getParcelableExtra(Env.EXTRA_STUB_INFO);
            if (targetInfo != null && stubInfo != null) {
                RunningActivities.onActivtyCreate(activity, targetInfo, stubInfo);
                if (activity.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
                        && targetInfo.screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
                    activity.setRequestedOrientation(targetInfo.screenOrientation);
                }
                PluginManager.getInstance().onActivityCreated(stubInfo, targetInfo);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    fixTaskDescription(activity, targetInfo);
                }
            }
        }
    } catch (Exception e) {
        Log.i(TAG, "onActivityCreated fail", e);
    }
}
 
Example 6
Source Project: whiteboard   File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * ��ת��Ļ
 */
public void rotateScreen(Activity activity, PainterSettings settings)
{
	if (activity.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
	{
		settings.setOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		Utils.getInstance().saveSettings(activity, settings);

		activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
	} else
	{
		settings.setOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		Utils.getInstance().saveSettings(activity, settings);
		activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	}
}
 
Example 7
Source Project: scene   File: ActivityStatusRecord.java    License: Apache License 2.0 5 votes vote down vote up
public static ActivityStatusRecord newInstance(Activity activity) {
    ActivityStatusRecord record = new ActivityStatusRecord();
    Window window = activity.getWindow();
    View decorView = window.getDecorView();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        record.mStatusBarColor = window.getStatusBarColor();
        record.mNavigationBarColor = window.getNavigationBarColor();
    }
    record.mSystemUiVisibility = decorView.getSystemUiVisibility();
    record.mSoftInputMode = window.getAttributes().softInputMode;
    record.mWindowFlags = window.getAttributes().flags;
    record.mRequestedOrientation = activity.getRequestedOrientation();
    return record;
}
 
Example 8
Source Project: DKVideoPlayer   File: VodControlView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onPlayerStateChanged(int playerState) {
    switch (playerState) {
        case VideoView.PLAYER_NORMAL:
            mFullScreen.setSelected(false);
            break;
        case VideoView.PLAYER_FULL_SCREEN:
            mFullScreen.setSelected(true);
            break;
    }

    Activity activity = PlayerUtils.scanForActivity(getContext());
    if (activity != null && mControlWrapper.hasCutout()) {
        int orientation = activity.getRequestedOrientation();
        int cutoutHeight = mControlWrapper.getCutoutHeight();
        if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
            mBottomContainer.setPadding(0, 0, 0, 0);
            mBottomProgress.setPadding(0, 0, 0, 0);
        } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            mBottomContainer.setPadding(cutoutHeight, 0, 0, 0);
            mBottomProgress.setPadding(cutoutHeight, 0, 0, 0);
        } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
            mBottomContainer.setPadding(0, 0, cutoutHeight, 0);
            mBottomProgress.setPadding(0, 0, cutoutHeight, 0);
        }
    }
}
 
Example 9
Source Project: FastLib   File: ActivityControlImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置屏幕方向--注意targetSDK设置27以上不能设置windowIsTranslucent=true属性不然应用直接崩溃-强烈建议手机应用锁定竖屏
 * 错误为 Only fullscreen activities can request orientation
 * 默认自动 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
 * 竖屏 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
 * 横屏 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
 * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}
 *
 * @param activity
 */
public void setActivityOrientation(Activity activity) {
    //全局控制屏幕横竖屏
    //先判断xml没有设置屏幕模式避免将开发者本身想设置的覆盖掉
    if (activity.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
        try {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } catch (Exception e) {
            e.printStackTrace();
            LoggerManager.e(TAG, "setRequestedOrientation:" + e.getMessage());
        }
    }
}
 
Example 10
Source Project: FastLib   File: ActivityControlImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置屏幕方向--注意targetSDK设置27以上不能设置windowIsTranslucent=true属性不然应用直接崩溃-强烈建议手机应用锁定竖屏
 * 错误为 Only fullscreen activities can request orientation
 * 默认自动 ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
 * 竖屏 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
 * 横屏 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
 * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}
 *
 * @param activity
 */
public void setActivityOrientation(Activity activity) {
    //全局控制屏幕横竖屏
    //先判断xml没有设置屏幕模式避免将开发者本身想设置的覆盖掉
    if (activity.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
        try {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } catch (Exception e) {
            e.printStackTrace();
            LoggerManager.e(TAG, "setRequestedOrientation:" + e.getMessage());
        }
    }
}
 
Example 11
private void switchFullScreenInternal(int requestOrientation) {
    Activity activity = (Activity) getContext();
    int currOrientation = activity.getRequestedOrientation();
    if (currOrientation == requestOrientation) {
        return;
    }

    if (requestOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
        switchFullScreen(true);
    } else if (requestOrientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
        switchFullScreen(true, true);
    } else if (requestOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
        switchFullScreen(false);
    }
}
 
Example 12
Source Project: whiteboard   File: PainterHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * ��ת��Ļ�ķ���
 * 
 * @param activity
 * @param settings
 */
public void rotateScreen(Activity activity, PainterSettings settings) {
	if (activity.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
		settings.setOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		Utils.getInstance().saveSettings(activity, settings);
		activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
	} else {
		settings.setOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		Utils.getInstance().saveSettings(activity, settings);
		activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	}
}
 
Example 13
public static void lockOrientation(Activity activity)
{
    if (activity == null || prevOrientation != -10)
    {
        return;
    }
    try
    {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null)
        {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

            if (rotation == Surface.ROTATION_270)
            {
                if (orientation == Configuration.ORIENTATION_PORTRAIT)
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
                else
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
            }
            else if (rotation == Surface.ROTATION_90)
            {
                if (orientation == Configuration.ORIENTATION_PORTRAIT)
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
                else
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
            }
            else if (rotation == Surface.ROTATION_0)
            {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE)
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
                else
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            }
            else
            {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE)
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
                else
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
            }
        }
    }
    catch (Exception e)
    {
        FileLog.e(e);
    }
}
 
Example 14
public static void lockOrientation(Activity activity)
{
    if (activity == null || prevOrientation != -10)
    {
        return;
    }
    try
    {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null)
        {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

            if (rotation == Surface.ROTATION_270)
            {
                if (orientation == Configuration.ORIENTATION_PORTRAIT)
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
                else
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
            }
            else if (rotation == Surface.ROTATION_90)
            {
                if (orientation == Configuration.ORIENTATION_PORTRAIT)
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
                else
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
            }
            else if (rotation == Surface.ROTATION_0)
            {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE)
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
                else
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            }
            else
            {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE)
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
                else
                {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
            }
        }
    }
    catch (Exception e)
    {
        FileLog.e(e);
    }
}
 
Example 15
public static void lockOrientation(Activity activity) {
    if (activity == null || prevOrientation != -10) {
        return;
    }
    try {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null) {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

            if (rotation == Surface.ROTATION_270) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_90) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_0) {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            } else {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 16
Source Project: Yahala-Messenger   File: OSUtilities.java    License: MIT License 4 votes vote down vote up
public static void lockOrientation(Activity activity) {
    if (prevOrientation != -10) {
        return;
    }
    try {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null) {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

            if (rotation == Surface.ROTATION_270) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                } else {
                    if (Build.VERSION.SDK_INT >= 9) {
                        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                    } else {
                        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                    }
                }
            } else if (rotation == Surface.ROTATION_90) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    if (Build.VERSION.SDK_INT >= 9) {
                        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                    } else {
                        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                    }
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_0) {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            } else {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    if (Build.VERSION.SDK_INT >= 9) {
                        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                    } else {
                        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                    }
                } else {
                    if (Build.VERSION.SDK_INT >= 9) {
                        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                    } else {
                        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                    }
                }
            }
        }
    } catch (Exception e) {
        FileLog.e("yahala", e);
    }
}
 
Example 17
@SuppressLint("WrongConstant")
public static void lockOrientation(Activity activity) {
    if (activity == null || prevOrientation != -10) {
        return;
    }
    try {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null) {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

            if (rotation == Surface.ROTATION_270) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_90) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_0) {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            } else {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 18
static int lockScreenOrientation(Activity activity) {
	int result = activity.getRequestedOrientation();
	final int screenOrientation = getScreenOrientation(activity);
	activity.setRequestedOrientation(screenOrientation);
	return result;
}
 
Example 19
@SuppressLint("WrongConstant")
public static void lockOrientation(Activity activity) {
    if (activity == null || prevOrientation != -10) {
        return;
    }
    try {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager) activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null) {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

            if (rotation == Surface.ROTATION_270) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_90) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_0) {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            } else {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 20
/**
 * Binds an Activity to VideoView. This is necessary to keep tracking on orientation changes
 *
 * @param activity The activity that VideoView is related to
 */
public void setActivity(Activity activity) {
    this.activity = activity;
    this.initialConfigOrientation = activity.getRequestedOrientation();
}