Search in sources :

Example 21 with WorkspaceItemInfo

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

the class TaskbarActivityContext method onTaskbarIconClicked.

protected void onTaskbarIconClicked(View view) {
    Object tag = view.getTag();
    if (tag instanceof Task) {
        Task task = (Task) tag;
        ActivityManagerWrapper.getInstance().startActivityFromRecents(task.key, ActivityOptions.makeBasic());
    } else if (tag instanceof FolderInfo) {
        FolderIcon folderIcon = (FolderIcon) view;
        Folder folder = folderIcon.getFolder();
        setTaskbarWindowFullscreen(true);
        getDragLayer().post(() -> {
            folder.animateOpen();
            folder.iterateOverItems((itemInfo, itemView) -> {
                itemView.setOnClickListener(mOnTaskbarIconClickListener);
                itemView.setOnLongClickListener(mOnTaskbarIconLongClickListener);
                // To play haptic when dragging, like other Taskbar items do.
                itemView.setHapticFeedbackEnabled(true);
                return false;
            });
        });
    } else if (tag instanceof WorkspaceItemInfo) {
        WorkspaceItemInfo info = (WorkspaceItemInfo) tag;
        if (!(info.isDisabled() && ItemClickHandler.handleDisabledItemClicked(info, this))) {
            Intent intent = new Intent(info.getIntent()).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try {
                if (mIsSafeModeEnabled && !PackageManagerHelper.isSystemApp(this, intent)) {
                    Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
                } else if (info.isPromise()) {
                    intent = new PackageManagerHelper(this).getMarketIntent(info.getTargetPackage()).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                } else if (info.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                    String id = info.getDeepShortcutId();
                    String packageName = intent.getPackage();
                    getSystemService(LauncherApps.class).startShortcut(packageName, id, null, null, info.user);
                } else if (info.user.equals(Process.myUserHandle())) {
                    startActivity(intent);
                } else {
                    getSystemService(LauncherApps.class).startMainActivity(intent.getComponent(), info.user, intent.getSourceBounds(), null);
                }
            } catch (NullPointerException | ActivityNotFoundException | SecurityException e) {
                Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
                Log.e(TAG, "Unable to launch. tag=" + info + " intent=" + intent, e);
            }
        }
    } else {
        Log.e(TAG, "Unknown type clicked: " + tag);
    }
    AbstractFloatingView.closeAllOpenViews(this);
}
Also used : Rect(android.graphics.Rect) Task(com.android.systemui.shared.recents.model.Task) NonNull(androidx.annotation.NonNull) WindowManager(android.view.WindowManager) Drawable(android.graphics.drawable.Drawable) DraggableView(com.android.launcher3.dragndrop.DraggableView) Process(android.os.Process) ITYPE_BOTTOM_TAPPABLE_ELEMENT(com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_BOTTOM_TAPPABLE_ELEMENT) ActivityOptions(android.app.ActivityOptions) ActivityManagerWrapper(com.android.systemui.shared.system.ActivityManagerWrapper) WindowManagerWrapper(com.android.systemui.shared.system.WindowManagerWrapper) LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS(android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) TYPE_APPLICATION_OVERLAY(android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY) ContextThemeWrapper(android.view.ContextThemeWrapper) FolderInfo(com.android.launcher3.model.data.FolderInfo) Display(android.view.Display) View(android.view.View) Log(android.util.Log) SysUINavigationMode(com.android.quickstep.SysUINavigationMode) Favorites(com.android.launcher3.LauncherSettings.Favorites) Mode(com.android.quickstep.SysUINavigationMode.Mode) LauncherApps(android.content.pm.LauncherApps) DeviceProfile(com.android.launcher3.DeviceProfile) DragOptions(com.android.launcher3.dragndrop.DragOptions) Nullable(androidx.annotation.Nullable) ActivityNotFoundException(android.content.ActivityNotFoundException) ITYPE_EXTRA_NAVIGATION_BAR(com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_EXTRA_NAVIGATION_BAR) Themes(com.android.launcher3.util.Themes) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) Folder(com.android.launcher3.folder.Folder) Context(android.content.Context) ItemInfo(com.android.launcher3.model.data.ItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) Intent(android.content.Intent) PixelFormat(android.graphics.PixelFormat) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Toast(android.widget.Toast) DragSource(com.android.launcher3.DragSource) ActivityContext(com.android.launcher3.views.ActivityContext) LayoutInflater(android.view.LayoutInflater) DropTarget(com.android.launcher3.DropTarget) DragController(com.android.launcher3.dragndrop.DragController) MATCH_PARENT(android.view.ViewGroup.LayoutParams.MATCH_PARENT) Point(android.graphics.Point) TaskbarButton(com.android.launcher3.taskbar.TaskbarNavButtonController.TaskbarButton) ItemClickHandler(com.android.launcher3.touch.ItemClickHandler) SystemProperties(android.os.SystemProperties) Gravity(android.view.Gravity) R(com.android.launcher3.R) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) DragView(com.android.launcher3.dragndrop.DragView) TraceHelper(com.android.launcher3.util.TraceHelper) Task(com.android.systemui.shared.recents.model.Task) Intent(android.content.Intent) LauncherApps(android.content.pm.LauncherApps) Folder(com.android.launcher3.folder.Folder) FolderInfo(com.android.launcher3.model.data.FolderInfo) ActivityNotFoundException(android.content.ActivityNotFoundException) FolderIcon(com.android.launcher3.folder.FolderIcon) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 22 with WorkspaceItemInfo

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

the class TaskbarView method updateHotseatItems.

/**
 * Inflates/binds the Hotseat views to show in the Taskbar given their ItemInfos.
 */
protected void updateHotseatItems(ItemInfo[] hotseatItemInfos) {
    for (int i = 0; i < hotseatItemInfos.length; i++) {
        ItemInfo hotseatItemInfo = hotseatItemInfos[!mIsRtl ? i : hotseatItemInfos.length - i - 1];
        View hotseatView = mHotseatIconsContainer.getChildAt(i);
        // Replace any Hotseat views with the appropriate type if it's not already that type.
        final int expectedLayoutResId;
        boolean isFolder = false;
        boolean needsReinflate = false;
        if (hotseatItemInfo != null && hotseatItemInfo.isPredictedItem()) {
            expectedLayoutResId = R.layout.taskbar_predicted_app_icon;
        } else if (hotseatItemInfo instanceof FolderInfo) {
            expectedLayoutResId = R.layout.folder_icon;
            isFolder = true;
            // Unlike for BubbleTextView, we can't reapply a new FolderInfo after inflation, so
            // if the info changes we need to reinflate. This should only happen if a new folder
            // is dragged to the position that another folder previously existed.
            needsReinflate = hotseatView != null && hotseatView.getTag() != hotseatItemInfo;
        } else {
            expectedLayoutResId = R.layout.taskbar_app_icon;
        }
        if (hotseatView == null || hotseatView.getSourceLayoutResId() != expectedLayoutResId || needsReinflate) {
            mHotseatIconsContainer.removeView(hotseatView);
            if (isFolder) {
                FolderInfo folderInfo = (FolderInfo) hotseatItemInfo;
                FolderIcon folderIcon = FolderIcon.inflateFolderAndIcon(expectedLayoutResId, mActivityContext, this, folderInfo);
                folderIcon.setTextVisible(false);
                hotseatView = folderIcon;
            } else {
                hotseatView = inflate(expectedLayoutResId);
            }
            int iconSize = mActivityContext.getDeviceProfile().iconSizePx;
            LayoutParams lp = new LayoutParams(iconSize, iconSize);
            lp.setMargins(mItemMarginLeftRight, 0, mItemMarginLeftRight, 0);
            mHotseatIconsContainer.addView(hotseatView, i, lp);
        }
        // Apply the Hotseat ItemInfos, or hide the view if there is none for a given index.
        if (hotseatView instanceof BubbleTextView && hotseatItemInfo instanceof WorkspaceItemInfo) {
            ((BubbleTextView) hotseatView).applyFromWorkspaceItem((WorkspaceItemInfo) hotseatItemInfo);
            hotseatView.setOnClickListener(mIconClickListener);
            hotseatView.setOnLongClickListener(mIconLongClickListener);
        } else if (isFolder) {
            hotseatView.setOnClickListener(mIconClickListener);
            hotseatView.setOnLongClickListener(mIconLongClickListener);
        } else {
            hotseatView.setOnClickListener(null);
            hotseatView.setOnLongClickListener(null);
            hotseatView.setTag(null);
        }
        updateHotseatItemVisibility(hotseatView);
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) BubbleTextView(com.android.launcher3.BubbleTextView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) FolderInfo(com.android.launcher3.model.data.FolderInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 23 with WorkspaceItemInfo

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

the class PredictedAppIcon method updateRingPath.

private void updateRingPath() {
    boolean isBadged = false;
    if (getTag() instanceof WorkspaceItemInfo) {
        WorkspaceItemInfo info = (WorkspaceItemInfo) getTag();
        isBadged = !Process.myUserHandle().equals(info.user) || info.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT || info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
    }
    mRingPath.reset();
    mTmpMatrix.setTranslate(getOutlineOffsetX(), getOutlineOffsetY());
    mRingPath.addPath(mShapePath, mTmpMatrix);
    if (isBadged) {
        float outlineSize = mNormalizedIconSize * RING_EFFECT_RATIO;
        float iconSize = getIconSize() * (1 - 2 * RING_EFFECT_RATIO);
        float badgeSize = LauncherIcons.getBadgeSizeForIconSize((int) iconSize) + outlineSize;
        float scale = badgeSize / mNormalizedIconSize;
        mTmpMatrix.postTranslate(mNormalizedIconSize, mNormalizedIconSize);
        mTmpMatrix.preScale(scale, scale);
        mTmpMatrix.preTranslate(-mNormalizedIconSize, -mNormalizedIconSize);
        mRingPath.addPath(mShapePath, mTmpMatrix);
    }
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 24 with WorkspaceItemInfo

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

the class PopupPopulator method createUpdateRunnable.

/**
 * Returns a runnable to update the provided shortcuts and notifications
 */
public static Runnable createUpdateRunnable(final BaseDraggingActivity launcher, 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(launcher, sbn, originalInfo)).collect(Collectors.toList());
            }
            uiHandler.post(() -> container.applyNotificationInfos(infos));
        }
        List<ShortcutInfo> shortcuts = new ShortcutRequest(launcher, user).withContainer(activity).query(ShortcutRequest.PUBLISHED);
        String shortcutIdToDeDupe = notificationKeys.isEmpty() ? null : notificationKeys.get(0).shortcutId;
        shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, shortcutIdToDeDupe);
        IconCache cache = LauncherAppState.getInstance(launcher).getIconCache();
        for (int i = 0; i < shortcuts.size() && i < shortcutViews.size(); i++) {
            final ShortcutInfo shortcut = shortcuts.get(i);
            final WorkspaceItemInfo si = new WorkspaceItemInfo(shortcut, launcher);
            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 : Iterator(java.util.Iterator) 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) BaseDraggingActivity(com.android.launcher3.BaseDraggingActivity) 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 25 with WorkspaceItemInfo

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

the class PackageUpdatedTask method updateWorkspaceItemIntent.

/**
 * Updates {@param si}'s intent to point to a new ComponentName.
 * @return Whether the shortcut intent was changed.
 */
private boolean updateWorkspaceItemIntent(Context context, WorkspaceItemInfo si, String packageName) {
    if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
        // about the shortcut.
        return false;
    }
    // Try to find the best match activity.
    Intent intent = new PackageManagerHelper(context).getAppLaunchIntent(packageName, mUser);
    if (intent != null) {
        si.intent = intent;
        si.status = WorkspaceItemInfo.DEFAULT;
        return true;
    }
    return false;
}
Also used : Intent(android.content.Intent) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)418 View (android.view.View)168 ArrayList (java.util.ArrayList)145 ItemInfo (com.android.launcher3.model.data.ItemInfo)125 Intent (android.content.Intent)119 FolderInfo (com.android.launcher3.model.data.FolderInfo)100 AppInfo (com.android.launcher3.model.data.AppInfo)94 BubbleTextView (com.android.launcher3.BubbleTextView)87 AppWidgetHostView (android.appwidget.AppWidgetHostView)84 SuppressLint (android.annotation.SuppressLint)78 DragView (com.android.launcher3.dragndrop.DragView)78 ComponentName (android.content.ComponentName)76 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)73 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)72 Rect (android.graphics.Rect)68 FolderIcon (com.android.launcher3.folder.FolderIcon)68 Context (android.content.Context)62 HashSet (java.util.HashSet)62 Point (android.graphics.Point)59 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)57