Search in sources :

Example 11 with FolderInfo

use of com.android.launcher3.FolderInfo 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 12 with FolderInfo

use of com.android.launcher3.FolderInfo 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 13 with FolderInfo

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

the class ItemInfo method buildProto.

/**
 * Creates {@link LauncherAtom.ItemInfo} with important fields and parent container info.
 */
public LauncherAtom.ItemInfo buildProto(FolderInfo fInfo) {
    LauncherAtom.ItemInfo.Builder itemBuilder = getDefaultItemInfoBuilder();
    Optional<ComponentName> nullableComponent = Optional.ofNullable(getTargetComponent());
    switch(itemType) {
        case ITEM_TYPE_APPLICATION:
            itemBuilder.setApplication(nullableComponent.map(component -> LauncherAtom.Application.newBuilder().setComponentName(component.flattenToShortString()).setPackageName(component.getPackageName())).orElse(LauncherAtom.Application.newBuilder()));
            break;
        case ITEM_TYPE_DEEP_SHORTCUT:
            itemBuilder.setShortcut(nullableComponent.map(component -> {
                Shortcut.Builder lsb = Shortcut.newBuilder().setShortcutName(component.flattenToShortString());
                Optional.ofNullable(getIntent()).map(i -> i.getStringExtra(EXTRA_SHORTCUT_ID)).ifPresent(lsb::setShortcutId);
                return lsb;
            }).orElse(LauncherAtom.Shortcut.newBuilder()));
            break;
        case ITEM_TYPE_SHORTCUT:
            itemBuilder.setShortcut(nullableComponent.map(component -> LauncherAtom.Shortcut.newBuilder().setShortcutName(component.flattenToShortString())).orElse(LauncherAtom.Shortcut.newBuilder()));
            break;
        case ITEM_TYPE_APPWIDGET:
            itemBuilder.setWidget(nullableComponent.map(component -> LauncherAtom.Widget.newBuilder().setComponentName(component.flattenToShortString()).setPackageName(component.getPackageName())).orElse(LauncherAtom.Widget.newBuilder()).setSpanX(spanX).setSpanY(spanY));
            break;
        case ITEM_TYPE_TASK:
            itemBuilder.setTask(LauncherAtom.Task.newBuilder().setComponentName(getTargetComponent().flattenToShortString()).setIndex(screenId));
            break;
        default:
            break;
    }
    if (fInfo != null) {
        LauncherAtom.FolderContainer.Builder folderBuilder = LauncherAtom.FolderContainer.newBuilder();
        folderBuilder.setGridX(cellX).setGridY(cellY).setPageIndex(screenId);
        switch(fInfo.container) {
            case CONTAINER_HOTSEAT:
            case CONTAINER_HOTSEAT_PREDICTION:
                folderBuilder.setHotseat(LauncherAtom.HotseatContainer.newBuilder().setIndex(fInfo.screenId));
                break;
            case CONTAINER_DESKTOP:
                folderBuilder.setWorkspace(LauncherAtom.WorkspaceContainer.newBuilder().setPageIndex(fInfo.screenId).setGridX(fInfo.cellX).setGridY(fInfo.cellY));
                break;
        }
        itemBuilder.setContainerInfo(ContainerInfo.newBuilder().setFolder(folderBuilder));
    } else {
        ContainerInfo containerInfo = getContainerInfo();
        if (!containerInfo.getContainerCase().equals(CONTAINER_NOT_SET)) {
            itemBuilder.setContainerInfo(containerInfo);
        }
    }
    return itemBuilder.build();
}
Also used : ContainerInfo(com.android.launcher3.logger.LauncherAtom.ContainerInfo) CONTAINER_WIDGETS_TRAY(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY) ITEM_TYPE_APPLICATION(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) Intent(android.content.Intent) LauncherSettings(com.android.launcher3.LauncherSettings) Process(android.os.Process) AllAppsContainer(com.android.launcher3.logger.LauncherAtom.AllAppsContainer) SearchResultContainer(com.android.launcher3.logger.LauncherAtom.SearchResultContainer) CONTAINER_TASKSWITCHER(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_TASKSWITCHER) CONTAINER_HOTSEAT(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT) LauncherAtom(com.android.launcher3.logger.LauncherAtom) ITEM_TYPE_APPWIDGET(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) UserHandle(android.os.UserHandle) TaskSwitcherContainer(com.android.launcher3.logger.LauncherAtom.TaskSwitcherContainer) ExtendedContainers(com.android.launcher3.logger.LauncherAtomExtensions.ExtendedContainers) Shortcut(com.android.launcher3.logger.LauncherAtom.Shortcut) EXTRA_SHORTCUT_ID(com.android.launcher3.shortcuts.ShortcutKey.EXTRA_SHORTCUT_ID) Favorites(com.android.launcher3.LauncherSettings.Favorites) ComponentName(android.content.ComponentName) CONTAINER_SHORTCUTS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS) ITEM_TYPE_DEEP_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) ITEM_TYPE_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) CONTAINER_DESKTOP(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP) CONTAINER_SEARCH_RESULTS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SEARCH_RESULTS) CONTAINER_HOTSEAT_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) ShortcutsContainer(com.android.launcher3.logger.LauncherAtom.ShortcutsContainer) Nullable(androidx.annotation.Nullable) PredictionContainer(com.android.launcher3.logger.LauncherAtom.PredictionContainer) ITEM_TYPE_TASK(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_TASK) ContentWriter(com.android.launcher3.util.ContentWriter) EXTENDED_CONTAINERS(com.android.launcher3.LauncherSettings.Favorites.EXTENDED_CONTAINERS) CONTAINER_SETTINGS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SETTINGS) CONTAINER_NOT_SET(com.android.launcher3.logger.LauncherAtom.ContainerInfo.ContainerCase.CONTAINER_NOT_SET) Optional(java.util.Optional) Workspace(com.android.launcher3.Workspace) CONTAINER_ALL_APPS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APPS) ContentValues(android.content.ContentValues) CONTAINER_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_PREDICTION) SettingsContainer(com.android.launcher3.logger.LauncherAtom.SettingsContainer) ModelWriter(com.android.launcher3.model.ModelWriter) Shortcut(com.android.launcher3.logger.LauncherAtom.Shortcut) ContainerInfo(com.android.launcher3.logger.LauncherAtom.ContainerInfo) ComponentName(android.content.ComponentName)

Example 14 with FolderInfo

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

the class DefaultLayoutProviderTest method testCustomProfileLoaded_with_folder_custom_title.

@Test
public void testCustomProfileLoaded_with_folder_custom_title() throws Exception {
    writeLayoutAndLoad(new LauncherLayoutBuilder().atHotseat(0).putFolder("CustomFolder").addApp(TEST_PACKAGE, TEST_PACKAGE).addApp(TEST_PACKAGE, TEST_PACKAGE).addApp(TEST_PACKAGE, TEST_PACKAGE).build());
    // Verify folder
    assertEquals(1, mModelHelper.getBgDataModel().workspaceItems.size());
    ItemInfo info = mModelHelper.getBgDataModel().workspaceItems.get(0);
    assertEquals(LauncherSettings.Favorites.ITEM_TYPE_FOLDER, info.itemType);
    assertEquals(3, ((FolderInfo) info).contents.size());
    assertEquals("CustomFolder", info.title.toString());
}
Also used : LauncherLayoutBuilder(com.android.launcher3.util.LauncherLayoutBuilder) ItemInfo(com.android.launcher3.model.data.ItemInfo) FolderInfo(com.android.launcher3.model.data.FolderInfo) Test(org.junit.Test)

Example 15 with FolderInfo

use of com.android.launcher3.FolderInfo in project android_packages_apps_Launcher3 by AOSPA.

the class ItemClickHandler method onClick.

private static void onClick(View v) {
    // view has detached (it's possible for this to happen if the view is removed mid touch).
    if (v.getWindowToken() == null)
        return;
    Launcher launcher = Launcher.getLauncher(v.getContext());
    if (!launcher.getWorkspace().isFinishedSwitchingState())
        return;
    Object tag = v.getTag();
    if (tag instanceof WorkspaceItemInfo) {
        onClickAppShortcut(v, (WorkspaceItemInfo) tag, launcher);
    } else if (tag instanceof FolderInfo) {
        if (v instanceof FolderIcon) {
            onClickFolderIcon(v);
        }
    } else if (tag instanceof AppInfo) {
        startAppShortcutOrInfoActivity(v, (AppInfo) tag, launcher);
    } else if (tag instanceof LauncherAppWidgetInfo) {
        if (v instanceof PendingAppWidgetHostView) {
            onClickPendingWidget((PendingAppWidgetHostView) v, launcher);
        }
    } else if (tag instanceof SearchActionItemInfo) {
        onClickSearchAction(launcher, (SearchActionItemInfo) tag);
    }
}
Also used : FolderIcon(com.android.launcher3.folder.FolderIcon) Launcher(com.android.launcher3.Launcher) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) FolderInfo(com.android.launcher3.model.data.FolderInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) AppInfo(com.android.launcher3.model.data.AppInfo)

Aggregations

FolderInfo (com.android.launcher3.model.data.FolderInfo)152 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)121 ItemInfo (com.android.launcher3.model.data.ItemInfo)100 View (android.view.View)98 FolderIcon (com.android.launcher3.folder.FolderIcon)73 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)65 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)61 ArrayList (java.util.ArrayList)59 AppWidgetHostView (android.appwidget.AppWidgetHostView)55 DragView (com.android.launcher3.dragndrop.DragView)51 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)50 Point (android.graphics.Point)47 AppInfo (com.android.launcher3.model.data.AppInfo)41 SuppressLint (android.annotation.SuppressLint)39 Rect (android.graphics.Rect)28 Folder (com.android.launcher3.folder.Folder)28 IntArray (com.android.launcher3.util.IntArray)28 HashSet (java.util.HashSet)28 UserHandle (android.os.UserHandle)27 Intent (android.content.Intent)26