Search in sources :

Example 96 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.widget.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.

the class LauncherAppWidgetProviderInfoTest method isMinSizeFulfilled_minHeightAndMinResizeHeightExceededGridRows_shouldReturnFalse.

@Test
public void isMinSizeFulfilled_minHeightAndMinResizeHeightExceededGridRows_shouldReturnFalse() {
    LauncherAppWidgetProviderInfo info = new LauncherAppWidgetProviderInfo();
    info.minWidth = 80;
    info.minHeight = CELL_SIZE * (NUM_OF_ROWS + 2);
    info.minResizeWidth = 50;
    info.minResizeHeight = CELL_SIZE * (NUM_OF_ROWS + 1);
    InvariantDeviceProfile idp = createIDP();
    info.initSpans(mContext, idp);
    assertThat(info.isMinSizeFulfilled()).isFalse();
}
Also used : InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 97 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.widget.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.

the class WidgetsListContentEntryTest method createWidgetItem.

private WidgetItem createWidgetItem(ComponentName componentName, int spanX, int spanY) {
    String label = mWidgetsToLabels.get(componentName);
    AppWidgetProviderInfo widgetInfo = createAppWidgetProviderInfo(componentName);
    LauncherAppWidgetProviderInfo launcherAppWidgetProviderInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(getApplicationContext(), widgetInfo);
    launcherAppWidgetProviderInfo.spanX = spanX;
    launcherAppWidgetProviderInfo.spanY = spanY;
    launcherAppWidgetProviderInfo.label = label;
    return new WidgetItem(launcherAppWidgetProviderInfo, mTestProfile, mIconCache);
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) WidgetUtils.createAppWidgetProviderInfo(com.android.launcher3.util.WidgetUtils.createAppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 98 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.widget.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.

the class DatabaseWidgetPreviewLoader method generateWidgetPreview.

/**
 * Generates the widget preview from either the {@link WidgetManagerHelper} or cache
 * and add badge at the bottom right corner.
 *
 * @param info                        information about the widget
 * @param maxPreviewWidth             width of the preview on either workspace or tray
 * @param preScaledWidthOut           return the width of the returned bitmap
 */
public Bitmap generateWidgetPreview(LauncherAppWidgetProviderInfo info, int maxPreviewWidth, int[] preScaledWidthOut) {
    // Load the preview image if possible
    if (maxPreviewWidth < 0)
        maxPreviewWidth = Integer.MAX_VALUE;
    Drawable drawable = null;
    if (info.previewImage != 0) {
        try {
            drawable = info.loadPreviewImage(mContext, 0);
        } catch (OutOfMemoryError e) {
            Log.w(TAG, "Error loading widget preview for: " + info.provider, e);
            // During OutOfMemoryError, the previous heap stack is not affected. Catching
            // an OOM error here should be safe & not affect other parts of launcher.
            drawable = null;
        }
        if (drawable != null) {
            drawable = mutateOnMainThread(drawable);
        } else {
            Log.w(TAG, "Can't load widget preview drawable 0x" + Integer.toHexString(info.previewImage) + " for provider: " + info.provider);
        }
    }
    final boolean widgetPreviewExists = (drawable != null);
    final int spanX = info.spanX;
    final int spanY = info.spanY;
    int previewWidth;
    int previewHeight;
    DeviceProfile dp = ActivityContext.lookupContext(mContext).getDeviceProfile();
    if (widgetPreviewExists && drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0) {
        previewWidth = drawable.getIntrinsicWidth();
        previewHeight = drawable.getIntrinsicHeight();
    } else {
        Size widgetSize = WidgetSizes.getWidgetPaddedSizePx(mContext, info.provider, dp, spanX, spanY);
        previewWidth = widgetSize.getWidth();
        previewHeight = widgetSize.getHeight();
    }
    if (preScaledWidthOut != null) {
        preScaledWidthOut[0] = previewWidth;
    }
    // Scale to fit width only - let the widget preview be clipped in the
    // vertical dimension
    final float scale = previewWidth > maxPreviewWidth ? (maxPreviewWidth / (float) (previewWidth)) : 1f;
    if (scale != 1f) {
        previewWidth = Math.max((int) (scale * previewWidth), 1);
        previewHeight = Math.max((int) (scale * previewHeight), 1);
    }
    final int previewWidthF = previewWidth;
    final int previewHeightF = previewHeight;
    final Drawable drawableF = drawable;
    return BitmapRenderer.createHardwareBitmap(previewWidth, previewHeight, c -> {
        // Draw the scaled preview into the final bitmap
        if (widgetPreviewExists) {
            drawableF.setBounds(0, 0, previewWidthF, previewHeightF);
            drawableF.draw(c);
        } else {
            RectF boxRect;
            // Draw horizontal and vertical lines to represent individual columns.
            final Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
            if (Utilities.ATLEAST_S) {
                boxRect = new RectF(/* left= */
                0, /* top= */
                0, /* right= */
                previewWidthF, /* bottom= */
                previewHeightF);
                p.setStyle(Paint.Style.FILL);
                p.setColor(Color.WHITE);
                float roundedCorner = mContext.getResources().getDimension(android.R.dimen.system_app_widget_background_radius);
                c.drawRoundRect(boxRect, roundedCorner, roundedCorner, p);
            } else {
                boxRect = drawBoxWithShadow(c, previewWidthF, previewHeightF);
            }
            p.setStyle(Paint.Style.STROKE);
            p.setStrokeWidth(mContext.getResources().getDimension(R.dimen.widget_preview_cell_divider_width));
            p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
            float t = boxRect.left;
            float tileSize = boxRect.width() / spanX;
            for (int i = 1; i < spanX; i++) {
                t += tileSize;
                c.drawLine(t, 0, t, previewHeightF, p);
            }
            t = boxRect.top;
            tileSize = boxRect.height() / spanY;
            for (int i = 1; i < spanY; i++) {
                t += tileSize;
                c.drawLine(0, t, previewWidthF, t, p);
            }
            // Draw icon in the center.
            try {
                Drawable icon = LauncherAppState.getInstance(mContext).getIconCache().getFullResIcon(info.provider.getPackageName(), info.icon);
                if (icon != null) {
                    int appIconSize = dp.iconSizePx;
                    int iconSize = (int) Math.min(appIconSize * scale, Math.min(boxRect.width(), boxRect.height()));
                    icon = mutateOnMainThread(icon);
                    int hoffset = (previewWidthF - iconSize) / 2;
                    int yoffset = (previewHeightF - iconSize) / 2;
                    icon.setBounds(hoffset, yoffset, hoffset + iconSize, yoffset + iconSize);
                    icon.draw(c);
                }
            } catch (Resources.NotFoundException e) {
            }
        }
    });
}
Also used : RectF(android.graphics.RectF) DeviceProfile(com.android.launcher3.DeviceProfile) Size(android.util.Size) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint) Resources(android.content.res.Resources) Paint(android.graphics.Paint)

Example 99 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.widget.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.

the class WidgetCell method applyPreviewOnAppWidgetHostView.

private void applyPreviewOnAppWidgetHostView(WidgetItem item) {
    if (mRemoteViewsPreview != null) {
        mAppWidgetHostViewPreview = createAppWidgetHostView(getContext());
        setAppWidgetHostViewPreview(mAppWidgetHostViewPreview, item.widgetInfo, mRemoteViewsPreview);
        return;
    }
    if (!item.hasPreviewLayout())
        return;
    Context context = getContext();
    // If the context is a Launcher activity, DragView will show mAppWidgetHostViewPreview as
    // a preview during drag & drop. And thus, we should use LauncherAppWidgetHostView, which
    // supports applying local color extraction during drag & drop.
    mAppWidgetHostViewPreview = isLauncherContext(context) ? new LauncherAppWidgetHostView(context) : createAppWidgetHostView(context);
    LauncherAppWidgetProviderInfo launcherAppWidgetProviderInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(context, item.widgetInfo.clone());
    // A hack to force the initial layout to be the preview layout since there is no API for
    // rendering a preview layout for work profile apps yet. For non-work profile layout, a
    // proper solution is to use RemoteViews(PackageName, LayoutId).
    launcherAppWidgetProviderInfo.initialLayout = item.widgetInfo.previewLayout;
    setAppWidgetHostViewPreview(mAppWidgetHostViewPreview, launcherAppWidgetProviderInfo, /* remoteViews= */
    null);
}
Also used : Context(android.content.Context) ActivityContext(com.android.launcher3.views.ActivityContext)

Example 100 with LauncherAppWidgetProviderInfo

use of com.android.launcher3.widget.LauncherAppWidgetProviderInfo in project android_packages_apps_404Launcher by P-404.

the class LauncherPreviewRenderer method inflateAndAddWidgets.

private void inflateAndAddWidgets(LauncherAppWidgetInfo info, LauncherAppWidgetProviderInfo providerInfo) {
    AppWidgetHostView view;
    if (FeatureFlags.WIDGETS_IN_LAUNCHER_PREVIEW.get()) {
        view = mAppWidgetHost.createView(mContext, info.appWidgetId, providerInfo);
    } else {
        view = new NavigableAppWidgetHostView(this) {

            @Override
            protected boolean shouldAllowDirectClick() {
                return false;
            }
        };
        view.setAppWidget(-1, providerInfo);
        view.updateAppWidget(null);
    }
    if (mWallpaperColorResources != null) {
        view.setColorResources(mWallpaperColorResources);
    }
    view.setTag(info);
    addInScreenFromBind(view, info);
}
Also used : BaseLauncherAppWidgetHostView(com.android.launcher3.widget.BaseLauncherAppWidgetHostView) NavigableAppWidgetHostView(com.android.launcher3.widget.NavigableAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) NavigableAppWidgetHostView(com.android.launcher3.widget.NavigableAppWidgetHostView)

Aggregations

Test (org.junit.Test)108 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)81 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)77 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)65 SmallTest (androidx.test.filters.SmallTest)52 LargeTest (androidx.test.filters.LargeTest)42 AbstractLauncherUiTest (com.android.launcher3.ui.AbstractLauncherUiTest)42 PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)33 Bundle (android.os.Bundle)32 WidgetManagerHelper (com.android.launcher3.widget.WidgetManagerHelper)31 Point (android.graphics.Point)29 LauncherAppWidgetProviderInfo (com.android.launcher3.LauncherAppWidgetProviderInfo)28 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)23 Context (android.content.Context)23 DeviceProfile (com.android.launcher3.DeviceProfile)23 ArrayList (java.util.ArrayList)21 AppWidgetHostView (android.appwidget.AppWidgetHostView)20 WidgetItem (com.android.launcher3.model.WidgetItem)17 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)14 WidgetAddFlowHandler (com.android.launcher3.widget.WidgetAddFlowHandler)14