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

Commit 81190bef authored by Jim Miller's avatar Jim Miller
Browse files

Fix issue where transport control shows up off-screen on tablets

This fix selects the current page ealier in the reconstruction
of Keyguard to ensure the layout bounds of KeyguardWidgetPager are
correct by the time it does the initial layout.

In addition this change postpones selecting the transport page if
the transport was just added.

Fixes bug 11287144

Change-Id: I92ba8bb5e13c166d13fbaa26881f5034d5ab2104
parent 65d4a84b
Loading
Loading
Loading
Loading
+22 −9
Original line number Original line Diff line number Diff line
@@ -218,7 +218,7 @@ public class KeyguardHostView extends KeyguardViewBase {
        mTransportState = (dcs.clearing ? TRANSPORT_GONE :
        mTransportState = (dcs.clearing ? TRANSPORT_GONE :
            (isMusicPlaying(dcs.playbackState) ? TRANSPORT_VISIBLE : TRANSPORT_INVISIBLE));
            (isMusicPlaying(dcs.playbackState) ? TRANSPORT_VISIBLE : TRANSPORT_INVISIBLE));


        if (DEBUG) Log.v(TAG, "Initial transport state: "
        if (DEBUGXPORT) Log.v(TAG, "Initial transport state: "
                + mTransportState + ", pbstate=" + dcs.playbackState);
                + mTransportState + ", pbstate=" + dcs.playbackState);
    }
    }


@@ -1369,7 +1369,7 @@ public class KeyguardHostView extends KeyguardViewBase {
        }
        }
    }
    }


    Runnable mSwitchPageRunnable = new Runnable() {
    private final Runnable mSwitchPageRunnable = new Runnable() {
        @Override
        @Override
        public void run() {
        public void run() {
           showAppropriateWidgetPage();
           showAppropriateWidgetPage();
@@ -1438,7 +1438,7 @@ public class KeyguardHostView extends KeyguardViewBase {
        mAppWidgetToShow = ss.appWidgetToShow;
        mAppWidgetToShow = ss.appWidgetToShow;
        setInsets(ss.insets);
        setInsets(ss.insets);
        if (DEBUG) Log.d(TAG, "onRestoreInstanceState, transport=" + mTransportState);
        if (DEBUG) Log.d(TAG, "onRestoreInstanceState, transport=" + mTransportState);
        post(mSwitchPageRunnable);
        mSwitchPageRunnable.run();
    }
    }


    @Override
    @Override
@@ -1472,11 +1472,22 @@ public class KeyguardHostView extends KeyguardViewBase {
    }
    }


    private void showAppropriateWidgetPage() {
    private void showAppropriateWidgetPage() {
        int state = mTransportState;
        final int state = mTransportState;
        ensureTransportPresentOrRemoved(state);
        final boolean transportAdded = ensureTransportPresentOrRemoved(state);
        int pageToShow = getAppropriateWidgetPage(state);
        final int pageToShow = getAppropriateWidgetPage(state);
        if (!transportAdded) {
            mAppWidgetContainer.setCurrentPage(pageToShow);
        } else if (state == TRANSPORT_VISIBLE) {
            // If the transport was just added, we need to wait for layout to happen before
            // we can set the current page.
            post(new Runnable() {
                @Override
                public void run() {
                    mAppWidgetContainer.setCurrentPage(pageToShow);
                    mAppWidgetContainer.setCurrentPage(pageToShow);
                }
                }
            });
        }
    }


    /**
    /**
     * Examines the current state and adds the transport to the widget pager when the state changes.
     * Examines the current state and adds the transport to the widget pager when the state changes.
@@ -1499,12 +1510,11 @@ public class KeyguardHostView extends KeyguardViewBase {
     *
     *
     * @param state
     * @param state
     */
     */
    private void ensureTransportPresentOrRemoved(int state) {
    private boolean ensureTransportPresentOrRemoved(int state) {
        final boolean showing = getWidgetPosition(R.id.keyguard_transport_control) != -1;
        final boolean showing = getWidgetPosition(R.id.keyguard_transport_control) != -1;
        final boolean visible = state == TRANSPORT_VISIBLE;
        final boolean visible = state == TRANSPORT_VISIBLE;
        final boolean shouldBeVisible = state == TRANSPORT_INVISIBLE && isMusicPlaying(state);
        final boolean shouldBeVisible = state == TRANSPORT_INVISIBLE && isMusicPlaying(state);
        if (!showing && (visible || shouldBeVisible)) {
        if (!showing && (visible || shouldBeVisible)) {
            if (DEBUGXPORT) Log.v(TAG, "add transport");
            // insert to left of camera if it exists, otherwise after right-most widget
            // insert to left of camera if it exists, otherwise after right-most widget
            int lastWidget = mAppWidgetContainer.getChildCount() - 1;
            int lastWidget = mAppWidgetContainer.getChildCount() - 1;
            int position = 0; // handle no widget case
            int position = 0; // handle no widget case
@@ -1512,13 +1522,16 @@ public class KeyguardHostView extends KeyguardViewBase {
                position = mAppWidgetContainer.isCameraPage(lastWidget) ?
                position = mAppWidgetContainer.isCameraPage(lastWidget) ?
                        lastWidget : lastWidget + 1;
                        lastWidget : lastWidget + 1;
            }
            }
            if (DEBUGXPORT) Log.v(TAG, "add transport at " + position);
            mAppWidgetContainer.addWidget(getOrCreateTransportControl(), position);
            mAppWidgetContainer.addWidget(getOrCreateTransportControl(), position);
            return true;
        } else if (showing && state == TRANSPORT_GONE) {
        } else if (showing && state == TRANSPORT_GONE) {
            if (DEBUGXPORT) Log.v(TAG, "remove transport");
            if (DEBUGXPORT) Log.v(TAG, "remove transport");
            mAppWidgetContainer.removeWidget(getOrCreateTransportControl());
            mAppWidgetContainer.removeWidget(getOrCreateTransportControl());
            mTransportControl = null;
            mTransportControl = null;
            KeyguardUpdateMonitor.getInstance(getContext()).dispatchSetBackground(null);
            KeyguardUpdateMonitor.getInstance(getContext()).dispatchSetBackground(null);
        }
        }
        return false;
    }
    }


    private CameraWidgetFrame findCameraPage() {
    private CameraWidgetFrame findCameraPage() {