文章较长建议先收藏再看
拆解步骤1、app 强制横屏显示,无视 androID:screenorIEntation="portrait" 属性
2、屏幕触摸坐标修改为横屏
3、开机动画横屏
4、开机logo、关机充电动画横屏
5、RecoveryUI 横屏
上代码 1、app 强制横屏显示修改 rotationForOrIEntationLw(),默认返回 270
frameworks\base\services\core\java\com\androID\server\policy\PhoneWindowManager.java
@OverrIDe public int rotationForOrIEntationLw(int orIEntation,int lastRotation,boolean defaultdisplay) { .... synchronized (mlock) { ... default: // For USER,UnspecIFIED,NOSENSOR,SENSOR and FulL_SENSOR,// just return the preferred orIEntation we already calculated. if (preferredRotation >= 0) { return preferredRotation; } // return Surface.ROTATION_0; return Surface.ROTATION_270;//cczheng add for land scap } } }
activity 默认强制属性为 SCREEN_ORIENTATION_LANDSCAPE
frameworks\base\services\core\java\com\androID\server\wm\WindowManagerService.java
boolean updateOrIEntationFromAppTokensLocked(int displayID,boolean forceUpdate) { long IDent = Binder.clearCallingIDentity(); try { final displayContent dc = mRoot.getdisplayContent(displayID); // final int req = dc.getorIEntation(); int req = androID.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;//cczheng add for land scap if (req != dc.getLastOrIEntation() || forceUpdate) { if (DEBUG_ORIENTATION) { Slog.v(TAG,"updateOrIEntation: req= " + req + ",mLastOrIEntation= " + dc.getLastOrIEntation(),new Throwable("updateOrIEntation")); } dc.setLastOrIEntation(req); //send a message to Policy indicating orIEntation change to take //action like disabling/enabling sensors etc.,// Todo(multi-display): Implement policy for secondary displays. if (dc.isDefaultdisplay) { mPolicy.setCurrentOrIEntationLw(req); } return dc.updateRotationUnchecked(forceUpdate); } return false; } finally { Binder.restoreCallingIDentity(IDent); } }
disPlayContent 显示 mRotation 默认改为 3 (270)
frameworks\base\services\core\java\com\androID\server\wm\displayContent.java
/** * Current rotation of the display. * Constants as per {@link androID.vIEw.Surface.Rotation}. * * @see #updateRotationUnchecked() */ // private int mRotation = 0; private int mRotation = 3;//cczheng add for land scap
修改默认值 config_reverseDefaultRotation 为 true,翻转显示角度
frameworks\base\core\res\res\values\config.xml
<!-- If true,the direction rotation is applIEd to get to an application's requested orIEntation is reversed. normally,the model is that landscape is clockwise from portrait; thus on a portrait device an app requesting landscape will cause a clockwise rotation,and on a landscape device an app requesting portrait will cause a counter-clockwise rotation. Setting true here reverses that logic. --> <!-- cczheng add for land scap --> <bool name="config_reverseDefaultRotation">true</bool> <!-- The number of degrees to rotate the display when the keyboard is open. A value of -1 means no change in orIEntation by default. --> <!-- cczheng add for land scap --> <integer name="config_lIDOpenRotation">270</integer>2、屏幕触摸坐标修改为横屏
对调 frame 的宽和高,设置方向为 270
frameworks\native\services\surfaceflinger\displayDevice.cpp
voID displayDevice::setProjection(int orIEntation,const Rect& newVIEwport,const Rect& newFrame) { Rect vIEwport(newVIEwport); Rect frame(newFrame); const int w = mdisplayWIDth; const int h = mdisplayHeight; transform R; displayDevice::orIEntationToTransfrom(orIEntation,w,h,&R); if (!frame.isValID()) { // the destination frame can be invalID if it has never been set,// in that case we assume the whole display frame. //cczheng add for land scap // frame = Rect(w,h); if (w < h) frame = Rect(h,w); else frame = Rect(w,h); } ....}// clang-format offdisplayDevice::displayDevice( const sp<SurfaceFlinger>& flinger,displayType type,int32_t hwcID,bool isSecure,const wp<IBinder>& displayToken,const sp<ANativeWindow>& nativeWindow,const sp<displaySurface>& displaySurface,std::unique_ptr<RE::Surface> renderSurface,int displayWIDth,int displayHeight,bool hasWIDecolorGamut,const HdrCapabilitIEs& hdrCapabilitIEs,const int32_t supportedPerFrameMetadata,const std::unordered_map<colorMode,std::vector<RenderIntent>>& hwccolorModes,int initialPowerMode) ..... mHdrCapabilitIEs = HdrCapabilitIEs(types,maxluminance,maxAverageluminance,minluminance); // initialize the display orIEntation transform. // setProjection(displayState::eOrIEntationDefault,mVIEwport,mFrame); //cczheng add for land scap setProjection(displayState::eOrIEntation270,mFrame);#ifdef MTK_SF_DEBUG_SUPPORT mfps = FpsCounterLoader::getInstance().create();#endif}
frameworks\native\services\surfaceflinger\SurfaceFlinger.cpp
voID SurfaceFlinger::onInitializedisplays() { // reset screen orIEntation and use primary layer stack Vector<ComposerState> state; Vector<displayState> displays; displayState d; d.what = displayState::edisplayProjectionChanged | displayState::eLayerStackChanged; d.token = mBuiltindisplays[displayDevice::disPLAY_PRIMARY]; d.layerStack = 0; //d.orIEntation = displayState::eOrIEntationDefault; //cczheng add for land scap d.orIEntation = displayState::eOrIEntation270; d.frame.makeInvalID(); d.vIEwport.makeInvalID(); d.wIDth = 0; d.height = 0; displays.add(d); ....}3、开机动画横屏
对调 createSurface() 的 w 和 h
frameworks\base\cmds\bootanimation\BootAnimation.cpp
status_t BootAnimation::readyToRun() { mAssets.addDefaultAssets(); sp<IBinder> dtoken(SurfaceComposerClIEnt::getBuiltIndisplay( ISurfaceComposer::edisplayIDMain)); displayInfo dinfo; status_t status = SurfaceComposerClIEnt::getdisplayInfo(dtoken,&dinfo); if (status) return -1; // create the native surface /*sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),dinfo.w,dinfo.h,PIXEL_FORMAT_RGB_565);*/ //cczheng add for land scap [S] sp<SurfaceControl> control; if(dinfo.w < dinfo.h) control = session()->createSurface(String8("BootAnimation"),PIXEL_FORMAT_RGB_565); else control = session()->createSurface(String8("BootAnimation"),PIXEL_FORMAT_RGB_565); //cczheng add for land scap [E] SurfaceComposerClIEnt::Transaction t; t.setLayer(control,0x40000000) .apply(); .....}
开机动画制作替换后面补充。。。
4、开机logo、关机充电动画横屏开机logo定义屏幕分辨率以对应资源文件夹的位置为
vendor\mediatek\proprIEtary\bootable\bootloader\lk\project\xxxx.mk 没有则看下面的
device\mediateksample\xxxx\ProjectConfig.mk
mk 中的 BOOT_logo = wxga
对应的资源文件位置在 vendor/mediatek/proprIEtary/bootable/bootloader/lk/dev/logo/wxga
可以看到 wxga 中都是竖屏的图片,而 wxganl 中已经是横屏的图片
@L_404_0@
则我们将 BOOT_logo 修改为 wxganl 即可
接下来还需要继续修改显示的角度,依旧改成 270,不然会出现花屏的现象
开机第一张图片 uboot 对应显示
vendor\mediatek\proprIEtary\bootable\bootloader\lk\platform\mt6765\mt_logo.c
voID init_fb_screen(){ ..... // in JB2.MP need to allign wIDth and height to 32,but jb5.mp needn't phical_screen.needAllign = 1; phical_screen.allignWIDth = AliGN_TO(CFG_disPLAY_WIDTH,MTK_FB_AlignmENT); /* In GB,no need to adjust 180 showing logo,for fb driver dealing the change */ /* but in JB,need adjust it for screen 180 roration */ phical_screen.need180Adjust = 0; // need sync with chip driver dprintf(INFO,"[lk logo: %s %d]MTK_LCM_PHYSICAL_ROTATION = %s\n",__FUNCTION__,__liNE__,MTK_LCM_PHYSICAL_ROTATION); if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION,"270",3)) { phical_screen.rotation = 270; } else if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION,"90",2)) { phical_screen.rotation = 90; } else if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION,"180",3) && (phical_screen.need180Adjust == 1)) { phical_screen.rotation = 180; } else { phical_screen.rotation = 270;//cczheng add for land scap } ....
开机第二张图片 kernel 对应显示
vendor\mediatek\proprIEtary\external\libshowlogo\charging_animation.cpp
int anim_fb_init(voID){ ..... phical_screen.needAllign = 1; phical_screen.need180Adjust = 1; phical_screen.fb_size = fb_size; if (MTK_LOG_ENABLE == 1) { SLOGD("[libshowlogo: %s %d]MTK_LCM_PHYSICAL_ROTATION = %s\n",MTK_LCM_PHYSICAL_ROTATION); } if(0 == strncmp(MTK_LCM_PHYSICAL_ROTATION,3)) { phical_screen.rotation = 270; } else if(0 == strncmp(MTK_LCM_PHYSICAL_ROTATION,2)){ phical_screen.rotation = 90; } else if(0 == strncmp(MTK_LCM_PHYSICAL_ROTATION,3) && (phical_screen.need180Adjust == 1)){ phical_screen.rotation = 180; } else { phical_screen.rotation = 270;//cczheng add for land scap } if (MTK_LOG_ENABLE == 1) { SLOGD("[libshowlogo]phical_screen: wIDth= %d,height= %d,bits_per_pixel =%d,needAllign = %d,allignWIDth=%d rotation =%d,need180Adjust = %d\n",phical_screen.wIDth,phical_screen.height,phical_screen.bits_per_pixel,phical_screen.needAllign,phical_screen.allignWIDth,phical_screen.rotation,phical_screen.need180Adjust); SLOGD("[libshowlogo: %s %d]show old animtion= 1,running show_animationm_ver %d\n",show_animationm_ver); SLOGD("[libshowlogo: %s %d]draw_anim_mode = 1,running mode %d\n",draw_anim_mode); } return 0;}
如果出现充电动画图片错位的现象,多数都是因为图形绘制点和屏幕尺寸不匹配导致的。可通过调整 cust_display.h 中位置参数
AndroID M 后:/vendor/mediatek/proprIEtary/external/libshowlogo/cust_display.h
AndroID M 前: /vendor/mediatek/proprIEtary/bootable/bootloader/lk/target/${PROJECT}/include/target/cust_display.h
(1 ,使用old version动画方案的调整如下设置,
#define bar_left (215)
#define bar_top (156)
#define bar_RIGHT (265)
#define bar_BottOM (278)
可以用windows的画图软件打开第1点里提到的图片,根据电池边框的像素来调整。
这里坐标的参考原点是左上角,背景图片的左上角是(0,0),这四个值都是相对于左上角的坐标来确定的,因此RIGHT > left,BottOM > top
小技巧:1)打开画图软件,选择 查看->缩放->自定义,将图片放到到800%
2)选择 查看->缩放->显示网格
这样就可以看到一个一个的像素
(2,使用new version动画方案调整如下设置:
#define CAPACITY_left (278) #define CAPACITY_top (556)#define CAPACITY_RIGHT (441)#define CAPACITY_BottOM (817)5、RecoveryUI 横屏
参考之前写的文章 MTK Recovery 模式横屏修改(适用于6.0 + 8.1+9.0)
6、系统导航栏位置调整,横屏后 navigationbarposition 默认在左边作为平板项目,需要将位置改为底部,直接修改 navigationbarposition() 返回 NAV_bar_BottOM
frameworks\base\services\core\java\com\androID\server\policy\PhoneWindowManager.java
@Navigationbarposition private int navigationbarposition(int displayWIDth,int displayRotation) { //cchzneg annotaion for land scape /*if (mNavigationbarCanMove && displayWIDth > displayHeight) { if (displayRotation == Surface.ROTATION_270) { return NAV_bar_left; } else { return NAV_bar_RIGHT; } }*/ return NAV_bar_BottOM; }
这样位置是变为底部了,但是三个按钮都重叠在一起了,需要修改 systemUI 的布局显示
vendor\mediatek\proprIEtary\packages\apps\systemUI\src\com\androID\systemUI\statusbar\phone\NavigationbarVIEw.java
private voID updateRotatedVIEws() { //cczheng change rot0 rot90 for landscape mRotatedVIEws[Surface.ROTATION_0] = mRotatedVIEws[Surface.ROTATION_180] = findVIEwByID(R.ID.rot90); // mRotatedVIEws[Surface.ROTATION_180] = findVIEwByID(R.ID.rot0); mRotatedVIEws[Surface.ROTATION_270] = mRotatedVIEws[Surface.ROTATION_90] = findVIEwByID(R.ID.rot0); // mRotatedVIEws[Surface.ROTATION_90] = findVIEwByID(R.ID.rot90); updateCurrentVIEw(); }
顺带再调整下 NavigationbarVIEw 的默认高度和左边 Back 键区域太大的问题
vendor\mediatek\proprIEtary\packages\apps\systemUI\src\com\androID\systemUI\statusbar\phone\NavigationbarInflaterVIEw.java
private VIEw createVIEw(String buttonSpec,VIEwGroup parent,LayoutInflater inflater) { VIEw v = null; String button = extractbutton(buttonSpec); if (left.equals(button)) { //cchzheng change NAVSPACE to MENU_IME for small left back click area String s = Dependency.get(TunerService.class).getValue(NAV_bar_left,MENU_IME_ROTATE/*NAVSPACE*/); button = extractbutton(s); } else if (RIGHT.equals(button)) { String s = Dependency.get(TunerService.class).getValue(NAV_bar_RIGHT,MENU_IME_ROTATE); button = extractbutton(s); } ...
frameworks\base\core\res\res\values\dimens.xml
<!-- Height of the bottom navigation / system bar. --> <!--cczheng change 48dp to 30dp--> <dimen name="navigation_bar_height">30dp</dimen>
ok,这样就大功告成了,完美的横屏适配
总结以上是内存溢出为你收集整理的Android9.0 MTK 平板横屏方案修改(强制app横屏 + 开机logo/动画+关机充电横屏 + RecoveryUI 横屏)全部内容,希望文章能够帮你解决Android9.0 MTK 平板横屏方案修改(强制app横屏 + 开机logo/动画+关机充电横屏 + RecoveryUI 横屏)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)