android BSP 开发总结之四

news/2025/2/5 5:59:37/

1.设置状态栏的显示或隐藏


frameworks/base 路劲下面有个services/core/java/com/android/server/wm/DisplayPolicy.java, 该文件中有一个”mHasNavigationBar” , 设置为false则隐藏,否则显示。
String navBarOverride = "1";
if ("1".equals(navBarOverride)) {mHasNavigationBar = false;
} else if ("0".equals(navBarOverride)) {mHasNavigationBar = true;
}

2.修改Snapdragon camera preview size 和image distortion

Snapdragon camera 不支持landscape的情况,将camera设置为landscape后,会出现preview size 和image distortion 不正确. 有遇到两种snapdragon camera的code。分别使用两种修改方式:

修改PhotoUI VideoUI文件

修改src/com/android/camera/PhotoUI.java文件中的”layoutPreview(float ratio)” 部分code,如下:

             Log.v(TAG, "setTransformMatrix: scaledTextureWidth = " + scaledTextureWidth+ ", scaledTextureHeight = " + scaledTextureHeight);
+            scaledTextureWidth = mMaxPreviewWidth - (mTopMargin + mBottomMargin);
+            scaledTextureHeight = mMaxPreviewHeight;if (((rotation == 0 || rotation == 180) && scaledTextureWidth > scaledTextureHeight)|| ((rotation == 90 || rotation == 270)&& scaledTextureWidth < scaledTextureHeight)) {
+                lp = new FrameLayout.LayoutParams((int)scaledTextureWidth ,
+                        (int) scaledTextureHeight, Gravity.CENTER);
+            } else {lp = new FrameLayout.LayoutParams((int) scaledTextureHeight,(int) scaledTextureWidth, Gravity.CENTER);
-            } else {
-                lp = new FrameLayout.LayoutParams((int) scaledTextureWidth,
-                        (int) scaledTextureHeight, Gravity.CENTER);
-            }
-            if(mScreenRatio == CameraUtil.RATIO_4_3) {
-                lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
-                lp.setMargins(0, mTopMargin, 0, mBottomMargin);}
+//            if(mScreenRatio == CameraUtil.RATIO_4_3) {
+//                lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
+                lp.gravity = Gravity.TOP;
+                lp.setMargins(mTopMargin, 0, 0, mBottomMargin);
+//            }

修改src/com/android/camera/VideoUI.java文件中的layoutPreview(float ratio)” 部分code,如下:

 Log.v(TAG, "setTransformMatrix: scaledTextureWidth = " + scaledTextureWidth+ ", scaledTextureHeight = " + scaledTextureHeight);
-
+            scaledTextureWidth = mMaxPreviewWidth - (mTopMargin + mBottomMargin);
+            scaledTextureHeight = mMaxPreviewHeight;if (((rotation == 0 || rotation == 180) && scaledTextureWidth > scaledTextureHeight)|| ((rotation == 90 || rotation == 270)&& scaledTextureWidth < scaledTextureHeight)) {
-                lp = new FrameLayout.LayoutParams((int) scaledTextureHeight,
-                        (int) scaledTextureWidth, Gravity.CENTER);
+                lp = new FrameLayout.LayoutParams((int) scaledTextureWidth,
+                        (int) scaledTextureHeight, Gravity.CENTER);} else {lp = new FrameLayout.LayoutParams((int) scaledTextureWidth,(int) scaledTextureHeight, Gravity.CENTER);}
+            lp.gravity = Gravity.TOP;
+            lp.setMargins(mTopMargin, 0, 0, mBottomMargin);}

修改CaptureUI 文件

修改src/com/android/camera/CaptureUI.java文件中的showSurfaceView的code,代码如下:
 

public void showSurfaceView() {Log.d(TAG, "showSurfaceView");if(mPreviewHeight > mDisplaySize.y){mPreviewHeight = mDisplaySize.y;}mSurfaceView.getHolder().setFixedSize(mPreviewWidth, mPreviewHeight);FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(mPreviewWidth , mPreviewHeight, Gravity.CENTER);lp.gravity = Gravity.TOP ;int left = (mDisplaySize.x - mPreviewWidth )/2;int top = (mDisplaySize.y - mPreviewHeight) /2;lp.setMargins(left, top, mDisplaySize.x, mDisplaySize.y);mSurfaceView.setLayoutParams(lp);mSurfaceView.setVisibility(View.VISIBLE);mIsVideoUI = false;}

3.Google search bar 和 search apps bar在横屏不显示
 

XXX设备在竖屏的情况下,google search bar 和search apps bar是正常显示,但是在转到横屏的情况不会显示不来。XXX 的home screen 和其他设备home screen 不一样的地方是,XXX 的home screen上有date time widget 并且google search bar 在底部. 当前修改都是基于GMS版本

横屏不显示google search bar原因

在/vendor/partner_gms/apps/SearchLauncher/quickstep/src/com/android/searchlauncher/HotseatQsbWidget.java 文件中有一段代码设置为横屏的时候不显示
 

@Overridepublic void setInsets(Rect insets) {setVisibility(mActivity.getDeviceProfile().isVerticalBarLayout() ? GONE : VISIBLE);MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams();mlp.topMargin = Math.round(Math.max(-mFixedTranslationY, insets.top - mMarginTopAdjusting));Rect padding = mActivity.getDeviceProfile().getHotseatLayoutPadding();setPaddingUnchecked(padding.left, 0, padding.right, 0);requestLayout();}

把上面红色代码改为:setVisibility(VISIBLE); google search bar和 search apps bar会显示出来,因为google search bar显示在home screen底部,所以会看不到,实际上是显示出来的. 如果想看google search bar 实际上有没有显示, 可以调整上面代码中的mlp.topMargin的值为负值,大概为-400.

使用google search bar 替换顶部的date widget

Home screen顶部的date widget代码在vendor/partner_gms/apps/SearchLauncher/quickstep/res/layout/search_container_workspace.xml文件中,代码如下:
 

<?xml version="1.0" encoding="utf-8"?>
<com.android.searchlauncher.SmartspaceQsbWidgetxmlns:android="http://schemas.android.com/apk/res/android"android:id="@id/search_container_workspace"android:layout_width="match_parent"android:layout_height="0dp"><fragmentandroid:name="com.android.searchlauncher.SmartspaceQsbWidget$SmartSpaceFragment"android:layout_width="match_parent"android:tag="smart_space_view"android:layout_height="match_parent"/></com.android.searchlauncher.SmartspaceQsbWidget>

把上面红色代码替换为vendor/partner_gms/apps/SearchLauncher/quickstep/res/layout/search_container_all_apps.xml 文件中的android:name="com.android.searchlauncher.HotseatQsbWidget$HotseatQsbFragment"则替换成功.

删除home screen 底部的google search bar

执行第二步的代码后在竖屏的情况下,会出现两个google search bar, z这个时候需要去掉底部的google search bar, home screen 底部google search bar 在vendor/partner_gms/apps/SearchLauncher/quickstep/res/layout/search_container_all_apps.xml 文件中.
 

<com.android.searchlauncher.HotseatQsbWidgetxmlns:android="http://schemas.android.com/apk/res/android"android:id="@id/search_container_all_apps"android:layout_width="match_parent"android:layout_height="56dp"android:layout_gravity="top|center_horizontal"android:translationY="28dp"><fragmentandroid:id="@+id/search_wrapper_view"android:name="com.android.searchlauncher.HotseatQsbWidget$HotseatQsbFragment"android:layout_width="match_parent"android:layout_height="match_parent"android:tag="qsb_view"/><com.android.launcher3.ExtendedEditTextandroid:id="@+id/fallback_search_view"android:layout_width="match_parent"android:layout_height="@dimen/all_apps_search_bar_field_height"android:layout_gravity="center"android:layout_marginLeft="8dp"android:layout_marginRight="8dp"android:background="@drawable/bg_all_apps_searchbox"android:elevation="1dp"android:focusableInTouchMode="true"

把上面红色代码删除后,在竖屏情况下Hotseat距离底部有一段距离,需要调整。

调整竖屏Hotseat与底部的距离

调整竖屏情况下Hotseat与home screen底部的距离,更改packages/apps/Launcher3/src/com/android/launcher3/DeviceProfile.java文件中hotseatBarBottomPaddingPx的值为0.
 

hotseatBarTopPaddingPx =res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);hotseatBarBottomPaddingPx = (isTallDevice ? 0: res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding))+ res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);hotseatBarBottomPaddingPx = 0;hotseatBarSidePaddingEndPx =res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);// Add a bit of space between nav bar and hotseat in vertical bar layout.hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? verticalDragHandleSizePx : 0;hotseatBarSizePx = ResourceUtils.pxFromDp(inv.iconSize, dm) + (isVerticalBarLayout()? (hotseatBarSidePaddingStartPx + hotseatBarSidePaddingEndPx): (res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size)+ hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx));

调整hotseatBarBottomPaddingPx的值为0后,会出现workspace 中app icon上下之间的距离较大,需要更改updateWorkspacePadding

方法中的bottompadding的值.
 

private void updateWorkspacePadding() {Rect padding = workspacePadding;if (isVerticalBarLayout()) {padding.top = 0;padding.bottom = edgeMarginPx;if (isSeascape()) {padding.left = hotseatBarSizePx;padding.right = verticalDragHandleSizePx;} else {padding.left = verticalDragHandleSizePx;padding.right = hotseatBarSizePx;}} else {int paddingBottom = hotseatBarSizePx + verticalDragHandleSizePx- verticalDragHandleOverlapWorkspace;if (isTablet) {// Pad the left and right of the workspace to ensure consistent spacing// between all icons// The amount of screen space available for left/right padding.int availablePaddingX = Math.max(0, widthPx - ((inv.numColumns * cellWidthPx) +((inv.numColumns - 1) * cellWidthPx)));availablePaddingX = (int) Math.min(availablePaddingX,widthPx * MAX_HORIZONTAL_PADDING_PERCENT);int availablePaddingY = Math.max(0, heightPx - edgeMarginPx - paddingBottom- (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx- hotseatBarBottomPaddingPx);padding.set(availablePaddingX / 2, edgeMarginPx + availablePaddingY / 2,availablePaddingX / 2, paddingBottom + availablePaddingY / 2);} else {// Pad the top and bottom of the workspace with search/hotseat bar sizespadding.set(desiredWorkspaceLeftRightMarginPx,edgeMarginPx,desiredWorkspaceLeftRightMarginPx,paddingBottom);}}}

将红色代码改为 “int paddingBottom = hotseatBarSizePx;”, 更改之后如果还是较大,则需要增大paddingBottom的值.

修改mHotseatPadding的bottom的值为0.
 

public Rect getHotseatLayoutPadding() {if (isVerticalBarLayout()) {if (isSeascape()) {mHotseatPadding.set(mInsets.left + hotseatBarSidePaddingStartPx,mInsets.top, hotseatBarSidePaddingEndPx, mInsets.bottom);} else {mHotseatPadding.set(hotseatBarSidePaddingEndPx, mInsets.top,mInsets.right + hotseatBarSidePaddingStartPx, mInsets.bottom);}} else {// We want the edges of the hotseat to line up with the edges of the workspace, but the// icons in the hotseat are a different size, and so don't line up perfectly. To account// for this, we pad the left and right of the hotseat with half of the difference of a// workspace cell vs a hotseat cell.float workspaceCellWidth = (float) widthPx / inv.numColumns;float hotseatCellWidth = (float) widthPx / inv.numHotseatIcons;int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);mHotseatPadding.set(hotseatAdjustment + workspacePadding.left + cellLayoutPaddingLeftRightPx,hotseatBarTopPaddingPx,hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);}return mHotseatPadding;}

移除红色代码中的 hotseatBarBottomPaddingPx, 因为 mInsets.bottom和 cellLayoutBottomPaddingPx的值是0.


http://www.ppmy.cn/news/1243042.html

相关文章

黑马点评Redis笔记

黑马点评Redis笔记 Redis基础篇&#xff1a;https://cyborg2077.github.io/2022/10/21/RedisBasic/ Redis实战篇&#xff1a;https://cyborg2077.github.io/2022/10/22/RedisPractice/ 一、手机号验证码注册登录 RandomUtil 生成定长随机数列 String code RandomUtil.ran…

Flask学习二:项目拆分、请求与响应、cookie

教程 教程地址&#xff1a; 千锋教育Flask2框架从入门到精通&#xff0c;Python全栈开发必备教程 老师讲的很好&#xff0c;可以看一下。 项目拆分 项目结构 在项目根目录下&#xff0c;创建一个App目录&#xff0c;这是项目下的一个应用&#xff0c;应该类似于后端的微服…

【python】Python将100个PDF文件对应的json文件存储到MySql数据库(源码)【独一无二】

&#x1f449;博__主&#x1f448;&#xff1a;米码收割机 &#x1f449;技__能&#x1f448;&#xff1a;C/Python语言 &#x1f449;公众号&#x1f448;&#xff1a;测试开发自动化【获取源码商业合作】 &#x1f449;荣__誉&#x1f448;&#xff1a;阿里云博客专家博主、5…

Kotlin学习——kt中的类,数据类 枚举类 密封类,以及对象

Kotlin 是一门现代但已成熟的编程语言&#xff0c;旨在让开发人员更幸福快乐。 它简洁、安全、可与 Java 及其他语言互操作&#xff0c;并提供了多种方式在多个平台间复用代码&#xff0c;以实现高效编程。 https://play.kotlinlang.org/byExample/01_introduction/02_Functio…

video标签在h5中被劫持问题

将video的视频链接转为blob export const encryptionVideo (options: URL) > {return new Promise((resolve, reject) > {window.URL window.URL || window.webkitURL;var xhr new XMLHttpRequest();xhr.open(GET, options.url, true);xhr.responseType blob;xhr.onl…

记一次处理大数据而导致的内存溢出问题

问题 订单服务通过MQ进行订单同步时&#xff0c;刚启动可以正常消费&#xff0c;但是跑一会就会卡住&#xff0c;每次都是第8个kafka分区不行再进行消费&#xff0c;其他分区消费的很慢。 现象 首先&#xff0c;CPU超高&#xff0c;达到百分之300多&#xff1b;其次&#xf…

【Spring Boot】如何集成Swagger

Swagger简单介绍 Swagger是一个规范和完整的框架&#xff0c;用于生成、描述、调用和可视化RESTful风格的Web服务。功能主要包含以下几点&#xff1a; 可以使前后端分离开发更加方便&#xff0c;有利于团队协作接口文档可以在线自动生成&#xff0c;有利于降低后端开发人员编写…

从Qt源码的角度分析Qt对象树与内存管理模式

作者:令狐掌门 技术交流QQ群:675120140 csdn博客:https://mingshiqiang.blog.csdn.net/ 文章目录 一、Qt对象树(Object Tree)和父子关系二、源码角度:QObject的内存管理构造函数析构函数addChild() 和 removeChild()三、C++模拟实现Qt的对象树内存管理模式Qt框架提供了一…