MTK 安卓14 launcher3修改桌面模式,替换某些应用图标,以及定制化Hotseat

news2024/9/22 7:27:53

原生的launcher的Hotseat如下图(1)所示,我想把效果改成图(2)

图(1)

图(2)

一:定制化HotSeat

修改的类:packages/apps/Launcher3/com/android/launcher3/Hotseat.java

(1).修改hotseat的宽 Hotseat------->setInsets
		
			@Override
			public void setInsets(Rect insets) {
				FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
				DeviceProfile grid = mActivity.getDeviceProfile();//这是拖拽的是时候预览位图判断
			
				if (grid.isVerticalBarLayout()) {
					mQsb.setVisibility(View.GONE);
					lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
					if (grid.isSeascape()) {
						lp.gravity = Gravity.LEFT;
						lp.width = grid.hotseatBarSizePx + insets.left;
					} else {
						lp.gravity = Gravity.RIGHT;
						lp.width = grid.hotseatBarSizePx + insets.right;
					}
				} else {
					 mQsb.setVisibility(View.VISIBLE);
					//lp.gravity = Gravity.BOTTOM;//注释原本的
					//这两句不用管,下面会更改
					lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
					lp.height = grid.hotseatBarSizePx;
					
					Log.e("TAG","Hotseat  with=========================="+grid.hotseatBarSizePx);
					
					//以下是新增的代码
					lp.gravity = Gravity.BOTTOM | Gravity.CENTER;
					WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
					DisplayMetrics displayMetrics = new DisplayMetrics();
					if (windowManager != null) {
						windowManager.getDefaultDisplay().getMetrics(displayMetrics);
						int screenWidth = displayMetrics.widthPixels;
						Log.e("TAG","Hotseat  screenWidth=========================="+screenWidth);
						// 计算80%的宽度
						int desiredWidth = (int) (screenWidth * 0.8);
						Log.e("TAG","Hotseat  desiredWidth=========================="+desiredWidth);
						lp.width = desiredWidth;
					}
					
					//添加这一句把位置拉上去
					lp.bottomMargin = insets.bottom;
				}
			
				Rect padding = grid.getHotseatLayoutPadding(getContext());
				//setPadding(padding.left, padding.top, padding.right, padding.bottom);
				//因为底部的hotseat是占用全部的,所有这里我们把位置调节一下
				setPadding( (insets.bottom / 4), 0,  (insets.bottom / 4), 0);
				setLayoutParams(lp);
				InsettableFrameLayout.dispatchInsets(this, insets);
			}
		(2).修改hotseat的背景色,有个定制化颜色的框 这里我们用颜色来替代
			drawable------>hotseat_bg.xml
			<?xml version="1.0" encoding="utf-8"?>
				<shape xmlns:android="http://schemas.android.com/apk/res/android">
				<solid android:color="#33FFFFFF"/>  
				<corners android:radius="10dp"/>  
				<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
			</shape> 
			暂时修改为:
			<?xml version="1.0" encoding="utf-8"?>
				<shape xmlns:android="http://schemas.android.com/apk/res/android">
				<solid android:color="#80FFFFFF"/>  
				<corners android:radius="20dp"/>  
				<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
			</shape> 
			最后再在Hotseat初始化的地方添加:setBackgroundResource(R.drawable.hotseat_bg);

 二、替换图标(这里的图标我是直接放在mipmap里面)

(1).直接替换某些应用图标
			\packages\apps\Launcher3\src\com\android\launcher3\BubbleTextView\packages\apps\Launcher3\src\com\android\launcher3\BubbleTextView.java
			//先导包
			import com.android.launcher3.icons.LauncherIcons;
			import android.graphics.Bitmap;
			import com.android.launcher3.icons.BitmapInfo;
			import com.android.launcher3.icons.BitmapInfo.DrawableCreationFlags;
			import android.content.res.Resources;
			import android.graphics.drawable.BitmapDrawable;
			import android.graphics.drawable.ColorDrawable;
			import android.graphics.drawable.Drawable;
			import androidx.core.content.res.ResourcesCompat;
			import android.util.Log;
			//放入图片到mipmap
			//根据包名替换图片,新增方法convertBitmapInfoSpecial
			
			public BitmapInfo convertBitmapInfoSpecial(String packname){
				Resources resources = getContext().getResources();
				Drawable drawable = null;
				try {
					if (packname.equals("com.android.calculator2")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("calculator_icon", "mipmap", getContext().getPackageName()), null);
					} else if (packname.equals("com.android.soundrecorder")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("soundrecorder_icon", "mipmap", getContext().getPackageName()), null);
					} else if (packname.equals("com.android.calendar")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("calendar_icon", "mipmap", getContext().getPackageName()), null);
					} else if (packname.equals("com.android.settings")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("settings_icon", "mipmap", getContext().getPackageName()), null);
					} else if (packname.equals("com.android.camera2")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("camera_icon", "mipmap", getContext().getPackageName()), null);
					} else if (packname.equals("com.android.music")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("music_icon", "mipmap", getContext().getPackageName()), null);
					} else if (packname.equals("com.android.gallery3d")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("gallery3d_icon", "mipmap", getContext().getPackageName()), null);
					}
					
					if(drawable!=null){
						Bitmap bitmap = drawableToBitmap(drawable);
						LauncherIcons li = LauncherIcons.obtain(getContext());
						return li.createIconBitmap(bitmap);
					}else{
						return null;
					}
				} catch (Exception e) {
					Log.e("TAG", "没有获取到对应的包名======");
				}
				return null;
			}
			
			//在applyIconAndLabel里面替换图片
			@UiThread
			protected void applyIconAndLabel(ItemInfoWithIcon info) {
				int flags = shouldUseTheme() ? FLAG_THEMED : 0;
				if (mHideBadge) {
					flags |= FLAG_NO_BADGE;
				}
				
				//这几句是新增的 用于替换图片用
				BitmapInfo bitmapInfo = convertBitmapInfoSpecial(info.getTargetComponent().getPackageName());
				if (bitmapInfo != null){
					info.bitmap = bitmapInfo;
				}
				
				FastBitmapDrawable iconDrawable = info.newIcon(getContext(), flags);
				mDotParams.appColor = iconDrawable.getIconColor();
				mDotParams.dotColor = Themes.getAttrColor(getContext(), R.attr.notificationDotColor);
				setIcon(iconDrawable);
				applyLabel(info);
			}

		(2).第一步替换图片以后,发现在按住移动的时候会还原,那么我们找到按住显示图片的地方再修改一次
			\packages\apps\Launcher3\src\com\android\launcher3\Utilities.java
			//先导包
			import com.android.launcher3.icons.LauncherIcons;
			import android.graphics.Bitmap;
			import com.android.launcher3.icons.BitmapInfo;
			import com.android.launcher3.icons.BitmapInfo.DrawableCreationFlags;
			import android.content.res.Resources;
			import android.graphics.drawable.BitmapDrawable;
			import android.graphics.drawable.ColorDrawable;
			import android.graphics.drawable.Drawable;
			import androidx.core.content.res.ResourcesCompat;
			import android.util.Log;
			
			//根据包名替换图片,新增方法getDrawableSpecial
			public static Drawable getDrawableSpecial(Context context,String pckName) {
				Resources resources = context.getResources();
				Drawable drawable = null;
				try {
					if (pckName.equals("com.android.calculator2")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("calculator_icon", "mipmap", context.getPackageName()), null);
					} else if (pckName.equals("com.android.soundrecorder")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("soundrecorder_icon", "mipmap", context.getPackageName()), null);
					} else if (pckName.equals("com.android.calendar")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("calendar_icon", "mipmap", context.getPackageName()), null);
					} else if (pckName.equals("com.android.settings")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("settings_icon", "mipmap", context.getPackageName()), null);
					} else if (pckName.equals("com.android.camera2")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("camera_icon", "mipmap", context.getPackageName()), null);
					} else if (pckName.equals("com.android.music")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("music_icon", "mipmap", context.getPackageName()), null);
					} else if (pckName.equals("com.android.gallery3d")) {
						drawable = ResourcesCompat.getDrawable(resources, resources.getIdentifier("gallery3d_icon", "mipmap", context.getPackageName()), null);
					}
					return drawable;
				} catch (Exception e) {
					Log.e("TAG", "没有获取到对应的包名======");
				}
				return null;
			}
				
			//然后在loadFullDrawableWithoutTheme里面修改
			if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
				LauncherActivityInfo activityInfo = context.getSystemService(LauncherApps.class)
						.resolveActivity(info.getIntent(), info.user);
				outObj[0] = activityInfo;
				
				//这就是新增的 
				Drawable drawableSpecial = getDrawableSpecial(context,info.getTargetComponent().getPackageName());
				if (drawableSpecial == null){
				//这里是原本的代码,放到这里
					return activityInfo == null ? null : LauncherAppState.getInstance(context)
							.getIconProvider().getIcon(
									activityInfo, activity.getDeviceProfile().inv.fillResIconDpi);
				}else{
					//如果找到了对应的包名,那么我们就替换图标
					return drawableSpecial;
				}
			//这里是原本的代码 我们先备份注释一份
            //return activityInfo == null ? null : LauncherAppState.getInstance(context)
                  //  .getIconProvider().getIcon(
                    //        activityInfo, activity.getDeviceProfile().inv.fillResIconDpi);
			}
			
			这时候图标不管移动还是显示都是正常的,但是替换图标以后会变大,我们尝试更改
			\frameworks\libs\systemui\iconloaderlib\src\com\android\launcher3\icons\BaseIconFactory.java
			
			 public BitmapInfo createIconBitmap(Bitmap icon) {
				Log.e("TAG","createIconBitmap===============================================0.8");
				if (mIconBitmapSize != icon.getWidth() || mIconBitmapSize != icon.getHeight()) {
					//这里本来是1.0f的,我们改成0.8f
					icon = createIconBitmap(new BitmapDrawable(mContext.getResources(), icon), 0.8f);
				}
		
				return BitmapInfo.of(icon, mColorExtractor.findDominantColorByHue(icon));
			}

三:默认桌面模式(14的launcher3有抽屉模式以及桌面模式)

 修改的类:

vendor/sprd/platform/packages/apps/Launcher3/res_unisoc/values/config_ext.xml

因为安卓14的launcher3支持桌面模式以及抽屉模式切换,所以我们默认为桌面模式更改
	//修改的这个属性来设置抽屉还是没有抽屉模式 dual为抽屉模式 single为桌面模式
	<!--The value must be dual or single-->
	<string name="default_home_screen_style" translatable="false">single</string>

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1943377.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Java 22 中的4个永久特性

功能处于孵化或预览阶段是什么意思&#xff1f; 实际上&#xff0c;这是向 Java 编程语言添加新功能的新过程&#xff0c;Java 社区使用这种过程来在 API 和工具处于早期实验阶段时从社区获得反馈&#xff08;孵化功能&#xff09;或已经完全指定但尚未永久的阶段&#xff08;…

ConstraintLayout属性说明

ayout_constraintTop_toTopOf&#xff1a;将某一控件的顶部与另一控件的顶部对齐。 layout_constraintTop_toBottomOf&#xff1a;将某一控件的顶部与另一控件的底部对齐。 layout_constraintBottom_toTopOf&#xff1a;将某一控件的底部与另一控件的顶部对齐。 layout_cons…

3GPP R18 Multi-USIM是怎么回事?(四)

前几篇主要是MUSIM feature NAS 部分内容的总结,这篇开始看RRC部分相关的内容,由于RRC部分内容过长,也分成了2篇。这篇就着重看下musim gap以及RRC触发UE离开RRC Connected mode相关的内容,直入正题, 上面的内容在overview中有提到,对应的是如下38.300中的描述。 处于网络…

【Node.js基础02】fs、path模块

目录 一&#xff1a;fs模块-读写文件 1 加载fs模块对象 2 读制定文件内容文件 3 向文件中写入内容 二&#xff1a;path模块-路径处理 1 问题引入 2 __dirname内置变量 使用方法 一&#xff1a;fs模块-读写文件 fs模块封装了与本机文件系统交互方法和属性 1 加载fs模块…

Win11 改造

记录一些安装 win11 系统之后&#xff0c;对使用不习惯的地方&#xff0c;进行的个人改造 右键菜单 Hiyoung006/Win11Useable: 将Win11右键菜单及资源管理器恢复为Win10样式的脚本 切换到旧版右键菜单&#xff1a; reg add "HKCU\Software\Classes\CLSID\{86ca1aa0-34…

Chapter18 基于物理的渲染——Shader入门精要学习

Chapter18 基于物理的渲染 一、PBS理论和数学基础1.光是什么微表面模型 2.渲染方程3.精确光源4.双向反射分布函数 BRDF5.漫反射项&#xff08;Lambert 模型&#xff09;Lambertian BRDF为&#xff1a;Disney BRDF中漫反射项 6.高光反射项微面元理论BRDF的高光反射项①菲涅尔反射…

LabVIEW和IQ测试仪进行WiFi测试

介绍一个使用LabVIEW和LitePoint IQxel-MW IQ测试仪进行WiFi测试的系统。包括具体的硬件型号、如何实现通讯、开发中需要注意的事项以及实现的功能。 使用的硬件​ IQ测试仪型号: LitePoint IQxel-MW 电脑: 配置高效的台式机或笔记本电脑 路由器: 支持802.11ax (Wi-Fi 6) 的…

便携气象站:科技助力气象观测

在科技飞速发展的今天&#xff0c;便携气象站以其轻便、高效、全面的特点&#xff0c;正逐渐改变着气象观测的传统模式。这款小巧而强大的设备&#xff0c;不仅为气象学研究和气象灾害预警提供了有力支持&#xff0c;更为户外活动、农业生产等领域带来了诸多便利。 便携气象站是…

遗传算法模型Python代码——用Python实现遗传算法案例

一、遗传算法概述 1.1适用范围 遗传算法&#xff08;Genetic Algorithm, GA&#xff09;是一种启发式搜索算法&#xff0c;广泛应用于以下领域&#xff1a; 优化问题&#xff1a;如函数优化、路径规划、资源分配等。机器学习&#xff1a;用于特征选择、超参数优化等。经济与…

服务器系统盘存储不够,添加数据盘并挂载(阿里云)

目录 1.获取数据盘设备名称 2.为数据盘创建分区 3.为分区创建文件系统 4.配置开机自动挂载分区 阿里云数据盘挂载说明链接&#xff1a;在Linux系统中初始化小于等于2 TiB的数据盘_云服务器 ECS(ECS)-阿里云帮助中心 1.获取数据盘设备名称 sudo fdisk -lu 运行结果如下所示…

解决 elementUI 组件在 WebStorm 中显示为未知标签的问题

解决 elementUI 组件在 WebStorm 中显示为未知标签的问题 一、问题 自从转到 ts 之后&#xff0c;编辑器就一直提示用到的 elementUI 标签未知&#xff0c;一直显示一溜黄色警示&#xff0c;很烦&#xff1a; 二、解决 把它改成大写就可以了。 如下&#xff1a; 把整个项目…

【C++】学习笔记——哈希_2

文章目录 十八、哈希3. 实现哈希表哈希表的存储节点哈希函数哈希表的定义哈希表的插入哈希表的查找哈希表的删除测试函数完整代码结果 未完待续 十八、哈希 3. 实现哈希表 哈希表的实现方法有蛮多种&#xff0c;这里我们选一个比较经典的开散列法来实现哈希表。由于STL库里的…

使用PicGo操作gitee图床(及web端html不能访问图片的解决办法)

1.新建仓库 2.输入仓库名称,也就是图床名称,必须设置开源可见 也可以在创建仓库后,点击管理->基本信息->是否开源进行设置 鼠标悬浮到右上角头像->设置 点击私人令牌 点击生成新令牌,填写描述,直接点提交即可 点击提交后输入登录密码会生成一个token秘钥,如下,这个…

新版本异次元荔枝V4自动发卡系统源码

新版本异次元荔枝V4自动发卡系统源码&#xff0c;增加主站货源系统&#xff0c;支持分站自定义支付接口&#xff0c;目前插件大部分免费&#xff0c;UI页面全面更新&#xff0c;分站可支持对接其他分站产品&#xff0c;分站客服可自定义&#xff0c;支持限定优惠。 源码下载&a…

matlab--legend利用for循环添加图例

第一种方法 %% 第一种方法 R 1:4; THETA1 atand(R./1.8); legend_name {}; for i 1:4THETA atand(R(i)./1.8);intTheta floor(THETA);R_THERA 1.8 - (R(i)./tand(intTheta-10:intTheta10));R_THERA1 1.8 - (R(i)/tand(intTheta));plot(R_THERA);grid on;hold onlegend…

Git之repo sync -c与repo sync -dc用法区别(四十八)

简介&#xff1a; CSDN博客专家&#xff0c;专注Android/Linux系统&#xff0c;分享多mic语音方案、音视频、编解码等技术&#xff0c;与大家一起成长&#xff01; 优质专栏&#xff1a;Audio工程师进阶系列【原创干货持续更新中……】&#x1f680; 优质专栏&#xff1a;多媒…

了解Linux中的shell脚本

目录 1、什么是shell 2、编写第一个shell文件 3、shell的权限 4、变量 5、 shell传递参数 6、shell数组 7、shell基本运算符 7.1 算术运算符 7.2 关系运算符 7.3 布尔运算符 7.4 逻辑运算符 7.5 字符串运算符 8、控制语句 8.1 if 8.2 for 8.3 while语句 9、其他 1、…

C++~~string模拟实现(3)

目录 1.传统写法和现代写法 2.对于流提取的优化 3.简单机制了解 4.string类的几个构造函数总结 4.1基本用法 4.2两个赋值方式 4.3拷贝构造 4.4获取字符 4.5一个容易混淆的对比 4.6创建对象 1.传统写法和现代写法 &#xff08;1&#xff09;上面的代码里面的左边部分是…

排序---归并排序

归并排序 一、定义二、实现原理三、代码实现 一、定义 归并排序&#xff08;MERGE-SORT&#xff09;是建立在归并操作上的一种有效的排序算法,该算法是采用分治法&#xff08;Divide andConquer&#xff09;的一个非常典型的应用。将已有序的子序列合并&#xff0c;得到完全有…

ES中聚合查询之date_histogram查询出现key_as_string 和 key含义

ES中聚合查询之date_histogram查询出现key_as_string 和 key含义 DSL语句 #实例 GET /capture_features_202407/_search {"query": {"bool": {"must": [{"terms": {"plateNo": ["汉A00001"]}},{"range&quo…