更改android默认屏幕方向 - [技术]

2011-12-11

分类: 技术

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://glizardy.blogbus.com/logs/180916299.html

frameworks/policies/base/phone/com/android/internal/policy/impl/PhoneWindow­­Manager.java function: rotationForOrientationLw return a direction of what you want; *the red lines are my change: (in eclair)* */*added by wylhistory for test*/* * Log.d(TAG,"the before switch orientation :"+orientation);* * if(false){* * /*above is added by wylhistory for test*/* synchronized (mLock) { switch (orientation) { case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: //always return landscape if orientation set to landscape return mLandscapeRotation; case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: //always return portrait if orientation set to portrait return mPortraitRotation; } // case for nosensor meaning ignore sensor and consider only lid // or orientation sensor disabled //or case.unspecified if (mLidOpen) { return mLidOpenRotation; } else if (mDockState == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) { return mCarDockRotation; } else if (mDockState == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation > = 0) { return mDeskDockRotation; } else { if (useSensorForOrientationLp(orientation)) { // If the user has enabled auto rotation by default, do it. int curRotation = mOrientationListener.getCurrentRotation(); return curRotation >= 0 ? curRotation : lastRotation; } return Surface.ROTATION_0; } } */*added by wylhistory for test*/* * ** }* * return Surface.ROTATION_90;/here you can change to any other direction of your like;* * /*added by wylhistory */* *

此方法可以修改初始方向。

另外可修改package/apps/launcher2/AndroidManifest.xml

android:screenOrientation

此方法无法更改初始锁屏界面的方向。

synchronized (mLock) {
switch (orientation) {
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
boolean isConnected = isHdmiConnected(HdmiState);
if (isConnected){
return mLandscapeRotation;
}else
{
return mPortraitRotation;
}
//always return portrait if orientation set to portrait
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
//always return landscape if orientation set to landscape
return mLandscapeRotation;
case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
//always return portrait if orientation set to portrait
return mUpsideDownRotation;
case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
//always return seascape if orientation set to reverse landscape
return mSeascapeRotation;
case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
//return either landscape rotation based on the sensor
mOrientationListener.setAllow180Rotation(false);
return getCurrentLandscapeRotation(lastRotation);
case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
mOrientationListener.setAllow180Rotation(true);
return getCurrentPortraitRotation(lastRotation);
}

mOrientationListener.setAllow180Rotation(
orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);

// case for nosensor meaning ignore sensor and consider only lid
// or orientation sensor disabled
//or case.unspecified
if (mLidOpen) {
return mLidOpenRotation;
} else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {
return mCarDockRotation;
} else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) {
return mDeskDockRotation;
} else {
if (useSensorForOrientationLp(orientation)) {
return mOrientationListener.getCurrentRotation(lastRotation);
}

if (SystemProperties.get("ro.sf.hwrotation").equals("270")) {
//Log.d("------->xzj","ro.sf.hwrotation is set ,care");
return Surface.ROTATION_90;
}
return Surface.ROTATION_0; //can change lockscreen rotation
}
}
}

更多相关文章

  1. android 5.0多用户支持
  2. Android(安卓)P sensor对某个APP方向做旋转
  3. android MediaPlayer出现RuntimeException: failure code: -38崩
  4. Android: 更改语言时Launcher2更新apps
  5. 开发中常用到的几处代码设置
  6. Android(安卓)横屏时禁止输入法全屏
  7. Android(安卓)WIFI热点默认安全性的修改方法
  8. android 判断横竖屏的方法
  9. android常见问题汇总大全

随机推荐

  1. Android的ContextMenu(上下文菜单)知识链
  2. android TextView 容纳不下内容,让字向左
  3. Android属性系统
  4. Android横竖屏切换总结
  5. Android(安卓)TV webview禁止自动获取焦
  6. android studio打开react-native的androi
  7. 从Android界面开发谈起
  8. android控件属性
  9. 使用 Android(安卓)Studio 跑新浪微博SDK
  10. Android学习札记15:对Android中View绘制流