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

The following examples show how to use android.app.Activity#getRequestedOrientation() . 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: CompleteView.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) {
        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 File: LiveControlView.java    From DKVideoPlayer with 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 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 4
Source File: AppInstrumentation.java    From container with GNU General Public License v3.0 6 votes vote down vote up
@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
Source File: PluginInstrumentation.java    From DroidPlugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 File: Utils.java    From whiteboard with 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 File: ActivityStatusRecord.java    From scene with 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 File: VodControlView.java    From DKVideoPlayer with 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 File: ActivityControlImpl.java    From FastLib with 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 File: ActivityControlImpl.java    From FastLib with 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
Source File: PainterHandler.java    From whiteboard with 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 12
Source File: MediaPlayerFrame.java    From android-jungle-mediaplayer with Apache License 2.0 5 votes vote down vote up
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 13
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@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 14
Source File: Utilities.java    From TurkcellUpdater_android_sdk with Apache License 2.0 4 votes vote down vote up
static int lockScreenOrientation(Activity activity) {
	int result = activity.getRequestedOrientation();
	final int screenOrientation = getScreenOrientation(activity);
	activity.setRequestedOrientation(screenOrientation);
	return result;
}
 
Example 15
Source File: AndroidUtilities.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@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 16
Source File: OSUtilities.java    From Yahala-Messenger with 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
Source File: AndroidUtilities.java    From KrGallery with GNU General Public License v2.0 4 votes vote down vote up
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 18
Source File: AndroidUtilities.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
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 19
Source File: AndroidUtilities.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
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
Source File: FullscreenVideoView.java    From FullscreenVideoView with Apache License 2.0 2 votes vote down vote up
/**
 * 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();
}