New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(android): Adds extended support for color customization of Ti.UI.Android.SearchView #10719
Conversation
….Android.SearchView
This comment has been minimized.
This comment has been minimized.
* @module.api | ||
*/ | ||
public static final String PROPERTY_ICON_SEARCH_HINT_COLOR = "iconSearchHintColor"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the property names, perhaps we should rename them:
- "iconSearchColor" -> "iconSearchTintColor"
- "iconSearchCloseColor" -> "iconSearchCloseTintColor"
- "iconSearchHintColor" -> "iconSearchHintTintColor"
Notice that I added the word "Tint" to the above properties.
This is for consistency with our other tint color properties such as:
ProgressBar.trackTintColor
Window.navTintColor
TabGroup.unselectedItemTintColor
TabGroup.activeTabIconTint
(This one is missing the word "Color".)
I'm also contemplating if the word "Search" is necessary in the property names since all properties belonging to SearchView
is search related. For example, a property named closeIconTintColor
may be good enough.
@garymathews, do you have an opinion on the property names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the proposed name changes and I will update them.
{ | ||
try { | ||
int id = TiRHelper.getResource("id.search_src_text"); | ||
EditText text = (EditText) searchView.findViewById(id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Member variable searchView
can be null
when this object's release()
method gets called. So, we need to do a null
check in all update methods.
Also, I'm not sure how I feel about blindly casting the reference returned by findViewById()
to EditText
. We could run into a class cast exception if the support library changes the implementation in the future. I'm thinking that this is likely to happen once we add gradle support and devs can have better control of the support library version they're using. Perhaps changing the catch()
block below to catch Exception
instead of ResourceNotFoundException
would be better.
try { | ||
searchIconDrawable = TiApplication.getInstance().getResources().getDrawable( | ||
TiRHelper.getResource("drawable.abc_ic_search_api_material"), null); | ||
searchIconDrawable.setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to call searchIconDrawable.mutate()
since you're receiving a global reference to the drawable here.
ssb.append(getProxy().getProperty(TiC.PROPERTY_HINT_TEXT).toString()); | ||
} | ||
// Add it as a hint. | ||
editText.setHint(ssb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ The above makes me nervous. It makes assumptions about the internal implementation details on Google's end, which could change in the future. Is there really no other nice way to do this? I was able to replace this icon via a theme/style, except when the SearchView
was embedded within the ActionBar
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, you might be right. There might be no other way to do this without hacks... but we then have to be concerned about potential breakage/issues in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I tested providing a custom theme with overridden properties for close, hintIcon and searchIcon worked just fine. The case where I embedded the SearchView as a Menu item in the ActionBar required to separately pass the drawable I used for <item name="searchIcon">@drawable/pictureduo</item>
because it is different from the already embedded resources which are referenced by ID (like the sample icon: Ti.Android.R.drawable.ic_menu_search,
)
Possibly the biggest benefit would be that we can have partial parity with the properties of Ti.UI.SearchBar, but that leaves us at "Is it worth it to have that at the price of blindly assuming what is happening under the AppCompat library?" Maybe we can discuss this in details offline ?
|
JIRA: https://jira.appcelerator.org/browse/TIMOB-26822
Description:
Adds a few new properties for color customization of Ti.UI.Android.SearchView.
Test case:
app.js