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

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

Add a missing setOnCloseListener and a new setIconfied method.

Keep track of the currently iconified state as well, if the app
wants to know.
parent 023606ab
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -234035,6 +234035,17 @@
 visibility="public"
>
</method>
<method name="isIconified"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="isSubmitButtonEnabled"
 return="boolean"
 abstract="false"
@@ -234046,6 +234057,19 @@
 visibility="public"
>
</method>
<method name="setIconified"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="iconify" type="boolean">
</parameter>
</method>
<method name="setIconifiedByDefault"
 return="void"
 abstract="false"
@@ -234059,6 +234083,19 @@
<parameter name="iconified" type="boolean">
</parameter>
</method>
<method name="setOnCloseListener"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="listener" type="android.widget.SearchView.OnCloseListener">
</parameter>
</method>
<method name="setOnQueryChangeListener"
 return="void"
 abstract="false"
+52 −8
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ public class SearchView extends LinearLayout {
    private OnCloseListener mOnCloseListener;

    private boolean mIconifiedByDefault;
    private boolean mIconified;
    private CursorAdapter mSuggestionsAdapter;
    private View mSearchButton;
    private View mSubmitButton;
@@ -139,8 +140,6 @@ public class SearchView extends LinearLayout {
        mQueryTextView.setOnItemClickListener(mOnItemClickListener);
        mQueryTextView.setOnItemSelectedListener(mOnItemSelectedListener);

        mSubmitButtonEnabled = false;

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SearchView, 0, 0);
        setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true));
        a.recycle();
@@ -174,6 +173,15 @@ public class SearchView extends LinearLayout {
        mOnQueryChangeListener = listener;
    }

    /**
     * Sets a listener to inform when the user closes the SearchView.
     *
     * @param listener the listener to call when the user closes the SearchView.
     */
    public void setOnCloseListener(OnCloseListener listener) {
        mOnCloseListener = listener;
    }

    /**
     * Sets a query string in the text field and optionally submits the query as well.
     *
@@ -205,19 +213,53 @@ public class SearchView extends LinearLayout {
     * Sets the default or resting state of the search field. If true, a single search icon is
     * shown by default and expands to show the text field and other buttons when pressed. Also,
     * if the default state is iconified, then it collapses to that state when the close button
     * is pressed.
     * is pressed. Changes to this property will take effect immediately.
     *
     * @param iconified
     * <p>The default value is false.</p>
     *
     * @param iconified whether the search field should be iconified by default
     */
    public void setIconifiedByDefault(boolean iconified) {
        mIconifiedByDefault = iconified;
        updateViewsVisibility(iconified);
    }

    /**
     * Returns the default iconified state of the search field.
     * @return
     */
    public boolean isIconfiedByDefault() {
        return mIconifiedByDefault;
    }

    /**
     * Iconifies or expands the SearchView. Any query text is cleared when iconified. This is
     * a temporary state and does not override the default iconified state set by
     * {@link #setIconifiedByDefault(boolean)}. If the default state is iconified, then
     * a false here will only be valid until the user closes the field. And if the default
     * state is expanded, then a true here will only clear the text field and not close it.
     *
     * @param iconify a true value will collapse the SearchView to an icon, while a false will
     * expand it.
     */
    public void setIconified(boolean iconify) {
        if (iconify) {
            onCloseClicked();
        } else {
            onSearchClicked();
        }
    }

    /**
     * Returns the current iconified state of the SearchView.
     *
     * @return true if the SearchView is currently iconified, false if the search field is
     * fully visible.
     */
    public boolean isIconified() {
        return mIconified;
    }

    /**
     * Enables showing a submit button when the query is non-empty. In cases where the SearchView
     * is being used to filter the contents of the current activity and doesn't launch a separate
@@ -263,11 +305,12 @@ public class SearchView extends LinearLayout {
        return mSuggestionsAdapter;
    }

    private void updateViewsVisibility(boolean collapsed) {
    private void updateViewsVisibility(final boolean collapsed) {
        mIconified = collapsed;
        // Visibility of views that are visible when collapsed
        int visCollapsed = collapsed? VISIBLE : GONE;
        final int visCollapsed = collapsed ? VISIBLE : GONE;
        // Visibility of views that are visible when expanded
        int visExpanded = collapsed? GONE : VISIBLE;
        final int visExpanded = collapsed ? GONE : VISIBLE;

        mSearchButton.setVisibility(visCollapsed);
        mSubmitButton.setVisibility(mSubmitButtonEnabled ? visExpanded : GONE);
@@ -322,7 +365,8 @@ public class SearchView extends LinearLayout {
        // entered query with the action key
        SearchableInfo.ActionKeyInfo actionKey = mSearchable.findActionKey(keyCode);
        if ((actionKey != null) && (actionKey.getQueryActionMsg() != null)) {
            launchQuerySearch(keyCode, actionKey.getQueryActionMsg(), mQueryTextView.getText().toString());
            launchQuerySearch(keyCode, actionKey.getQueryActionMsg(), mQueryTextView.getText()
                    .toString());
            return true;
        }