本文整理了Java中android.app.Activity.setRequestedOrientation()
方法的一些代码示例,展示了Activity.setRequestedOrientation()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.setRequestedOrientation()
方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:setRequestedOrientation
暂无
代码示例来源:origin: stackoverflow.com
@Override
public void onCreate() {
super.onCreate();
registerActivityLifecycleCallbacks(new ActivityLifecycleAdapter() {
@Override
public void onActivityCreated(Activity a, Bundle savedInstanceState) {
a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
});
}
代码示例来源:origin: stackoverflow.com
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if(isVisibleToUser) {
Activity a = getActivity();
if(a != null) a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
}
}
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* Unlock the screen orientation
* @param activity
*/
public static void unlockScreenOrientation(Activity activity) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
代码示例来源:origin: stackoverflow.com
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if(isVisibleToUser) {
Activity a = getActivity();
if(a != null) a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* 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);
}
}
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* Lock the screen orientation as the current state
* @param activity
*/
public static void lockScreenOrientation(Activity activity) {
if (activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
if (activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
代码示例来源:origin: jjdxmashl/jjdxm_ijkplayer
/**
* 是否仅仅为全屏
*/
public PlayerView setOnlyFullScreen(boolean isFull) {
this.isOnlyFullScreen = isFull;
tryFullScreen(isOnlyFullScreen);
if (isOnlyFullScreen) {
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
return this;
}
代码示例来源:origin: RobotiumTech/robotium
/**
* 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);
}
}
代码示例来源:origin: jjdxmashl/jjdxm_ijkplayer
/**
* 全屏切换
*/
public PlayerView toggleFullScreen() {
if (getScreenOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
updateFullScreenButton();
return this;
}
代码示例来源:origin: xfumihiro/ViewInspector
public void showProgressbar() {
windowManager.addView(profileProgressbar, ProfileProgressbar.createLayoutParams(mContext));
// lock screen orientation
int currentOrientation = mContext.getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
((Activity) mContext).setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
} else {
((Activity) mContext).setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
}
}
代码示例来源:origin: xfumihiro/ViewInspector
private void closeProgressbar() {
windowManager.removeViewImmediate(profileProgressbar);
// unlock screen orientation
((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
}
代码示例来源:origin: Tencent/tinker
private void fixActivityParams(Activity target, ActivityInfo targetAInfo) {
target.setRequestedOrientation(targetAInfo.screenOrientation);
target.setTheme(targetAInfo.theme);
try {
final Field aInfoField = ShareReflectUtil.findField(target, "mActivityInfo");
aInfoField.set(target, targetAInfo);
} catch (Throwable thr) {
throw new TinkerRuntimeException("see next stacktrace.", thr);
}
}
代码示例来源:origin: CarGuo/GSYVideoPlayer
/**
* 列表返回的样式判断。因为立即旋转会导致界面跳动的问题
*/
public int backToProtVideo() {
if (mIsLand > 0) {
mClick = true;
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
if (gsyVideoPlayer != null && gsyVideoPlayer.getFullscreenButton() != null)
gsyVideoPlayer.getFullscreenButton().setImageResource(gsyVideoPlayer.getEnlargeImageRes());
mIsLand = 0;
mClickPort = false;
return 500;
}
return 0;
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected void setRequestedOrientation(int requestedOrientation) {
if (getParent() != null) {
getParent().setRequestedOrientation(requestedOrientation);
} else {
this.requestedOrientation = requestedOrientation;
}
}
代码示例来源:origin: lipangit/JiaoZiVideoPlayer
public static void setRequestedOrientation(Context context, int orientation) {
if (JZUtils.getAppCompActivity(context) != null) {
JZUtils.getAppCompActivity(context).setRequestedOrientation(
orientation);
} else {
JZUtils.scanForActivity(context).setRequestedOrientation(
orientation);
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldSetOrientation() {
activity = Robolectric.setupActivity(DialogLifeCycleActivity.class);
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
assertThat(activity.getRequestedOrientation()).isEqualTo(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(qualifiers = "land")
public void testMultiOrientation_explicitLandscape() throws Exception {
Activity activity = buildActivity(Activity.class).create().start().resume().get();
// Confirm explicit "orientation = landscape" works.
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
ViewGroup view =
(ViewGroup) LayoutInflater.from(activity).inflate(layout.multi_orientation, null);
assertThat(view.getId()).isEqualTo(R.id.landscape);
assertThat(view).isInstanceOf(LinearLayout.class);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testMultiOrientation() throws Exception {
Activity activity = buildActivity(Activity.class).create().start().resume().get();
// Default screen orientation should be portrait.
ViewGroup view =
(ViewGroup) LayoutInflater.from(activity).inflate(layout.multi_orientation, null);
assertThat(view).isInstanceOf(LinearLayout.class);
assertThat(view.getId()).isEqualTo(R.id.portrait);
assertSame(activity, view.getContext());
// Confirm explicit "orientation = portrait" works.
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
int layoutResId = R.layout.multi_orientation;
view = (ViewGroup) LayoutInflater.from(activity).inflate(layoutResId, null);
assertThat(view).isInstanceOf(LinearLayout.class);
assertThat(view.getId()).isEqualTo(R.id.portrait);
assertSame(activity, view.getContext());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getAndSetRequestedOrientation_shouldRemember() throws Exception {
Activity activity = new Activity();
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, activity.getRequestedOrientation());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void getAndSetRequestedOrientation_shouldDelegateToParentIfPresent() throws Exception {
Activity parentActivity = new Activity();
Activity activity = new Activity();
shadowOf(activity).setParent(parentActivity);
parentActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, activity.getRequestedOrientation());
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
assertEquals(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE, parentActivity.getRequestedOrientation());
}
内容来源于网络,如有侵权,请联系作者删除!