Search in sources :

Example 61 with Folder

use of com.android.launcher3.tapl.Folder in project android_packages_apps_Trebuchet by LineageOS.

the class DragView method setItemInfo.

/**
 * Initialize {@code #mIconDrawable} if the item can be represented using
 * an {@link AdaptiveIconDrawable} or {@link FolderAdaptiveIcon}.
 */
@TargetApi(Build.VERSION_CODES.O)
public void setItemInfo(final ItemInfo info) {
    if (!Utilities.ATLEAST_OREO) {
        return;
    }
    if (info.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && info.itemType != LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT && info.itemType != LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
        return;
    }
    // Load the adaptive icon on a background thread and add the view in ui thread.
    MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(new Runnable() {

        @Override
        public void run() {
            Object[] outObj = new Object[1];
            int w = mBitmap.getWidth();
            int h = mBitmap.getHeight();
            Drawable dr = Utilities.getFullDrawable(mLauncher, info, w, h, outObj);
            if (dr instanceof AdaptiveIconDrawable) {
                int blurMargin = (int) mLauncher.getResources().getDimension(R.dimen.blur_size_medium_outline) / 2;
                Rect bounds = new Rect(0, 0, w, h);
                bounds.inset(blurMargin, blurMargin);
                // Badge is applied after icon normalization so the bounds for badge should not
                // be scaled down due to icon normalization.
                Rect badgeBounds = new Rect(bounds);
                mBadge = getBadge(mLauncher, info, outObj[0]);
                mBadge.setBounds(badgeBounds);
                // Do not draw the background in case of folder as its translucent
                mDrawBitmap = !(dr instanceof FolderAdaptiveIcon);
                try (LauncherIcons li = LauncherIcons.obtain(mLauncher)) {
                    // drawable to be normalized
                    Drawable nDr;
                    if (mDrawBitmap) {
                        nDr = dr;
                    } else {
                        // Since we just want the scale, avoid heavy drawing operations
                        nDr = new AdaptiveIconDrawable(new ColorDrawable(Color.BLACK), null);
                    }
                    Utilities.scaleRectAboutCenter(bounds, li.getNormalizer().getScale(nDr, null, null, null));
                }
                AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) dr;
                // Shrink very tiny bit so that the clip path is smaller than the original bitmap
                // that has anti aliased edges and shadows.
                Rect shrunkBounds = new Rect(bounds);
                Utilities.scaleRectAboutCenter(shrunkBounds, 0.98f);
                adaptiveIcon.setBounds(shrunkBounds);
                final Path mask = adaptiveIcon.getIconMask();
                mTranslateX = new SpringFloatValue(DragView.this, w * AdaptiveIconDrawable.getExtraInsetFraction());
                mTranslateY = new SpringFloatValue(DragView.this, h * AdaptiveIconDrawable.getExtraInsetFraction());
                bounds.inset((int) (-bounds.width() * AdaptiveIconDrawable.getExtraInsetFraction()), (int) (-bounds.height() * AdaptiveIconDrawable.getExtraInsetFraction()));
                mBgSpringDrawable = adaptiveIcon.getBackground();
                if (mBgSpringDrawable == null) {
                    mBgSpringDrawable = new ColorDrawable(Color.TRANSPARENT);
                }
                mBgSpringDrawable.setBounds(bounds);
                mFgSpringDrawable = adaptiveIcon.getForeground();
                if (mFgSpringDrawable == null) {
                    mFgSpringDrawable = new ColorDrawable(Color.TRANSPARENT);
                }
                mFgSpringDrawable.setBounds(bounds);
                new Handler(Looper.getMainLooper()).post(new Runnable() {

                    @Override
                    public void run() {
                        // Assign the variable on the UI thread to avoid race conditions.
                        mScaledMaskPath = mask;
                        if (info.isDisabled()) {
                            FastBitmapDrawable d = new FastBitmapDrawable((Bitmap) null);
                            d.setIsDisabled(true);
                            mBaseFilter = (ColorMatrixColorFilter) d.getColorFilter();
                        }
                        updateColorFilter();
                    }
                });
            }
        }
    });
}
Also used : Path(android.graphics.Path) FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) Rect(android.graphics.Rect) ColorDrawable(android.graphics.drawable.ColorDrawable) LauncherIcons(com.android.launcher3.icons.LauncherIcons) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) Handler(android.os.Handler) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) TargetApi(android.annotation.TargetApi)

Example 62 with Folder

use of com.android.launcher3.tapl.Folder in project android_packages_apps_Trebuchet by LineageOS.

the class FolderIcon method drawLeaveBehindIfExists.

public void drawLeaveBehindIfExists() {
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams();
    // While the folder is open, the position of the icon cannot change.
    lp.canReorder = false;
    if (mInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        CellLayout cl = (CellLayout) getParent().getParent();
        cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
    }
}
Also used : CellLayout(com.android.launcher3.CellLayout)

Example 63 with Folder

use of com.android.launcher3.tapl.Folder in project android_packages_apps_Trebuchet by LineageOS.

the class Folder method replaceFolderWithFinalItem.

@Thunk
void replaceFolderWithFinalItem() {
    // Add the last remaining child to the workspace in place of the folder
    Runnable onCompleteRunnable = new Runnable() {

        @Override
        public void run() {
            int itemCount = getItemCount();
            if (itemCount <= 1) {
                View newIcon = null;
                WorkspaceItemInfo finalItem = null;
                if (itemCount == 1) {
                    // Move the item from the folder to the workspace, in the position of the
                    // folder
                    CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId);
                    finalItem = mInfo.contents.remove(0);
                    newIcon = mLauncher.createShortcut(cellLayout, finalItem);
                    mLauncher.getModelWriter().addOrMoveItemInDatabase(finalItem, mInfo.container, mInfo.screenId, mInfo.cellX, mInfo.cellY);
                }
                // Remove the folder
                mLauncher.removeItem(mFolderIcon, mInfo, true);
                if (mFolderIcon instanceof DropTarget) {
                    mDragController.removeDropTarget((DropTarget) mFolderIcon);
                }
                if (newIcon != null) {
                    // We add the child after removing the folder to prevent both from existing
                    // at the same time in the CellLayout.  We need to add the new item with
                    // addInScreenFromBind() to ensure that hotseat items are placed correctly.
                    mLauncher.getWorkspace().addInScreenFromBind(newIcon, mInfo);
                    // Focus the newly created child
                    newIcon.requestFocus();
                }
                if (finalItem != null) {
                    mLauncher.folderConvertedToItem(mFolderIcon.getFolder(), finalItem);
                }
            }
        }
    };
    View finalChild = mContent.getLastItem();
    if (finalChild != null) {
        mFolderIcon.performDestroyAnimation(onCompleteRunnable);
    } else {
        onCompleteRunnable.run();
    }
    mDestroyed = true;
}
Also used : CellLayout(com.android.launcher3.CellLayout) DropTarget(com.android.launcher3.DropTarget) ClipPathView(com.android.launcher3.views.ClipPathView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PagedView(com.android.launcher3.PagedView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) SuppressLint(android.annotation.SuppressLint) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Thunk(com.android.launcher3.util.Thunk)

Example 64 with Folder

use of com.android.launcher3.tapl.Folder in project android_packages_apps_Trebuchet by LineageOS.

the class Folder method updateTextViewFocus.

// This method keeps track of the first and last item in the folder for the purposes
// of keyboard focus
public void updateTextViewFocus() {
    final View firstChild = mContent.getFirstItem();
    final View lastChild = mContent.getLastItem();
    if (firstChild != null && lastChild != null) {
        mFolderName.setNextFocusDownId(lastChild.getId());
        mFolderName.setNextFocusRightId(lastChild.getId());
        mFolderName.setNextFocusLeftId(lastChild.getId());
        mFolderName.setNextFocusUpId(lastChild.getId());
        // Hitting TAB from the folder name wraps around to the first item on the current
        // folder page, and hitting SHIFT+TAB from that item wraps back to the folder name.
        mFolderName.setNextFocusForwardId(firstChild.getId());
        // When clicking off the folder when editing the name, this Folder gains focus. When
        // pressing an arrow key from that state, give the focus to the first item.
        this.setNextFocusDownId(firstChild.getId());
        this.setNextFocusRightId(firstChild.getId());
        this.setNextFocusLeftId(firstChild.getId());
        this.setNextFocusUpId(firstChild.getId());
        // When pressing shift+tab in the above state, give the focus to the last item.
        setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                boolean isShiftPlusTab = keyCode == KeyEvent.KEYCODE_TAB && event.hasModifiers(KeyEvent.META_SHIFT_ON);
                if (isShiftPlusTab && Folder.this.isFocused()) {
                    return lastChild.requestFocus();
                }
                return false;
            }
        });
    } else {
        setOnKeyListener(null);
    }
}
Also used : KeyEvent(android.view.KeyEvent) ClipPathView(com.android.launcher3.views.ClipPathView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PagedView(com.android.launcher3.PagedView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) SuppressLint(android.annotation.SuppressLint)

Example 65 with Folder

use of com.android.launcher3.tapl.Folder in project android_packages_apps_Trebuchet by LineageOS.

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)

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