Java Code Examples for android.app.Activity#setRequestedOrientation()
The following examples show how to use
android.app.Activity#setRequestedOrientation() .
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: UCDMediaPlayer_Android File: URotateLayout.java License: MIT License | 6 votes |
public void toggleOrientation() { if (getContext() instanceof Activity && orientation != ORIENTATION_LOCKED) { Activity mActivity = (Activity) getContext(); if (isLandscape()) { mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } else { mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } if (orientation == ORIENTATION_SENSOR) { getHandler().postDelayed(new Runnable() { @Override public void run() { setOrientation(orientation); } }, 2000); } } }
Example 2
Source Project: whiteboard File: Utils.java License: Apache License 2.0 | 6 votes |
/** * ��ת��Ļ */ 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 3
Source Project: react-native-orientation-locker File: OrientationModule.java License: MIT License | 6 votes |
@ReactMethod public void lockToLandscapeRight() { final Activity activity = getCurrentActivity(); if (activity == null) return; activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); isLocked = true; // force send an UI orientation event lastOrientationValue = "LANDSCAPE-RIGHT"; WritableMap params = Arguments.createMap(); params.putString("orientation", lastOrientationValue); if (ctx.hasActiveCatalystInstance()) { ctx .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("orientationDidChange", params); } // send a locked event WritableMap lockParams = Arguments.createMap(); lockParams.putString("orientation", lastOrientationValue); if (ctx.hasActiveCatalystInstance()) { ctx .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("lockDidChange", lockParams); } }
Example 4
Source Project: Telegram-FOSS File: AndroidUtilities.java License: GNU General Public License v2.0 | 5 votes |
@SuppressLint("WrongConstant") public static void unlockOrientation(Activity activity) { if (activity == null) { return; } try { if (prevOrientation != -10) { activity.setRequestedOrientation(prevOrientation); prevOrientation = -10; } } catch (Exception e) { FileLog.e(e); } }
Example 5
Source Project: FastLib File: ActivityControlImpl.java License: Apache License 2.0 | 5 votes |
/** * 设置屏幕方向--注意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 6
Source Project: DKVideoPlayer File: BaseVideoController.java License: Apache License 2.0 | 5 votes |
/** * 反向横屏 */ protected void onOrientationReverseLandscape(Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); if (mControlWrapper.isFullScreen()) { handlePlayerStateChanged(VideoView.PLAYER_FULL_SCREEN); } else { mControlWrapper.startFullScreen(); } }
Example 7
Source Project: showCaseCordova File: YoikScreenOrientation.java License: Apache License 2.0 | 5 votes |
private boolean routeScreenOrientation(JSONArray args, CallbackContext callbackContext) { String action = args.optString(0); if (action.equals("set")) { String orientation = args.optString(1); Log.d(TAG, "Requested ScreenOrientation: " + orientation); Activity activity = cordova.getActivity(); if (orientation.equals(UNLOCKED)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } else if (orientation.equals(LANDSCAPE_PRIMARY)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else if (orientation.equals(PORTRAIT_PRIMARY)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (orientation.equals(LANDSCAPE)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } else if (orientation.equals(PORTRAIT)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } else if (orientation.equals(LANDSCAPE_SECONDARY)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } else if (orientation.equals(PORTRAIT_SECONDARY)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); } callbackContext.success(); return true; } else { callbackContext.error("ScreenOrientation not recognised"); return false; } }
Example 8
Source Project: UltimateAndroid File: BasicUiUtils.java License: Apache License 2.0 | 5 votes |
/** * Set activity to be portrait * @param activity * @param isPortrait */ public static void setActivityPortraitOrientation(Activity activity, boolean isPortrait) { if (isPortrait) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } }
Example 9
Source Project: FTCVision File: ImageRotationExtension.java License: MIT License | 5 votes |
private void setActivityOrientation(int state) { try { Activity activity = Util.getActivity(); activity.setRequestedOrientation(state); } catch (IllegalArgumentException e) { Log.e("ScreenOrientation", "Looks like screen orientation changed and the app crashed!\r\n" + "It's likely you are using an incompatible Activity or a TestableVisionOpMode.\r\n" + "Refrain from setting screen orientation settings to fix this issue."); } }
Example 10
Source Project: VirtualAPK File: VAInstrumentation.java License: Apache License 2.0 | 5 votes |
protected void injectActivity(Activity activity) { final Intent intent = activity.getIntent(); if (PluginUtil.isIntentFromPlugin(intent)) { Context base = activity.getBaseContext(); try { LoadedPlugin plugin = this.mPluginManager.getLoadedPlugin(intent); Reflector.with(base).field("mResources").set(plugin.getResources()); Reflector reflector = Reflector.with(activity); reflector.field("mBase").set(plugin.createPluginContext(activity.getBaseContext())); reflector.field("mApplication").set(plugin.getApplication()); // set screenOrientation ActivityInfo activityInfo = plugin.getActivityInfo(PluginUtil.getComponent(intent)); if (activityInfo.screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { activity.setRequestedOrientation(activityInfo.screenOrientation); } // for native activity ComponentName component = PluginUtil.getComponent(intent); Intent wrapperIntent = new Intent(intent); wrapperIntent.setClassName(component.getPackageName(), component.getClassName()); activity.setIntent(wrapperIntent); } catch (Exception e) { Log.w(TAG, e); } } }
Example 11
Source Project: AndroidRipper File: ActivityUtils.java License: GNU Affero General Public License v3.0 | 5 votes |
/** * Sets the Orientation (Landscape/Portrait) for the current activity. * * @param orientation An orientation constant such as {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE} or {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_PORTRAIT} */ public void setActivityOrientation(int orientation) { Activity activity = getCurrentActivity(); if(activity != null){ activity.setRequestedOrientation(orientation); } }
Example 12
Source Project: Kore File: EspressoTestUtils.java License: Apache License 2.0 | 5 votes |
public static void rotateDevice(Activity activity) { int orientation = activity.getResources().getConfiguration().orientation; activity.setRequestedOrientation( (orientation == Configuration.ORIENTATION_PORTRAIT) ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }
Example 13
Source Project: TelePlus-Android File: AndroidUtilities.java License: GNU General Public License v2.0 | 4 votes |
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 Project: Android-Plugin-Framework File: PluginInjector.java License: MIT License | 4 votes |
static void resetWindowConfig(final Context pluginContext, final PluginDescriptor pd, final Activity activity, final ActivityInfo activityInfo, final PluginActivityInfo pluginActivityInfo) { if (pluginActivityInfo != null) { //如果PluginContextTheme的getPackageName返回了插件包名,需要在这里对attribute修正 activity.getWindow().getAttributes().packageName = FairyGlobal.getHostApplication().getPackageName(); if (null != pluginActivityInfo.getWindowSoftInputMode()) { activity.getWindow().setSoftInputMode((int)Long.parseLong(pluginActivityInfo.getWindowSoftInputMode().replace("0x", ""), 16)); } if (Build.VERSION.SDK_INT >= 14) { if (null != pluginActivityInfo.getUiOptions()) { activity.getWindow().setUiOptions((int)Long.parseLong(pluginActivityInfo.getUiOptions().replace("0x", ""), 16)); } } if (null != pluginActivityInfo.getScreenOrientation()) { int orientation = (int)Long.parseLong(pluginActivityInfo.getScreenOrientation()); //noinspection ResourceType if (orientation != activityInfo.screenOrientation && !activity.isChild()) { //noinspection ResourceType //框架中只内置了unspec和landscape两种screenOrientation //如果是其他类型,这里通过代码实现切换 LogUtil.v("修改screenOrientation"); activity.setRequestedOrientation(orientation); } } if (Build.VERSION.SDK_INT >= 18 && !activity.isChild()) { Boolean isImmersive = ResourceUtil.getBoolean(pluginActivityInfo.getImmersive(), pluginContext); if (isImmersive != null) { activity.setImmersive(isImmersive); } } String activityClassName = activity.getClass().getName(); LogUtil.v(activityClassName, "immersive", pluginActivityInfo.getImmersive()); LogUtil.v(activityClassName, "screenOrientation", pluginActivityInfo.getScreenOrientation()); LogUtil.v(activityClassName, "launchMode", pluginActivityInfo.getLaunchMode()); LogUtil.v(activityClassName, "windowSoftInputMode", pluginActivityInfo.getWindowSoftInputMode()); LogUtil.v(activityClassName, "uiOptions", pluginActivityInfo.getUiOptions()); } //如果是独立插件,由于没有合并资源,这里还需要替换掉 mActivityInfo, //避免activity试图通过ActivityInfo中的资源id来读取资源时失败 activityInfo.icon = pd.getApplicationIcon(); activityInfo.logo = pd.getApplicationLogo(); if (Build.VERSION.SDK_INT >= 19) { activity.getWindow().setIcon(activityInfo.icon); activity.getWindow().setLogo(activityInfo.logo); } }
Example 15
Source Project: letv File: Util.java License: Apache License 2.0 | 4 votes |
public static void screenLandscape(Activity activity) { activity.setRequestedOrientation(0); }
Example 16
Source Project: AndroidBlueprints File: Utils.java License: Apache License 2.0 | 4 votes |
/** * Locks the device window in portrait mode */ public static void lockOrientationPortrait(Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }
Example 17
Source Project: letv File: UIsUtils.java License: Apache License 2.0 | 4 votes |
public static void setScreenPortrait(Activity activity) { activity.setRequestedOrientation(1); }
Example 18
Source Project: letv File: UIsUtils.java License: Apache License 2.0 | 4 votes |
public static void setScreenLandscape(Activity activity) { activity.setRequestedOrientation(0); }
Example 19
Source Project: RxEasyHttp File: AppTools.java License: Apache License 2.0 | 2 votes |
/** * </br><b>title : </b> 设置Activity的显示方向为垂直方向 * </br><b>description :</b>强制设置Actiity的显示方向为垂直方向。 * * @param activity Activity对象 */ public static void setScreenVertical(Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }
Example 20
Source Project: Common File: ScreenUtils.java License: Apache License 2.0 | 2 votes |
/** * Set the screen to portrait. * * @param activity The activity. */ public static void setPortrait(@NonNull final Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }