当前位置: 首页 > article >正文

Android13 Launcher3 定制

去掉Google搜索栏

aosp/packages/apps/Launcher3/src_build_config/com/android/launcher3/BuildConfig.java

修改QSB_ON_FIRST_SCREEN为false

    public static final boolean QSB_ON_FIRST_SCREEN = false;

去掉抽屉菜单,所有应用都放到桌面

增加控制变量

aosp/packages/apps/Launcher3/src_build_config/com/android/launcher3/BuildConfig.java

增加

  public static final boolean REMOVE_DRAWER = true;

aosp/packages/apps/Launcher3/src/com/android/launcher3/config/FeatureFlags.java

增加

public static final boolean REMOVE_DRAWER =  BuildConfig.REMOVE_DRAWER;

禁用上滑打开抽屉应用菜单

aosp/packages/apps/Launcher3/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/PortraitStatesTouchController.java


 @Override
    protected boolean canInterceptTouch(MotionEvent ev) {
        if(FeatureFlags.REMOVE_DRAWER){
            return false;
        }
 		....
    }

加载所有应用

aosp/packages/apps/Launcher3/src/com/android/launcher3/model/LoaderTask.java

  public void run() {
  	...
		Trace.beginSection("LoadAllApps");
     List<LauncherActivityInfo> allActivityList;
     try {
        allActivityList = loadAllApps();
     } finally {
         Trace.endSection();
     }
     logASplit(logger, "loadAllApps");

		// 增加
     if (FeatureFlags.REMOVE_DRAWER){
         getAllApplications();
     }

     verifyNotStopped();
     mResults.bindAllApps();
     logASplit(logger, "bindAllApps");
     ...
  }

	private void getAllApplications() {
      Log.d(TAG,"getAllApplications");
      final Context context =mApp.getContext();
      ArrayList<Pair<ItemInfo,Object>> installQueue = new ArrayList<>();
      final List<UserHandle> profiles =mUserManager.getUserProfiles();
      for (UserHandle user : profiles) {
          final List<LauncherActivityInfo> apps = mLauncherApps.getActivityList(null,user);
          ArrayList<ItemInstallQueue.PendingInstallShortcutInfo>added = new ArrayList<ItemInstallQueue.PendingInstallShortcutInfo>();
          synchronized (this) {
              for (LauncherActivityInfo app :apps) {
//                    if(app.getComponentName().getPackageName().equals("com.android.stk")||app.getComponentName().getPackageName().equals("com.android.fmradio")){
//                        continue;
//                    }
                  Log.d(TAG,"getAllApplications packageName: " + app.getComponentName().getPackageName());
                  ItemInstallQueue.PendingInstallShortcutInfo pendingInstallShortcutInfo
                          = new ItemInstallQueue.PendingInstallShortcutInfo(app.getActivityInfo().packageName, user);
                  added.add(pendingInstallShortcutInfo);
                  installQueue.add(pendingInstallShortcutInfo.getItemInfo(context));
              }
          }
          if (!added.isEmpty()) {
              mApp.getModel().addAndBindAddedWorkspaceItems(installQueue);
          }
      }
  }
    

aosp/packages/apps/Launcher3/src/com/android/launcher3/model/ItemInstallQueue.java

// 修改private为public
 public static class PendingInstallShortcutInfo extends ItemInfo {}

安装的app添加到workspace工作区

aosp/packages/apps/Launcher3/src/com/android/launcher3/model/PackageUpdatedTask.java

 @Override
    public void execute(@NonNull final LauncherAppState app, @NonNull final BgDataModel dataModel,
            @NonNull final AllAppsList appsList) {
      ...
  		bindApplicationsIfNeeded();
  			
				// 增加
        if(FeatureFlags.REMOVE_DRAWER){
            updateToWorkSpace(context, app,appsList);
        }

        final IntSet removedShortcuts = new IntSet();
        // Shortcuts to keep even if the corresponding app was removed
        final IntSet forceKeepShortcuts = new IntSet();
        ...
		}

		//安装的app添加到workspace工作区
    public void updateToWorkSpace(Context context, LauncherAppState app, AllAppsList appsList){
        Log.d(TAG,"updateToWorkSpace");
        ArrayList<Pair<ItemInfo,Object>> installQueue = new ArrayList<>();
        UserManager mUserManager = app.getContext().getSystemService(UserManager.class);
        final List<UserHandle> profiles = mUserManager.getUserProfiles();
        ArrayList<ItemInstallQueue.PendingInstallShortcutInfo> added = new ArrayList<>();
        LauncherApps mLauncherApps = app.getContext().getSystemService(LauncherApps.class);
        for(UserHandle user : profiles){
            final List<LauncherActivityInfo> apps = mLauncherApps.getActivityList(null,user);
                   synchronized (this){
                        for(LauncherActivityInfo info :apps){
                            for(AppInfo appInfo : appsList.data){
                                String packageName = info.getComponentName().getPackageName();
                                if(info.getComponentName().equals(appInfo.componentName)){
                                   if(DEBUG){
                                       Log.d(TAG,"updateToWorkSpace packageName: " + packageName);
                                   }
                                    ItemInstallQueue.PendingInstallShortcutInfo mPendingInstallShortcutInfo
                                                    = new ItemInstallQueue.PendingInstallShortcutInfo(packageName,user);
                                    added.add(mPendingInstallShortcutInfo);
                                    installQueue.add(mPendingInstallShortcutInfo.getItemInfo(context));
                                }
                            }
                        }
                   }
        }
        if(!added.isEmpty()){
            app.getModel().addAndBindAddedWorkspaceItems(installQueue);
        }
    }

打开限制

清除数据重新加载还能加载图标
aosp/packages/apps/Launcher3/src/com/android/launcher3/model/AddWorkspaceItemsTask.java

public void execute(@NonNull final LauncherAppState app, @NonNull final BgDataModel dataModel,
            @NonNull final AllAppsList apps) {
...
   // b/139663018 Short-circuit this logic if the icon is a system app
   if (PackageManagerHelper.isSystemApp(app.getContext(),
           Objects.requireNonNull(item.getIntent()))) {
       if (TestProtocol.sDebugTracing) {
           Log.d(TestProtocol.MISSING_PROMISE_ICON,
                   LOG + " Item is a system app.");
       }
       if(!FeatureFlags.REMOVE_DRAWER){
           continue;
       }
   }
...
}

这里不做修改的话如果清除所有数据,那么图标就不会加载
aosp/packages/apps/Launcher3/src/com/android/launcher3/model/BaseModelUpdateTask.java

  @Override
    public final void run() {
        if (!Objects.requireNonNull(mModel).isModelLoaded()) {
            if (DEBUG_TASKS) {
                Log.d(TAG, "Ignoring model task since loader is pending=" + this);
            }
            // Loader has not yet run.
            if(!FeatureFlags.REMOVE_DRAWER) {
               return;
            }
        }
        execute(mApp, mDataModel, mAllAppsList);
    }

顶部菜单移除remove换成取消cancel,无法移除

remove变成cancel

aosp/packages/apps/Launcher3/src/com/android/launcher3/DeleteDropTarget.java

 private boolean canRemove(ItemInfo item) {
        // 增加
        if(FeatureFlags.REMOVE_DRAWER) {
            return false ;
        }
        return item.id != ItemInfo.NO_ID;
    }

无法删除图标

aosp/packages/apps/Launcher3/src/com/android/launcher3/dragndrop/DragController.java

protected void drop(DropTarget dropTarget, Runnable flingAnimation) {
...
 // Drop onto the target.
 boolean accepted = false;
  if (dropTarget != null) {
      dropTarget.onDragExit(mDragObject);
      if (dropTarget.acceptDrop(mDragObject)) {
          if (flingAnimation != null) {
              flingAnimation.run();
          } else {
              dropTarget.onDrop(mDragObject, mOptions);
          }
          accepted = true;    
				 
				 // 增加
          if (FeatureFlags.REMOVE_DRAWER && dropTarget instanceof DeleteDropTarget
             && isNeedCancelDrag(mDragObject.dragInfo)
          ) {
              cancelDrag();
          }
      }
  }

  final View dropTargetAsView = dropTarget instanceof View ? (View) dropTarget : null;
  dispatchDropComplete(dropTargetAsView, accepted);
}

private boolean isNeedCancelDrag(ItemInfo item){
	return (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
	    item.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER);
}

Android 13.0 桌面改成单层桌面的代码记录
launcher3去掉抽屉菜单,所有用都放到桌面,无法拖拽删除图标,去除hotseat
Android11去除抽屉模式


http://www.kler.cn/a/133472.html

相关文章:

  • Exploring Defeasible Reasoning in Large Language Models: A Chain-of-Thought A
  • AutoHotKey自动热键AHK-正则表达式
  • HarmonyOS NEXT应用开发实战 ( 应用的签名、打包上架,各种证书详解)
  • sealos部署K8s,安装docker时master节点突然NotReady
  • 408笔记合集
  • web安全测试渗透案例知识点总结(上)——小白入狱
  • 怎样备份电脑文件比较安全
  • “腾易视连”构建汽车生态新格局 星选计划赋能创作者价值提升
  • Windows安装Java环境(OracleJDK)
  • 【Feign】 基于 Feign 远程调用、 自定义配置、性能优化、实现 Feign 最佳实践
  • 基于鼠群算法优化概率神经网络PNN的分类预测 - 附代码
  • 量化交易:借助talib使用技术分析指标
  • 如何构建风险矩阵?3大注意事项
  • 【小沐学GIS】电子海图OpenCPN源代码编译和运行(VS2017 + Win10)
  • VScode 配置用户片段
  • 基于libcurl+libopenssl开源库编译出curl下载工具及代码集成curl功能
  • Linux QT交叉编译环境安装
  • Vite 启动默认只能访问localhost解决方法
  • 基于枚举实现的桥接模式
  • 物联网赋能:WIFI HaLow在无线连接中的优势
  • java 实现串口通讯
  • 将word中的表格无变形的弄进excel中
  • 论文阅读:JINA EMBEDDINGS: A Novel Set of High-Performance Sentence Embedding Models
  • 开发一款小程序游戏需要多少钱?
  • 【uniapp/uview1.x】u-upload 在 v-for 中的使用时, before-upload 如何传参
  • Redis7.2.3集群安装,新增节点,删除节点,分配哈希槽,常见问题