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

Commit ad3e9d87 authored by Daisuke Miyakawa's avatar Daisuke Miyakawa
Browse files

Show filter menu on the right of SearchView when no menu button

TESTED:
- filter option menu shows up on the right side of SearchView
  instead of being shown as an overflow menu when the device
  doesn't have a hard menu button
- filter option menu keeps shown as one of menus when
  the device has a hard menu button

Bug: 5131136
Change-Id: Ice630533cfd4fb13383958489549236f9229053d
parent 766c5848
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!-- Dimensions are set at runtime in ActionBarAdapter -->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0dip"
    android:layout_height="0dip"
    android:orientation="horizontal">

    <SearchView
        android:id="@+id/search_view"
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:iconifiedByDefault="false" />

    <ImageButton
        android:id="@+id/search_option"
        android:layout_width="wrap_content"
        android:paddingRight="8dip"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:src="@drawable/ic_menu_overflow"
        android:background="@android:color/transparent"
        android:visibility="gone" />

</LinearLayout>
+22 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<!-- Used with DialtactsActivity's search mode. -->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/filter_option"
        android:title="@string/menu_contacts_filter"
        android:showAsAction="withText" />
</menu>
+36 −5
Original line number Diff line number Diff line
@@ -57,9 +57,10 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnClickListener;
import android.view.ViewConfiguration;
import android.view.inputmethod.InputMethodManager;
import android.widget.PopupMenu;
import android.widget.SearchView;
import android.widget.SearchView.OnCloseListener;
import android.widget.SearchView.OnQueryTextListener;
@@ -244,6 +245,23 @@ public class DialtactsActivity extends Activity {
    private boolean mInSearchUi;
    private SearchView mSearchView;

    /**
     * Available only when the device doesn't have hard menu key. Used to show "filter option"
     * menu on the right of {@link SearchView}.
     */
    private View mFilterOptionView;
    private final OnClickListener mFilterOptionClickListener = new OnClickListener() {
        @Override
        public void onClick(View view) {
            final PopupMenu popupMenu = new PopupMenu(DialtactsActivity.this, view);
            final Menu menu = popupMenu.getMenu();
            popupMenu.inflate(R.menu.dialtacts_search_options);
            final MenuItem filterOptionMenuItem = menu.findItem(R.id.filter_option);
            filterOptionMenuItem.setOnMenuItemClickListener(mFilterOptionsMenuItemClickListener);
            popupMenu.show();
        }
    };

    /**
     * The index of the Fragment (or, the tab) that has last been manually selected.
     * This value does not keep track of programmatically set Tabs (e.g. Call Log after a Call)
@@ -393,7 +411,7 @@ public class DialtactsActivity extends Activity {

    private void prepareSearchView() {
        final View searchViewLayout =
                getLayoutInflater().inflate(R.layout.custom_action_bar, null);
                getLayoutInflater().inflate(R.layout.dialtacts_custom_action_bar, null);
        mSearchView = (SearchView) searchViewLayout.findViewById(R.id.search_view);
        mSearchView.setOnQueryTextListener(mPhoneSearchQueryTextListener);
        mSearchView.setOnCloseListener(mPhoneSearchCloseListener);
@@ -406,6 +424,14 @@ public class DialtactsActivity extends Activity {
        mSearchView.setIconifiedByDefault(true);
        mSearchView.setQueryHint(getString(R.string.hint_findContacts));
        mSearchView.setIconified(false);

        if (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
            // Filter option menu should be shown on the right side of SearchView.
            mFilterOptionView = searchViewLayout.findViewById(R.id.search_option);
            mFilterOptionView.setVisibility(View.VISIBLE);
            mFilterOptionView.setOnClickListener(mFilterOptionClickListener);
        }

        getActionBar().setCustomView(searchViewLayout,
                new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    }
@@ -675,9 +701,14 @@ public class DialtactsActivity extends Activity {
        Tab tab = getActionBar().getSelectedTab();
        if (mInSearchUi) {
            searchMenuItem.setVisible(false);
            if (ViewConfiguration.get(this).hasPermanentMenuKey()) {
                filterOptionMenuItem.setVisible(true);
                filterOptionMenuItem.setOnMenuItemClickListener(
                        mFilterOptionsMenuItemClickListener);
            } else {
                // Filter option menu should be not be shown as a overflow menu.
                filterOptionMenuItem.setVisible(false);
            }
            callSettingsMenuItem.setVisible(false);
        } else {
            final boolean showCallSettingsMenu;