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

Commit ff603b5e authored by Wenyi Wang's avatar Wenyi Wang
Browse files

Keep overflow menu button from closing on changing device orientation

Bug: 21650562
Change-Id: Ic2459b0768866e4a76734345ffa75edad8dac702
parent 3f18d619
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -27,4 +27,7 @@
    <!-- Max suggestions limit showing in quick contact suggestion card [CHAR LIMIT=30]-->
    <integer name="quickcontact_suggestions_limit">10</integer>

    <!-- The delay (in milliseconds) until the overflow options menu is shown automatically -->
    <integer name="open_overflow_menu_delay_millis">250</integer>

</resources>
+22 −1
Original line number Diff line number Diff line
@@ -73,11 +73,14 @@ public class ActionBarAdapter implements OnCloseListener {
    private static final String EXTRA_KEY_QUERY = "navBar.query";
    private static final String EXTRA_KEY_SELECTED_TAB = "navBar.selectedTab";
    private static final String EXTRA_KEY_SELECTED_MODE = "navBar.selectionMode";
    private static final String EXTRA_KEY_SHOULD_OPEN_OVERFLOW = "navBar.shouldOpenOverflow";

    private static final String PERSISTENT_LAST_TAB = "actionBarAdapter.lastTab";

    private boolean mSelectionMode;
    private boolean mSearchMode;
    private boolean mShouldOverflowOpen;
    private boolean mIsOverflowOpen;
    private String mQueryString;

    private EditText mSearchView;
@@ -198,11 +201,12 @@ public class ActionBarAdapter implements OnCloseListener {
            mQueryString = request.getQueryString();
            mCurrentTab = loadLastTabPreference();
            mSelectionMode = false;
            setShouldOpenOverflow(false);
        } else {
            mSearchMode = savedState.getBoolean(EXTRA_KEY_SEARCH_MODE);
            mSelectionMode = savedState.getBoolean(EXTRA_KEY_SELECTED_MODE);
            mQueryString = savedState.getString(EXTRA_KEY_QUERY);

            setShouldOpenOverflow(savedState.getBoolean(EXTRA_KEY_SHOULD_OPEN_OVERFLOW));
            // Just set to the field here.  The listener will be notified by update().
            mCurrentTab = savedState.getInt(EXTRA_KEY_SELECTED_TAB);
        }
@@ -319,6 +323,22 @@ public class ActionBarAdapter implements OnCloseListener {
        }
    }

    public void setShouldOpenOverflow(boolean shouldOpenOverflow) {
        mShouldOverflowOpen = shouldOpenOverflow;
    }

    public boolean shouldOpenOverflow() {
        return mShouldOverflowOpen;
    }

    public void setOverflowOpen(boolean isOverflowOpen) {
        mIsOverflowOpen = isOverflowOpen;
    }

    public boolean isOverflowOpen() {
        return mIsOverflowOpen;
    }

    public String getQueryString() {
        return mSearchMode ? mQueryString : null;
    }
@@ -547,6 +567,7 @@ public class ActionBarAdapter implements OnCloseListener {
    public void onSaveInstanceState(Bundle outState) {
        outState.putBoolean(EXTRA_KEY_SEARCH_MODE, mSearchMode);
        outState.putBoolean(EXTRA_KEY_SELECTED_MODE, mSelectionMode);
        outState.putBoolean(EXTRA_KEY_SHOULD_OPEN_OVERFLOW, mShouldOverflowOpen);
        outState.putString(EXTRA_KEY_QUERY, mQueryString);
        outState.putInt(EXTRA_KEY_SELECTED_TAB, mCurrentTab);
    }
+31 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.UserManager;
import android.os.Handler;
import android.preference.PreferenceActivity;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
@@ -436,6 +437,16 @@ public class PeopleActivity extends ContactsActivity implements
        // Current tab may have changed since the last onSaveInstanceState().  Make sure
        // the actual contents match the tab.
        updateFragmentsVisibility();

        if (mActionBarAdapter.shouldOpenOverflow() && !mActionBarAdapter.isOverflowOpen()) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    openOptionsMenu();
                }
            }, /* delayMillis = */ getResources().getInteger(R.integer.
                    open_overflow_menu_delay_millis));
        }
    }

    @Override
@@ -1422,4 +1433,24 @@ public class PeopleActivity extends ContactsActivity implements
        }
        return position;
    }

    @Override
    public boolean onMenuOpened(int featureId, Menu menu) {
        // When the overflow menu button opens (both manually and automatically), we need to
        // update both variables; same for closing event.
        mActionBarAdapter.setOverflowOpen(true);
        mActionBarAdapter.setShouldOpenOverflow(true);
        return super.onMenuOpened(featureId, menu);
    }

    @Override
    public void onPanelClosed(int featureId, Menu menu) {
        // Since onPanelClosed will be called when the activity is destroyed on rotation even if
        // user leaves the menu open, we are relying on onSaveInstanceState being called before
        // onDestroy and onPanelClosed are invoked in order to store the "opening" status of the
        // menu.
        mActionBarAdapter.setOverflowOpen(false);
        mActionBarAdapter.setShouldOpenOverflow(false);
        super.onMenuOpened(featureId, menu);
    }
}