Search in sources :

Example 76 with BubbleTextView

use of com.android.launcher3.BubbleTextView in project android_packages_apps_Launcher3 by ProtonAOSP.

the class FolderPagedView method arrangeChildren.

/**
 * Updates position and rank of all the children in the view.
 * It essentially removes all views from all the pages and then adds them again in appropriate
 * page.
 *
 * @param list the ordered list of children.
 */
@SuppressLint("RtlHardcoded")
public void arrangeChildren(List<View> list) {
    int itemCount = list.size();
    ArrayList<CellLayout> pages = new ArrayList<>();
    for (int i = 0; i < getChildCount(); i++) {
        CellLayout page = (CellLayout) getChildAt(i);
        page.removeAllViews();
        pages.add(page);
    }
    mOrganizer.setFolderInfo(mFolder.getInfo());
    setupContentDimensions(itemCount);
    Iterator<CellLayout> pageItr = pages.iterator();
    CellLayout currentPage = null;
    int position = 0;
    int rank = 0;
    for (int i = 0; i < itemCount; i++) {
        View v = list.size() > i ? list.get(i) : null;
        if (currentPage == null || position >= mOrganizer.getMaxItemsPerPage()) {
            // Next page
            if (pageItr.hasNext()) {
                currentPage = pageItr.next();
            } else {
                currentPage = createAndAddNewPage();
            }
            position = 0;
        }
        if (v != null) {
            CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
            ItemInfo info = (ItemInfo) v.getTag();
            lp.setCellXY(mOrganizer.getPosForRank(rank));
            currentPage.addViewToCellLayout(v, -1, info.getViewId(), lp, true);
            if (mOrganizer.isItemInPreview(rank) && v instanceof BubbleTextView) {
                ((BubbleTextView) v).verifyHighRes();
            }
        }
        rank++;
        position++;
    }
    // Remove extra views.
    boolean removed = false;
    while (pageItr.hasNext()) {
        removeView(pageItr.next());
        removed = true;
    }
    if (removed) {
        setCurrentPage(0);
    }
    setEnableOverscroll(getPageCount() > 1);
    // Update footer
    mPageIndicator.setVisibility(getPageCount() > 1 ? View.VISIBLE : View.GONE);
    // Set the gravity as LEFT or RIGHT instead of START, as START depends on the actual text.
    mFolder.mFolderName.setGravity(getPageCount() > 1 ? (mIsRtl ? Gravity.RIGHT : Gravity.LEFT) : Gravity.CENTER_HORIZONTAL);
}
Also used : CellLayout(com.android.launcher3.CellLayout) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrayList(java.util.ArrayList) BubbleTextView(com.android.launcher3.BubbleTextView) ClipPathView(com.android.launcher3.views.ClipPathView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) PagedView(com.android.launcher3.PagedView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 77 with BubbleTextView

use of com.android.launcher3.BubbleTextView in project android_packages_apps_Launcher3 by ProtonAOSP.

the class FolderPagedView method createNewView.

@SuppressLint("InflateParams")
public View createNewView(WorkspaceItemInfo item) {
    if (item == null) {
        return null;
    }
    final BubbleTextView textView = mViewCache.getView(R.layout.folder_application, getContext(), null);
    textView.applyFromWorkspaceItem(item);
    textView.setOnClickListener(ItemClickHandler.INSTANCE);
    textView.setOnLongClickListener(mFolder);
    textView.setOnFocusChangeListener(mFocusIndicatorHelper);
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) textView.getLayoutParams();
    if (lp == null) {
        textView.setLayoutParams(new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY));
    } else {
        lp.cellX = item.cellX;
        lp.cellY = item.cellY;
        lp.cellHSpan = lp.cellVSpan = 1;
    }
    return textView;
}
Also used : CellLayout(com.android.launcher3.CellLayout) BubbleTextView(com.android.launcher3.BubbleTextView) SuppressLint(android.annotation.SuppressLint)

Example 78 with BubbleTextView

use of com.android.launcher3.BubbleTextView in project android_packages_apps_Launcher3 by ProtonAOSP.

the class FloatingIconView method fetchIcon.

/**
 * Loads the icon drawable on a worker thread to reduce latency between swapping views.
 */
@UiThread
public static IconLoadResult fetchIcon(Launcher l, View v, ItemInfo info, boolean isOpening) {
    RectF position = new RectF();
    getLocationBoundsForView(l, v, isOpening, position);
    final FastBitmapDrawable btvIcon;
    if (v instanceof BubbleTextView) {
        BubbleTextView btv = (BubbleTextView) v;
        if (info instanceof ItemInfoWithIcon && (((ItemInfoWithIcon) info).runtimeStatusFlags & ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK) != 0) {
            btvIcon = btv.makePreloadIcon();
        } else {
            btvIcon = btv.getIcon();
        }
    } else {
        btvIcon = null;
    }
    IconLoadResult result = new IconLoadResult(info, btvIcon == null ? false : btvIcon.isThemed());
    result.btvDrawable = btvIcon;
    final long fetchIconId = sFetchIconId++;
    MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(() -> {
        if (fetchIconId < sRecycledFetchIconId) {
            return;
        }
        getIconResult(l, v, info, position, btvIcon, result);
    });
    sIconLoadResult = result;
    return result;
}
Also used : RectF(android.graphics.RectF) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) BubbleTextView(com.android.launcher3.BubbleTextView) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) UiThread(androidx.annotation.UiThread)

Example 79 with BubbleTextView

use of com.android.launcher3.BubbleTextView in project android_packages_apps_Launcher3 by ProtonAOSP.

the class FloatingIconView method getIconResult.

/**
 * Loads the icon and saves the results to {@link #sIconLoadResult}.
 * Runs onIconLoaded callback (if any), which signifies that the FloatingIconView is
 * ready to display the icon. Otherwise, the FloatingIconView will grab the results when its
 * initialized.
 *
 * @param originalView The View that the FloatingIconView will replace.
 * @param info ItemInfo of the originalView
 * @param pos The position of the view.
 */
@WorkerThread
@SuppressWarnings("WrongThread")
private static void getIconResult(Launcher l, View originalView, ItemInfo info, RectF pos, Drawable btvIcon, IconLoadResult iconLoadResult) {
    Drawable drawable;
    boolean supportsAdaptiveIcons = ADAPTIVE_ICON_WINDOW_ANIM.get() && // Use original icon for disabled icons.
    !info.isDisabled();
    Drawable badge = null;
    if (info instanceof SystemShortcut) {
        if (originalView instanceof ImageView) {
            drawable = ((ImageView) originalView).getDrawable();
        } else if (originalView instanceof DeepShortcutView) {
            drawable = ((DeepShortcutView) originalView).getIconView().getBackground();
        } else {
            drawable = originalView.getBackground();
        }
    } else if (btvIcon instanceof PreloadIconDrawable) {
        // Force the progress bar to display.
        drawable = btvIcon;
    } else {
        int width = (int) pos.width();
        int height = (int) pos.height();
        if (supportsAdaptiveIcons) {
            drawable = getFullDrawable(l, info, width, height, sTmpObjArray);
            if (drawable instanceof AdaptiveIconDrawable) {
                badge = getBadge(l, info, sTmpObjArray[0]);
            } else {
                // The drawable we get back is not an adaptive icon, so we need to use the
                // BubbleTextView icon that is already legacy treated.
                drawable = btvIcon;
            }
        } else {
            if (originalView instanceof BubbleTextView) {
                // Similar to DragView, we simply use the BubbleTextView icon here.
                drawable = btvIcon;
            } else {
                drawable = getFullDrawable(l, info, width, height, sTmpObjArray);
            }
        }
    }
    drawable = drawable == null ? null : drawable.getConstantState().newDrawable();
    int iconOffset = getOffsetForIconBounds(l, drawable, pos);
    synchronized (iconLoadResult) {
        iconLoadResult.btvDrawable = btvIcon == null || drawable == btvIcon ? null : btvIcon.getConstantState().newDrawable();
        iconLoadResult.drawable = drawable;
        iconLoadResult.badge = badge;
        iconLoadResult.iconOffset = iconOffset;
        if (iconLoadResult.onIconLoaded != null) {
            l.getMainExecutor().execute(iconLoadResult.onIconLoaded);
            iconLoadResult.onIconLoaded = null;
        }
        iconLoadResult.isIconLoaded = true;
    }
}
Also used : SystemShortcut(com.android.launcher3.popup.SystemShortcut) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) Utilities.getFullDrawable(com.android.launcher3.Utilities.getFullDrawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) ImageView(android.widget.ImageView) BubbleTextView(com.android.launcher3.BubbleTextView) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) WorkerThread(androidx.annotation.WorkerThread)

Example 80 with BubbleTextView

use of com.android.launcher3.BubbleTextView in project android_packages_apps_Launcher3 by ProtonAOSP.

the class LauncherBindableItemsContainer method updateRestoreItems.

/**
 * Called to update restored items as a result of
 * {@link com.android.launcher3.model.BgDataModel.Callbacks#bindRestoreItemsChange(HashSet)}}
 */
default void updateRestoreItems(final HashSet<ItemInfo> updates, ActivityContext context) {
    ItemOperator op = (info, v) -> {
        if (info instanceof WorkspaceItemInfo && v instanceof BubbleTextView && updates.contains(info)) {
            ((BubbleTextView) v).applyLoadingState(false);
        } else if (v instanceof PendingAppWidgetHostView && info instanceof LauncherAppWidgetInfo && updates.contains(info)) {
            ((PendingAppWidgetHostView) v).applyState();
        } else if (v instanceof FolderIcon && info instanceof FolderInfo) {
            ((FolderIcon) v).updatePreviewItems(updates::contains);
        }
        // process all the shortcuts
        return false;
    };
    mapOverItems(op);
    Folder folder = Folder.getOpen(context);
    if (folder != null) {
        folder.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) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) BubbleTextView(com.android.launcher3.BubbleTextView) Folder(com.android.launcher3.folder.Folder) FolderInfo(com.android.launcher3.model.data.FolderInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

BubbleTextView (com.android.launcher3.BubbleTextView)157 View (android.view.View)82 Rect (android.graphics.Rect)62 Point (android.graphics.Point)61 Drawable (android.graphics.drawable.Drawable)60 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)57 ItemInfo (com.android.launcher3.model.data.ItemInfo)56 SuppressLint (android.annotation.SuppressLint)48 ArrayList (java.util.ArrayList)43 CellLayout (com.android.launcher3.CellLayout)39 Animator (android.animation.Animator)36 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)36 DragView (com.android.launcher3.dragndrop.DragView)34 FolderIcon (com.android.launcher3.folder.FolderIcon)34 Handler (android.os.Handler)33 ViewGroup (android.view.ViewGroup)30 DraggableView (com.android.launcher3.dragndrop.DraggableView)30 PreloadIconDrawable (com.android.launcher3.graphics.PreloadIconDrawable)30 AbstractFloatingView (com.android.launcher3.AbstractFloatingView)28 Folder (com.android.launcher3.folder.Folder)28