Search in sources :

Example 1 with BaseActivity

use of com.android.launcher3.BaseActivity in project android_packages_apps_Launcher3 by crdroidandroid.

the class WidgetsListAdapter method ensureAllPreviewsReady.

/**
 * Checks that all preview images are loaded and starts loading for those that aren't ready.
 *
 * @return true if all previews are ready and the data can be updated, false otherwise.
 */
private boolean ensureAllPreviewsReady() {
    boolean allReady = true;
    BaseActivity activity = BaseActivity.fromContext(mContext);
    for (WidgetsListBaseEntry entry : mAllEntries) {
        if (!(entry instanceof WidgetsListContentEntry))
            continue;
        WidgetsListContentEntry contentEntry = (WidgetsListContentEntry) entry;
        if (!matchesKey(entry, mWidgetsContentVisiblePackageUserKey)) {
            // If the entry isn't visible, clear any loaded previews.
            mCachingPreviewLoader.clearPreviews(contentEntry.mWidgets);
            continue;
        }
        for (int i = 0; i < entry.mWidgets.size(); i++) {
            WidgetItem widgetItem = entry.mWidgets.get(i);
            DeviceProfile deviceProfile = activity.getDeviceProfile();
            Size widgetSize = WidgetSizes.getWidgetItemSizePx(mContext, deviceProfile, widgetItem);
            if (widgetItem.isShortcut()) {
                widgetSize = new Size(widgetSize.getWidth() + mShortcutPreviewPadding, widgetSize.getHeight() + mShortcutPreviewPadding);
            }
            if (widgetItem.hasPreviewLayout() || mCachingPreviewLoader.isPreviewLoaded(widgetItem, widgetSize)) {
                // preview bitmap is in the cache.
                continue;
            }
            // If we've reached this point, we should load the preview for the widget.
            allReady = false;
            mCachingPreviewLoader.loadPreview(activity, widgetItem, widgetSize, mPreviewLoadedCallback);
        }
    }
    return allReady;
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) Size(android.util.Size) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) BaseActivity(com.android.launcher3.BaseActivity) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 2 with BaseActivity

use of com.android.launcher3.BaseActivity in project android_packages_apps_Launcher3 by crdroidandroid.

the class OverviewWithoutFocusInputConsumer method onSwipeUp.

@Override
public void onSwipeUp(boolean wasFling, PointF finalVelocity) {
    try {
        mContext.startActivity(mGestureState.getHomeIntent());
    } catch (NullPointerException | ActivityNotFoundException | SecurityException e) {
        mContext.startActivity(createHomeIntent());
    }
    ActiveGestureLog.INSTANCE.addLog("startQuickstep");
    BaseActivity activity = BaseDraggingActivity.fromContext(mContext);
    int state = (mGestureState != null && mGestureState.getEndTarget() != null) ? mGestureState.getEndTarget().containerType : LAUNCHER_STATE_HOME;
    activity.getStatsLogManager().logger().withSrcState(LAUNCHER_STATE_BACKGROUND).withDstState(state).withContainerInfo(LauncherAtom.ContainerInfo.newBuilder().setWorkspace(LauncherAtom.WorkspaceContainer.newBuilder().setPageIndex(-1)).build()).log(LAUNCHER_HOME_GESTURE);
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) BaseActivity(com.android.launcher3.BaseActivity)

Example 3 with BaseActivity

use of com.android.launcher3.BaseActivity in project android_packages_apps_Launcher3 by crdroidandroid.

the class DatabaseWidgetPreviewLoader method generateShortcutPreview.

private Bitmap generateShortcutPreview(BaseActivity launcher, ShortcutConfigActivityInfo info, int maxWidth, int maxHeight, Bitmap preview) {
    int iconSize = launcher.getDeviceProfile().allAppsIconSizePx;
    int padding = launcher.getResources().getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding);
    int size = iconSize + 2 * padding;
    if (maxHeight < size || maxWidth < size) {
        throw new RuntimeException("Max size is too small for preview");
    }
    final Canvas c = new Canvas();
    if (preview == null || preview.getWidth() < size || preview.getHeight() < size) {
        preview = Bitmap.createBitmap(size, size, Config.ARGB_8888);
        c.setBitmap(preview);
    } else {
        if (preview.getWidth() > size || preview.getHeight() > size) {
            preview.reconfigure(size, size, preview.getConfig());
        }
        // Reusing bitmap. Clear it.
        c.setBitmap(preview);
        c.drawColor(0, PorterDuff.Mode.CLEAR);
    }
    drawBoxWithShadow(c, size, size);
    LauncherIcons li = LauncherIcons.obtain(mContext);
    Drawable icon = li.createBadgedIconBitmap(mutateOnMainThread(info.getFullResIcon(mIconCache)), Process.myUserHandle(), 0).newIcon(launcher);
    li.recycle();
    icon.setBounds(padding, padding, padding + iconSize, padding + iconSize);
    icon.draw(c);
    c.setBitmap(null);
    return preview;
}
Also used : LauncherIcons(com.android.launcher3.icons.LauncherIcons) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) Paint(android.graphics.Paint)

Example 4 with BaseActivity

use of com.android.launcher3.BaseActivity in project android_packages_apps_Launcher3 by crdroidandroid.

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 launcher
 * @param info                        information about the widget
 * @param maxPreviewWidth             width of the preview on either workspace or tray
 * @param preview                     bitmap that can be recycled
 * @param preScaledWidthOut           return the width of the returned bitmap
 * @return Pair<Bitmap (the preview) , Boolean (should be stored in db)>
 */
public Pair<Bitmap, Boolean> generateWidgetPreview(BaseActivity launcher, LauncherAppWidgetProviderInfo info, int maxPreviewWidth, Bitmap preview, 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;
    boolean savePreviewImage = widgetPreviewExists || info.previewImage == 0;
    if (widgetPreviewExists && drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0) {
        previewWidth = drawable.getIntrinsicWidth();
        previewHeight = drawable.getIntrinsicHeight();
    } else {
        DeviceProfile dp = launcher.getDeviceProfile();
        Size widgetSize = WidgetSizes.getWidgetPaddedSizePx(mContext, info.provider, dp, spanX, spanY);
        previewWidth = widgetSize.getWidth();
        previewHeight = widgetSize.getHeight();
    }
    // Scale to fit width only - let the widget preview be clipped in the
    // vertical dimension
    float scale = 1f;
    if (preScaledWidthOut != null) {
        preScaledWidthOut[0] = previewWidth;
    }
    if (previewWidth > maxPreviewWidth) {
        scale = maxPreviewWidth / (float) (previewWidth);
    }
    if (scale != 1f) {
        previewWidth = Math.max((int) (scale * previewWidth), 1);
        previewHeight = Math.max((int) (scale * previewHeight), 1);
    }
    final Canvas c = new Canvas();
    if (preview == null) {
        // If no bitmap was provided, then allocate a new one with the right size.
        preview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888);
        c.setBitmap(preview);
    } else {
        // as the preview.
        try {
            preview.reconfigure(previewWidth, previewHeight, preview.getConfig());
        } catch (IllegalArgumentException e) {
            // This occurs if the preview can't be reconfigured for any reason. In this case,
            // allocate a new bitmap with the right size.
            preview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888);
        }
        c.setBitmap(preview);
        c.drawColor(0, PorterDuff.Mode.CLEAR);
    }
    // Draw the scaled preview into the final bitmap
    if (widgetPreviewExists) {
        drawable.setBounds(0, 0, previewWidth, previewHeight);
        drawable.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= */
            previewWidth, /* bottom= */
            previewHeight);
            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, previewWidth, previewHeight);
        }
        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, previewHeight, p);
        }
        t = boxRect.top;
        tileSize = boxRect.height() / spanY;
        for (int i = 1; i < spanY; i++) {
            t += tileSize;
            c.drawLine(0, t, previewWidth, t, p);
        }
        // Draw icon in the center.
        try {
            Drawable icon = mIconCache.getFullResIcon(info.provider.getPackageName(), info.icon);
            if (icon != null) {
                int appIconSize = launcher.getDeviceProfile().iconSizePx;
                int iconSize = (int) Math.min(appIconSize * scale, Math.min(boxRect.width(), boxRect.height()));
                icon = mutateOnMainThread(icon);
                int hoffset = (previewWidth - iconSize) / 2;
                int yoffset = (previewHeight - iconSize) / 2;
                icon.setBounds(hoffset, yoffset, hoffset + iconSize, yoffset + iconSize);
                icon.draw(c);
            }
        } catch (Resources.NotFoundException e) {
            savePreviewImage = false;
        }
        c.setBitmap(null);
    }
    return new Pair<>(preview, savePreviewImage);
}
Also used : Size(android.util.Size) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) Paint(android.graphics.Paint) Paint(android.graphics.Paint) RectF(android.graphics.RectF) DeviceProfile(com.android.launcher3.DeviceProfile) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Resources(android.content.res.Resources) Pair(android.util.Pair)

Example 5 with BaseActivity

use of com.android.launcher3.BaseActivity in project android_packages_apps_Launcher3 by crdroidandroid.

the class DigitalWellBeingToast method openAppUsageSettings.

public void openAppUsageSettings(View view) {
    final Intent intent = new Intent(OPEN_APP_USAGE_SETTINGS_TEMPLATE).putExtra(Intent.EXTRA_PACKAGE_NAME, mTask.getTopComponent().getPackageName()).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    try {
        final BaseActivity activity = BaseActivity.fromContext(view.getContext());
        final ActivityOptions options = ActivityOptions.makeScaleUpAnimation(view, 0, 0, view.getWidth(), view.getHeight());
        activity.startActivity(intent, options.toBundle());
    // TODO: add WW logging on the app usage settings click.
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Failed to open app usage settings for task " + mTask.getTopComponent().getPackageName(), e);
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) BaseActivity(com.android.launcher3.BaseActivity) Intent(android.content.Intent) ActivityOptions(android.app.ActivityOptions)

Aggregations

BaseActivity (com.android.launcher3.BaseActivity)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Canvas (android.graphics.Canvas)2 Paint (android.graphics.Paint)2 Drawable (android.graphics.drawable.Drawable)2 Size (android.util.Size)2 DeviceProfile (com.android.launcher3.DeviceProfile)2 ActivityOptions (android.app.ActivityOptions)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 PorterDuffXfermode (android.graphics.PorterDuffXfermode)1 RectF (android.graphics.RectF)1 Pair (android.util.Pair)1 LauncherIcons (com.android.launcher3.icons.LauncherIcons)1 WidgetItem (com.android.launcher3.model.WidgetItem)1 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)1 WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)1