下面列出了android.content.pm.ActivityInfo#SCREEN_ORIENTATION_USER 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 旋转处理
*
* @param activity 页面
* @param newConfig 配置
* @param orientationUtils 旋转工具类
* @param hideActionBar 是否隐藏actionbar
* @param hideStatusBar 是否隐藏statusbar
*/
public void onConfigurationChanged(Activity activity, Configuration newConfig, OrientationUtils orientationUtils, boolean hideActionBar, boolean hideStatusBar) {
super.onConfigurationChanged(newConfig);
//如果旋转了就全屏
if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_USER) {
if (!isIfCurrentIsFullscreen()) {
startWindowFullscreen(activity, hideActionBar, hideStatusBar);
}
} else {
//新版本isIfCurrentIsFullscreen的标志位内部提前设置了,所以不会和手动点击冲突
if (isIfCurrentIsFullscreen() && !isVerticalFullByVideoSize()) {
backFromFull(activity);
}
if (orientationUtils != null) {
orientationUtils.setEnable(true);
}
}
}
public final int intoOrientation(int flag) {
int or = ActivityInfo.SCREEN_ORIENTATION_USER;
if (flag == 1) {// portrait
or = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
} else if (flag == 2) {// landscape
or = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
} else if (flag == 4) {// reverse portrait
or = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
} else if (flag == 8) {// reverse landscape
or = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
} else if (flag == 5) {// portrait and reverse portrait, Some devices only portrait effective
if (Build.VERSION.SDK_INT >= 18) {
or = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT;
} else {
or = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
}
} else if (flag == 10) {// landscape and reverse landscape
if (Build.VERSION.SDK_INT >= 18) {
or = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE;
} else {
or = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
}
}
return or;
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_USER) {
//这里没必要,因为我们使用的是setColorForSwipeBack,并不会有这个虚拟的view,而是设置的padding
StatusBarUtil.hideFakeStatusBarView(this);
} else if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimary));
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_USER) {
//这里没必要,因为我们使用的是setColorForSwipeBack,并不会有这个虚拟的view,而是设置的padding
StatusBarUtil.hideFakeStatusBarView(this);
} else if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimary));
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_USER) {
//这里没必要,因为我们使用的是setColorForSwipeBack,并不会有这个虚拟的view,而是设置的padding
StatusBarUtil.hideFakeStatusBarView(this);
} else if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimary));
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_USER) {
//这里没必要,因为我们使用的是setColorForSwipeBack,并不会有这个虚拟的view,而是设置的padding
StatusBarUtil.hideFakeStatusBarView(this);
} else if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimary));
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_USER) {
//这里没必要,因为我们使用的是setColorForSwipeBack,并不会有这个虚拟的view,而是设置的padding
StatusBarUtil.hideFakeStatusBarView(this);
} else if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimary));
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_USER) {
//这里没必要,因为我们使用的是setColorForSwipeBack,并不会有这个虚拟的view,而是设置的padding
StatusBarUtil.hideFakeStatusBarView(this);
} else if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimary));
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_USER) {
//这里没必要,因为我们使用的是setColorForSwipeBack,并不会有这个虚拟的view,而是设置的padding
StatusBarUtil.hideFakeStatusBarView(this);
} else if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimary));
}
}
/**
* The requested screen orientation. Commonly used values are
unspecified (-1), landscape (0), portrait (1), sensor (4), and user (2). " +
"See the Android developer documentation for ActivityInfo.Screen_Orientation for the " +
"complete list of possible settings.
*
* ScreenOrientation property getter method.
*
* @return screen orientation
*/
@SimpleProperty(category = PropertyCategory.APPEARANCE,
description = "The requested screen orientation, specified as a text value. " +
"Commonly used values are " +
"landscape, portrait, sensor, user and unspecified. " +
"See the Android developer documentation for ActivityInfo.Screen_Orientation for the " +
"complete list of possible settings.")
public String ScreenOrientation() {
switch (getRequestedOrientation()) {
case ActivityInfo.SCREEN_ORIENTATION_BEHIND:
return "behind";
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
return "landscape";
case ActivityInfo.SCREEN_ORIENTATION_NOSENSOR:
return "nosensor";
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
return "portrait";
case ActivityInfo.SCREEN_ORIENTATION_SENSOR:
return "sensor";
case ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED:
return "unspecified";
case ActivityInfo.SCREEN_ORIENTATION_USER:
return "user";
case 10: // ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
return "fullSensor";
case 8: // ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
return "reverseLandscape";
case 9: // ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
return "reversePortrait";
case 6: // ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
return "sensorLandscape";
case 7: // ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
return "sensorPortrait";
}
return "unspecified";
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//如果旋转了就全屏
if (newConfig.orientation != ActivityInfo.SCREEN_ORIENTATION_USER) {
mFull = false;
} else {
mFull = true;
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//如果旋转了就全屏
if (newConfig.orientation != ActivityInfo.SCREEN_ORIENTATION_USER) {
mFull = false;
} else {
mFull = true;
}
}
public static String screenOrientationDesc(int curScreenOr) {
String oriDesc = curScreenOr + "";
switch (curScreenOr) {
case ActivityInfo.SCREEN_ORIENTATION_BEHIND:
oriDesc = "在后面BEHIND";
break;
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
oriDesc = "竖屏";
break;
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
oriDesc = "横屏";
break;
case ActivityInfo.SCREEN_ORIENTATION_USER:
oriDesc = "跟随用户";
break;
case ActivityInfo.SCREEN_ORIENTATION_SENSOR:
oriDesc = "跟随传感器";
break;
case ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED:
oriDesc = "未指明的";
break;
case ActivityInfo.SCREEN_ORIENTATION_LOCKED:
oriDesc = "locked";
break;
}
return oriDesc;
}
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";
}
}
private int getScreenOrietationFromPref() {
try {
mScreenOrientation = Integer.parseInt(mSharedPref.getString(PERF_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_USER + ""));
} catch (Exception e) {
mScreenOrientation = ActivityInfo.SCREEN_ORIENTATION_USER;
}
return mScreenOrientation;
}
public final void setAutorotateEnable(int enabled) {
int ori = ActivityInfo.SCREEN_ORIENTATION_USER;
if (enabled == 1) {
ori = getOrientationForRotation();
}
final int orientation = ori;
new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
setRequestedOrientation(orientation);
;
}
}.sendEmptyMessageDelayed(0, 100);
}
private int getOrientationForRotation() {
int ori = ActivityInfo.SCREEN_ORIENTATION_USER;
int rotation = this.getWindowManager().getDefaultDisplay().getRotation();
if (rotation == Surface.ROTATION_0) {
ori = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
} else if (rotation == Surface.ROTATION_90) {
ori = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
} else if (rotation == Surface.ROTATION_180) {
ori = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
} else if (rotation == Surface.ROTATION_270) {
ori = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
}
return ori;
}