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

Commit 5dddb70b authored by Alan Viverette's avatar Alan Viverette
Browse files

Add style for SearchView

BUG: 6420978
Change-Id: I31d9f7e66c2404388ccbe6d2e43a005deb0b7c25
parent 0c116e15
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -391,6 +391,7 @@ package android {
    field public static final int clipOrientation = 16843274; // 0x101020a
    field public static final int clipToPadding = 16842987; // 0x10100eb
    field public static final int clipToPath = 16843817; // 0x1010429
    field public static final int closeIcon = 16843907; // 0x1010483
    field public static final int codes = 16843330; // 0x1010242
    field public static final int collapseColumns = 16843083; // 0x101014b
    field public static final int color = 16843173; // 0x10101a5
@@ -414,6 +415,7 @@ package android {
    field public static final int columnDelay = 16843215; // 0x10101cf
    field public static final int columnOrderPreserved = 16843640; // 0x1010378
    field public static final int columnWidth = 16843031; // 0x1010117
    field public static final int commitIcon = 16843911; // 0x1010487
    field public static final int compatibleWidthLimitDp = 16843621; // 0x1010365
    field public static final int completionHint = 16843122; // 0x1010172
    field public static final int completionHintView = 16843123; // 0x1010173
@@ -598,6 +600,7 @@ package android {
    field public static final int gestureStrokeType = 16843385; // 0x1010279
    field public static final int gestureStrokeWidth = 16843380; // 0x1010274
    field public static final int glEsVersion = 16843393; // 0x1010281
    field public static final int goIcon = 16843908; // 0x1010484
    field public static final int gradientRadius = 16843172; // 0x10101a4
    field public static final int grantUriPermissions = 16842779; // 0x101001b
    field public static final int gravity = 16842927; // 0x10100af
@@ -951,6 +954,7 @@ package android {
    field public static final int publicKey = 16843686; // 0x10103a6
    field public static final int queryActionMsg = 16843227; // 0x10101db
    field public static final int queryAfterZeroResults = 16843394; // 0x1010282
    field public static final int queryBackground = 16843913; // 0x1010489
    field public static final int queryHint = 16843608; // 0x1010358
    field public static final int quickContactBadgeStyleSmallWindowLarge = 16843443; // 0x10102b3
    field public static final int quickContactBadgeStyleSmallWindowMedium = 16843442; // 0x10102b2
@@ -1026,6 +1030,7 @@ package android {
    field public static final int scrollbars = 16842974; // 0x10100de
    field public static final int scrollingCache = 16843006; // 0x10100fe
    field public static final deprecated int searchButtonText = 16843269; // 0x1010205
    field public static final int searchIcon = 16843909; // 0x1010485
    field public static final int searchKeyphrase = 16843873; // 0x1010461
    field public static final int searchKeyphraseId = 16843872; // 0x1010460
    field public static final int searchKeyphraseSupportedLocales = 16843874; // 0x1010462
@@ -1037,6 +1042,7 @@ package android {
    field public static final int searchSuggestPath = 16843223; // 0x10101d7
    field public static final int searchSuggestSelection = 16843224; // 0x10101d8
    field public static final int searchSuggestThreshold = 16843373; // 0x101026d
    field public static final int searchViewStyle = 16843906; // 0x1010482
    field public static final int secondaryProgress = 16843064; // 0x1010138
    field public static final int secondaryProgressTint = 16843881; // 0x1010469
    field public static final int secondaryProgressTintMode = 16843882; // 0x101046a
@@ -1130,6 +1136,7 @@ package android {
    field public static final int strokeLineJoin = 16843816; // 0x1010428
    field public static final int strokeOpacity = 16843810; // 0x1010422
    field public static final int strokeWidth = 16843811; // 0x1010423
    field public static final int submitBackground = 16843914; // 0x101048a
    field public static final int subtitle = 16843473; // 0x10102d1
    field public static final int subtitleTextAppearance = 16843825; // 0x1010431
    field public static final int subtitleTextStyle = 16843513; // 0x10102f9
@@ -1138,6 +1145,7 @@ package android {
    field public static final int subtypeLocale = 16843673; // 0x1010399
    field public static final int suggestActionMsg = 16843228; // 0x10101dc
    field public static final int suggestActionMsgColumn = 16843229; // 0x10101dd
    field public static final int suggestionRowLayout = 16843912; // 0x1010488
    field public static final int summary = 16843241; // 0x10101e9
    field public static final int summaryColumn = 16843426; // 0x10102a2
    field public static final int summaryOff = 16843248; // 0x10101f0
@@ -1317,6 +1325,7 @@ package android {
    field public static final int visibilityMode = 16843902; // 0x101047e
    field public static final int visible = 16843156; // 0x1010194
    field public static final int vmSafeMode = 16843448; // 0x10102b8
    field public static final int voiceIcon = 16843910; // 0x1010486
    field public static final int voiceLanguage = 16843349; // 0x1010255
    field public static final int voiceLanguageModel = 16843347; // 0x1010253
    field public static final int voiceMaxResults = 16843350; // 0x1010256
+69 −52
Original line number Diff line number Diff line
@@ -99,6 +99,26 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
     */
    private static final String IME_OPTION_NO_MICROPHONE = "nm";

    private final SearchAutoComplete mQueryTextView;
    private final View mSearchEditFrame;
    private final View mSearchPlate;
    private final View mSubmitArea;
    private final ImageView mSearchButton;
    private final ImageView mSubmitButton;
    private final ImageView mCloseButton;
    private final ImageView mVoiceButton;
    private final ImageView mSearchHintIcon;
    private final View mDropDownAnchor;
    private final int mSearchIconResId;

    // Resources used by SuggestionsAdapter to display suggestions.
    private final int mSuggestionRowLayout;
    private final int mSuggestionCommitIconResId;

    // Intents used for voice searching.
    private final Intent mVoiceWebSearchIntent;
    private final Intent mVoiceAppSearchIntent;

    private OnQueryTextListener mOnQueryChangeListener;
    private OnCloseListener mOnCloseListener;
    private OnFocusChangeListener mOnQueryTextFocusChangeListener;
@@ -108,16 +128,6 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
    private boolean mIconifiedByDefault;
    private boolean mIconified;
    private CursorAdapter mSuggestionsAdapter;
    private View mSearchButton;
    private View mSubmitButton;
    private View mSearchPlate;
    private View mSubmitArea;
    private ImageView mCloseButton;
    private View mSearchEditFrame;
    private View mVoiceButton;
    private SearchAutoComplete mQueryTextView;
    private View mDropDownAnchor;
    private ImageView mSearchHintIcon;
    private boolean mSubmitButtonEnabled;
    private CharSequence mQueryHint;
    private boolean mQueryRefinement;
@@ -161,10 +171,6 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
        }
    };

    // For voice searching
    private final Intent mVoiceWebSearchIntent;
    private final Intent mVoiceAppSearchIntent;

    // A weak map of drawables we've gotten from other packages, so we don't load them
    // more than once.
    private final WeakHashMap<String, Drawable.ConstantState> mOutsideDrawablesCache =
@@ -242,7 +248,7 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
    }

    public SearchView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
        this(context, attrs, R.attr.searchViewStyle);
    }

    public SearchView(Context context, AttributeSet attrs, int defStyleAttr) {
@@ -252,22 +258,39 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
    public SearchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.search_view, this, true);
        final TypedArray a = context.obtainStyledAttributes(
                attrs, R.styleable.SearchView, defStyleAttr, defStyleRes);
        final LayoutInflater inflater = (LayoutInflater) context.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        final int layoutResId = a.getResourceId(R.styleable.SearchView_layout, 0);
        inflater.inflate(layoutResId, this, true);

        mSearchButton = findViewById(R.id.search_button);
        mQueryTextView = (SearchAutoComplete) findViewById(R.id.search_src_text);
        mQueryTextView.setSearchView(this);

        mSearchEditFrame = findViewById(R.id.search_edit_frame);
        mSearchPlate = findViewById(R.id.search_plate);
        mSubmitArea = findViewById(R.id.submit_area);
        mSubmitButton = findViewById(R.id.search_go_btn);
        mSearchButton = (ImageView) findViewById(R.id.search_button);
        mSubmitButton = (ImageView) findViewById(R.id.search_go_btn);
        mCloseButton = (ImageView) findViewById(R.id.search_close_btn);
        mVoiceButton = findViewById(R.id.search_voice_btn);
        mVoiceButton = (ImageView) findViewById(R.id.search_voice_btn);
        mSearchHintIcon = (ImageView) findViewById(R.id.search_mag_icon);

        // Set up icons and backgrounds.
        mSearchPlate.setBackground(a.getDrawable(R.styleable.SearchView_queryBackground));
        mSubmitArea.setBackground(a.getDrawable(R.styleable.SearchView_submitBackground));
        mSearchIconResId = a.getResourceId(R.styleable.SearchView_searchIcon, 0);
        mSearchButton.setImageResource(mSearchIconResId);
        mSubmitButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_goIcon));
        mCloseButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_closeIcon));
        mVoiceButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_voiceIcon));
        mSearchHintIcon.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon));

        // Extract dropdown layout resource IDs for later use.
        mSuggestionRowLayout = a.getResourceId(R.styleable.SearchView_suggestionRowLayout, 0);
        mSuggestionCommitIconResId = a.getResourceId(R.styleable.SearchView_commitIcon, 0);

        mSearchButton.setOnClickListener(mOnClickListener);
        mCloseButton.setOnClickListener(mOnClickListener);
        mSubmitButton.setOnClickListener(mOnClickListener);
@@ -279,6 +302,7 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
        mQueryTextView.setOnItemClickListener(mOnItemClickListener);
        mQueryTextView.setOnItemSelectedListener(mOnItemSelectedListener);
        mQueryTextView.setOnKeyListener(mTextKeyListener);

        // Inform any listener of focus changes
        mQueryTextView.setOnFocusChangeListener(new OnFocusChangeListener() {

@@ -288,36 +312,30 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
                }
            }
        });

        TypedArray a = context.obtainStyledAttributes(
                attrs, R.styleable.SearchView, defStyleAttr, defStyleRes);
        setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true));
        int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_maxWidth, -1);

        final int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_maxWidth, -1);
        if (maxWidth != -1) {
            setMaxWidth(maxWidth);
        }
        CharSequence queryHint = a.getText(R.styleable.SearchView_queryHint);

        final CharSequence queryHint = a.getText(R.styleable.SearchView_queryHint);
        if (!TextUtils.isEmpty(queryHint)) {
            setQueryHint(queryHint);
        }
        int imeOptions = a.getInt(R.styleable.SearchView_imeOptions, -1);

        final int imeOptions = a.getInt(R.styleable.SearchView_imeOptions, -1);
        if (imeOptions != -1) {
            setImeOptions(imeOptions);
        }
        int inputType = a.getInt(R.styleable.SearchView_inputType, -1);

        final int inputType = a.getInt(R.styleable.SearchView_inputType, -1);
        if (inputType != -1) {
            setInputType(inputType);
        }

        a.recycle();

        boolean focusable = true;

        a = context.obtainStyledAttributes(attrs, R.styleable.View, defStyleAttr, defStyleRes);
        focusable = a.getBoolean(R.styleable.View_focusable, focusable);
        a.recycle();
        setFocusable(focusable);

        // Save voice intent for later queries/launching
        mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -342,6 +360,14 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
        updateQueryHint();
    }

    int getSuggestionRowLayout() {
        return mSuggestionRowLayout;
    }

    int getSuggestionCommitIconResId() {
        return mSuggestionCommitIconResId;
    }

    /**
     * Sets the SearchableInfo for this SearchView. Properties in the SearchableInfo are used
     * to display labels, hints, suggestions, create intents for launching search results screens
@@ -1046,22 +1072,18 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
        return result;
    }

    private int getSearchIconId() {
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(com.android.internal.R.attr.searchViewSearchIcon,
                outValue, true);
        return outValue.resourceId;
    }

    private CharSequence getDecoratedHint(CharSequence hintText) {
        // If the field is always expanded, then don't add the search icon to the hint
        if (!mIconifiedByDefault) return hintText;
        if (!mIconifiedByDefault) {
            return hintText;
        }

        SpannableStringBuilder ssb = new SpannableStringBuilder("   "); // for the icon
        ssb.append(hintText);
        Drawable searchIcon = getContext().getDrawable(getSearchIconId());
        int textSize = (int) (mQueryTextView.getTextSize() * 1.25);
        final Drawable searchIcon = getContext().getDrawable(mSearchIconResId);
        final int textSize = (int) (mQueryTextView.getTextSize() * 1.25);
        searchIcon.setBounds(0, 0, textSize, textSize);

        final SpannableStringBuilder ssb = new SpannableStringBuilder("   "); // for the icon
        ssb.append(hintText);
        ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return ssb;
    }
@@ -1363,11 +1385,6 @@ public class SearchView extends LinearLayout implements CollapsibleActionView {
        }
    };

    @Override
    public void onRtlPropertiesChanged(int layoutDirection) {
        mQueryTextView.setLayoutDirection(layoutDirection);
    }

    /**
     * Query rewriting.
     */
+20 −13
Original line number Diff line number Diff line
@@ -64,11 +64,13 @@ class SuggestionsAdapter extends ResourceCursorAdapter implements OnClickListene
    static final int REFINE_BY_ENTRY = 1;
    static final int REFINE_ALL = 2;

    private SearchManager mSearchManager;
    private SearchView mSearchView;
    private SearchableInfo mSearchable;
    private Context mProviderContext;
    private WeakHashMap<String, Drawable.ConstantState> mOutsideDrawablesCache;
    private final SearchManager mSearchManager;
    private final SearchView mSearchView;
    private final SearchableInfo mSearchable;
    private final Context mProviderContext;
    private final WeakHashMap<String, Drawable.ConstantState> mOutsideDrawablesCache;
    private final int mCommitIconResId;

    private boolean mClosed = false;
    private int mQueryRefinement = REFINE_BY_ENTRY;

@@ -94,18 +96,18 @@ class SuggestionsAdapter extends ResourceCursorAdapter implements OnClickListene
     */
    private static final long DELETE_KEY_POST_DELAY = 500L;

    public SuggestionsAdapter(Context context, SearchView searchView,
            SearchableInfo searchable,
    public SuggestionsAdapter(Context context, SearchView searchView, SearchableInfo searchable,
            WeakHashMap<String, Drawable.ConstantState> outsideDrawablesCache) {
        super(context,
                com.android.internal.R.layout.search_dropdown_item_icons_2line,
                null,   // no initial cursor
                true);  // auto-requery
        super(context, searchView.getSuggestionRowLayout(), null /* no initial cursor */,
                true /* auto-requery */);

        mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
        mSearchView = searchView;
        mSearchable = searchable;
        mCommitIconResId = searchView.getSuggestionCommitIconResId();

        // set up provider resources (gives us icons, etc.)
        Context activityContext = mSearchable.getActivityContext(mContext);
        final Context activityContext = mSearchable.getActivityContext(mContext);
        mProviderContext = mSearchable.getProviderContext(mContext, activityContext);

        mOutsideDrawablesCache = outsideDrawablesCache;
@@ -279,8 +281,13 @@ class SuggestionsAdapter extends ResourceCursorAdapter implements OnClickListene
     */
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        View v = super.newView(context, cursor, parent);
        final View v = super.newView(context, cursor, parent);
        v.setTag(new ChildViewCache(v));

        // Set up icon.
        final ImageView iconRefine = (ImageView) v.findViewById(R.id.edit_query);
        iconRefine.setImageResource(mCommitIconResId);

        return v;
    }

+739 B
Loading image diff...
+874 B
Loading image diff...
Loading