Android Launcher 修改记录

OS:Android 9.0

Source:Launcher3源码

Path:packages\apps\Launcher3

 

一、修改默认配置

1.图标修改

 

Path: xml/device_profiles.xml

    //1024x600

    <profile

        launcher:name="Nexus 7"

        launcher:minWidthDps="575"

        launcher:minHeightDps="904"

        launcher:numRows="3"            行图标数量

        launcher:numColumns="4"          列图标数量

        launcher:numFolderRows="4"

        launcher:numFolderColumns="5"

        launcher:iconSize="80"             图标大小

        launcher:iconTextSize="20"          文字大小

        launcher:numHotseatIcons="7"

        launcher:defaultLayoutId="@xml/default_workspace_5x6"

 

配置预设小部件

Path: xml/default_workspace_5x6.xml

    <appwidget

        launcher:className="com.wits.widget.WidgetProvider"

        launcher:packageName="com.wits.widget"

        launcher:screen="1"

        launcher:spanX="4"

        launcher:spanY="3"

        launcher:x="0"

        launcher:y="0" />

 

配置预设图标

Path: xml/default_workspace_5x6.xml

 

        <favorite

        launcher:className="com.google.android.apps.chrome.Main"

        launcher:packageName="com.android.chrome"

        launcher:screen="2"                          显示到第二屏

        launcher:x="0"                                                                

        launcher:y="0"/>

 

配置需要过滤的APK和替换定制图标

因为有可能出现一个APK多个图标的情况,所以通过类名去进行过滤和替换。

Path: values/config.xml

<!--wits-->

    <!--exclude class name-->

    <string-array name="exclude_class_list" translatable="false">

        <item>com.wits.pms.TestActivity</item>  需要隐藏的APK 类名

</string-array>

 

    <!--change icon: activity icon class name-->

    <string-array name="icon_class_name" translatable="false">

        <item>com.google.android.apps.chrome.Main</item> 定制图标对应的类名

        <item>com.android.settings.Settings</item>      

    </string-array>

 <!--change icon: icon @drawable/theme_play-->                

  <string-array name="icon_package_png" translatable="false">  

      <!--google-->                                            

      <item>@drawable/theme_play</item>          定制图标对应的图              

      <item>@drawable/theme_google</item>                      

</string-array>   

 

Path: com.android.launcher3.uioverrides.AllAppsSwipeController#canInterceptTouch

 

 protected boolean canInterceptTouch(MotionEvent ev) {

...

        if(mLauncher.isInState(ALL_APPS) && !mLauncher.getAppsView().shouldContainerScroll(ev)) {

            return false;

        }

        //add start

        if(FeatureFlags.CUSTOM_REMOVE){

           return false;

        }

        //add end

        return true;

}

 

去掉hotseat底栏

Path: com.android.launcher3.Hotseat#setInsets

屏蔽setInsets里面的所有代码。

 

去掉widget长按拖动

Path: com.android.launcher3.touch.ItemLongClickListener#onWorkspaceItemLongClick

private static boolean onWorkspaceItemLongClick(View v) {

        Launcher launcher = Launcher.getLauncher(v.getContext());

        if (!canStartDrag(launcher)) return false;

        if (!launcher.isInState(NORMAL) && !launcher.isInState(OVERVIEW)) return false;

        if (!(v.getTag() instanceof ItemInfo)) return false;

 

        launcher.setWaitingForResult(null);

        //remove APP WIDGET drag feature

        if (FeatureFlags.CUSTOM_REMOVE){

            if (((ItemInfo)v.getTag()).itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET){

                return false;

            }

        }

                 

        beginDrag(v, launcher, (ItemInfo) v.getTag(), new DragOptions());

        return true;

}

 

去掉hotseat提示上划跳动动画

Path: com.android.launcher3.Launcher#onResume

 //remove hotseat animator

        if (!FeatureFlags.CUSTOM_REMOVE) {

            DiscoveryBounce.showForHomeIfNeeded(this);

        }

 

去掉APP图标自动生成的底框

Path: com.android.launcher3.graphics.LauncherIcons#normalizeAndWrapToAdaptiveIcon

private Drawable normalizeAndWrapToAdaptiveIcon(Drawable icon, int iconAppTargetSdk,

            RectF outIconBounds, float[] outScale) {

                        ...

 if (!FeatureFlags.CUSTOM_REMOVE && ((Utilities.ATLEAST_OREO && iconAppTargetSdk >= Build.VERSION_CODES.O) ||

                    Utilities.ATLEAST_P)) {

                boolean[] outShape = new boolean[1];

                if (mWrapperIcon == null) {

                    mWrapperIcon = mContext.getDrawable(R.drawable.adaptive_icon_drawable_wrapper)

                            .mutate();

                }

                AdaptiveIconDrawable dr = (AdaptiveIconDrawable) mWrapperIcon;

                dr.setBounds(0, 0, 1, 1);

                scale = getNormalizer().getScale(icon, outIconBounds, dr.getIconMask(), outShape);

                if (Utilities.ATLEAST_OREO && !outShape[0] && !(icon instanceof AdaptiveIconDrawable)) {

                    FixedScaleDrawable fsd = ((FixedScaleDrawable) dr.getForeground());

                    fsd.setDrawable(icon);

                    fsd.setScale(scale);

                    icon = dr;

                    scale = getNormalizer().getScale(icon, outIconBounds, null, null);

 

                    ((ColorDrawable) dr.getBackground()).setColor(mWrapperBackgroundColor);

                }

            } else {

 

限制Workspace个数

  1. Path:om.android.launcher3.config.BaseFlags

    public static final int WORKSPACE_SCREEN_SIZE_MAX = 3;

  1. Path: com.android.launcher3.Workspace#addExtraEmptyScreenOnDrag

   public void addExtraEmptyScreenOnDrag() {

                                    ...

                  //limit Workspace size

        if (FeatureFlags.CUSTOM_REMOVE) {

            if (mWorkspaceScreens.size() >= FeatureFlags.WORKSPACE_SCREEN_SIZE_MAX) {

                return;

            }

        }

 

                                      ...

}

 

去掉APP图标长按弹出菜单

Path: com.android.launcher3.Workspace#beginDragShared

 

 public DragView beginDragShared(View child, DragSource source, ItemInfo dragObject,

            DragPreviewProvider previewProvider, DragOptions dragOptions) {

       ...

        if (child.getParent() instanceof ShortcutAndWidgetContainer) {

            mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent();

        }

 

                 if (!FeatureFlags.CUSTOM_REMOVE && child instanceof BubbleTextView && !dragOptions.isAccessibleDrag)     {

            PopupContainerWithArrow popupContainer = PopupContainerWithArrow

                    .showForIcon((BubbleTextView) child);

                             ...

}

 

页指示器修改

 

  1. 配置

Path: values/dimens.xml

    <dimen name="dynamic_grid_page_indicator_line_height">5dp</dimen>指示器高度

    <dimen name="dynamic_grid_page_indicator_line_width">70dp</dimen>指示器宽度(新增)

    <dimen name="dynamic_grid_page_indicator_line_space">16dp</dimen>指示器间隔(新增)

 

  1. Path: com.android.launcher3.pageindicators.WorkspacePageIndicator#onDraw

在onDraw中修改绘图

 

  1. 修改为不自动隐藏

Path:com.android.launcher3.pageindicators.WorkspacePageIndicator#setScroll

if (!FeatureFlags.CUSTOM_REMOVE) {

            animateLineToAlpha(mActiveAlpha);

}

 

修改Workspace长按弹出墙纸设置

Path: com.android.launcher3.touch.WorkspaceTouchListener#run

 @Override

    public void run() {

        if (mLongPressState == STATE_REQUESTED) {

            if (canHandleLongPress()) {

                mLongPressState = STATE_PENDING_PARENT_INFORM;

                mWorkspace.getParent().requestDisallowInterceptTouchEvent(true);

 

                mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,

                        HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);

                mLauncher.getUserEventDispatcher().logActionOnContainer(Action.Touch.LONGPRESS,

                        Action.Direction.NONE, ContainerType.WORKSPACE,

                        mWorkspace.getCurrentPage());

                if(FeatureFlags.CUSTOM_REMOVE){

                    OptionsPopupView.startWallpaperPicker(mLauncher.getRootView());

                }else {

                    OptionsPopupView.showDefaultOptions(mLauncher, mTouchDownPoint.x, mTouchDownPoint.y);

                }

            } else {

                cancelLongPress();

            }

        }

}

 

去掉首页搜索框和allapps按键

Path:com.android.launcher3.config.BaseFlags

 

    // Feature flag to enable moving the QSB on the 0th screen of the workspace.

    public static final boolean QSB_ON_FIRST_SCREEN = false;

    // When enabled the all-apps icon is not added to the hotseat.

public static final boolean NO_ALL_APPS_ICON = true;

 

 

修改AllApps背景透明

  1. Path:com.android.launcher3.views.ScrimView#ScrimView

public ScrimView(Context context, AttributeSet attrs) {

        super(context, attrs);

                         ...

        //全透明

        mMaxScrimAlpha = 0;//0.7f;

...

}

 

  1. Path: values/styles.xml

对应主题下的allAppsScrimColor

 <item name="allAppsScrimColor">#00000000</item>