Search in sources :

Example 1 with ModelDelegate

use of com.android.launcher3.model.ModelDelegate in project android_packages_apps_Launcher3 by AOSPA.

the class PreviewSurfaceRenderer method loadModelData.

@WorkerThread
private void loadModelData() {
    final boolean migrated = doGridMigrationIfNecessary();
    final Context inflationContext;
    if (mWallpaperColors != null) {
        // Create a themed context, without affecting the main application context
        Context context = mContext.createDisplayContext(mDisplay);
        if (Utilities.ATLEAST_R) {
            context = context.createWindowContext(LayoutParams.TYPE_APPLICATION_OVERLAY, null);
        }
        LocalColorExtractor.newInstance(mContext).applyColorsOverride(context, mWallpaperColors);
        inflationContext = new ContextThemeWrapper(context, Themes.getActivityThemeRes(context, mWallpaperColors.getColorHints()));
    } else {
        inflationContext = new ContextThemeWrapper(mContext, Themes.getActivityThemeRes(mContext));
    }
    if (migrated) {
        PreviewContext previewContext = new PreviewContext(inflationContext, mIdp);
        new LoaderTask(LauncherAppState.getInstance(previewContext), null, new BgDataModel(), new ModelDelegate(), null) {

            @Override
            public void run() {
                DeviceProfile deviceProfile = mIdp.getDeviceProfile(previewContext);
                String query = LauncherSettings.Favorites.SCREEN + " = " + Workspace.FIRST_SCREEN_ID + " or " + LauncherSettings.Favorites.CONTAINER + " = " + LauncherSettings.Favorites.CONTAINER_HOTSEAT;
                if (deviceProfile.isTwoPanels) {
                    query += " or " + LauncherSettings.Favorites.SCREEN + " = " + Workspace.SECOND_SCREEN_ID;
                }
                loadWorkspace(new ArrayList<>(), LauncherSettings.Favorites.PREVIEW_CONTENT_URI, query);
                MAIN_EXECUTOR.execute(() -> {
                    renderView(previewContext, mBgDataModel, mWidgetProvidersMap);
                    mOnDestroyCallbacks.add(previewContext::onDestroy);
                });
            }
        }.run();
    } else {
        LauncherAppState.getInstance(inflationContext).getModel().loadAsync(dataModel -> {
            if (dataModel != null) {
                MAIN_EXECUTOR.execute(() -> renderView(inflationContext, dataModel, null));
            } else {
                Log.e(TAG, "Model loading failed");
            }
        });
    }
}
Also used : Context(android.content.Context) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) ModelDelegate(com.android.launcher3.model.ModelDelegate) DeviceProfile(com.android.launcher3.DeviceProfile) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ContextThemeWrapper(android.view.ContextThemeWrapper) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) BgDataModel(com.android.launcher3.model.BgDataModel) ArrayList(java.util.ArrayList) LoaderTask(com.android.launcher3.model.LoaderTask) WorkerThread(androidx.annotation.WorkerThread)

Example 2 with ModelDelegate

use of com.android.launcher3.model.ModelDelegate in project android_packages_apps_404Launcher by P-404.

the class PreviewSurfaceRenderer method loadModelData.

@WorkerThread
private void loadModelData() {
    final boolean migrated = doGridMigrationIfNecessary();
    final Context inflationContext;
    if (mWallpaperColors != null) {
        // Create a themed context, without affecting the main application context
        Context context = mContext.createDisplayContext(mDisplay);
        if (Utilities.ATLEAST_R) {
            context = context.createWindowContext(LayoutParams.TYPE_APPLICATION_OVERLAY, null);
        }
        LocalColorExtractor.newInstance(mContext).applyColorsOverride(context, mWallpaperColors);
        inflationContext = new ContextThemeWrapper(context, Themes.getActivityThemeRes(context, mWallpaperColors.getColorHints()));
    } else {
        inflationContext = new ContextThemeWrapper(mContext, Themes.getActivityThemeRes(mContext));
    }
    if (migrated) {
        PreviewContext previewContext = new PreviewContext(inflationContext, mIdp);
        new LoaderTask(LauncherAppState.getInstance(previewContext), null, new BgDataModel(), new ModelDelegate(), null) {

            @Override
            public void run() {
                DeviceProfile deviceProfile = mIdp.getDeviceProfile(previewContext);
                String query = LauncherSettings.Favorites.SCREEN + " = " + Workspace.FIRST_SCREEN_ID + " or " + LauncherSettings.Favorites.CONTAINER + " = " + LauncherSettings.Favorites.CONTAINER_HOTSEAT;
                if (deviceProfile.isTwoPanels) {
                    query += " or " + LauncherSettings.Favorites.SCREEN + " = " + Workspace.SECOND_SCREEN_ID;
                }
                loadWorkspace(new ArrayList<>(), LauncherSettings.Favorites.PREVIEW_CONTENT_URI, query);
                MAIN_EXECUTOR.execute(() -> {
                    renderView(previewContext, mBgDataModel, mWidgetProvidersMap);
                    mOnDestroyCallbacks.add(previewContext::onDestroy);
                });
            }
        }.run();
    } else {
        LauncherAppState.getInstance(inflationContext).getModel().loadAsync(dataModel -> {
            if (dataModel != null) {
                MAIN_EXECUTOR.execute(() -> renderView(inflationContext, dataModel, null));
            } else {
                Log.e(TAG, "Model loading failed");
            }
        });
    }
}
Also used : Context(android.content.Context) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) ModelDelegate(com.android.launcher3.model.ModelDelegate) DeviceProfile(com.android.launcher3.DeviceProfile) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ContextThemeWrapper(android.view.ContextThemeWrapper) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) BgDataModel(com.android.launcher3.model.BgDataModel) ArrayList(java.util.ArrayList) LoaderTask(com.android.launcher3.model.LoaderTask) WorkerThread(androidx.annotation.WorkerThread)

Example 3 with ModelDelegate

use of com.android.launcher3.model.ModelDelegate in project android_packages_apps_Launcher3 by crdroidandroid.

the class PreviewSurfaceRenderer method loadModelData.

@WorkerThread
private void loadModelData() {
    final boolean migrated = doGridMigrationIfNecessary();
    final Context inflationContext;
    if (mWallpaperColors != null) {
        // Create a themed context, without affecting the main application context
        Context context = mContext.createDisplayContext(mDisplay);
        if (Utilities.ATLEAST_R) {
            context = context.createWindowContext(LayoutParams.TYPE_APPLICATION_OVERLAY, null);
        }
        LocalColorExtractor.newInstance(mContext).applyColorsOverride(context, mWallpaperColors);
        inflationContext = new ContextThemeWrapper(context, Themes.getActivityThemeRes(context, mWallpaperColors.getColorHints()));
    } else {
        inflationContext = new ContextThemeWrapper(mContext, R.style.AppTheme);
    }
    if (migrated) {
        PreviewContext previewContext = new PreviewContext(inflationContext, mIdp);
        new LoaderTask(LauncherAppState.getInstance(previewContext), null, new BgDataModel(), new ModelDelegate(), null) {

            @Override
            public void run() {
                loadWorkspace(new ArrayList<>(), LauncherSettings.Favorites.PREVIEW_CONTENT_URI, LauncherSettings.Favorites.SCREEN + " = 0 or " + LauncherSettings.Favorites.CONTAINER + " = " + LauncherSettings.Favorites.CONTAINER_HOTSEAT);
                MAIN_EXECUTOR.execute(() -> {
                    renderView(previewContext, mBgDataModel, mWidgetProvidersMap);
                    mOnDestroyCallbacks.add(previewContext::onDestroy);
                });
            }
        }.run();
    } else {
        LauncherAppState.getInstance(inflationContext).getModel().loadAsync(dataModel -> {
            if (dataModel != null) {
                MAIN_EXECUTOR.execute(() -> renderView(inflationContext, dataModel, null));
            } else {
                Log.e(TAG, "Model loading failed");
            }
        });
    }
}
Also used : Context(android.content.Context) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) ModelDelegate(com.android.launcher3.model.ModelDelegate) ContextThemeWrapper(android.view.ContextThemeWrapper) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) BgDataModel(com.android.launcher3.model.BgDataModel) ArrayList(java.util.ArrayList) LoaderTask(com.android.launcher3.model.LoaderTask) WorkerThread(androidx.annotation.WorkerThread)

Example 4 with ModelDelegate

use of com.android.launcher3.model.ModelDelegate in project android_packages_apps_Launcher3 by ArrowOS.

the class PreviewSurfaceRenderer method loadModelData.

@WorkerThread
private void loadModelData() {
    final boolean migrated = doGridMigrationIfNecessary();
    final Context inflationContext;
    if (mWallpaperColors != null) {
        // Create a themed context, without affecting the main application context
        Context context = mContext.createDisplayContext(mDisplay);
        if (Utilities.ATLEAST_R) {
            context = context.createWindowContext(LayoutParams.TYPE_APPLICATION_OVERLAY, null);
        }
        LocalColorExtractor.newInstance(mContext).applyColorsOverride(context, mWallpaperColors);
        inflationContext = new ContextThemeWrapper(context, Themes.getActivityThemeRes(context, mWallpaperColors.getColorHints()));
    } else {
        inflationContext = new ContextThemeWrapper(mContext, Themes.getActivityThemeRes(mContext));
    }
    if (migrated) {
        PreviewContext previewContext = new PreviewContext(inflationContext, mIdp);
        new LoaderTask(LauncherAppState.getInstance(previewContext), null, new BgDataModel(), new ModelDelegate(), null) {

            @Override
            public void run() {
                DeviceProfile deviceProfile = mIdp.getDeviceProfile(previewContext);
                String query = LauncherSettings.Favorites.SCREEN + " = " + Workspace.FIRST_SCREEN_ID + " or " + LauncherSettings.Favorites.CONTAINER + " = " + LauncherSettings.Favorites.CONTAINER_HOTSEAT;
                if (deviceProfile.isTwoPanels) {
                    query += " or " + LauncherSettings.Favorites.SCREEN + " = " + Workspace.SECOND_SCREEN_ID;
                }
                loadWorkspace(new ArrayList<>(), LauncherSettings.Favorites.PREVIEW_CONTENT_URI, query);
                MAIN_EXECUTOR.execute(() -> {
                    renderView(previewContext, mBgDataModel, mWidgetProvidersMap);
                    mOnDestroyCallbacks.add(previewContext::onDestroy);
                });
            }
        }.run();
    } else {
        LauncherAppState.getInstance(inflationContext).getModel().loadAsync(dataModel -> {
            if (dataModel != null) {
                MAIN_EXECUTOR.execute(() -> renderView(inflationContext, dataModel, null));
            } else {
                Log.e(TAG, "Model loading failed");
            }
        });
    }
}
Also used : Context(android.content.Context) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) ModelDelegate(com.android.launcher3.model.ModelDelegate) DeviceProfile(com.android.launcher3.DeviceProfile) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ContextThemeWrapper(android.view.ContextThemeWrapper) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) BgDataModel(com.android.launcher3.model.BgDataModel) ArrayList(java.util.ArrayList) LoaderTask(com.android.launcher3.model.LoaderTask) WorkerThread(androidx.annotation.WorkerThread)

Example 5 with ModelDelegate

use of com.android.launcher3.model.ModelDelegate in project android_packages_apps_Launcher3 by ProtonAOSP.

the class PreviewSurfaceRenderer method loadModelData.

@WorkerThread
private void loadModelData() {
    final boolean migrated = doGridMigrationIfNecessary();
    final Context inflationContext;
    if (mWallpaperColors != null) {
        // Create a themed context, without affecting the main application context
        Context context = mContext.createDisplayContext(mDisplay);
        if (Utilities.ATLEAST_R) {
            context = context.createWindowContext(LayoutParams.TYPE_APPLICATION_OVERLAY, null);
        }
        LocalColorExtractor.newInstance(mContext).applyColorsOverride(context, mWallpaperColors);
        inflationContext = new ContextThemeWrapper(context, Themes.getActivityThemeRes(context, mWallpaperColors.getColorHints()));
    } else {
        inflationContext = new ContextThemeWrapper(mContext, Themes.getActivityThemeRes(mContext));
    }
    if (migrated) {
        PreviewContext previewContext = new PreviewContext(inflationContext, mIdp);
        new LoaderTask(LauncherAppState.getInstance(previewContext), null, new BgDataModel(), new ModelDelegate(), null) {

            @Override
            public void run() {
                DeviceProfile deviceProfile = mIdp.getDeviceProfile(previewContext);
                String query = LauncherSettings.Favorites.SCREEN + " = " + Workspace.FIRST_SCREEN_ID + " or " + LauncherSettings.Favorites.CONTAINER + " = " + LauncherSettings.Favorites.CONTAINER_HOTSEAT;
                if (deviceProfile.isTwoPanels) {
                    query += " or " + LauncherSettings.Favorites.SCREEN + " = " + Workspace.SECOND_SCREEN_ID;
                }
                loadWorkspace(new ArrayList<>(), LauncherSettings.Favorites.PREVIEW_CONTENT_URI, query);
                MAIN_EXECUTOR.execute(() -> {
                    renderView(previewContext, mBgDataModel, mWidgetProvidersMap);
                    mOnDestroyCallbacks.add(previewContext::onDestroy);
                });
            }
        }.run();
    } else {
        LauncherAppState.getInstance(inflationContext).getModel().loadAsync(dataModel -> {
            if (dataModel != null) {
                MAIN_EXECUTOR.execute(() -> renderView(inflationContext, dataModel, null));
            } else {
                Log.e(TAG, "Model loading failed");
            }
        });
    }
}
Also used : Context(android.content.Context) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) ModelDelegate(com.android.launcher3.model.ModelDelegate) DeviceProfile(com.android.launcher3.DeviceProfile) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ContextThemeWrapper(android.view.ContextThemeWrapper) PreviewContext(com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext) BgDataModel(com.android.launcher3.model.BgDataModel) ArrayList(java.util.ArrayList) LoaderTask(com.android.launcher3.model.LoaderTask) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

Context (android.content.Context)5 ContextThemeWrapper (android.view.ContextThemeWrapper)5 WorkerThread (androidx.annotation.WorkerThread)5 PreviewContext (com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext)5 BgDataModel (com.android.launcher3.model.BgDataModel)5 LoaderTask (com.android.launcher3.model.LoaderTask)5 ModelDelegate (com.android.launcher3.model.ModelDelegate)5 ArrayList (java.util.ArrayList)5 DeviceProfile (com.android.launcher3.DeviceProfile)4 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)4