android如何改变系统默认横竖屏方向
在android4.2sdk上,机器默认是横屏,横屏下camera位于机器右上角,安装竖屏APK后,APK旋转180度,需要将camera位置朝下使用。
这一点不符合消费者使用习惯,需要在竖屏APK的情况下,camera位置朝上。 强制改变屏幕启动的方向,我是改的out目录下的build.prop中的ro.sf.hwrotation=90//270,不过这样改,重力感应和camera,开机logo都要翻转方向
由此引出以下开机logo的修改,原生态的logo是ppm格式的,如何修改ppm格式呢,从网上查到的信息是通过代码
具体方法如下
1. pngtopnm logo_linux_clut224.png > logo_linux_clut224.pnm
2. pnmquant 224 logo_linux_clut224.pnm > logo_linux_clut224.pnm
3.pnmtoplainpnm logo_linux_clut224.pnm > logo_linux_clut224.ppm
要删除logo_linux_clut224.clogo_linux_clut224.o 文件,重新编译内核,
注意编译完内核后,也要将上层编译下在打包,不然第一次烧录和recovery时,logo还会出现原来的现象
以下为转载部分
如何改变android默认的横竖屏,修改源码一个地方就可以了。
[java] view plain copy print ?
- public int rotationForOrientationLw(int orientation, int lastRotation,
- boolean displayEnabled) {
- if (mPortraitRotation < 0) {
- // 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_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.is not PlayingVideo");
- synchronized (mLock) {
- switch (orientation) {
- case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
- //always return portrait if orientation set to portrait
- //return mPortraitRotation;
- return mUpsideDownRotation;
- 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;
- return mPortraitRotation;
- 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(
- isLandscapeOrSeascape(Surface.ROTATION_180));
- return getCurrentLandscapeRotation(lastRotation);
- case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
- mOrientationListener.setAllow180Rotation(
- !isLandscapeOrSeascape(Surface.ROTATION_180));
- return getCurrentPortraitRotation(lastRotation);
- }
- mOrientationListener.setAllow180Rotation(
- orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
- || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
- // 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);
- }
- return Surface.ROTATION_0;
- }
- }
- }
- }
public int rotationForOrientationLw(int orientation, int lastRotation,
boolean displayEnabled) {if (mPortraitRotation < 0) {
// 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_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.is not PlayingVideo");
synchronized (mLock) {
switch (orientation) {
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
//always return portrait if orientation set to portrait
//return mPortraitRotation;
return mUpsideDownRotation;
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;
return mPortraitRotation;
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(
isLandscapeOrSeascape(Surface.ROTATION_180));
return getCurrentLandscapeRotation(lastRotation);
case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
mOrientationListener.setAllow180Rotation(
!isLandscapeOrSeascape(Surface.ROTATION_180));
return getCurrentPortraitRotation(lastRotation);
}mOrientationListener.setAllow180Rotation(
orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
|| orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
// 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);
}
return Surface.ROTATION_0;
}
}
}
}
修改上面倒数一行代码把return Surface.ROTATION_0改为你要的方向,记得这个要和上面的匹配,宽高不同,Surface.ROTATION_0也不同。因为代码开头就有
[java] view plain copy print ?
- if (mPortraitRotation < 0) {
- // 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_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;
- }
- }
if (mPortraitRotation < 0) {
// 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_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;
}
}
【android如何改变系统默认横竖屏方向】
推荐阅读
- 2018-02-06第三天|2018-02-06第三天 不能再了,反思到位就差改变
- android第三方框架(五)ButterKnife
- 考研英语阅读终极解决方案——阅读理解如何巧拿高分
- 如何寻找情感问答App的分析切入点
- mybatisplus如何在xml的连表查询中使用queryWrapper
- MybatisPlus使用queryWrapper如何实现复杂查询
- Android中的AES加密-下
- 带有Hilt的Android上的依赖注入
- 改变自己,先从自我反思开始
- 如何在Mac中的文件选择框中打开系统隐藏文件夹