android 8.1launcher去掉抽屉,显示allapp

OS:MTK 8.1

需求:所有应用在workspaces上展示

1.首先添加一个标志位
  • packages/apps/Launcher3/src/com/android/launcher3/config/BaseFlags.java
  // Feature to control launcher drawer
  public static final boolean REMOVE_DRAWER = true;
2.所有应用在workspaces上展示

2.1 加载所有安装应用到workspace

  • packages/apps/Launcher3/src/com/android/launcher3/model/LoaderTask.java
 // second step
 if (DEBUG_LOADERS) Log.d(TAG, "step 2.1: loading all apps");
 loadAllApps();
 // add 
 if (FeatureFlags.REMOVE_DRAWER && (mBgAllAppsList.data.size() > 0)) {
     ArrayList<AppInfo> appInfos = new ArrayList<AppInfo>(mBgAllAppsList.data);
     mApp.getModel().addAndBindAddedWorkspaceItems(new LzyProvider(appInfos));
 }
 // end
 if (DEBUG_LOADERS) Log.d(TAG, "step 2.2: Binding all apps");
	
  // 添加自定义Provider  参考InstallShortcutReceiver中provider写法
  // add
  private static class LzyProvider extends Provider<List<Pair<ItemInfo, Object>>> {

     private  ArrayList<AppInfo> mItems;
     public LzyProvider(ArrayList<AppInfo> items) {
            mItems = items;
     }

     @Override
     public ArrayList<Pair<ItemInfo, Object>> get() {
       ArrayList<Pair<ItemInfo, Object>> installQueue = new ArrayList<>();
       for (AppInfo info : mItems ) {
            ShortcutInfo si = info.makeShortcut();
            installQueue.add(Pair.create((ItemInfo) si, null));
       }
       return installQueue;
     }
  }
  // end

2.2 有app变化时,更新workspace

  • packages/apps/Launcher3/src/com/android/launcher3/model/PackageUpdatedTask.java
 final ArrayList<AppInfo> addedOrModified = new ArrayList<>();
      	 addedOrModified.addAll(appsList.added);
         appsList.added.clear();
         addedOrModified.addAll(appsList.modified);
         appsList.modified.clear();
         // add  在此处按照LoaderTask.java中添加
         
  • packages/apps/Launcher3/src/com/android/launcher3/model/BaseModelUpdateTask.java
 @Override
 public final void run() {
   if (!mModel.isModelLoaded()) {
       if (DEBUG_TASKS) {
           Log.d(TAG, "Ignoring model task since loader is pending=" + this);
       }
       // Loader has not yet run.
       // add
       if (!FeatureFlags.REMOVE_DRAWER) {
           return;
       }
       // end
   }
   execute(mApp, mDataModel, mAllAppsList);
 }
3.去掉qsb
  • packages/apps/Launcher3/src/com/android/launcher3/Workspace.java
 注释掉下面这段代码
 if(!FeatureFlags.REMOVE_DRAWER){
 	// Always add a QSB on the first screen.
 	if (qsb == null) {
 	 	// In transposed layout, we add the QSB in the Grid. As workspace does not touch the
     	// edges, we do not need a full width QSB.
     	qsb = LayoutInflater.from(getContext())
                  .inflate(R.layout.search_container_workspace,firstPage, false);
  	}

  	CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstPage.getCountX(), 1);
  	lp.canReorder = false;
  	if (!firstPage.addViewToCellLayout(qsb, 0, R.id.search_container_workspace, lp, true)) {
      	Log.e(TAG, "Failed to add to item at (0, 0) to CellLayout");
  	}
 }
4.去掉hotseat
  • packages/apps/Launcher3/src/com/android/launcher3/DeviceProfile.java
  // add
  if (FeatureFlags.REMOVE_DRAWER) {
      lp.height = 0;
  }
  // end
  hotseat.setLayoutParams(lp);
5.隐藏allapps button
  • packages/apps/Launcher3/src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java
 @Override
 protected void onFinishInflate() {
   super.onFinishInflate();
   mAllAppsHandle = (ImageView) findViewById(R.id.all_apps_handle);
   mAllAppsHandle.setVisibility(View.GONE);     //  add for hide allapp button
   ...
 }
6.去掉滑动显示allapp

隐藏了allapp按钮,此时在屏幕上滑还是可以展示allapp

  • packages/apps/Launcher3/src/com/android/launcher3/allapps/AllAppsTransitionController.java
 @Override
 public boolean onDrag(float displacement, float velocity) {
   if (mAppsView == null) {
       return false;   // early termination.
   }
   // add by
   if (FeatureFlags.REMOVE_DRAWER) {
       return false;
   }
   // end 
   mContainerVelocity = velocity;

   float shift = Math.min(Math.max(0, mShiftStart + displacement), mShiftRange);
   setProgress(shift / mShiftRange); // 滑动时设置allapp从底部显示一点
 }

 @Override
 public void onDragEnd(float velocity, boolean fling) {
   if (mAppsView == null) {
       return; // early termination.
   }
   // add  
   if (FeatureFlags.REMOVE_DRAWER) {
       return;
   }
   // end
   final int containerType = mTouchEventStartedOnHotseat
                 ? ContainerType.HOTSEAT : ContainerType.WORKSPACE;

   if (fling) {
       ...
       mLauncher.showAppsView(true /* animated */, false /* updatePredictedApps */);
       ...
   }
 }

手指在屏幕移动,onDrag方法会先设置allapp显示出来一点,在onDragEnd方法中判断if(fling)是滑动,就会调用showAppsView()方法,和点击allapp走一样的流程

7.所有应用在workspace第一页中显示

修改之后看效果,发现应用icon都是在第二页中显示,除了默认的几个icon在第一页

  • packages/apps/Launcher3/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
  int screenCount = workspaceScreens.size();
  // First check the preferred screen.     
  // add by 
  // int preferredScreenIndex = workspaceScreens.isEmpty() ? 0 : 1;   
  int preferredScreenIndex = 0;
  //end
  if (preferredScreenIndex < screenCount) {
8.hotseat中应用的icon不能被添加到workspace

所有应用可以再第一页显示,但是发现少了几个应用的icon,开始没注意到是hotseat中的几个应用,后面抓log发现,loadworkspace时会做判断,dw_phone_hotseat.xml中标记-101,不会添加,具体代码在 LoadCursor中
注释掉dw_phone_hotseat.xml中的代码

9.修改workspace行列
  • packages/apps/Launcher3/src/com/android/launcher3/InvariantDeviceProfile.java
 // add
  //numRows = closestProfile.numRows;
  //numColumns = closestProfile.numColumns;
  numRows = 4;
  numColumns = 3;
 // end
10.onResume状态时,HotSeat和这个箭头会一起做一个向上跳动的动画
  • packages/apps/Launcher3/src/com/android/launcher3/Launcher.java
	...
 if (shouldShowDiscoveryBounce()) {
	//注释 begin
	// mAllAppsController.showDiscoveryBounce();
	//注释 end
 }
 if (mLauncherCallbacks != null) {
     mLauncherCallbacks.onResume();
 }
       ...

参考博文:Android8.1 Launcher3 去掉抽屉

你可能感兴趣的:(系统修改)