Launcher3 模块的简单设计
Lancher3 路劲: Z:\xxx\packages\apps\Launcher3
任务
1、AllApps背景透明化。
2、Allapps前3个图标变为Chrome、youtube、play商店。
3、长按桌面空白处在弹出的按钮下添加一个图标变大按钮,一个图标变小按钮,点击按钮图标变大或变小。
4、APP 标题两行显示
5、后台任务界面添加一个按钮,点击弹出吐司,默认图标为方形。。
单编
Linux 指令
-
cd (项目目录)
-
source build/envsetup.sh -
lunch xxx-userdebug-gms trunk -
make Launcher3QuickStepGo
push
adb root
adb remount
adb push Z:\xxx\out\target\product\xxx\system_ext\priv-app\Launcher3QuickStepGo\Launcher3QuickStepGo.apk /system_ext/priv-app/Launcher3QuickStepGo/
adb reboot
任务 1
思路:先利用 uiautomatorviewer.bat 工具找到能够包括抽屉模式背景的最小背景布局

修改布局背景时不应在对应 xml 中使用 background ,而应该在清单文件 AndroidManifest.xml中修改主题。
路径: apps/Launcher3/res/values/styles.xml
修改:<item name="allAppsScrimColor">#01000000</item>
任务 2
Allapps前3个图标变为Chrome、youtube、play商店。
Chrome应用路径: Z:\xxx\out\target\product\xxx\product\app\Chrome
注意:严格按照所提供的模板 空格与 / 需注意!!!
修改路径: packages\apps\Launcher3\ext\res\xml\arrays.xml
<!-- Add for customize app position feature: start --><string-array name="customize_app_position" translatable="false"><!-- ex: packageName/className#position --><!-- ex: com.android.settings/#0 --><item> com.android.chrome/#0</item><item> com.google.android.youtube/#1</item><item> com.android.vending/#2</item></string-array><!-- Add for customize app position feature: end -->
在 com 命令行窗口输入 adb shell am monitor

利用此命令可以获取 apk 的包名。
任务 3
长按桌面空白处在弹出的按钮下添加一个图标变大按钮,一个图标变小按钮,点击按钮图标变大或变小。

查询后找到 OptionsPopupView.java 文件, 路径:Z:\xxx\packages\apps\Launcher3\src\com\android\launcher3\views\OptionsPopupView.java
在下述方法 showDefaultOptions(Launcher launcher, float x, float y) 中添加 PopupView, 并且对相应 string 进行定义。
showDefaultOptions(Launcher launcher, float x, float y)options.add(new OptionItem(R.string.icon_bigger_button_text,R.drawable.ic_setting,LAUNCHER_SELECT_MODE_RESIZE_BIGGER_ICON, OptionsPopupView::biggerIconSizePx));options.add(new OptionItem(R.string.icon_smaller_button_text,R.drawable.ic_setting, LAUNCHER_SELECT_MODE_RESIZE_SMALLER_ICON, OptionsPopupView::smallerIconSizePx));
思路是通过 PopupView 的点击事件发送广播
private static finalString BIGGER_ICONPX_ACTION ="com.android.launcher3.views.OptionsPopupView_bigger";private static finalString SMALLER_ICONPX_ACTION ="com.android.launcher3.views.OptionsPopupView_smaller";public static boolean biggerIconSizePx(View view){Launcher launcher = Launcher.getLauncher(view.getContext());Intent intent = new Intent();intent.setAction(BIGGER_ICONPX_ACTION);launcher.sendBroadcast(intent);return true;}public static boolean smallerIconSizePx(View view){Launcher launcher = Launcher.getLauncher(view.getContext());Intent intent = new Intent();intent.setAction(SMALLER_ICONPX_ACTION);launcher.sendBroadcast(intent);return true;}
DeviceProfile.java 文件对广播进行接受, 路径:Z:\xxx\packages\apps\Launcher3\src\com\android\launcher3\DeviceProfile.java
private int mResize;private Context mContext;private static finalString BIGGER_ICONPX_ACTION ="com.android.launcher3.views.OptionsPopupView_bigger";private static finalString SMALLER_ICONPX_ACTION ="com.android.launcher3.views.OptionsPopupView_smaller";// 构造器中注册广播并且获取上下文ResizeIconPx resizeIconPx = new ResizeIconPx();IntentFilter filter = new IntentFilter();filter.addAction(BIGGER_ICONPX_ACTION);filter.addAction(SMALLER_ICONPX_ACTION);context.registerReceiver(resizeIconPx, filter);mContext = context;
// 该方法为更新图标方法,在此方法中对图标大小进行改变且存储
updateIconSize(float scale, Resources res)mResize = Settings.Global.getInt(mContext.getContentResolver(), "ChangeValue", 0);Toast.makeText(mContext, "mResize"+mResize, Toast.LENGTH_SHORT).show();iconSizePx = Math.max(1, (int) (ResourceUtils.pxFromDp(invIconSizeDp, mInfo.metrics)* scale) + mResize);// 用内部类对广播进行实现并接受发送过来的广播public class ResizeIconPx extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {if (intent.getAction().equals(BIGGER_ICONPX_ACTION)){mResize += 5;Settings.Global.putInt(context.getContentResolver(), "ChangeValue", mResize);updateIconSize(1f,context.getResources());System.out.println("变大" + mResize);}else if(intent.getAction().equals(SMALLER_ICONPX_ACTION)){mResize -= 5;Settings.Global.putInt(context.getContentResolver(), "ChangeValue", mResize);updateIconSize(1f,context.getResources());System.out.println("变小" + mResize);}LauncherAppState app = LauncherAppState.getInstanceNoCreate();if (app != null) {app.getModel().forceReload();}}}
任务 4
APP 标题两行显示
查阅文档可知:
修改路径:Launcher3\res\values\config_ext.xml
<!== add for app icon label display double lines ==>
<bool name="enable_icon_label_show_double_lines">false</bool>
另外需要将此功能的实现进行开启,否则无法实现功能
private static boolean getProp(String prop) {return getProp(prop, true);}
任务 5
后台任务界面添加一个按钮,点击弹出吐司,默认图标为方形。
思路:先找到相似的按钮,并且找到其实现方法,仿照实现点击吐司的功能。

根据 id 找到了 屏幕截图的 xml 文件, 路径:**Z:\xxx\packages\apps\Launcher3\quickstep\res\layout\overview_actions_container.xml **
<Buttonandroid:id="@+id/action_screenshot"style="@style/OverviewActionButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:drawableStart="@drawable/ic_screenshot"android:text="@string/action_screenshot"android:theme="@style/ThemeControlHighlightWorkspaceColor" />
对其进行仿写,并且对所需要的 string 进行定义。
<Buttonandroid:id="@+id/action_change_icon_style"style="@style/OverviewActionButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/action_change_icon_style" />
布局实现后,对其功能进行实现, 根据 xml 的 id 查询其被调用的文件。路径: Z:\xxx\packages\apps\Launcher3\quickstep\recents_ui_overrides\src\com\android\quickstep\views\OverviewActionsView.java
设置点击事件
@Overrideprotected void onFinishInflate() {super.onFinishInflate();View share = findViewById(R.id.action_share);share.setOnClickListener(this);findViewById(R.id.action_screenshot).setOnClickListener(this);findViewById(R.id.action_change_icon_style).setOnClickListener(this);if (ENABLE_OVERVIEW_SHARE.get()) {share.setVisibility(VISIBLE);findViewById(R.id.share_space).setVisibility(VISIBLE);}}
实现点击事件, 发现仅仅只是调用,所以存在另一个类对方法进行具体实现。
@Overridepublic void onClick(View view) {if (mCallbacks == null) {return;}int id = view.getId();if (id == R.id.action_share) {mCallbacks.onShare();} else if (id == R.id.action_screenshot) {mCallbacks.onScreenshot();}else if (id == R.id.action_change_icon_style){mCallbacks.onChange();}}
方法具体实现以及添加接口的定义, 路径: Z:\xxx\packages\apps\Launcher3\quickstep\recents_ui_overrides\src\com\android\quickstep\TaskOverlayFactory.java
/*** Called when the current task is interactive for the user*/public void initOverlay(Task task, ThumbnailData thumbnail, Matrix matrix,boolean rotated) {final boolean isAllowedByPolicy = thumbnail.isRealSnapshot;getActionsView().updateDisabledFlags(DISABLED_ROTATED, rotated);getActionsView().setCallbacks(new OverlayUICallbacks() {@Overridepublic void onShare() {if (isAllowedByPolicy) {mImageApi.startShareActivity();} else {showBlockedByPolicyMessage();}}@SuppressLint("NewApi")@Overridepublic void onScreenshot() {saveScreenshot(task);}@Overridepublic void onChange(){Toast.makeText(mApplicationContext, "Start monitoring", Toast.LENGTH_SHORT).show();}});}public interface OverlayUICallbacks {/** User has indicated they want to share the current task. */void onShare();/** User has indicated they want to screenshot the current task. */void onScreenshot();void onChange();}
默认图标的改变,首先根据自己的想法找到 IconSpace.java,路径:Z:\xxx\packages\apps\Launcher3\src\com\android\launcher3\graphics\IconShape.java
对其修改以及修改 config.xml 文件 将默认的圆形 修改 M50,0L92,0C96.42,0 100,4.58 100 8L100,92C100, 96.42 96.42 100 92 100L8 100C4.58, 100 0 96.42 0 92L0 8 C 0 4.42 4.42 0 8 0L50 0Z 后仍发现无效,需要在客制化中对其进行修改,路径:Z:\xxx\vendor\xxxx\xxx\trunk\overlay\frameworks\base\core\res\res\values
<?xml version="1.0" encoding="utf-8"?><resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"><!-- Flag indicating whether round icons should be parsed from the application manifest. --><integer name="config_safe_media_volume_index">9</integer><bool name="config_useRoundIcon">true</bool><!-- Flag indicating whether we should enable the automatic brightness.Software implementation will be used if config_hardware_auto_brightness_available is not set --><bool name="config_automatic_brightness_available">false</bool><!-- Specifies the path that is used by AdaptiveIconDrawable class to crop launcher icons. --><string name="config_icon_mask" translatable="false">"M50,0L92,0C96.42,0 100,4.58 100 8L100,92C100, 96.42 96.42 100 92 100L8 100C4.58, 100 0 96.42 0 92L0 8 C 0 4.42 4.42 0 8 0L50 0Z"</string><bool name="config_intrusiveNotificationLed">false</bool><string translatable="false" name="config_ethernet_iface_regex"></string><integer name="config_screenBrightnessSettingDefault">255</integer><!--KDBAAN-386 R4 工具上verifier fail--><string-array name="config_biometric_sensors" translatable="false" ><!-- <item>0:2:15</item> ID0:Fingerprint:Strong --><item>0:8:4095</item> <!-- ID1:Face:Convenience --></string-array></resources>














