Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea8ac5a2 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Only inflating taskbar views for valid items

Also enabling view cache for folders

Bug: 187353581
Test: Manual
Change-Id: I5bc695fd86475f30611bc6b362b4ae93c48c26bb
parent 99cbbc60
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -56,6 +56,7 @@ import com.android.launcher3.touch.ItemClickHandler;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.TraceHelper;
import com.android.launcher3.util.TraceHelper;
import com.android.launcher3.util.ViewCache;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.ActivityContext;
import com.android.quickstep.SysUINavigationMode;
import com.android.quickstep.SysUINavigationMode;
import com.android.quickstep.SysUINavigationMode.Mode;
import com.android.quickstep.SysUINavigationMode.Mode;
@@ -88,6 +89,7 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ
    private int mLastRequestedNonFullscreenHeight;
    private int mLastRequestedNonFullscreenHeight;


    private final SysUINavigationMode.Mode mNavMode;
    private final SysUINavigationMode.Mode mNavMode;
    private final ViewCache mViewCache = new ViewCache();


    private final boolean mIsSafeModeEnabled;
    private final boolean mIsSafeModeEnabled;


@@ -187,6 +189,11 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ
        return mControllers.taskbarDragController;
        return mControllers.taskbarDragController;
    }
    }


    @Override
    public ViewCache getViewCache() {
        return mViewCache;
    }

    /**
    /**
     * Sets a new data-source for this taskbar instance
     * Sets a new data-source for this taskbar instance
     */
     */
+5 −2
Original line number Original line Diff line number Diff line
@@ -15,6 +15,9 @@
 */
 */
package com.android.launcher3.taskbar;
package com.android.launcher3.taskbar;


import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;

import android.content.ClipData;
import android.content.ClipData;
import android.content.ClipDescription;
import android.content.ClipDescription;
import android.content.Intent;
import android.content.Intent;
@@ -86,7 +89,7 @@ public class TaskbarDragController extends DragController<TaskbarActivityContext
        mActivity.setTaskbarWindowFullscreen(true);
        mActivity.setTaskbarWindowFullscreen(true);
        view.post(() -> {
        view.post(() -> {
            startInternalDrag(btv);
            startInternalDrag(btv);
            btv.setAlpha(0);
            btv.setVisibility(INVISIBLE);
        });
        });
        return true;
        return true;
    }
    }
@@ -293,7 +296,7 @@ public class TaskbarDragController extends DragController<TaskbarActivityContext


    private void maybeOnDragEnd() {
    private void maybeOnDragEnd() {
        if (!isDragging()) {
        if (!isDragging()) {
            ((View) mDragObject.originalView).setAlpha(1);
            ((View) mDragObject.originalView).setVisibility(VISIBLE);
        }
        }
    }
    }


+50 −43
Original line number Original line Diff line number Diff line
@@ -103,9 +103,6 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
        mControllerCallbacks = callbacks;
        mControllerCallbacks = callbacks;
        mIconClickListener = mControllerCallbacks.getOnClickListener();
        mIconClickListener = mControllerCallbacks.getOnClickListener();
        mIconLongClickListener = mControllerCallbacks.getOnLongClickListener();
        mIconLongClickListener = mControllerCallbacks.getOnLongClickListener();

        int numHotseatIcons = mActivityContext.getDeviceProfile().numShownHotseatIcons;
        updateHotseatItems(new ItemInfo[numHotseatIcons]);
    }
    }


    /**
    /**
@@ -127,13 +124,11 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
        int count = getChildCount();
        int count = getChildCount();
        for (int i = 0; i < count; i++) {
        for (int i = 0; i < count; i++) {
            View child = getChildAt(i);
            View child = getChildAt(i);
            if (child.getVisibility() != VISIBLE) {
            ItemInfo info = (ItemInfo) child.getTag();
                continue;
            }
            setter.setFloat(child, SCALE_PROPERTY, scaleUp, LINEAR);
            setter.setFloat(child, SCALE_PROPERTY, scaleUp, LINEAR);


            float childCenter = (child.getLeft() + child.getRight()) / 2;
            float childCenter = (child.getLeft() + child.getRight()) / 2;
            float hotseatIconCenter = hotseatPadding.left + hotseatCellSize * (i)
            float hotseatIconCenter = hotseatPadding.left + hotseatCellSize * info.screenId
                    + hotseatCellSize / 2;
                    + hotseatCellSize / 2;
            setter.setFloat(child, VIEW_TRANSLATE_X, hotseatIconCenter - childCenter, LINEAR);
            setter.setFloat(child, VIEW_TRANSLATE_X, hotseatIconCenter - childCenter, LINEAR);
        }
        }
@@ -155,34 +150,58 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
                mActivityContext.getDeviceProfile().taskbarSize);
                mActivityContext.getDeviceProfile().taskbarSize);
    }
    }


    private void removeAndRecycle(View view) {
        removeView(view);
        view.setOnClickListener(null);
        view.setOnLongClickListener(null);
        if (!(view.getTag() instanceof FolderInfo)) {
            mActivityContext.getViewCache().recycleView(view.getSourceLayoutResId(), view);
        }
        view.setTag(null);
    }

    /**
    /**
     * Inflates/binds the Hotseat views to show in the Taskbar given their ItemInfos.
     * Inflates/binds the Hotseat views to show in the Taskbar given their ItemInfos.
     */
     */
    protected void updateHotseatItems(ItemInfo[] hotseatItemInfos) {
    protected void updateHotseatItems(ItemInfo[] hotseatItemInfos) {
        int nextViewIndex = 0;

        for (int i = 0; i < hotseatItemInfos.length; i++) {
        for (int i = 0; i < hotseatItemInfos.length; i++) {
            ItemInfo hotseatItemInfo = hotseatItemInfos[i];
            ItemInfo hotseatItemInfo = hotseatItemInfos[i];
            View hotseatView = getChildAt(i);
            if (hotseatItemInfo == null) {
                continue;
            }


            // Replace any Hotseat views with the appropriate type if it's not already that type.
            // Replace any Hotseat views with the appropriate type if it's not already that type.
            final int expectedLayoutResId;
            final int expectedLayoutResId;
            boolean isFolder = false;
            boolean isFolder = false;
            boolean needsReinflate = false;
            if (hotseatItemInfo.isPredictedItem()) {
            if (hotseatItemInfo != null && hotseatItemInfo.isPredictedItem()) {
                expectedLayoutResId = R.layout.taskbar_predicted_app_icon;
                expectedLayoutResId = R.layout.taskbar_predicted_app_icon;
            } else if (hotseatItemInfo instanceof FolderInfo) {
            } else if (hotseatItemInfo instanceof FolderInfo) {
                expectedLayoutResId = R.layout.folder_icon;
                expectedLayoutResId = R.layout.folder_icon;
                isFolder = true;
                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 {
            } else {
                expectedLayoutResId = R.layout.taskbar_app_icon;
                expectedLayoutResId = R.layout.taskbar_app_icon;
            }
            }
            if (hotseatView == null

                    || hotseatView.getSourceLayoutResId() != expectedLayoutResId
            View hotseatView = null;
                    || needsReinflate) {
            while (nextViewIndex < getChildCount()) {
                removeView(hotseatView);
                hotseatView = getChildAt(nextViewIndex);

                // see if the view can be reused
                if ((hotseatView.getSourceLayoutResId() != expectedLayoutResId)
                        || (isFolder && (hotseatView.getTag() != hotseatItemInfo))) {
                    // 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.
                    removeAndRecycle(hotseatView);
                } else {
                    // View found
                    break;
                }
            }

            if (hotseatView == null) {
                if (isFolder) {
                if (isFolder) {
                    FolderInfo folderInfo = (FolderInfo) hotseatItemInfo;
                    FolderInfo folderInfo = (FolderInfo) hotseatItemInfo;
                    FolderIcon folderIcon = FolderIcon.inflateFolderAndIcon(expectedLayoutResId,
                    FolderIcon folderIcon = FolderIcon.inflateFolderAndIcon(expectedLayoutResId,
@@ -194,7 +213,7 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
                }
                }
                LayoutParams lp = new LayoutParams(mIconTouchSize, mIconTouchSize);
                LayoutParams lp = new LayoutParams(mIconTouchSize, mIconTouchSize);
                hotseatView.setPadding(mItemPadding, mItemPadding, mItemPadding, mItemPadding);
                hotseatView.setPadding(mItemPadding, mItemPadding, mItemPadding, mItemPadding);
                addView(hotseatView, i, lp);
                addView(hotseatView, nextViewIndex, lp);
            }
            }


            // Apply the Hotseat ItemInfos, or hide the view if there is none for a given index.
            // Apply the Hotseat ItemInfos, or hide the view if there is none for a given index.
@@ -202,15 +221,13 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
                    && hotseatItemInfo instanceof WorkspaceItemInfo) {
                    && hotseatItemInfo instanceof WorkspaceItemInfo) {
                ((BubbleTextView) hotseatView).applyFromWorkspaceItem(
                ((BubbleTextView) hotseatView).applyFromWorkspaceItem(
                        (WorkspaceItemInfo) hotseatItemInfo);
                        (WorkspaceItemInfo) hotseatItemInfo);
            }
            setClickAndLongClickListenersForIcon(hotseatView);
            setClickAndLongClickListenersForIcon(hotseatView);
            } else if (isFolder) {
            nextViewIndex++;
                setClickAndLongClickListenersForIcon(hotseatView);
            } else {
                hotseatView.setOnClickListener(null);
                hotseatView.setOnLongClickListener(null);
                hotseatView.setTag(null);
        }
        }
            hotseatView.setVisibility(hotseatView.getTag() != null ? VISIBLE : INVISIBLE);
        // Remove remaining views
        while (nextViewIndex < getChildCount()) {
            removeAndRecycle(getChildAt(nextViewIndex));
        }
        }
    }
    }


@@ -225,15 +242,7 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
    @Override
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        int count = getChildCount();
        int count = getChildCount();
        // Find total visible children
        int spaceNeeded = count * (mItemMarginLeftRight * 2 + mIconTouchSize);
        int visibleChildren = 0;
        for (int i = 0; i < count; i++) {
            if (getChildAt(i).getVisibility() == VISIBLE) {
                visibleChildren++;
            }
        }

        int spaceNeeded = visibleChildren * (mItemMarginLeftRight * 2 + mIconTouchSize);
        int iconStart = (right - left - spaceNeeded) / 2;
        int iconStart = (right - left - spaceNeeded) / 2;
        int startOffset = ApiWrapper.getHotseatStartOffset(getContext());
        int startOffset = ApiWrapper.getHotseatStartOffset(getContext());
        if (startOffset > iconStart) {
        if (startOffset > iconStart) {
@@ -246,13 +255,11 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
        mIconLayoutBounds.bottom = mIconLayoutBounds.top + mIconTouchSize;
        mIconLayoutBounds.bottom = mIconLayoutBounds.top + mIconTouchSize;
        for (int i = 0; i < count; i++) {
        for (int i = 0; i < count; i++) {
            View child = getChildAt(i);
            View child = getChildAt(i);
            if (child.getVisibility() == VISIBLE) {
            iconStart += mItemMarginLeftRight;
            iconStart += mItemMarginLeftRight;
            int iconEnd = iconStart + mIconTouchSize;
            int iconEnd = iconStart + mIconTouchSize;
            child.layout(iconStart, mIconLayoutBounds.top, iconEnd, mIconLayoutBounds.bottom);
            child.layout(iconStart, mIconLayoutBounds.top, iconEnd, mIconLayoutBounds.bottom);
            iconStart = iconEnd + mItemMarginLeftRight;
            iconStart = iconEnd + mItemMarginLeftRight;
        }
        }
        }
        mIconLayoutBounds.right = iconStart;
        mIconLayoutBounds.right = iconStart;
    }
    }


@@ -307,7 +314,7 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
    }
    }


    private View inflate(@LayoutRes int layoutResId) {
    private View inflate(@LayoutRes int layoutResId) {
        return mActivityContext.getLayoutInflater().inflate(layoutResId, this, false);
        return mActivityContext.getViewCache().getView(layoutResId, mActivityContext, this);
    }
    }


    @Override
    @Override