更改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 实现全屏显示的几种方法整理
  2. Android中TextView中内容不换行的解决方法
  3. Android P sensor对某个APP方向做旋转
  4. Android模拟、实现、触发系统按键事件的方法
  5. android 2.2+ 完全退出程序的方法
  6. android MediaPlayer出现RuntimeException: failure code: -38崩
  7. android 技术
  8. android 设置壁纸几种方法

随机推荐

  1. android 开发技巧(8)--格式化 TextView
  2. 查看 apk 的信息
  3. Android线程间通信的Message机制
  4. Gradle在Android(安卓)Studio 的应用
  5. Android 服务的五大级别
  6. 2011.09.23——— android sample之Notep
  7. android——xml drawable实现背景样式
  8. android之button
  9. Android P Launcher显示ALL APP ICON 和
  10. Run native executable in Android App