android Launcher3定制

本文基于高通SC200E 2290和展锐T606平台对于原生Launcher3进行UI和功能的定制。

1. 去掉桌面首页的搜索框

Index: packages/apps/Launcher3/src_build_config/com/android/launcher3/BuildConfig.java
===================================================================
--- packages/apps/Launcher3/src_build_config/com/android/launcher3/BuildConfig.java	(版本 177)
+++ packages/apps/Launcher3/src_build_config/com/android/launcher3/BuildConfig.java	(工作副本)
@@ -23,5 +23,5 @@
      * Flag to state if the QSB is on the first screen and placed on the top,
      * this can be overwritten in other launchers with a different value, if needed.
      */
-    public static final boolean QSB_ON_FIRST_SCREEN = true;
+    public static final boolean QSB_ON_FIRST_SCREEN = false;
 }

2. 添加功能宏控制

Index: vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/config/FeatureFlags.java
===================================================================
--- vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/config/FeatureFlags.java	(版本 196)
+++ vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/config/FeatureFlags.java	(工作副本)
@@ -71,6 +71,8 @@
     @Deprecated
     public static final boolean QSB_ON_FIRST_SCREEN = BuildConfig.QSB_ON_FIRST_SCREEN;
 
+    public static final boolean REMOVE_DRAWER = BuildConfig.REMOVE_DRAWER; // @ +
+
     /**
      * Feature flag to handle define config changes dynamically instead of killing the process.
      * <p>
Index: vendor/mediatek/proprietary/packages/apps/Launcher3/src_build_config/com/android/launcher3/BuildConfig.java
===================================================================
--- vendor/mediatek/proprietary/packages/apps/Launcher3/src_build_config/com/android/launcher3/BuildConfig.java	(版本 196)
+++ vendor/mediatek/proprietary/packages/apps/Launcher3/src_build_config/com/android/launcher3/BuildConfig.java	(工作副本)
@@ -30,4 +30,7 @@
      * Flag to control various developer centric features
      */
     public static final boolean IS_DEBUG_DEVICE = false;
+
+    // When enabled, remove drawer type
+    public static final boolean REMOVE_DRAWER = true; // @ +
 }

3. 取消上划显示AllApp动作

Index: packages/apps/Launcher3/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/PortraitStatesTouchController.java
===================================================================
--- packages/apps/Launcher3/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/PortraitStatesTouchController.java	(版本 177)
+++ packages/apps/Launcher3/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/PortraitStatesTouchController.java	(工作副本)
@@ -42,6 +42,7 @@
 import com.android.launcher3.LauncherState;
 import com.android.launcher3.allapps.AllAppsTransitionController;
 import com.android.launcher3.anim.Interpolators;
+import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.states.StateAnimationConfig;
 import com.android.launcher3.touch.AbstractStateChangeTouchController;
 import com.android.launcher3.touch.SingleAxisSwipeDetector;
@@ -114,6 +115,7 @@
 
     @Override
     protected boolean canInterceptTouch(MotionEvent ev) {
   
+    	if (FeatureFlags.REMOVE_DRAWER) return false;
         // If we are swiping to all apps instead of overview, allow it from anywhere.
         boolean interceptAnywhere = mLauncher.isInState(NORMAL);
         if (mCurrentAnimation != null) {
   

4. 桌面显示所有app(安装也显示)

4.1 方案一

Index: packages/apps/Launcher3/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
===================================================================
--- packages/apps/Launcher3/src/com/android/launcher3/model/AddWorkspaceItemsTask.java	(版本 177)
+++ packages/apps/Launcher3/src/com/android/launcher3/model/AddWorkspaceItemsTask.java	(工作副本)
@@ -30,6 +30,7 @@
 import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.LauncherModel.CallbackTask;
 import com.android.launcher3.LauncherSettings;
+import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.logging.FileLog;
 import com.android.launcher3.model.BgDataModel.Callbacks;
 import com.android.launcher3.model.data.AppInfo;
@@ -114,15 +115,17 @@
                         continue;
                     }
 
-                    // b/139663018 Short-circuit this logic if the icon is a system app
-                    if (!MultiModeController.isSingleLayerMode(app.getContext())
-                            && PackageManagerHelper.isSystemApp(app.getContext(), item.getIntent())) {
   
-                        if (TestProtocol.sDebugTracing) {
   
-                            Log.d(TestProtocol.MISSING_PROMISE_ICON,
-                                    LOG + " Item is a system app.");
-                        }
-                        continue;
-                    }
+                    if (!FeatureFlags.REMOVE_DRAWER){
   
+	                    // b/139663018 Short-circuit this logic if the icon is a system app
+	                    if (!MultiModeController.isSingleLayerMode(app.getContext())
+	                            && PackageManagerHelper.isSystemApp(app.getContext(), item.getIntent())) {
   
+	                        if (TestProtocol.sDebugTracing) {
   
+	                            Log.d(TestProtocol.MISSING_PROMISE_ICON,
+	                                    LOG + " Item is a system app.");
+	                        }
+	                        continue;
+	                    }
+					}
                 }
 
                 if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
   
Index: packages/apps/Launcher3/src/com/android/launcher3/model/BaseModelUpdateTask.java
===================================================================
--- packages/apps/Launcher3/src/com/android/launcher3/model/BaseModelUpdateTask.java	(版本 177)
+++ packages/apps/Launcher3/src/com/android/launcher3/model/BaseModelUpdateTask.java	(工作副本)
@@ -23,6 +23,7 @@
 import com.android.launcher3.LauncherModel;
 import com.android.launcher3.LauncherModel.CallbackTask;
 import com.android.launcher3.LauncherModel.ModelUpdateTask;
+import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.model.BgDataModel.Callbacks;
 import com.android.launcher3.model.BgDataModel.FixedContainerItems;
 import com.android.launcher3.model.data.AppInfo;
@@ -75,7 +76,9 @@
                 Log.d(TAG, "Ignoring model task since loader is pending=" + this);
             }
             // Loader has not yet run.
-            return;
+            if(!FeatureFlags.REMOVE_DRAWER){
   
+            	return;
+			}
         }
         execute(mApp, mDataModel, mAllAppsList);
     }

Index: packages/apps/Launcher3/src/com/android/launcher3/model/LoaderTask.java
===================================================================
--- packages/apps/Launcher3/src/com/android/launcher3/model/LoaderTask.java	(版本 177)
+++ packages/apps/Launcher3/src/com/android/launcher3/model/LoaderTask.java	(工作副本)
@@ -50,6 +50,7 @@
 import android.util.ArrayMap;
 import android.util.Log;
 import android.util.LongSparseArray;
+import android.util.Pair;
 import android.util.TimingLogger;
 
 import androidx.annotation.Nullable;
@@ -261,6 +262,10 @@
             }
             logASplit(logger, "loadAllApps");
 
+			if (FeatureFlags.REMOVE_DRAWER) {
   
+                verifyApplications();
+            }
+
             verifyNotStopped();
             mResults.bindAllApps();
             logASplit(logger, "bindAllApps");
@@ -344,6 +349,28 @@
         TraceHelper.INSTANCE.endSection(traceToken);
     }
 
+    private void verifyApplications() {
   
+        final Context context = mApp.getContext();
+        final List<UserHandle> profiles = mUserManager.getUserProfiles();
+		ArrayList<Pair<ItemInfo, Object>> installQueue = new ArrayList<>();
+        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) {
   
+                    ItemInstallQueue.PendingInstallShortcutInfo pendingInstallShortcutInfo = new ItemInstallQueue.PendingInstallShortcutInfo(app.getComponentName().getPackageName(), app.getUser());
+                    added.add(pendingInstallShortcutInfo);
+					installQueue.add(pendingInstallShortcutInfo.getItemInfo(context));
+                }
+            }
+            if (!added.isEmpty()) {
   
+                mApp.getModel().addAndBindAddedWorkspaceItems(installQueue);
+            }
+        }
+    }
+
     public synchronized void stopLocked() {
   
         mStopped = true;
         this.notify();

Index: packages/apps/Launcher3/src/com/android/launcher3/model/PackageUpdatedTask.java
===================================================================
--- packages/apps/Launcher3/src/com/android/launcher3/model/PackageUpdatedTask.java	(版本 177)
+++ packages/apps/Launcher3/src/com/android/launcher3/model/PackageUpdatedTask.java	(工作副本)
@@ -28,6 +28,7 @@
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.util.Log;
+import android.util.Pair;
 
 import com.android.launcher3.Launcher;
 import com.android.launcher3.LauncherAppState;
@@ -38,6 +39,7 @@
 import com.android.launcher3.icons.IconCache;
 import com.android.launcher3.icons.LauncherIcons;
 import com.android.launcher3.logging.FileLog;
+import com.android.launcher3.model.data.AppInfo;
 import com.android.launcher3.model.data.ItemInfo;
 import com.android.launcher3.model.data.LauncherAppWidgetInfo;
 import com.android.launcher3.model.data.WorkspaceItemInfo;
@@ -373,10 +375,43 @@
             bindUpdatedWidgets(dataModel);
         }
 
+		if(FeatureFlags.REMOVE_DRAWER){
   
+            updateToWorkSpace(context, app, appsList);
+		}
+
         // Do this in UI thread to make sure all Task has done before.
         scheduleCallbackTask(callbacks -> LauncherAppMonitor.getInstance(context).onPackagesUpdated(packages, mUser, mOp));
     }
 
+    public void updateToWorkSpace(Context context, LauncherAppState app , AllAppsList appsList) {
   
+        ArrayList<Pair<ItemInfo, Object>> installQueue = new ArrayList<>();
+		UserManager mUserManager = context.getSystemService(UserManager.class);
+		LauncherApps launcherApps = context.getSystemService(LauncherApps.class);
+		final List<UserHandle> profiles = mUserManager.getUserProfiles();
+		ArrayList<ItemInstallQueue.PendingInstallShortcutInfo> added = new ArrayList<ItemInstallQueue.PendingInstallShortcutInfo>();
+        
+        for (UserHandle user : profiles) {
   
+            final List<LauncherActivityInfo> apps = launcherApps.getActivityList(null, user);
+            synchronized (this) {
   
+                for (LauncherActivityInfo info : apps) {
   
+                    for (AppInfo appInfo : appsList.data) {
   
+                        if(info.getComponentName().equals(appInfo.componentName)){
   
+                            ItemInstallQueue.PendingInstallShortcutInfo mPendingInstallShortcutInfo 
+                                    =  new ItemInstallQueue.PendingInstallShortcutInfo(info.getComponentName().getPackageName(), info.getUser());
+                            added.add(mPendingInstallShortcutInfo);
+							installQueue.add(mPendingInstallShortcutInfo.getItemInfo(context));
+                        }
+                    }
+                }
+            }
+        }
+        if (!added.isEmpty()) {
   
+            app.getModel().addAndBindAddedWorkspaceItems(installQueue);
+        }
+    }
+
     /**
      * Updates {@param si}'s intent to point to a new ComponentName.
      * @return Whether the shortcut intent was changed.

4.2 方案二(MTK平台)

4.2.1 不包含install安装的应用

Index: vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/LauncherModel.java
===================================================================
--- vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/LauncherModel.java	(版本 196)
+++ vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/LauncherModel.java	(工作副本)
@@ -45,6 +45,7 @@
 import com.android.launcher3.icons.IconCache;
 import com.android.launcher3.logging.FileLog;
 import com.android.launcher3.model.AddWorkspaceItemsTask;
+import com.android.launcher3.model.AllAppOnWorkspaceItem;
 import com.android.launcher3.model.AllAppsList;
 import com.android.launcher3.model.BaseModelUpdateTask;
 import com.android.launcher3.model.BgDataModel;
@@ -446,6 +447,9 @@
                     // Always post the loader task, instead of running directly
                     // (even on same thread) so that we exit any nested synchronized blocks
                     MODEL_EXECUTOR.post(mLoaderTask);
+                    if (FeatureFlags.REMOVE_DRAWER) {
    // @ +
+                        enqueueModelUpdateTask(new AllAppOnWorkspaceItem());
+                    }
                 }
             }
         }
Index: vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
===================================================================
--- vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/model/AddWorkspaceItemsTask.java	(版本 196)
+++ vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/model/AddWorkspaceItemsTask.java	(工作副本)
@@ -28,6 +28,7 @@
 import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.LauncherModel.CallbackTask;
 import com.android.launcher3.LauncherSettings;
+import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.logging.FileLog;
 import com.android.launcher3.model.BgDataModel.Callbacks;
 import com.android.launcher3.model.data.AppInfo;
@@ -98,10 +99,12 @@
                         continue;
                     }
 
-                    // b/139663018 Short-circuit this logic if the icon is a system app
-                    if (PackageManagerHelper.isSystemApp(app.getContext(),
-                            Objects.requireNonNull(item.getIntent()))) {
   
-                        continue;
+                    if (!FeatureFlags.REMOVE_DRAWER){
    // @ +
+                        // b/139663018 Short-circuit this logic if the icon is a system app
+                        if (PackageManagerHelper.isSystemApp(app.getContext(),
+                                Objects.requireNonNull(item.getIntent()))) {
   
+                            continue;
+                        }
                     }
                 }
 
Index: vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/model/AllAppOnWorkspaceItem.java
===================================================================
--- vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/model/AllAppOnWorkspaceItem.java	(不存在的)
+++ vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/model/AllAppOnWorkspaceItem.java	(工作副本)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.model;
+
+import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_ENABLED;
+import static com.android.launcher3.model.data.WorkspaceItemInfo.FLAG_AUTOINSTALL_ICON;
+import static com.android.launcher3.model.data.WorkspaceItemInfo.FLAG_RESTORED_ICON;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.LauncherApps;
+import android.content.pm.ShortcutInfo;
+import android.content.pm.LauncherActivityInfo;
+import android.os.Process;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值