|
1:WindowManagerService:
platform\frameworks\base\services\core\java\com\android\server\wm\WindowManagerService.class
具体改动的地方看代码吧,
public int getOrientationFromWindowsLocked() {
....
-- return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
++ return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
/*
* Determine the new desired orientation of the display, returning
* a non-null new Configuration if it has changed from the current
* orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
* setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
* SCREEN. This will typically be done for you if you call
* sendNewConfiguration().
*
* The orientation is computed from non-application windows first. If none of
* the non-application windows specify orientation, the orientation is computed from
* application tokens.
* @see android.view.IWindowManager#updateOrientationFromAppTokens(
* android.os.IBinder)
*/
boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
long ident = Binder.clearCallingIdentity();
try {
int req = getOrientationFromWindowsLocked();
if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
-- mForcedAppOrientation = req;
-- req = getOrientationFromAppTokensLocked();
++req=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
if (req != mForcedAppOrientation) {
-- mForcedAppOrientation = req;
++ mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
....
}
boolean computeScreenConfigurationLocked(Configuration config) {
....
if (config != null) {
-- config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT:Configuration.ORIENTATION_LANDSCAPE;
++ config.orientation = Configuration.ORIENTATION_LANDSCAPE;
}
....
return true;
}
修改这几处代码便能把系统默认的竖屏变成横屏,但是会有其他的应用出现问题,比如拨号盘原本竖屏显示的,但是在这种横屏模式下打开拨号盘会报空指针错误,进源码一看原来拨号盘也准备了两套的布局,一套横屏一套竖屏的,单独修改windowmanagerservice后不知道为什么这些系统应用没有变成竖屏模式,或许是时间仓促,并没有对windowmanagerservice的流程作很详细的分析,以后有时间再找机会研究下这个流程吧。
2:PhoneWindowManager
- publicintrotationForOrientationLw(intorientation,intlastRotation,
- booleandisplayEnabled){
- if(mPortraitRotation<0){
- //Initializetherotationanglesforeachorientationonce.
- Displayd=((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
- .getDefaultDisplay();
- if(d.getWidth()>d.getHeight()){
- mPortraitRotation=Surface.ROTATION_90;
- mLandscapeRotation=Surface.ROTATION_0;
- mUpsideDownRotation=Surface.ROTATION_270;
- mSeascapeRotation=Surface.ROTATION_180;
- }else{
- mPortraitRotation=Surface.ROTATION_0;
- mLandscapeRotation=Surface.ROTATION_90;
- mUpsideDownRotation=Surface.ROTATION_180;
- mSeascapeRotation=Surface.ROTATION_270;
- }
- }
- {
- Log.i(TAG,"MediaPlayer.isnotPlayingVideo");
- synchronized(mLock){
- switch(orientation){
- caseActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
- //alwaysreturnportraitiforientationsettoportrait
- //returnmPortraitRotation;
- returnmUpsideDownRotation;
- caseActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
- //alwaysreturnlandscapeiforientationsettolandscape
- returnmLandscapeRotation;
- caseActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
- //alwaysreturnportraitiforientationsettoportrait
- //returnmUpsideDownRotation;
- returnmPortraitRotation;
- caseActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
- //alwaysreturnseascapeiforientationsettoreverselandscape
- returnmSeascapeRotation;
- caseActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
- //returneitherlandscaperotationbasedonthesensor
- mOrientationListener.setAllow180Rotation(
- isLandscapeOrSeascape(Surface.ROTATION_180));
- returngetCurrentLandscapeRotation(lastRotation);
- caseActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
- mOrientationListener.setAllow180Rotation(
- !isLandscapeOrSeascape(Surface.ROTATION_180));
- returngetCurrentPortraitRotation(lastRotation);
- }
- mOrientationListener.setAllow180Rotation(
- orientation==ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
- ||orientation==ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
- //casefornosensormeaningignoresensorandconsideronlylid
- //ororientationsensordisabled
- //orcase.unspecified
- if(mLidOpen){
- returnmLidOpenRotation;
- }elseif(mDockMode==Intent.EXTRA_DOCK_STATE_CAR&&mCarDockRotation>=0){
- returnmCarDockRotation;
- }elseif(mDockMode==Intent.EXTRA_DOCK_STATE_DESK&&mDeskDockRotation>=0){
- returnmDeskDockRotation;
- }else{
- if(useSensorForOrientationLp(orientation)){
- returnmOrientationListener.getCurrentRotation(lastRotation);
- }
- returnSurface.ROTATION_0;
- }
- }
- }
- }
修改上面倒数一行代码把return Surface.ROTATION_0改为你要的方向,记得这个要和上面的匹配,宽高不同,Surface.ROTATION_0也不同。因为代码开头就有
[java]view plaincopy
- if(mPortraitRotation<0){
- //Initializetherotationanglesforeachorientationonce.
- Displayd=((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
- .getDefaultDisplay();
- if(d.getWidth()>d.getHeight()){
- mPortraitRotation=Surface.ROTATION_90;
- mLandscapeRotation=Surface.ROTATION_0;
- mUpsideDownRotation=Surface.ROTATION_270;
- mSeascapeRotation=Surface.ROTATION_180;
- }else{
- mPortraitRotation=Surface.ROTATION_0;
- mLandscapeRotation=Surface.ROTATION_90;
- mUpsideDownRotation=Surface.ROTATION_180;
- mSeascapeRotation=Surface.ROTATION_270;
- }
- }
让所有应用都横屏显示:
frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
public int rotationForOrientationLw(int orientation, int lastRotation,
boolean displayEnabled) {
// Initialize the rotation angles for each orientation once.
Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
if (d.getWidth() > d.getHeight()) {
mPortraitRotation = Surface.ROTATION_0; //jeff. ROTATION_90;
mLandscapeRotation = Surface.ROTATION_0;
mUpsideDownRotation = Surface.ROTATION_90; //jeff. 270;
mSeascapeRotation = Surface.ROTATION_180;
} |