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

Commit bba19558 authored by Roman Birg's avatar Roman Birg
Browse files

SystemUI: handle hiding recents search bar dynamically



If the "Show recents search bar" is toggled inside Settings, we need to
catch that and reload the header bar as needed. Otherwise, having the
setting disabled would still include search bar bounds while the view
was hidden, causing some jarring animation jumps.

Ref: CYNGNOS-342

Change-Id: I74597d6d225af0395da6cb7a611bd230fc9e0675
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 76da31a8
Loading
Loading
Loading
Loading
+38 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.systemui.R;
import com.android.systemui.RecentsComponent;
import com.android.systemui.SystemUI;
import com.android.systemui.SystemUIApplication;
import com.android.systemui.cm.UserContentObserver;
import com.android.systemui.recents.misc.Console;
import com.android.systemui.recents.misc.SystemServicesProxy;
import com.android.systemui.recents.model.RecentsTaskLoadPlan;
@@ -61,6 +62,8 @@ import com.android.systemui.statusbar.phone.PhoneStatusBar;

import java.util.ArrayList;

import cyanogenmod.providers.CMSettings;

/**
 * Annotation for a method that is only called from the primary user's SystemUI process and will be
 * proxied to the current user.
@@ -161,6 +164,35 @@ public class Recents extends SystemUI
        }
    }

    class RecentsSettingsObserver extends UserContentObserver {

        public RecentsSettingsObserver(Handler handler) {
            super(handler);
        }

        @Override
        protected void observe() {
            super.observe();
            mContext.getContentResolver().registerContentObserver(
                    CMSettings.System.getUriFor(CMSettings.System.RECENTS_SHOW_SEARCH_BAR),
                    false, this);
            update();
        }

        @Override
        protected void unobserve() {
            super.unobserve();
            mContext.getContentResolver().unregisterContentObserver(this);
        }

        @Override
        protected void update() {
            if (mConfig.updateShowSearch(mContext)) {
                reloadHeaderBarLayout();
            }
        }
    }

    static RecentsComponent.Callbacks sRecentsComponentCallbacks;
    static RecentsTaskLoadPlan sInstanceLoadPlan;
    static Recents sInstance;
@@ -171,6 +203,7 @@ public class Recents extends SystemUI
    TaskStackListenerImpl mTaskStackListener;
    RecentsOwnerEventProxyReceiver mProxyBroadcastReceiver;
    RecentsAppWidgetHost mAppWidgetHost;
    RecentsSettingsObserver mSettingsObserver;
    boolean mBootCompleted;
    boolean mStartAnimationTriggered;
    boolean mCanReuseTaskStackViews = true;
@@ -259,6 +292,9 @@ public class Recents extends SystemUI
        // Load the header bar layout
        reloadHeaderBarLayout();

        mSettingsObserver = new RecentsSettingsObserver(mHandler);
        mSettingsObserver.observe();

        // When we start, preload the data associated with the previous recent tasks.
        // We can use a new plan since the caches will be the same.
        RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
@@ -549,7 +585,8 @@ public class Recents extends SystemUI
        // Try and pre-emptively bind the search widget on startup to ensure that we
        // have the right thumbnail bounds to animate to.
        // Note: We have to reload the widget id before we get the task stack bounds below
        if (mSystemServicesProxy.getOrBindSearchAppWidget(mContext, mAppWidgetHost) != null) {
        if (mConfig.searchBarEnabled &&
                mSystemServicesProxy.getOrBindSearchAppWidget(mContext, mAppWidgetHost) != null) {
            mConfig.getSearchBarBounds(mWindowRect.width(), mWindowRect.height(),
                    mStatusBarHeight, searchBarBounds);
        }
+7 −3
Original line number Diff line number Diff line
@@ -261,12 +261,16 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
                mEmptyView.setVisibility(View.GONE);
                mEmptyView.setOnClickListener(null);
            }
            if (!mConfig.searchBarEnabled) {
                mRecentsView.setSearchBarVisibility(View.GONE);
            } else {
                if (mRecentsView.hasValidSearchBar()) {
                    mRecentsView.setSearchBarVisibility(View.VISIBLE);
                } else {
                    refreshSearchWidgetView();
                }
            }
        }

        // Animate the SystemUI scrims into view
        mScrimViews.prepareEnterRecentsAnimation();
+9 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.systemui.R;
import com.android.systemui.recents.misc.Console;
import com.android.systemui.recents.misc.SystemServicesProxy;

import cyanogenmod.providers.CMSettings;

/** A static Recents configuration for the current context
 * NOTE: We should not hold any references to a Context from a static instance */
@@ -73,6 +74,7 @@ public class RecentsConfiguration {
    public int maxNumTasksToLoad;

    /** Search bar */
    public boolean searchBarEnabled = true;
    public int searchBarSpaceHeightPx;

    /** Task stack */
@@ -279,6 +281,13 @@ public class RecentsConfiguration {
        svelteLevel = res.getInteger(R.integer.recents_svelte_level);
    }

    public boolean updateShowSearch(Context context) {
        boolean wasEnabled = searchBarEnabled;
        searchBarEnabled = CMSettings.System.getInt(context.getContentResolver(),
                CMSettings.System.RECENTS_SHOW_SEARCH_BAR, 1) == 1;
        return wasEnabled != searchBarEnabled;
    }

    /** Updates the system insets */
    public void updateSystemInsets(Rect insets) {
        systemInsets.set(insets);
+2 −2
Original line number Diff line number Diff line
@@ -323,7 +323,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV

        // Get the search bar bounds and measure the search bar layout
        Rect searchBarSpaceBounds = new Rect();
        if (mSearchBar != null) {
        if (mSearchBar != null && mConfig.searchBarEnabled) {
            mConfig.getSearchBarBounds(width, height, mConfig.systemInsets.top, searchBarSpaceBounds);
            mSearchBar.measure(
                    MeasureSpec.makeMeasureSpec(searchBarSpaceBounds.width(), MeasureSpec.EXACTLY),
@@ -360,7 +360,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        // Get the search bar bounds so that we lay it out
        if (mSearchBar != null) {
        if (mSearchBar != null && mConfig.searchBarEnabled) {
            Rect searchBarSpaceBounds = new Rect();
            mConfig.getSearchBarBounds(getMeasuredWidth(), getMeasuredHeight(),
                    mConfig.systemInsets.top, searchBarSpaceBounds);