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

Commit 7ce471bd authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing support for CustomContent screen

The supported way to customize Launcher and add a "-1 page" is by
using LauncherOverlays. Custom content screen is no longer supported.

Change-Id: I3f8a2734c287d1a69ae0c038ec1de1d45fa1b464
parent 17e78079
Loading
Loading
Loading
Loading
+11 −40
Original line number Diff line number Diff line
@@ -89,8 +89,6 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
    private int mCountY;

    private boolean mDropPending = false;
    private boolean mIsDragTarget = true;
    private boolean mJailContent = true;

    // These are temporary variables to prevent having to allocate a new object just to
    // return an (x, y) value from helper functions. Do NOT use them to maintain other state.
@@ -404,14 +402,6 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
        }
    }

    void disableDragTarget() {
        mIsDragTarget = false;
    }

    public boolean isDragTarget() {
        return mIsDragTarget;
    }

    void setIsDragOverlapping(boolean isDragOverlapping) {
        if (mIsDragOverlapping != isDragOverlapping) {
            mIsDragOverlapping = isDragOverlapping;
@@ -421,26 +411,22 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
        }
    }

    public void disableJailContent() {
        mJailContent = false;
    }

    @Override
    protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) {
        if (mJailContent) {
        ParcelableSparseArray jail = getJailedArray(container);
        super.dispatchSaveInstanceState(jail);
        container.put(R.id.cell_layout_jail_id, jail);
        } else {
            super.dispatchSaveInstanceState(container);
        }
    }

    @Override
    protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
        super.dispatchRestoreInstanceState(mJailContent ? getJailedArray(container) : container);
        super.dispatchRestoreInstanceState(getJailedArray(container));
    }

    /**
     * Wrap the SparseArray in another Parcelable so that the item ids do not conflict with our
     * our internal resource ids
     */
    private ParcelableSparseArray getJailedArray(SparseArray<Parcelable> container) {
        final Parcelable parcelable = container.get(R.id.cell_layout_jail_id);
        return parcelable instanceof ParcelableSparseArray ?
@@ -453,10 +439,6 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {

    @Override
    protected void onDraw(Canvas canvas) {
        if (!mIsDragTarget) {
            return;
        }

        // When we're large, we are either drawn in a "hover" state (ie when dragging an item to
        // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f)
        // When we're small, we are either drawn normally or in the "accepts drops" state (during
@@ -838,16 +820,10 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        boolean isFullscreen = mShortcutsAndWidgets.getChildCount() > 0 &&
                ((LayoutParams) mShortcutsAndWidgets.getChildAt(0).getLayoutParams()).isFullscreen;
        int left = getPaddingLeft();
        if (!isFullscreen) {
        left += (int) Math.ceil(getUnusedHorizontalSpace() / 2f);
        }
        int right = r - l - getPaddingRight();
        if (!isFullscreen) {
        right -= (int) Math.ceil(getUnusedHorizontalSpace() / 2f);
        }

        int top = getPaddingTop();
        int bottom = b - t - getPaddingBottom();
@@ -888,7 +864,7 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {

    @Override
    protected boolean verifyDrawable(Drawable who) {
        return super.verifyDrawable(who) || (mIsDragTarget && who == mBackground);
        return super.verifyDrawable(who) || (who == mBackground);
    }

    public void setShortcutAndWidgetAlpha(float alpha) {
@@ -2653,11 +2629,6 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
         */
        public boolean isLockedToGrid = true;

        /**
         * Indicates that this item should use the full extents of its parent.
         */
        public boolean isFullscreen = false;

        /**
         * Indicates whether this item can be reordered. Always true except in the case of the
         * the AllApps button and QSB place holder.
+0 −14
Original line number Diff line number Diff line
@@ -288,25 +288,11 @@ public class FocusHelper {
            case FocusLogic.PREVIOUS_PAGE_RIGHT_COLUMN:
                // Go to the previous page but keep the focus on the same hotseat icon.
                workspace.snapToPage(pageIndex - 1);
                // If the page we are going to is fullscreen, have it take the focus from hotseat.
                CellLayout prevPage = (CellLayout) workspace.getPageAt(pageIndex - 1);
                boolean isPrevPageFullscreen = ((CellLayout.LayoutParams) prevPage
                        .getShortcutsAndWidgets().getChildAt(0).getLayoutParams()).isFullscreen;
                if (isPrevPageFullscreen) {
                    workspace.getPageAt(pageIndex - 1).requestFocus();
                }
                break;
            case FocusLogic.NEXT_PAGE_LEFT_COLUMN:
            case FocusLogic.NEXT_PAGE_RIGHT_COLUMN:
                // Go to the next page but keep the focus on the same hotseat icon.
                workspace.snapToPage(pageIndex + 1);
                // If the page we are going to is fullscreen, have it take the focus from hotseat.
                CellLayout nextPage = (CellLayout) workspace.getPageAt(pageIndex + 1);
                boolean isNextPageFullscreen = ((CellLayout.LayoutParams) nextPage
                        .getShortcutsAndWidgets().getChildAt(0).getLayoutParams()).isFullscreen;
                if (isNextPageFullscreen) {
                    workspace.getPageAt(pageIndex + 1).requestFocus();
                }
                break;
        }
        if (parent == iconParent && newIconIndex >= iconParent.getChildCount()) {
+5 −145
Original line number Diff line number Diff line
@@ -291,8 +291,6 @@ public class Launcher extends BaseActivity
    // it from the context.
    private SharedPreferences mSharedPrefs;

    private boolean mMoveToDefaultScreenFromNewIntent;

    // This is set to the view that launched the activity that navigated the user away from
    // launcher. Since there is no callback for when the activity has finished launching, enable
    // the press state and keep this reference to reset the press state when we return to launcher.
@@ -420,8 +418,6 @@ public class Launcher extends BaseActivity
        ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
                .addAccessibilityStateChangeListener(this);

        lockAllApps();

        restoreState(savedInstanceState);

        if (LauncherAppState.PROFILE_STARTUP) {
@@ -508,10 +504,6 @@ public class Launcher extends BaseActivity
        mExtractedColors.notifyChange();
    }

    public ExtractedColors getExtractedColors() {
        return mExtractedColors;
    }

    @Override
    public void onAppWidgetHostReset() {
        if (mAppWidgetHost != null) {
@@ -564,44 +556,6 @@ public class Launcher extends BaseActivity
        }
    }

    /** To be overridden by subclasses to hint to Launcher that we have custom content */
    protected boolean hasCustomContentToLeft() {
        if (mLauncherCallbacks != null) {
            return mLauncherCallbacks.hasCustomContentToLeft();
        }
        return false;
    }

    /**
     * To be overridden by subclasses to populate the custom content container and call
     * {@link #addToCustomContentPage}. This will only be invoked if
     * {@link #hasCustomContentToLeft()} is {@code true}.
     */
    protected void populateCustomContentContainer() {
        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.populateCustomContentContainer();
        }
    }

    /**
     * Invoked by subclasses to signal a change to the {@link #addToCustomContentPage} value to
     * ensure the custom content page is added or removed if necessary.
     */
    protected void invalidateHasCustomContentToLeft() {
        if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
            // Not bound yet, wait for bindScreens to be called.
            return;
        }

        if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
            // Create the custom content page and call the subclass to populate it.
            mWorkspace.createCustomContentContainer();
            populateCustomContentContainer();
        } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
            mWorkspace.removeCustomContentPage();
        }
    }

    public boolean isDraggingEnabled() {
        // We prevent dragging when we are loading the workspace as it is possible to pick up a view
        // that is subsequently removed from the workspace in startBinding().
@@ -801,7 +755,7 @@ public class Launcher extends BaseActivity
        }
    }

    /** @Override for MNC */
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions,
            int[] grantResults) {
        PendingRequestArgs pendingArgs = mPendingRequestArgs;
@@ -1017,21 +971,6 @@ public class Launcher extends BaseActivity
            Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
        }

        // We want to suppress callbacks about CustomContent being shown if we have just received
        // onNewIntent while the user was present within launcher. In that case, we post a call
        // to move the user to the main screen (which will occur after onResume). We don't want to
        // have onHide (from onPause), then onShow, then onHide again, which we get if we don't
        // suppress here.
        if (mWorkspace.getCustomContentCallbacks() != null
                && !mMoveToDefaultScreenFromNewIntent) {
            // If we are resuming and the custom content is the current page, we call onShow().
            // It is also possible that onShow will instead be called slightly after first layout
            // if PagedView#setRestorePage was set to the custom content page in onCreate().
            if (mWorkspace.isOnOrMovingToCustomContent()) {
                mWorkspace.getCustomContentCallbacks().onShow(true);
            }
        }
        mMoveToDefaultScreenFromNewIntent = false;
        updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
        mWorkspace.onResume();

@@ -1061,32 +1000,11 @@ public class Launcher extends BaseActivity
        mDragController.cancelDrag();
        mDragController.resetLastGestureUpTime();

        // We call onHide() aggressively. The custom content callbacks should be able to
        // debounce excess onHide calls.
        if (mWorkspace.getCustomContentCallbacks() != null) {
            mWorkspace.getCustomContentCallbacks().onHide();
        }

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onPause();
        }
    }

    public interface CustomContentCallbacks {
        // Custom content is completely shown. {@code fromResume} indicates whether this was caused
        // by a onResume or by scrolling otherwise.
        void onShow(boolean fromResume);

        // Custom content is completely hidden
        void onHide();

        // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
        void onScrollProgressChanged(float progress);

        // Indicates whether the user is allowed to scroll away from the custom content.
        boolean isScrollingAllowed();
    }

    public interface LauncherOverlay {

        /**
@@ -1136,16 +1054,6 @@ public class Launcher extends BaseActivity
        }
    }

    public void addToCustomContentPage(View customContent,
            CustomContentCallbacks callbacks, String description) {
        mWorkspace.addToCustomContentPage(customContent, callbacks, description);
    }

    // The custom content needs to offset its content to account for the QSB
    public int getTopOffsetForCustomContent() {
        return mWorkspace.getPaddingTop();
    }

    @Override
    public Object onRetainNonConfigurationInstance() {
        // Flag the loader to stop early before switching
@@ -1205,7 +1113,7 @@ public class Launcher extends BaseActivity
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_MENU) {
            // Ignore the menu key if we are currently dragging or are on the custom content screen
            if (!isOnCustomContent() && !mDragController.isDragging()) {
            if (!mDragController.isDragging()) {
                // Close any open floating view
                AbstractFloatingView.closeAllOpenViews(this);

@@ -1765,14 +1673,11 @@ public class Launcher extends BaseActivity
            if (shouldMoveToDefaultScreen && !mWorkspace.isTouchActive()
                    && callbackAllowsMoveToDefaultScreen) {

                // We use this flag to suppress noisy callbacks above custom content state
                // from onResume.
                mMoveToDefaultScreenFromNewIntent = true;
                mWorkspace.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mWorkspace != null) {
                            mWorkspace.moveToDefaultScreen(true);
                            mWorkspace.moveToDefaultScreen();
                        }
                    }
                });
@@ -1795,8 +1700,7 @@ public class Launcher extends BaseActivity
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        if (mWorkspace.getChildCount() > 0) {
            outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
                    mWorkspace.getCurrentPageOffsetFromCustomContent());
            outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());

        }
        super.onSaveInstanceState(outState);
@@ -1952,10 +1856,6 @@ public class Launcher extends BaseActivity
        }
    }

    public boolean isOnCustomContent() {
        return mWorkspace.isOnOrMovingToCustomContent();
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
@@ -2028,12 +1928,6 @@ public class Launcher extends BaseActivity
        }
    }

    protected void moveToCustomContentScreen(boolean animate) {
        // Close any folders that may be open.
        AbstractFloatingView.closeAllOpenViews(this, animate);
        mWorkspace.moveToCustomContentScreen(animate);
    }

    public void addPendingItem(PendingAddItemInfo info, long container, long screenId,
            int[] cell, int spanX, int spanY) {
        info.container = container;
@@ -2554,14 +2448,6 @@ public class Launcher extends BaseActivity
        mDragLayer.onAccessibilityStateChanged(enabled);
    }

    public void onDragStarted() {
        if (isOnCustomContent()) {
            // Custom content screen doesn't participate in drag and drop. If on custom
            // content screen, move to default.
            moveWorkspaceToDefaultScreen();
        }
    }

    /**
     * Called when the user stops interacting with the launcher.
     * This implies that the user is now on the homescreen and is not doing housekeeping.
@@ -3072,14 +2958,6 @@ public class Launcher extends BaseActivity
        }
    }

    void lockAllApps() {
        // TODO
    }

    void unlockAllApps() {
        // TODO
    }

    @Override
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
        final boolean result = super.dispatchPopulateAccessibilityEvent(event);
@@ -3219,13 +3097,6 @@ public class Launcher extends BaseActivity
        }
        bindAddScreens(orderedScreenIds);

        // Create the custom content page (this call updates mDefaultScreen which calls
        // setCurrentPage() so ensure that all pages are added before calling this).
        if (hasCustomContentToLeft()) {
            mWorkspace.createCustomContentContainer();
            populateCustomContentContainer();
        }

        // After we have added all the screens, if the wallpaper was locked to the default state,
        // then notify to indicate that it can be released and a proper wallpaper offset can be
        // computed before the next layout
@@ -3650,13 +3521,6 @@ public class Launcher extends BaseActivity
        return mDeviceProfile.isVerticalBarLayout();
    }

    public int getSearchBarHeight() {
        if (mLauncherCallbacks != null) {
            return mLauncherCallbacks.getSearchBarHeight();
        }
        return LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
    }

    /**
     * Add the icons for all apps.
     *
@@ -3910,10 +3774,6 @@ public class Launcher extends BaseActivity
        return mState == State.WORKSPACE && !mSharedPrefs.getBoolean(APPS_VIEW_SHOWN, false);
    }

    protected void moveWorkspaceToDefaultScreen() {
        mWorkspace.moveToDefaultScreen(false);
    }

    /**
     * $ adb shell dumpsys activity com.android.launcher3.Launcher [--all]
     */
@@ -3923,7 +3783,7 @@ public class Launcher extends BaseActivity

        if (args.length > 0 && TextUtils.equals(args[0], "--all")) {
            writer.println(prefix + "Workspace Items");
            for (int i = mWorkspace.numCustomPages(); i < mWorkspace.getPageCount(); i++) {
            for (int i = 0; i < mWorkspace.getPageCount(); i++) {
                writer.println(prefix + "  Homescreen " + i);

                ViewGroup layout = ((CellLayout) mWorkspace.getPageAt(i)).getShortcutsAndWidgets();
+0 −7
Original line number Diff line number Diff line
@@ -81,10 +81,6 @@ public interface LauncherCallbacks {
     */
    boolean startSearch(
            String initialQuery, boolean selectInitialQuery, Bundle appSearchData);
    boolean hasCustomContentToLeft();
    void populateCustomContentContainer();
    View getQsbBar();
    Bundle getAdditionalSearchWidgetOptions();

    /*
     * Extensions points for adding / replacing some other aspects of the Launcher experience.
@@ -92,7 +88,4 @@ public interface LauncherCallbacks {
    boolean shouldMoveToDefaultScreenOnHomeIntent();
    boolean hasSettings();
    List<ComponentKeyMapper<AppInfo>> getPredictedApps();
    int SEARCH_BAR_HEIGHT_NORMAL = 0, SEARCH_BAR_HEIGHT_TALL = 1;
    /** Must return one of {@link #SEARCH_BAR_HEIGHT_NORMAL} or {@link #SEARCH_BAR_HEIGHT_TALL} */
    int getSearchBarHeight();
}
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ public class PinchToOverviewListener extends ScaleGestureDetector.SimpleOnScaleG

    @Override
    public boolean onScaleBegin(ScaleGestureDetector detector) {
        if (mLauncher.mState != Launcher.State.WORKSPACE || mLauncher.isOnCustomContent()) {
        if (mLauncher.mState != Launcher.State.WORKSPACE) {
            // Don't listen for the pinch gesture if on all apps, widget picker, -1, etc.
            return false;
        }
Loading