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

Commit 79f7430b authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Searchview layout cleanup. Some more tweaks required for Market.

Bug: 3321263

Submit area should be visible when the field has focus, irrespective of text content.
Make sure that the fields get highlighted when focused.
Also fix an issue with hint not being applied from the SearchableInfo.
Bug: 3470348

Change-Id: If399d9551f89312c19485e249043f5823a862499
parent 39184a08
Loading
Loading
Loading
Loading
+22 −18
Original line number Original line Diff line number Diff line
@@ -83,6 +83,7 @@ public class SearchView extends LinearLayout {
    private CursorAdapter mSuggestionsAdapter;
    private CursorAdapter mSuggestionsAdapter;
    private View mSearchButton;
    private View mSearchButton;
    private View mSubmitButton;
    private View mSubmitButton;
    private View mSearchPlate;
    private View mSubmitArea;
    private View mSubmitArea;
    private ImageView mCloseButton;
    private ImageView mCloseButton;
    private View mSearchEditFrame;
    private View mSearchEditFrame;
@@ -190,6 +191,7 @@ public class SearchView extends LinearLayout {
        mQueryTextView.setSearchView(this);
        mQueryTextView.setSearchView(this);


        mSearchEditFrame = findViewById(R.id.search_edit_frame);
        mSearchEditFrame = findViewById(R.id.search_edit_frame);
        mSearchPlate = findViewById(R.id.search_plate);
        mSubmitArea = findViewById(R.id.submit_area);
        mSubmitArea = findViewById(R.id.submit_area);
        mSubmitButton = findViewById(R.id.search_go_btn);
        mSubmitButton = findViewById(R.id.search_go_btn);
        mCloseButton = (ImageView) findViewById(R.id.search_close_btn);
        mCloseButton = (ImageView) findViewById(R.id.search_close_btn);
@@ -258,6 +260,7 @@ public class SearchView extends LinearLayout {
        mSearchable = searchable;
        mSearchable = searchable;
        if (mSearchable != null) {
        if (mSearchable != null) {
            updateSearchAutoComplete();
            updateSearchAutoComplete();
            updateQueryHint();
        }
        }
        // Cache the voice search capability
        // Cache the voice search capability
        mVoiceButtonEnabled = hasVoiceSearch();
        mVoiceButtonEnabled = hasVoiceSearch();
@@ -575,19 +578,19 @@ public class SearchView extends LinearLayout {
    }
    }


    private void updateSubmitButton(boolean hasText) {
    private void updateSubmitButton(boolean hasText) {
        mSubmitButton.setVisibility(
        int visibility = GONE;
                isSubmitAreaEnabled() ? (hasText ? VISIBLE : INVISIBLE) : GONE);
        if (isSubmitAreaEnabled() && hasFocus() && (hasText || !mVoiceButtonEnabled)) {
            visibility = VISIBLE;
        }
        mSubmitButton.setVisibility(visibility);
    }
    }


    private void updateSubmitArea() {
    private void updateSubmitArea() {
        int visibility = GONE;
        int visibility = GONE;
        if (isSubmitAreaEnabled()) {
        if (isSubmitAreaEnabled()
            if (mSubmitButton.getVisibility() == VISIBLE
                && (mSubmitButton.getVisibility() == VISIBLE
                    || mVoiceButton.getVisibility() == VISIBLE) {
                        || mVoiceButton.getVisibility() == VISIBLE)) {
            visibility = VISIBLE;
            visibility = VISIBLE;
            } else {
                visibility = INVISIBLE;
            }
        }
        }
        mSubmitArea.setVisibility(visibility);
        mSubmitArea.setVisibility(visibility);
    }
    }
@@ -601,6 +604,11 @@ public class SearchView extends LinearLayout {
        mCloseButton.getDrawable().setState(hasText ? ENABLED_STATE_SET : EMPTY_STATE_SET);
        mCloseButton.getDrawable().setState(hasText ? ENABLED_STATE_SET : EMPTY_STATE_SET);
    }
    }


    private void updateFocusedState(boolean focused) {
        mSearchPlate.getBackground().setState(focused ? FOCUSED_STATE_SET : EMPTY_STATE_SET);
        mSubmitArea.getBackground().setState(focused ? FOCUSED_STATE_SET : EMPTY_STATE_SET);
    }

    private void setImeVisibility(boolean visible) {
    private void setImeVisibility(boolean visible) {
        InputMethodManager imm = (InputMethodManager)
        InputMethodManager imm = (InputMethodManager)
                getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
@@ -851,16 +859,11 @@ public class SearchView extends LinearLayout {
     * Update the visibility of the voice button.  There are actually two voice search modes,
     * Update the visibility of the voice button.  There are actually two voice search modes,
     * either of which will activate the button.
     * either of which will activate the button.
     * @param empty whether the search query text field is empty. If it is, then the other
     * @param empty whether the search query text field is empty. If it is, then the other
     * criteria apply to make the voice button visible. Otherwise the voice button will not
     * criteria apply to make the voice button visible.
     * be visible - i.e., if the user has typed a query, remove the voice button.
     */
     */
    private void updateVoiceButton(boolean empty) {
    private void updateVoiceButton(boolean empty) {
        // If the voice button is to be visible, show it
        int visibility = GONE;
        // Else, make it gone if the submit button is enabled, otherwise invisible to
        if (mVoiceButtonEnabled && !isIconified() && (empty || !mSubmitButtonEnabled)) {
        // avoid losing the real-estate
        int visibility = mSubmitButtonEnabled ? GONE : INVISIBLE;

        if (mVoiceButtonEnabled && !isIconified() && empty) {
            visibility = VISIBLE;
            visibility = VISIBLE;
            mSubmitButton.setVisibility(GONE);
            mSubmitButton.setVisibility(GONE);
        }
        }
@@ -958,7 +961,8 @@ public class SearchView extends LinearLayout {
    }
    }


    void onTextFocusChanged() {
    void onTextFocusChanged() {
        updateCloseButton();
        updateViewsVisibility(isIconified());
        updateFocusedState(mQueryTextView.hasFocus());
    }
    }


    private boolean onItemClicked(int position, int actionKey, String actionMsg) {
    private boolean onItemClicked(int position, int actionKey, String actionMsg) {
+4 −0
Original line number Original line Diff line number Diff line
@@ -54,6 +54,10 @@
        android:layout_height="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_weight="1"
        android:layout_gravity="center_vertical"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="4dip"
        android:layout_marginRight="4dip"
        android:layout_marginTop="4dip"
        android:layout_marginBottom="4dip"
        android:orientation="horizontal">
        android:orientation="horizontal">


        <!-- Inner layout contains the app icon, button(s) and EditText -->
        <!-- Inner layout contains the app icon, button(s) and EditText -->