下面列出了android.content.res.Configuration#ORIENTATION_UNDEFINED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void checkOrientation(View view){
int orientation = getResources()
.getConfiguration().orientation;
switch (orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
Toast.makeText(MainActivity.this, "ORIENTATION_LANDSCAPE",
Toast.LENGTH_SHORT).show();
break;
case Configuration.ORIENTATION_PORTRAIT:
Toast.makeText(MainActivity.this, "ORIENTATION_PORTRAIT",
Toast.LENGTH_SHORT).show();
break;
case Configuration.ORIENTATION_UNDEFINED:
Toast.makeText(MainActivity.this, "ORIENTATION_UNDEFINED",
Toast.LENGTH_SHORT).show();
break;
}
}
@Override
public void onConfigurationChanged(Configuration config)
{
super.onConfigurationChanged(config);
Log.v(TAG, "onConfigurationChanged");
if (config.orientation == Configuration.ORIENTATION_UNDEFINED)
{
return;
}
if (mLastLayoutOrientation != config.orientation)
{
mLastLayoutOrientation = config.orientation;
mCurrentModule.onLayoutOrientationChanged(mLastLayoutOrientation == Configuration.ORIENTATION_LANDSCAPE);
}
}
/**
* createTargetResource
*/
private void createTargetResource() {
try {
AssetManager am = (AssetManager) AssetManager.class.newInstance();
JavaCalls.callMethod(am, "addAssetPath", new Object[]{apkFile.getAbsolutePath()});
targetAssetManager = am;
} catch (Exception e) {
if (DEBUG) {
e.printStackTrace();
}
}
// 解决一个HTC ONE X上横竖屏会黑屏的问题
Resources hostRes = mHostAppContext.getResources();
Configuration config = new Configuration();
config.setTo(hostRes.getConfiguration());
config.orientation = Configuration.ORIENTATION_UNDEFINED;
targetResources = new ResourcesProxy(targetAssetManager, hostRes.getDisplayMetrics(), config, hostRes);
targetTheme = targetResources.newTheme();
targetTheme.setTo(mHostAppContext.getTheme());
targetTheme.applyStyle(targetMapping.getTheme(), true);
}
public static int getScreenOrientation(Context context)
{
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int orientation = Configuration.ORIENTATION_UNDEFINED;
if(display.getWidth()==display.getHeight()){
orientation = Configuration.ORIENTATION_SQUARE;
} else{
if(display.getWidth() < display.getHeight()){
orientation = Configuration.ORIENTATION_PORTRAIT;
}else {
orientation = Configuration.ORIENTATION_LANDSCAPE;
}
}
return orientation;
}
private void updateActivityOrientation()
{
Configuration config = mActivityRef.get().getResources().getConfiguration();
switch (config.orientation)
{
case Configuration.ORIENTATION_PORTRAIT:
mIsPortrait = true;
break;
case Configuration.ORIENTATION_LANDSCAPE:
mIsPortrait = false;
break;
case Configuration.ORIENTATION_UNDEFINED:
default:
break;
}
Log.i(LOGTAG, "Activity is in "
+ (mIsPortrait ? "PORTRAIT" : "LANDSCAPE"));
}
public static int getScreenOrientation(Context context)
{
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int orientation = Configuration.ORIENTATION_UNDEFINED;
if(display.getWidth()==display.getHeight()){
orientation = Configuration.ORIENTATION_SQUARE;
} else{
if(display.getWidth() < display.getHeight()){
orientation = Configuration.ORIENTATION_PORTRAIT;
}else {
orientation = Configuration.ORIENTATION_LANDSCAPE;
}
}
return orientation;
}
private void updateActivityOrientation()
{
Configuration config = mActivity.getResources().getConfiguration();
switch (config.orientation)
{
case Configuration.ORIENTATION_PORTRAIT:
mIsPortrait = true;
break;
case Configuration.ORIENTATION_LANDSCAPE:
mIsPortrait = false;
break;
case Configuration.ORIENTATION_UNDEFINED:
default:
break;
}
Log.i(LOGTAG, "Activity is in "
+ (mIsPortrait ? "PORTRAIT" : "LANDSCAPE"));
}
/**
* Get the device's current screen orientation.
*
* @return the device's current screen orientation, or null if unknown
*/
@SuppressWarnings("deprecation")
public static @Nullable Device.DeviceOrientation getOrientation(int orientation) {
switch (orientation) {
case Configuration.ORIENTATION_LANDSCAPE:
return Device.DeviceOrientation.LANDSCAPE;
case Configuration.ORIENTATION_PORTRAIT:
return Device.DeviceOrientation.PORTRAIT;
case Configuration.ORIENTATION_SQUARE:
case Configuration.ORIENTATION_UNDEFINED:
default:
return null;
}
}
/**
* Whether landscape screen.
*/
protected boolean isLandscape() {
switch (mConfiguration.orientation) {
case Configuration.ORIENTATION_LANDSCAPE: {
return true;
}
case Configuration.ORIENTATION_UNDEFINED:
case Configuration.ORIENTATION_PORTRAIT:
default: {
return false;
}
}
}
public void onConfigurationChanged(Configuration newConfig) {
if (newConfig.orientation != Configuration.ORIENTATION_UNDEFINED) {
if (layoutConfiguration != -1) {
recreateVideoControls();
}
}
}
/**
* Reliably get orientation. Return values are one of
* Configuration.ORIENTATION_XXXXX
*
* @return
*/
public int getScreenOrientation(Activity context) {
Display getOrient = context.getWindowManager().getDefaultDisplay();
int orientation = Configuration.ORIENTATION_UNDEFINED;
if (getOrient.getWidth() == getOrient.getHeight()) {
orientation = Configuration.ORIENTATION_SQUARE;
} else {
if (getOrient.getWidth() < getOrient.getHeight()) {
orientation = Configuration.ORIENTATION_PORTRAIT;
} else {
orientation = Configuration.ORIENTATION_LANDSCAPE;
}
}
return orientation;
}
@SuppressWarnings({"UnusedDeclaration", "UnusedAssignment"})
private void setOrientationProperties(ArrayList<Pair<String, String>> parameters) {
boolean allow_orientation_change = true;
AdActivity.OrientationEnum orientation = AdActivity.OrientationEnum.none;
for (Pair<String, String> bnvp : parameters) {
if (bnvp.first.equals("allow_orientation_change")) {
allow_orientation_change = Boolean.parseBoolean(bnvp.second);
} else if (bnvp.first.equals("force_orientation")) {
orientation = parseForceOrientation(bnvp.second);
}
}
// orientationProperties only affects expanded state
if (expanded || owner.adView.isInterstitial()) {
Activity containerActivity = owner.isFullScreen
? getFullscreenActivity() : (Activity) owner.getContextFromMutableContext();
if (allow_orientation_change) {
AdActivity.unlockOrientation(containerActivity);
} else {
int androidOrientation = Configuration.ORIENTATION_UNDEFINED;
switch (orientation) {
case landscape:
androidOrientation = Configuration.ORIENTATION_LANDSCAPE;
break;
case portrait:
androidOrientation = Configuration.ORIENTATION_PORTRAIT;
break;
case none:
default:
break;
}
AdActivity.lockToConfigOrientation(containerActivity, androidOrientation);
}
}
}
/**
* Resets this info state to the initial state.
* @hide
*/
public void reset() {
taskWidth = 0;
taskHeight = 0;
screenOrientation = Configuration.ORIENTATION_UNDEFINED;
}
public void onConfigurationChanged(Configuration newConfig) {
if (newConfig.orientation != Configuration.ORIENTATION_UNDEFINED && lastMenu != null) {
onAfterPrepareOptionsMenu(lastMenu);
}
}
public void onConfigurationChanged(Configuration newConfig) {
if (newConfig.orientation != Configuration.ORIENTATION_UNDEFINED) {
updateGridMetrics(false, newConfig);
}
}