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

Commit 24652989 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

SearchView improvements per design.

- X is visible only if there is text, or we need a way to close a
search field that is iconified by default.
- Search dialog (legacy) has a back button to the left.
- Hitting X on a non-focused search view will bring it into focus
and show the keyboard if necessary.

Change-Id: I5a30bb08adcf84639a922a9e13be1d1562f714e6
parent 03289747
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ public class SearchDialog extends Dialog {
    private View mSearchPlate;
    private SearchView mSearchView;
    private Drawable mWorkingSpinner;
    private View mCloseSearch;

    // interaction with searchable application
    private SearchableInfo mSearchable;
@@ -167,11 +168,18 @@ public class SearchDialog extends Dialog {
        SearchBar searchBar = (SearchBar) findViewById(com.android.internal.R.id.search_bar);
        searchBar.setSearchDialog(this);
        mSearchView = (SearchView) findViewById(com.android.internal.R.id.search_view);
        mSearchView.setSubmitButtonEnabled(true);
        mSearchView.setOnCloseListener(mOnCloseListener);
        mSearchView.setOnQueryTextListener(mOnQueryChangeListener);
        mSearchView.setOnSuggestionListener(mOnSuggestionSelectionListener);

        mCloseSearch = findViewById(com.android.internal.R.id.closeButton);
        mCloseSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        // TODO: Move the badge logic to SearchView or move the badge to search_bar.xml
        mBadgeLabel = (TextView) mSearchView.findViewById(com.android.internal.R.id.search_badge);
        mSearchAutoComplete = (AutoCompleteTextView)
+12 −7
Original line number Diff line number Diff line
@@ -603,7 +603,7 @@ public class SearchView extends LinearLayout {
        final boolean hasText = !TextUtils.isEmpty(mQueryTextView.getText());
        // Should we show the close button? It is not shown if there's no focus,
        // field is not iconified by default and there is no text in it.
        final boolean showClose = hasText || mIconifiedByDefault || mQueryTextView.hasFocus();
        final boolean showClose = hasText || mIconifiedByDefault;
        mCloseButton.setVisibility(showClose ? VISIBLE : INVISIBLE);
        mCloseButton.getDrawable().setState(hasText ? ENABLED_STATE_SET : EMPTY_STATE_SET);
    }
@@ -919,17 +919,22 @@ public class SearchView extends LinearLayout {
    }

    private void onCloseClicked() {
        if (mOnCloseListener == null || !mOnCloseListener.onClose()) {
        CharSequence text = mQueryTextView.getText();
        if (TextUtils.isEmpty(text)) {
            if (mIconifiedByDefault) {
                // query field already empty, hide the keyboard and remove focus
                clearFocus();
                setImeVisibility(false);
            }
        } else {
            mQueryTextView.setText("");
            mQueryTextView.requestFocus();
            setImeVisibility(true);
        }

        if (mIconifiedByDefault && (mOnCloseListener == null || !mOnCloseListener.onClose())) {
            updateViewsVisibility(mIconifiedByDefault);
            if (mIconifiedByDefault) setImeVisibility(false);
            setImeVisibility(false);
        }
    }

+198 B
Loading image diff...
+173 B
Loading image diff...
+41 −19
Original line number Diff line number Diff line
@@ -23,36 +23,58 @@
    android:id="@+id/search_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:orientation="vertical"
    android:background="@color/transparent"
    android:focusable="true"
    android:background="?android:attr/actionModeBackground"
    android:descendantFocusability="afterDescendants">

    <RelativeLayout
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/actionModeBackground"
        android:orientation="horizontal">

        <!-- Grouped to allow tapping on either item to exit search mode -->
        <LinearLayout
            android:id="@id/closeButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:focusable="true"
            android:background="?android:attr/selectableItemBackground">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
        >
                android:src="?android:attr/homeAsUpIndicator"/>

            <ImageView
                android:id="@+id/search_app_icon"
                android:layout_height="48dip"
                android:layout_width="48dip"
            android:layout_marginLeft="8dip"
            android:layout_marginRight="8dip"
                android:layout_gravity="center_vertical"
            android:layout_alignParentLeft="true"
            />

        </LinearLayout>

        <!-- Actual search view with search icon, text field, close
            and voice buttons -->
        <SearchView
            android:id="@+id/search_view"
            android:layout_width="match_parent"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:maxWidth="600dip"
            android:iconifiedByDefault="false"
            android:layout_alignParentRight="true"
            android:layout_gravity="center_vertical|right"
            android:layout_gravity="center_vertical"
            />

    </RelativeLayout>
    </LinearLayout>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:src="@drawable/title_bar_shadow"/>
</view>
Loading