Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7be16017 authored by Tracy Zhou's avatar Tracy Zhou Committed by Android (Google) Code Review
Browse files

Merge "Render user's actual workspace in ThemePicker preview (Part 5)" into ub-launcher3-master

parents 91f97cb2 10a285dc
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.launcher3.model;
package com.android.launcher3.model;


import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.os.UserHandle;
import android.os.UserHandle;


@@ -68,4 +69,9 @@ public class WidgetsModel {
    public void onPackageIconsUpdated(Set<String> packageNames, UserHandle user,
    public void onPackageIconsUpdated(Set<String> packageNames, UserHandle user,
            LauncherAppState app) {
            LauncherAppState app) {
    }
    }

    public WidgetItem getWidgetProviderInfoByProviderName(
            ComponentName providerName) {
        return null;
    }
}
}
 No newline at end of file
+55 −10
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.launcher3.model.ModelUtils.sortWorkspaceItemsSpatially


import android.annotation.TargetApi;
import android.annotation.TargetApi;
import android.app.Fragment;
import android.app.Fragment;
import android.appwidget.AppWidgetHostView;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
@@ -55,6 +56,7 @@ import com.android.launcher3.InsettableFrameLayout;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetInfo;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.LauncherSettings.Favorites;
@@ -72,6 +74,8 @@ import com.android.launcher3.model.AllAppsList;
import com.android.launcher3.model.BgDataModel;
import com.android.launcher3.model.BgDataModel;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.LoaderResults;
import com.android.launcher3.model.LoaderResults;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.BaseDragLayer;
import com.android.launcher3.views.BaseDragLayer;


@@ -248,6 +252,16 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> {
            addInScreenFromBind(folderIcon, info);
            addInScreenFromBind(folderIcon, info);
        }
        }


        private void inflateAndAddWidgets(LauncherAppWidgetInfo info, WidgetsModel widgetsModel) {
            WidgetItem widgetItem = widgetsModel.getWidgetProviderInfoByProviderName(
                    info.providerName);
            AppWidgetHostView view = new AppWidgetHostView(mContext);
            view.setAppWidget(-1, widgetItem.widgetInfo);
            view.updateAppWidget(null);
            view.setTag(info);
            addInScreenFromBind(view, info);
        }

        private void dispatchVisibilityAggregated(View view, boolean isVisible) {
        private void dispatchVisibilityAggregated(View view, boolean isVisible) {
            // Similar to View.dispatchVisibilityAggregated implementation.
            // Similar to View.dispatchVisibilityAggregated implementation.
            final boolean thisVisible = view.getVisibility() == VISIBLE;
            final boolean thisVisible = view.getVisibility() == VISIBLE;
@@ -272,9 +286,9 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> {
                        mContext).getModel();
                        mContext).getModel();
                final WorkspaceItemsInfoFetcher fetcher = new WorkspaceItemsInfoFetcher();
                final WorkspaceItemsInfoFetcher fetcher = new WorkspaceItemsInfoFetcher();
                launcherModel.enqueueModelUpdateTask(fetcher);
                launcherModel.enqueueModelUpdateTask(fetcher);
                ArrayList<ItemInfo> workspaceItems;
                WorkspaceResult workspaceResult;
                try {
                try {
                    workspaceItems = fetcher.mTask.get(5, TimeUnit.SECONDS);
                    workspaceResult = fetcher.mTask.get(5, TimeUnit.SECONDS);
                } catch (InterruptedException | ExecutionException | TimeoutException e) {
                } catch (InterruptedException | ExecutionException | TimeoutException e) {
                    Log.d(TAG, "Error fetching workspace items info", e);
                    Log.d(TAG, "Error fetching workspace items info", e);
                    return;
                    return;
@@ -284,9 +298,14 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> {
                // items
                // items
                ArrayList<ItemInfo> currentWorkspaceItems = new ArrayList<>();
                ArrayList<ItemInfo> currentWorkspaceItems = new ArrayList<>();
                ArrayList<ItemInfo> otherWorkspaceItems = new ArrayList<>();
                ArrayList<ItemInfo> otherWorkspaceItems = new ArrayList<>();

                ArrayList<LauncherAppWidgetInfo> currentAppWidgets = new ArrayList<>();
                filterCurrentWorkspaceItems(0 /* currentScreenId */, workspaceItems,
                ArrayList<LauncherAppWidgetInfo> otherAppWidgets = new ArrayList<>();
                        currentWorkspaceItems, otherWorkspaceItems);

                filterCurrentWorkspaceItems(0 /* currentScreenId */,
                        workspaceResult.mWorkspaceItems, currentWorkspaceItems,
                        otherWorkspaceItems);
                filterCurrentWorkspaceItems(0 /* currentScreenId */, workspaceResult.mAppWidgets,
                        currentAppWidgets, otherAppWidgets);
                sortWorkspaceItemsSpatially(mIdp, currentWorkspaceItems);
                sortWorkspaceItemsSpatially(mIdp, currentWorkspaceItems);


                for (ItemInfo itemInfo : currentWorkspaceItems) {
                for (ItemInfo itemInfo : currentWorkspaceItems) {
@@ -303,6 +322,17 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> {
                            break;
                            break;
                    }
                    }
                }
                }
                for (ItemInfo itemInfo : currentAppWidgets) {
                    switch (itemInfo.itemType) {
                        case Favorites.ITEM_TYPE_APPWIDGET:
                        case Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
                            inflateAndAddWidgets((LauncherAppWidgetInfo) itemInfo,
                                    workspaceResult.mWidgetsModel);
                            break;
                        default:
                            break;
                    }
                }
            } else {
            } else {
                // Add hotseat icons
                // Add hotseat icons
                for (int i = 0; i < mIdp.numHotseatIcons; i++) {
                for (int i = 0; i < mIdp.numHotseatIcons; i++) {
@@ -349,10 +379,10 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> {
        }
        }
    }
    }


    private static class WorkspaceItemsInfoFetcher implements Callable<ArrayList<ItemInfo>>,
    private static class WorkspaceItemsInfoFetcher implements Callable<WorkspaceResult>,
            LauncherModel.ModelUpdateTask {
            LauncherModel.ModelUpdateTask {


        private final FutureTask<ArrayList<ItemInfo>> mTask = new FutureTask<>(this);
        private final FutureTask<WorkspaceResult> mTask = new FutureTask<>(this);


        private LauncherAppState mApp;
        private LauncherAppState mApp;
        private LauncherModel mModel;
        private LauncherModel mModel;
@@ -374,14 +404,16 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> {
        }
        }


        @Override
        @Override
        public ArrayList<ItemInfo> call() throws Exception {
        public WorkspaceResult call() throws Exception {
            if (!mModel.isModelLoaded()) {
            if (!mModel.isModelLoaded()) {
                Log.d(TAG, "Workspace not loaded, loading now");
                Log.d(TAG, "Workspace not loaded, loading now");
                mModel.startLoaderForResults(
                mModel.startLoaderForResults(
                        new LoaderResults(mApp, mBgDataModel, mAllAppsList, new Callbacks[0]));
                        new LoaderResults(mApp, mBgDataModel, mAllAppsList, new Callbacks[0]));
                return new ArrayList<>();
                return null;
            }
            }
            return mBgDataModel.workspaceItems;

            return new WorkspaceResult(mBgDataModel.workspaceItems, mBgDataModel.appWidgets,
                    mBgDataModel.widgetsModel);
        }
        }
    }
    }


@@ -389,4 +421,17 @@ public class LauncherPreviewRenderer implements Callable<Bitmap> {
        view.measure(makeMeasureSpec(width, EXACTLY), makeMeasureSpec(height, EXACTLY));
        view.measure(makeMeasureSpec(width, EXACTLY), makeMeasureSpec(height, EXACTLY));
        view.layout(0, 0, width, height);
        view.layout(0, 0, width, height);
    }
    }

    private static class WorkspaceResult {
        private final ArrayList<ItemInfo> mWorkspaceItems;
        private final ArrayList<LauncherAppWidgetInfo> mAppWidgets;
        private final WidgetsModel mWidgetsModel;

        private WorkspaceResult(ArrayList<ItemInfo> workspaceItems,
                ArrayList<LauncherAppWidgetInfo> appWidgets, WidgetsModel widgetsModel) {
            mWorkspaceItems = workspaceItems;
            mAppWidgets = appWidgets;
            mWidgetsModel = widgetsModel;
        }
    }
}
}
+15 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.launcher3.model;
import com.android.launcher3.ItemInfoWithIcon;
import com.android.launcher3.ItemInfoWithIcon;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings;


import java.util.Objects;

/**
/**
 * Represents a {@link Package} in the widget tray section.
 * Represents a {@link Package} in the widget tray section.
 */
 */
@@ -48,4 +50,17 @@ public class PackageItemInfo extends ItemInfoWithIcon {
    public PackageItemInfo clone() {
    public PackageItemInfo clone() {
        return new PackageItemInfo(this);
        return new PackageItemInfo(this);
    }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PackageItemInfo that = (PackageItemInfo) o;
        return Objects.equals(packageName, that.packageName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(packageName);
    }
}
}
+13 −0
Original line number Original line Diff line number Diff line
@@ -6,6 +6,7 @@ import static android.appwidget.AppWidgetProviderInfo.WIDGET_FEATURE_HIDE_FROM_P
import static com.android.launcher3.pm.ShortcutConfigActivityInfo.queryList;
import static com.android.launcher3.pm.ShortcutConfigActivityInfo.queryList;


import android.appwidget.AppWidgetProviderInfo;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.os.Process;
import android.os.Process;
@@ -243,4 +244,16 @@ public class WidgetsModel {
            }
            }
        }
        }
    }
    }

    public WidgetItem getWidgetProviderInfoByProviderName(
            ComponentName providerName) {
        ArrayList<WidgetItem> widgetsList = mWidgetsList.get(
                new PackageItemInfo(providerName.getPackageName()));
        for (WidgetItem item : widgetsList) {
            if (item.componentName.equals(providerName)) {
                return item;
            }
        }
        return null;
    }
}
}
 No newline at end of file