Android P Launcher3显示所有APP到桌面

diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 61bee71fb..e948cd734 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -51,6 +51,7 @@
     <!--@ {bird: For fix bug#37449, add by shicuiliang@szba-mobile.com 2018/5/10. -->
     <!-- ningzhiyu stk title issue 20160524 -->
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
     <!--@ } -->
     <application
         android:backupAgent="com.android.launcher3.LauncherBackupAgent"
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml
index 640aa0e2f..b20227108 100644
--- a/res/values-zh-rCN/strings.xml
+++ b/res/values-zh-rCN/strings.xml
@@ -144,4 +144,6 @@
     <string name="work_mode_off_label" msgid="3194894777601421047">"通知和应用均已关闭"</string>
     <string name="bottom_work_tab_user_education_close_button" msgid="4224492243977802135">"关闭"</string>
     <string name="bottom_work_tab_user_education_closed" msgid="1098340939861869465">"已关闭"</string>
+    <string name="is_full_app_title">布局切换</string>
+    <string name="is_full_app_desc">显示app在桌面</string>
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7bc11c3be..9aa172baf 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -344,4 +344,7 @@
     <string name="work_mode_off_label">Notifications and apps are off</string>
     <string name="bottom_work_tab_user_education_close_button">Close</string>
     <string name="bottom_work_tab_user_education_closed">Closed</string>
+    <string name="is_full_app_title">Layout switching</string>
+    <string name="is_full_app_desc">Show app on desktop</string>
+    <string name="full_app_override_progress">full app override progress</string>
 </resources>
diff --git a/res/xml/default_workspace_tb_5x6.xml b/res/xml/default_workspace_tb_5x6.xml
new file mode 100644
index 000000000..909e180af
--- /dev/null
+++ b/res/xml/default_workspace_tb_5x6.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+
+<favorites xmlns:launcher="http://schemas.android.com/apk/res-auto/com.android.launcher3">
+
+    <!-- Hotseat -->
+    <include launcher:workspace="@xml/dw_tablet_hotseat" />
+
+    <!-- Bottom row -->
+
+<!-- add by lihan for FTM on 20170805 Begin-->
+    <favorite
+        launcher:packageName="com.nbbsw.factory_test"
+        launcher:className="com.nbbsw.factory_test.FactoryTest"
+        launcher:screen="0"
+        launcher:x="2"
+        launcher:y="2" />  
+    <favorite
+        launcher:packageName="com.nbbsw.factory_test"
+        launcher:className="com.nbbsw.factory_test.FactoryTest"
+        launcher:screen="1"
+        launcher:x="2"
+        launcher:y="2" />  
+<!-- add by lihan for FTM on 20170805 End-->
+
+
+    <favorite
+        launcher:screen="0"
+        launcher:x="0"
+        launcher:y="-1"
+        launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_CONTACTS;end" />
+
+    <resolve
+        launcher:screen="0"
+        launcher:x="-1"
+        launcher:y="-1" >
+        <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_MARKET;end" />
+        <favorite launcher:uri="market://details?id=com.android.launcher" />
+    </resolve>
+
+</favorites>
diff --git a/res/xml/default_workspace_tb_5x6_no_all_app.xml b/res/xml/default_workspace_tb_5x6_no_all_app.xml
new file mode 100644
index 000000000..909e180af
--- /dev/null
+++ b/res/xml/default_workspace_tb_5x6_no_all_app.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 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.
+-->
+
+<favorites xmlns:launcher="http://schemas.android.com/apk/res-auto/com.android.launcher3">
+
+    <!-- Hotseat -->
+    <include launcher:workspace="@xml/dw_tablet_hotseat" />
+
+    <!-- Bottom row -->
+
+<!-- add by lihan for FTM on 20170805 Begin-->
+    <favorite
+        launcher:packageName="com.nbbsw.factory_test"
+        launcher:className="com.nbbsw.factory_test.FactoryTest"
+        launcher:screen="0"
+        launcher:x="2"
+        launcher:y="2" />  
+    <favorite
+        launcher:packageName="com.nbbsw.factory_test"
+        launcher:className="com.nbbsw.factory_test.FactoryTest"
+        launcher:screen="1"
+        launcher:x="2"
+        launcher:y="2" />  
+<!-- add by lihan for FTM on 20170805 End-->
+
+
+    <favorite
+        launcher:screen="0"
+        launcher:x="0"
+        launcher:y="-1"
+        launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_CONTACTS;end" />
+
+    <resolve
+        launcher:screen="0"
+        launcher:x="-1"
+        launcher:y="-1" >
+        <favorite launcher:uri="#Intent;action=android.intent.action.MAIN;category=android.intent.category.APP_MARKET;end" />
+        <favorite launcher:uri="market://details?id=com.android.launcher" />
+    </resolve>
+
+</favorites>
diff --git a/res/xml/device_profiles.xml b/res/xml/device_profiles.xml
index a34f22515..1cc695fbb 100644
--- a/res/xml/device_profiles.xml
+++ b/res/xml/device_profiles.xml
@@ -170,5 +170,33 @@
         launcher:numHotseatIcons="7"
         launcher:defaultLayoutId="@xml/default_workspace_5x6"
         />
+    <profile
+        launcher:name="Tablet"
+        launcher:minWidthDps="376"
+        launcher:minHeightDps="586"
+        launcher:numRows="4"
+        launcher:numColumns="5"
+        launcher:numFolderRows="4"
+        launcher:numFolderColumns="5"
+        launcher:iconSize="50"
+        launcher:iconTextSize="11"
+        launcher:numHotseatIcons="5"
+        launcher:defaultLayoutId="@xml/default_workspace_tb_5x6"
+        />
+
+    <profile
+        launcher:name="Tablet_no_all_app"
+        launcher:minWidthDps="380"
+        launcher:minHeightDps="590"
+        launcher:numRows="4"
+        launcher:numColumns="5"
+        launcher:numFolderRows="4"
+        launcher:numFolderColumns="5"
+        launcher:iconSize="50"
+        launcher:iconTextSize="11"
+        launcher:numHotseatIcons="4"
+        launcher:defaultLayoutId="@xml/default_workspace_tb_5x6_no_all_app"
+        />
+
 
 </profiles>
\ No newline at end of file
diff --git a/res/xml/launcher_preferences.xml b/res/xml/launcher_preferences.xml
index 3bba73a6c..b98296021 100644
--- a/res/xml/launcher_preferences.xml
+++ b/res/xml/launcher_preferences.xml
@@ -51,5 +51,11 @@
         android:entryValues="@array/icon_shape_override_paths_values"
         android:defaultValue=""
         android:persistent="false" />
+    <SwitchPreference
+        android:key="pref_is_full_app"
+        android:title="@string/is_full_app_title"
+        android:summary="@string/is_full_app_desc"
+        android:defaultValue="false"
+        android:persistent="true" />
 
 </PreferenceScreen>
diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java
index aecb136c9..04d6b90db 100644
--- a/src/com/android/launcher3/DeleteDropTarget.java
+++ b/src/com/android/launcher3/DeleteDropTarget.java
@@ -27,6 +27,7 @@ import com.android.launcher3.folder.Folder;
 import com.android.launcher3.logging.LoggerUtils;
 import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
 import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
+import com.android.launcher3.LauncherAppState;
 
 public class DeleteDropTarget extends ButtonDropTarget {
 
@@ -96,6 +97,12 @@ public class DeleteDropTarget extends ButtonDropTarget {
             mText = getResources().getString(item.id != ItemInfo.NO_ID
                     ? R.string.remove_drop_target_label
                     : android.R.string.cancel);
+            if (LauncherAppState.isDisableAllApps()) {
+                android.util.Log.e("Launcher3", "hide delete drop target");
+                mText = getResources().getString(isCanDrop(item)
+                        ? R.string.remove_drop_target_label
+                        : android.R.string.cancel);
+            }
             requestLayout();
         }
     }
@@ -106,6 +113,10 @@ public class DeleteDropTarget extends ButtonDropTarget {
     private void setControlTypeBasedOnDragSource(ItemInfo item) {
         mControlType = item.id != ItemInfo.NO_ID ? ControlType.REMOVE_TARGET
                 : ControlType.CANCEL_TARGET;
+        if (LauncherAppState.isDisableAllApps()) {
+            mControlType = isCanDrop(item) ? ControlType.REMOVE_TARGET
+                    : ControlType.CANCEL_TARGET;
+        }
     }
 
     @Override
@@ -124,12 +135,17 @@ public class DeleteDropTarget extends ButtonDropTarget {
         // Remove the item from launcher and the db, we can ignore the containerInfo in this call
         // because we already remove the drag view from the folder (if the drag originated from
         // a folder) in Folder.beginDrag()
-        mLauncher.removeItem(view, item, true /* deleteFromDb */);
-        mLauncher.getWorkspace().stripEmptyScreens();
-        mLauncher.getDragLayer()
-                .announceForAccessibility(getContext().getString(R.string.item_removed));
+        if (!LauncherAppState.isDisableAllApps() || isCanDrop(item)) {
+            mLauncher.removeItem(view, item, true /* deleteFromDb */);
+            mLauncher.getWorkspace().stripEmptyScreens();
+            mLauncher.getDragLayer()
+                    .announceForAccessibility(getContext().getString(R.string.item_removed));
+        }
+    }
+    private boolean isCanDrop(ItemInfo item){
+        return !(item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
+                item.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER);
     }
-
     @Override
     public Target getDropTargetForLogging() {
         Target t = LoggerUtils.newTarget(Target.Type.CONTROL);
diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java
index 42b4ac1f8..835402903 100644
--- a/src/com/android/launcher3/Hotseat.java
+++ b/src/com/android/launcher3/Hotseat.java
@@ -92,6 +92,11 @@ public class Hotseat extends FrameLayout implements LogContainerProvider, Insett
         } else {
             mContent.setGridSize(4/*idp.numHotseatIcons*/, 1);
         }
+        if (!LauncherAppState.isDisableAllApps()) {
+            // Add the Apps button
+            Context context = getContext();
+            DeviceProfile grid = mLauncher.getDeviceProfile();
+        }
 
         if (!FeatureFlags.NO_ALL_APPS_ICON) {
             // Add the Apps button
diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java
index fe8a841be..508a26a08 100644
--- a/src/com/android/launcher3/InstallShortcutReceiver.java
+++ b/src/com/android/launcher3/InstallShortcutReceiver.java
@@ -223,7 +223,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
     /**
      * Verifies the intent and creates a {@link PendingInstallShortcutInfo}
      */
-    private static PendingInstallShortcutInfo createPendingInfo(Context context, Intent data) {
+    public static PendingInstallShortcutInfo createPendingInfo(Context context, Intent data) {
         if (!isValidExtraType(data, Intent.EXTRA_SHORTCUT_INTENT, Intent.class) ||
                 !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                         Intent.ShortcutIconResource.class)) ||
@@ -323,7 +323,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
         return name;
     }
 
-    private static class PendingInstallShortcutInfo {
+    public static class PendingInstallShortcutInfo {
 
         final LauncherActivityInfo activityInfo;
         final ShortcutInfoCompat shortcutInfo;
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index f63cce58d..bc7e0c989 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -132,6 +132,12 @@ public class InvariantDeviceProfile {
         minWidthDps = Utilities.dpiFromPx(Math.min(smallestSize.x, smallestSize.y), dm);
         minHeightDps = Utilities.dpiFromPx(Math.min(largestSize.x, largestSize.y), dm);
 
+        if (LauncherAppState.isDisableAllApps()) {
+//            Log.e("Launcher3.profiles", "load no all app profiles");
+            //对应 device_profiles.xml 中 Tablet_no_all_app 的值
+            minWidthDps = 380.0f;
+            minHeightDps = 590.0f;
+        }
         ArrayList<InvariantDeviceProfile> closestProfiles = findClosestDeviceProfiles(
                 minWidthDps, minHeightDps, getPredefinedDeviceProfiles(context));
         InvariantDeviceProfile interpolatedDeviceProfileOut =
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index a46692b0b..020c9009e 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -35,6 +35,7 @@ import com.android.launcher3.util.SettingsObserver;
 
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
+import android.provider.Settings;
 
 import static com.android.launcher3.SettingsActivity.NOTIFICATION_BADGING;
 
@@ -51,6 +52,15 @@ public class LauncherAppState {
     private final WidgetPreviewLoader mWidgetCache;
     private final InvariantDeviceProfile mInvariantDeviceProfile;
     private final SettingsObserver mNotificationBadgingObserver;
+    private static Context context;
+    public static boolean isDisableAllApps() {
+        if (context != null) {
+            return Settings.System.getInt(context.getContentResolver(),
+                    "sys.launcher3.is_full_app", 0) == 1;
+        }
+        return true;
+    }
+
 
     public static LauncherAppState getInstance(final Context context) {
         if (INSTANCE == null) {
diff --git a/src/com/android/launcher3/SettingsActivity.java b/src/com/android/launcher3/SettingsActivity.java
index 32c198ab0..608fca50f 100644
--- a/src/com/android/launcher3/SettingsActivity.java
+++ b/src/com/android/launcher3/SettingsActivity.java
@@ -49,6 +49,13 @@ import com.android.launcher3.util.SettingsObserver;
 import com.android.launcher3.views.ButtonPreference;
 
 import java.util.Objects;
+import android.preference.SwitchPreference;
+import android.util.Log;
+import android.app.ProgressDialog;
+import com.android.launcher3.util.LooperExecutor;
+import android.app.PendingIntent;
+import android.os.SystemClock;
+import android.app.AlarmManager;
 
 /**
  * Settings activity for Launcher. Currently implements the following setting: Allow rotation
@@ -137,6 +144,37 @@ public class SettingsActivity extends Activity {
                 // Initialize the UI once
                 rotationPref.setDefaultValue(getAllowRotationDefaultValue());
             }
+            int isFull = Settings.System.getInt(getActivity().getContentResolver(),
+                    "sys.launcher3.is_full_app", 0);
+            SwitchPreference fullSwitch = (SwitchPreference) findPreference("pref_is_full_app");
+            fullSwitch.setChecked(isFull==1);
+        }
+
+        //add for change is_full_app value
+        @Override
+        public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+            boolean result = true;
+            final String key = preference.getKey();
+
+            if ("pref_is_full_app".equals(key)) {
+                boolean checked = ((SwitchPreference) preference).isChecked();
+
+                Settings.System.putInt(getActivity().getContentResolver(), "sys.launcher3.is_full_app",
+                        checked ? 1 : 0);
+
+                Log.e("Launcher3", "SwitchPreference checked=" + checked);
+
+                // Value has changed
+                ProgressDialog.show(getActivity(),
+                        null /* title */,
+                        getActivity().getString(R.string.full_app_override_progress),
+                        true /* indeterminate */,
+                        false /* cancelable */);
+                new LooperExecutor(LauncherModel.getWorkerLooper()).execute(
+                        new OverrideApplyHandler(getActivity()));
+
+            }
+            return result;
         }
 
         @Override
@@ -229,8 +267,7 @@ public class SettingsActivity extends Activity {
         private final ContentResolver mResolver;
         private final FragmentManager mFragmentManager;
 
-        public IconBadgingObserver(ButtonPreference badgingPref, ContentResolver resolver,
-                FragmentManager fragmentManager) {
+        public IconBadgingObserver(ButtonPreference badgingPref, ContentResolver resolver, FragmentManager fragmentManager) {
             super(resolver);
             mBadgingPref = badgingPref;
             mResolver = resolver;
@@ -268,6 +305,51 @@ public class SettingsActivity extends Activity {
         }
     }
 
+    //add for change is_full_app value
+    private static class OverrideApplyHandler implements Runnable {
+
+        private final Context mContext;
+
+        private OverrideApplyHandler(Context context) {
+            mContext = context;
+        }
+
+        @Override
+        public void run() {
+            // Clear the icon cache.
+            LauncherAppState.getInstance(mContext).getIconCache().clear();
+
+            // Wait for it
+            try {
+                Thread.sleep(1000);
+            } catch (Exception e) {
+                Log.e("Launcher3", "Error waiting", e);
+            }
+
+            // Schedule an alarm before we kill ourself.
+            Intent homeIntent = new Intent(Intent.ACTION_MAIN)
+                    .addCategory(Intent.CATEGORY_HOME)
+                    .setPackage(mContext.getPackageName())
+                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            PendingIntent pi = PendingIntent.getActivity(mContext, 42,
+                    homeIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
+            mContext.getSystemService(AlarmManager.class).setExact(
+                    AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 50, pi);
+
+            //clear data will kill process
+            Intent intent = new Intent("com.android.action.CLEAR_APP_DATA");
+            intent.putExtra("pkgName", "com.android.launcher3");
+            intent.addFlags(0x01000000);
+            mContext.sendBroadcast(intent);
+            Log.i("Launcher3", "Clearing user data com.android.launcher3");
+
+            // Kill process
+            android.os.Process.killProcess(android.os.Process.myPid());
+        }
+    }
+
+
+
     public static class NotificationAccessConfirmation
             extends DialogFragment implements DialogInterface.OnClickListener {
 
diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java
index 8a216fc17..f7b5012c0 100644
--- a/src/com/android/launcher3/dragndrop/DragController.java
+++ b/src/com/android/launcher3/dragndrop/DragController.java
@@ -44,6 +44,9 @@ import com.android.launcher3.util.TouchController;
 import com.android.launcher3.util.UiThreadHelper;
 
 import java.util.ArrayList;
+import com.android.launcher3.LauncherSettings.Favorites;
+import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.DeleteDropTarget;
 
 /**
  * Class for initiating a drag within a view or across multiple views.
@@ -601,12 +604,20 @@ public class DragController implements DragDriver.EventListener, TouchController
                     dropTarget.onDrop(mDragObject, mOptions);
                 }
                 accepted = true;
+                if (LauncherAppState.isDisableAllApps() && dropTarget instanceof DeleteDropTarget /* &&
+                        isNeedCancelDrag(mDragObject.dragInfo)*/) {
+                    cancelDrag();
+                }
             }
         }
         final View dropTargetAsView = dropTarget instanceof View ? (View) dropTarget : null;
         mLauncher.getUserEventDispatcher().logDragNDrop(mDragObject, dropTargetAsView);
         dispatchDropComplete(dropTargetAsView, accepted);
     }
     private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
         mDragObject.x = x;
diff --git a/src/com/android/launcher3/model/BaseModelUpdateTask.java b/src/com/android/launcher3/model/BaseModelUpdateTask.java
index fcdc088a7..8514b2479 100644
--- a/src/com/android/launcher3/model/BaseModelUpdateTask.java
+++ b/src/com/android/launcher3/model/BaseModelUpdateTask.java
@@ -63,7 +63,7 @@ public abstract class BaseModelUpdateTask implements ModelUpdateTask {
                 Log.d(TAG, "Ignoring model task since loader is pending=" + this);
             }
             // Loader has not yet run.
-            return;
+//            return;
         }
         execute(mApp, mDataModel, mAllAppsList);
     }
diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java
index 31883dfe6..abd5c19f2 100644
--- a/src/com/android/launcher3/model/LoaderTask.java
+++ b/src/com/android/launcher3/model/LoaderTask.java
@@ -79,6 +79,8 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CancellationException;
+import com.android.launcher3.InstallShortcutReceiver;
+import android.util.Pair;
 
 /**
  * Runnable for the thread that loads the contents of the launcher:
@@ -184,6 +186,11 @@ public class LoaderTask implements Runnable {
             TraceHelper.partitionSection(TAG, "step 2.1: loading all apps");
             loadAllApps();
 
+            if (LauncherAppState.isDisableAllApps()) {
+                android.util.Log.e("Launcher3", "verifyApplications()");
+                verifyApplications();
+            }
+
             TraceHelper.partitionSection(TAG, "step 2.2: Binding all apps");
             verifyNotStopped();
             mResults.bindAllApps();
@@ -230,6 +237,25 @@ public class LoaderTask implements Runnable {
         mStopped = true;
         this.notify();
     }
+    private void verifyApplications() {
+        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<InstallShortcutReceiver.PendingInstallShortcutInfo> added = new ArrayList<InstallShortcutReceiver.PendingInstallShortcutInfo>();
+            synchronized (this) {
+                for (LauncherActivityInfo app : apps) {
+                    InstallShortcutReceiver.PendingInstallShortcutInfo pendingInstallShortcutInfo = new InstallShortcutReceiver.PendingInstallShortcutInfo(app, context);
+                    added.add(pendingInstallShortcutInfo);
+                    installQueue.add(pendingInstallShortcutInfo.getItemInfo());
+                }
+            }
+            if (!added.isEmpty()) {
+                mApp.getModel().addAndBindAddedWorkspaceItems(installQueue);
+            }
+        }
+    }
 
     private void loadWorkspace() {
         final Context context = mApp.getContext();
diff --git a/src/com/android/launcher3/model/PackageUpdatedTask.java b/src/com/android/launcher3/model/PackageUpdatedTask.java
index 089303ece..71262bc4a 100644
--- a/src/com/android/launcher3/model/PackageUpdatedTask.java
+++ b/src/com/android/launcher3/model/PackageUpdatedTask.java
@@ -52,6 +52,10 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
+import android.content.pm.LauncherActivityInfo;
+import com.android.launcher3.InstallShortcutReceiver;
+import android.util.Pair;
 
 /**
  * Handles updates due to changes in package manager (app installed/updated/removed)
@@ -153,6 +157,10 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
 
         final ArrayList<AppInfo> addedOrModified = new ArrayList<>();
         addedOrModified.addAll(appsList.added);
+        if (LauncherAppState.isDisableAllApps()) {
+            android.util.Log.e("cczLauncher3", "updateToWorkSpace()");
+            updateToWorkSpace(context, app, appsList);
+        }
         appsList.added.clear();
         addedOrModified.addAll(appsList.modified);
         appsList.modified.clear();
@@ -348,4 +356,29 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
             bindUpdatedWidgets(dataModel);
         }
     }
+    public void updateToWorkSpace(Context context, LauncherAppState app , AllAppsList appsList){
+        ArrayList<Pair<ItemInfo, Object>> installQueue = new ArrayList<>();
+        final List<UserHandle> profiles = UserManagerCompat.getInstance(context).getUserProfiles();
+        ArrayList<InstallShortcutReceiver.PendingInstallShortcutInfo> added
+                = new ArrayList<InstallShortcutReceiver.PendingInstallShortcutInfo>();
+
+        for (UserHandle user : profiles) {
+            final List<LauncherActivityInfo> apps = LauncherAppsCompat.getInstance(context).getActivityList(null, user);
+            synchronized (this) {
+                for (LauncherActivityInfo info : apps) {
+                    for (AppInfo appInfo : appsList.added) {
+                        if(info.getComponentName().equals(appInfo.componentName)){
+                            InstallShortcutReceiver.PendingInstallShortcutInfo mPendingInstallShortcutInfo
+                                    =  new InstallShortcutReceiver.PendingInstallShortcutInfo(info,context);
+                            added.add(mPendingInstallShortcutInfo);
+                            installQueue.add(mPendingInstallShortcutInfo.getItemInfo());
+                        }
+                    }
+                }
+            }
+        }
+        if (!added.isEmpty()) {
+            app.getModel().addAndBindAddedWorkspaceItems(installQueue);
+        }
+    }
 }
diff --git a/src/com/android/launcher3/pageindicators/PageIndicatorDots.java b/src/com/android/launcher3/pageindicators/PageIndicatorDots.java
index 709975f02..bdeffdcdf 100644
--- a/src/com/android/launcher3/pageindicators/PageIndicatorDots.java
+++ b/src/com/android/launcher3/pageindicators/PageIndicatorDots.java
@@ -38,12 +38,18 @@ import android.view.animation.OvershootInterpolator;
 import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.util.Themes;
+import android.graphics.Rect;
+import android.view.Gravity;
+import android.widget.FrameLayout;
+import com.android.launcher3.DeviceProfile;
+import com.android.launcher3.Launcher;
+import com.android.launcher3.Insettable;
 
 /**
  * {@link PageIndicator} which shows dots per page. The active page is shown with the current
  * accent color.
  */
-public class PageIndicatorDots extends View implements PageIndicator {
+public class PageIndicatorDots extends View implements PageIndicator,Insettable{
 
     private static final float SHIFT_PER_ANIMATION = 0.5f;
     private static final float SHIFT_THRESHOLD = 0.1f;
@@ -94,6 +100,7 @@ public class PageIndicatorDots extends View implements PageIndicator {
     private float mCurrentPosition;
     private float mFinalPosition;
     private ObjectAnimator mAnimator;
+    private final Launcher mLauncher;
 
     private float[] mEntryAnimationRadiusFactors;
 
@@ -108,6 +115,8 @@ public class PageIndicatorDots extends View implements PageIndicator {
     public PageIndicatorDots(Context context, AttributeSet attrs, int defStyleAttr) {
         super(context, attrs, defStyleAttr);
 
+        mLauncher = Launcher.getLauncher(context);
+
         mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
         mCirclePaint.setStyle(Style.FILL);
         mDotRadius = getResources().getDimension(R.dimen.page_indicator_dot_size) / 2;
@@ -119,6 +128,24 @@ public class PageIndicatorDots extends View implements PageIndicator {
         mIsRtl = Utilities.isRtl(getResources());
     }
 
+    @Override
+    public void setInsets(Rect insets) {
+        DeviceProfile grid = mLauncher.getDeviceProfile();
+        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
+
+        if (grid.isVerticalBarLayout()) {
+            Rect padding = grid.workspacePadding;
+            lp.leftMargin = padding.left + grid.workspaceCellPaddingXPx;
+            lp.rightMargin = padding.right + grid.workspaceCellPaddingXPx;
+            lp.bottomMargin = padding.bottom;
+        } else {
+            lp.leftMargin = lp.rightMargin = 0;
+            lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
+            lp.bottomMargin = grid.hotseatBarSizePx + insets.bottom;
+        }
+        setLayoutParams(lp);
+    }
+
     @Override
     public void setScroll(int currentScroll, int totalScroll) {
         if (mNumPages > 1) {
@@ -126,6 +153,9 @@ public class PageIndicatorDots extends View implements PageIndicator {
                 currentScroll = totalScroll - currentScroll;
             }
             int scrollPerPage = totalScroll / (mNumPages - 1);
+            if (scrollPerPage == 0) {
+                return;
+            }
             int pageToLeft = currentScroll / scrollPerPage;
             int pageToLeftScroll = pageToLeft * scrollPerPage;
             int pageToRightScroll = pageToLeftScroll + scrollPerPage;
diff --git a/src/com/android/launcher3/states/SpringLoadedState.java b/src/com/android/launcher3/states/SpringLoadedState.java
index 35f7f8831..acc3c36f7 100644
--- a/src/com/android/launcher3/states/SpringLoadedState.java
+++ b/src/com/android/launcher3/states/SpringLoadedState.java
@@ -76,7 +76,7 @@ public class SpringLoadedState extends LauncherState {
     public void onStateEnabled(Launcher launcher) {
         Workspace ws = launcher.getWorkspace();
         ws.showPageIndicatorAtCurrentScroll();
-        ws.getPageIndicator().setShouldAutoHide(false);
+        //ws.getPageIndicator().setShouldAutoHide(false);
 
         // Prevent any Un/InstallShortcutReceivers from updating the db while we are
         // in spring loaded mode
@@ -91,7 +91,7 @@ public class SpringLoadedState extends LauncherState {
 
     @Override
     public void onStateDisabled(final Launcher launcher) {
-        launcher.getWorkspace().getPageIndicator().setShouldAutoHide(true);
+        //launcher.getWorkspace().getPageIndicator().setShouldAutoHide(true);
 
         // Re-enable any Un/InstallShortcutReceiver and now process any queued items
         InstallShortcutReceiver.disableAndFlushInstallQueue(
-- 
2.22.0

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值