Search in sources :

Example 1 with ActivityContext

use of com.android.launcher3.views.ActivityContext in project android_packages_apps_Launcher3 by crdroidandroid.

the class PreviewBackground method setup.

public void setup(Context context, ActivityContext activity, View invalidateDelegate, int availableSpaceX, int topPadding) {
    mInvalidateDelegate = invalidateDelegate;
    TypedArray ta = context.getTheme().obtainStyledAttributes(R.styleable.FolderIconPreview);
    mDotColor = ta.getColor(R.styleable.FolderIconPreview_folderDotColor, 0);
    mStrokeColor = ta.getColor(R.styleable.FolderIconPreview_folderIconBorderColor, 0);
    mBgColor = ta.getColor(R.styleable.FolderIconPreview_folderFillColor, 0);
    ta.recycle();
    DeviceProfile grid = activity.getDeviceProfile();
    previewSize = grid.folderIconSizePx;
    basePreviewOffsetX = (availableSpaceX - previewSize) / 2;
    basePreviewOffsetY = topPadding + grid.folderIconOffsetYPx;
    // Stroke width is 1dp
    mStrokeWidth = context.getResources().getDisplayMetrics().density;
    if (DRAW_SHADOW) {
        float radius = getScaledRadius();
        float shadowRadius = radius + mStrokeWidth;
        int shadowColor = Color.argb(SHADOW_OPACITY, 0, 0, 0);
        mShadowShader = new RadialGradient(0, 0, 1, new int[] { shadowColor, Color.TRANSPARENT }, new float[] { radius / shadowRadius, 1 }, Shader.TileMode.CLAMP);
    }
    invalidate();
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) TypedArray(android.content.res.TypedArray) RadialGradient(android.graphics.RadialGradient) Paint(android.graphics.Paint)

Example 2 with ActivityContext

use of com.android.launcher3.views.ActivityContext in project android_packages_apps_Launcher3 by AOSPA.

the class PopupPopulator method createUpdateRunnable.

/**
 * Returns a runnable to update the provided shortcuts and notifications
 */
public static <T extends Context & ActivityContext> Runnable createUpdateRunnable(final T context, final ItemInfo originalInfo, final Handler uiHandler, final PopupContainerWithArrow container, final List<DeepShortcutView> shortcutViews, final List<NotificationKeyData> notificationKeys) {
    final ComponentName activity = originalInfo.getTargetComponent();
    final UserHandle user = originalInfo.user;
    return () -> {
        if (!notificationKeys.isEmpty()) {
            NotificationListener notificationListener = NotificationListener.getInstanceIfConnected();
            final List<NotificationInfo> infos;
            if (notificationListener == null) {
                infos = Collections.emptyList();
            } else {
                infos = notificationListener.getNotificationsForKeys(notificationKeys).stream().map(sbn -> new NotificationInfo(context, sbn, originalInfo)).collect(Collectors.toList());
            }
            uiHandler.post(() -> container.applyNotificationInfos(infos));
        }
        List<ShortcutInfo> shortcuts = new ShortcutRequest(context, user).withContainer(activity).query(ShortcutRequest.PUBLISHED);
        String shortcutIdToDeDupe = notificationKeys.isEmpty() ? null : notificationKeys.get(0).shortcutId;
        shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, shortcutIdToDeDupe);
        IconCache cache = LauncherAppState.getInstance(context).getIconCache();
        for (int i = 0; i < shortcuts.size() && i < shortcutViews.size(); i++) {
            final ShortcutInfo shortcut = shortcuts.get(i);
            final WorkspaceItemInfo si = new WorkspaceItemInfo(shortcut, context);
            cache.getUnbadgedShortcutIcon(si, shortcut);
            si.rank = i;
            si.container = CONTAINER_SHORTCUTS;
            final DeepShortcutView view = shortcutViews.get(i);
            uiHandler.post(() -> view.applyShortcutInfo(si, shortcut, container));
        }
    };
}
Also used : Context(android.content.Context) Iterator(java.util.Iterator) ActivityContext(com.android.launcher3.views.ActivityContext) ComponentName(android.content.ComponentName) ShortcutInfo(android.content.pm.ShortcutInfo) CONTAINER_SHORTCUTS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS) LauncherAppState(com.android.launcher3.LauncherAppState) ItemInfo(com.android.launcher3.model.data.ItemInfo) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) IconCache(com.android.launcher3.icons.IconCache) Collectors(java.util.stream.Collectors) NotificationInfo(com.android.launcher3.notification.NotificationInfo) NotificationKeyData(com.android.launcher3.notification.NotificationKeyData) ArrayList(java.util.ArrayList) List(java.util.List) Nullable(androidx.annotation.Nullable) NotificationListener(com.android.launcher3.notification.NotificationListener) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Handler(android.os.Handler) UserHandle(android.os.UserHandle) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) Comparator(java.util.Comparator) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) NotificationInfo(com.android.launcher3.notification.NotificationInfo) ShortcutInfo(android.content.pm.ShortcutInfo) UserHandle(android.os.UserHandle) IconCache(com.android.launcher3.icons.IconCache) ComponentName(android.content.ComponentName) ArrayList(java.util.ArrayList) List(java.util.List) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) NotificationListener(com.android.launcher3.notification.NotificationListener) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 3 with ActivityContext

use of com.android.launcher3.views.ActivityContext in project android_packages_apps_Launcher3 by AOSPA.

the class LauncherBindableItemsContainer method updateWorkspaceItems.

/**
 * Called to update workspace items as a result of
 * {@link com.android.launcher3.model.BgDataModel.Callbacks#bindWorkspaceItemsChanged(List)}
 */
default void updateWorkspaceItems(List<WorkspaceItemInfo> shortcuts, ActivityContext context) {
    final HashSet<WorkspaceItemInfo> updates = new HashSet<>(shortcuts);
    ItemOperator op = (info, v) -> {
        if (v instanceof BubbleTextView && updates.contains(info)) {
            WorkspaceItemInfo si = (WorkspaceItemInfo) info;
            BubbleTextView shortcut = (BubbleTextView) v;
            Drawable oldIcon = shortcut.getIcon();
            boolean oldPromiseState = (oldIcon instanceof PreloadIconDrawable) && ((PreloadIconDrawable) oldIcon).hasNotCompleted();
            shortcut.applyFromWorkspaceItem(si, si.isPromise() != oldPromiseState);
        } else if (info instanceof FolderInfo && v instanceof FolderIcon) {
            ((FolderIcon) v).updatePreviewItems(updates::contains);
        }
        // Iterate all items
        return false;
    };
    mapOverItems(op);
    Folder openFolder = Folder.getOpen(context);
    if (openFolder != null) {
        openFolder.iterateOverItems(op);
    }
}
Also used : Folder(com.android.launcher3.folder.Folder) ActivityContext(com.android.launcher3.views.ActivityContext) ItemInfo(com.android.launcher3.model.data.ItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) Drawable(android.graphics.drawable.Drawable) BubbleTextView(com.android.launcher3.BubbleTextView) HashSet(java.util.HashSet) List(java.util.List) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) FolderInfo(com.android.launcher3.model.data.FolderInfo) View(android.view.View) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) FolderIcon(com.android.launcher3.folder.FolderIcon) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) BubbleTextView(com.android.launcher3.BubbleTextView) Folder(com.android.launcher3.folder.Folder) FolderInfo(com.android.launcher3.model.data.FolderInfo) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) HashSet(java.util.HashSet)

Example 4 with ActivityContext

use of com.android.launcher3.views.ActivityContext in project android_packages_apps_Launcher3 by AOSPA.

the class PreviewBackground method setup.

public void setup(Context context, ActivityContext activity, View invalidateDelegate, int availableSpaceX, int topPadding) {
    mInvalidateDelegate = invalidateDelegate;
    TypedArray ta = context.getTheme().obtainStyledAttributes(R.styleable.FolderIconPreview);
    mDotColor = ta.getColor(R.styleable.FolderIconPreview_folderDotColor, 0);
    mStrokeColor = ta.getColor(R.styleable.FolderIconPreview_folderIconBorderColor, 0);
    mBgColor = ta.getColor(R.styleable.FolderIconPreview_folderPreviewColor, 0);
    ta.recycle();
    DeviceProfile grid = activity.getDeviceProfile();
    previewSize = grid.folderIconSizePx;
    basePreviewOffsetX = (availableSpaceX - previewSize) / 2;
    basePreviewOffsetY = topPadding + grid.folderIconOffsetYPx;
    // Stroke width is 1dp
    mStrokeWidth = context.getResources().getDisplayMetrics().density;
    if (DRAW_SHADOW) {
        float radius = getScaledRadius();
        float shadowRadius = radius + mStrokeWidth;
        int shadowColor = Color.argb(SHADOW_OPACITY, 0, 0, 0);
        mShadowShader = new RadialGradient(0, 0, 1, new int[] { shadowColor, Color.TRANSPARENT }, new float[] { radius / shadowRadius, 1 }, Shader.TileMode.CLAMP);
    }
    invalidate();
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) TypedArray(android.content.res.TypedArray) RadialGradient(android.graphics.RadialGradient) Paint(android.graphics.Paint)

Example 5 with ActivityContext

use of com.android.launcher3.views.ActivityContext in project android_packages_apps_Trebuchet by LineageOS.

the class PreviewBackground method setup.

public void setup(Context context, ActivityContext activity, View invalidateDelegate, int availableSpaceX, int topPadding) {
    mInvalidateDelegate = invalidateDelegate;
    TypedArray ta = context.getTheme().obtainStyledAttributes(R.styleable.FolderIconPreview);
    mDotColor = ta.getColor(R.styleable.FolderIconPreview_folderDotColor, 0);
    mStrokeColor = ta.getColor(R.styleable.FolderIconPreview_folderIconBorderColor, 0);
    mBgColor = ta.getColor(R.styleable.FolderIconPreview_folderFillColor, 0);
    ta.recycle();
    DeviceProfile grid = activity.getDeviceProfile();
    previewSize = grid.folderIconSizePx;
    basePreviewOffsetX = (availableSpaceX - previewSize) / 2;
    basePreviewOffsetY = topPadding + grid.folderIconOffsetYPx;
    // Stroke width is 1dp
    mStrokeWidth = context.getResources().getDisplayMetrics().density;
    float radius = getScaledRadius();
    float shadowRadius = radius + mStrokeWidth;
    int shadowColor = Color.argb(SHADOW_OPACITY, 0, 0, 0);
    mShadowShader = new RadialGradient(0, 0, 1, new int[] { shadowColor, Color.TRANSPARENT }, new float[] { radius / shadowRadius, 1 }, Shader.TileMode.CLAMP);
    invalidate();
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) TypedArray(android.content.res.TypedArray) RadialGradient(android.graphics.RadialGradient) Paint(android.graphics.Paint)

Aggregations

ActivityContext (com.android.launcher3.views.ActivityContext)19 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)18 List (java.util.List)16 DeviceProfile (com.android.launcher3.DeviceProfile)15 ItemInfo (com.android.launcher3.model.data.ItemInfo)12 View (android.view.View)9 Drawable (android.graphics.drawable.Drawable)8 BubbleTextView (com.android.launcher3.BubbleTextView)8 Folder (com.android.launcher3.folder.Folder)8 FolderIcon (com.android.launcher3.folder.FolderIcon)8 PreloadIconDrawable (com.android.launcher3.graphics.PreloadIconDrawable)8 FolderInfo (com.android.launcher3.model.data.FolderInfo)8 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)8 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)8 HashSet (java.util.HashSet)8 TypedArray (android.content.res.TypedArray)7 Paint (android.graphics.Paint)7 RadialGradient (android.graphics.RadialGradient)7 FrameLayout (android.widget.FrameLayout)6 FolderDotInfo (com.android.launcher3.dot.FolderDotInfo)6