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 去掉抽屜

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章