Search in sources :

Example 21 with Folder

use of com.android.launcher3.tapl.Folder in project android_packages_apps_Launcher3 by crdroidandroid.

the class Utilities method getBadge.

/**
 * For apps icons and shortcut icons that have badges, this method creates a drawable that can
 * later on be rendered on top of the layers for the badges. For app icons, work profile badges
 * can only be applied. For deep shortcuts, when dragged from the pop up container, there's no
 * badge. When dragged from workspace or folder, it may contain app AND/OR work profile badge
 */
@TargetApi(Build.VERSION_CODES.O)
public static Drawable getBadge(Launcher launcher, ItemInfo info, Object obj) {
    LauncherAppState appState = LauncherAppState.getInstance(launcher);
    int iconSize = appState.getInvariantDeviceProfile().iconBitmapSize;
    if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
        boolean iconBadged = (info instanceof ItemInfoWithIcon) && (((ItemInfoWithIcon) info).runtimeStatusFlags & FLAG_ICON_BADGED) > 0;
        if ((info.id == ItemInfo.NO_ID && !iconBadged) || !(obj instanceof ShortcutInfo)) {
            // The item is not yet added on home screen.
            return new FixedSizeEmptyDrawable(iconSize);
        }
        ShortcutInfo si = (ShortcutInfo) obj;
        Bitmap badge = LauncherAppState.getInstance(appState.getContext()).getIconCache().getShortcutInfoBadge(si).icon;
        float badgeSize = LauncherIcons.getBadgeSizeForIconSize(iconSize);
        float insetFraction = (iconSize - badgeSize) / iconSize;
        return new InsetDrawable(new FastBitmapDrawable(badge), insetFraction, insetFraction, 0, 0);
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
        return ((FolderAdaptiveIcon) obj).getBadge();
    } else {
        return launcher.getPackageManager().getUserBadgedIcon(new FixedSizeEmptyDrawable(iconSize), info.user);
    }
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Bitmap(android.graphics.Bitmap) ShortcutInfo(android.content.pm.ShortcutInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) InsetDrawable(android.graphics.drawable.InsetDrawable) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) Paint(android.graphics.Paint) Point(android.graphics.Point) TargetApi(android.annotation.TargetApi)

Example 22 with Folder

use of com.android.launcher3.tapl.Folder 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 23 with Folder

use of com.android.launcher3.tapl.Folder 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 24 with Folder

use of com.android.launcher3.tapl.Folder 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 25 with Folder

use of com.android.launcher3.tapl.Folder in project android_packages_apps_Launcher3 by crdroidandroid.

the class LauncherUIScrollTest method testFolderPageScroll.

@Test
public void testFolderPageScroll() throws Exception {
    // Add a folder with multiple icons
    FolderBuilder fb = mLayoutBuilder.atWorkspace(mIdp.numColumns / 2, mIdp.numRows / 2, 0).putFolder(0);
    for (int i = 0; i < 100; i++) {
        fb.addApp(TEST_PACKAGE, TEST_PACKAGE);
    }
    // Bind and open folder
    Launcher launcher = loadLauncher();
    doLayout(launcher);
    launcher.getWorkspace().getFirstMatch((i, v) -> v instanceof FolderIcon).performClick();
    ShadowLooper.idleMainLooper();
    doLayout(launcher);
    FolderPagedView folderPages = Folder.getOpen(launcher).getContent();
    assertEquals(0, folderPages.getNextPage());
    launcher.dispatchGenericMotionEvent(createScrollEvent(-1));
    assertNotEquals("Folder page was not scrolled", 0, folderPages.getNextPage());
    assertEquals("Workspace was scrolled", 0, launcher.getWorkspace().getNextPage());
}
Also used : Folder(com.android.launcher3.folder.Folder) Context(android.content.Context) WidgetsFullSheet(com.android.launcher3.widget.picker.WidgetsFullSheet) PointerProperties(android.view.MotionEvent.PointerProperties) LauncherLayoutBuilder(com.android.launcher3.util.LauncherLayoutBuilder) FolderIcon(com.android.launcher3.folder.FolderIcon) RunWith(org.junit.runner.RunWith) LauncherUIHelper.buildAndBindLauncher(com.android.launcher3.util.LauncherUIHelper.buildAndBindLauncher) SystemClock(android.os.SystemClock) Mode(org.robolectric.annotation.LooperMode.Mode) InputDevice(android.view.InputDevice) MotionEvent(android.view.MotionEvent) TEST_PACKAGE(com.android.launcher3.util.LauncherModelHelper.TEST_PACKAGE) Settings(android.provider.Settings) FolderPagedView(com.android.launcher3.folder.FolderPagedView) Before(org.junit.Before) Launcher(com.android.launcher3.Launcher) LauncherModelHelper(com.android.launcher3.util.LauncherModelHelper) ShadowLooper(org.robolectric.shadows.ShadowLooper) Test(org.junit.Test) LooperMode(org.robolectric.annotation.LooperMode) RuntimeEnvironment(org.robolectric.RuntimeEnvironment) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) DeviceProfile(com.android.launcher3.DeviceProfile) LauncherState(com.android.launcher3.LauncherState) FolderBuilder(com.android.launcher3.util.LauncherLayoutBuilder.FolderBuilder) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) LauncherUIHelper.doLayout(com.android.launcher3.util.LauncherUIHelper.doLayout) Assert.assertEquals(org.junit.Assert.assertEquals) FolderPagedView(com.android.launcher3.folder.FolderPagedView) FolderBuilder(com.android.launcher3.util.LauncherLayoutBuilder.FolderBuilder) FolderIcon(com.android.launcher3.folder.FolderIcon) LauncherUIHelper.buildAndBindLauncher(com.android.launcher3.util.LauncherUIHelper.buildAndBindLauncher) Launcher(com.android.launcher3.Launcher) Test(org.junit.Test)

Aggregations

View (android.view.View)119 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)112 FolderInfo (com.android.launcher3.model.data.FolderInfo)93 ItemInfo (com.android.launcher3.model.data.ItemInfo)86 Point (android.graphics.Point)83 FolderIcon (com.android.launcher3.folder.FolderIcon)83 Folder (com.android.launcher3.folder.Folder)82 AppWidgetHostView (android.appwidget.AppWidgetHostView)80 SuppressLint (android.annotation.SuppressLint)73 DragView (com.android.launcher3.dragndrop.DragView)64 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)64 Rect (android.graphics.Rect)63 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)61 BubbleTextView (com.android.launcher3.BubbleTextView)56 ArrayList (java.util.ArrayList)49 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)47 Animator (android.animation.Animator)40 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)40 Drawable (android.graphics.drawable.Drawable)37 CellLayout (com.android.launcher3.CellLayout)37