-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Add vector drawable support via appcompat #1946
Conversation
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
CLAs look good, thanks! |
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 don't think that's SVG, there's no SVG in Android as far as I know, only vector drawables:
https://developer.android.com/reference/android/graphics/drawable/VectorDrawable.html
The path descriptor mini-language is the only thing that's borrowed from SVG.
Please change the commit message to not mislead people.
library/build.gradle
Outdated
@@ -20,7 +20,7 @@ dependencies { | |||
compile project(':third_party:disklrucache') | |||
compile project(':annotation') | |||
compile "com.android.support:support-v4:${SUPPORT_V4_VERSION}" | |||
|
|||
compile "com.android.support:appcompat-v7:${SUPPORT_V7_VERSION}" |
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.
Would it be possible to make this optional? Without adding a hard dependency on v7?
Also, @sjudd, we should probably revise the v4 dep and use the more fine-grained exploded libraries (core, fragment, etc).
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.
Yeah I'm not 100% sure it makes sense to add a hard dependency on v7 either. Maybe this should be an integration library? You can probably override the setPlaceholder methods with a GlideExtension, though it's a bit weird.
As an alternative Apps can also pass in Drawables directly, so those that are using v7 can call this method themselves.
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 would prefer to be able to pass an drawable id.
- Terser calls (no need to initialise the drawable yourself, just pass the id)
- No risk of a crash because you passed the id of a VD to glide (right now it does crash)
- If you refactor a raster to VD, no need to check all the glide calls
Alternatively,
I have not toyed too much with reflection in this kind of use case but I think it might be possible to check for the presence of the class & method from the support lib and use them if they are here.
If it is not there, fallback to the previous method.
I would also need to add a proguard rule for this class in the library's rules. Although I don't know yet whether I can add a rule for a class that might not be present in the classpath.
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.
Would that be an acceptable implementation ?
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 a better way would be to use a provided scope and try { loadVectorWithV7 } catch(ClassNotFoundException ex) { loadVectorWithV4 }
(could cache failure so the weight of the exception only happens once). This way there's no need for proguard.
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 support the PR: the more formats we support out of the box, the better)
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.
Just read about provided dependencies
Indeed it looks like a good way to do this.
<item> | ||
<bitmap | ||
android:src="@android:drawable/sym_def_app_icon" | ||
android:gravity="center" /> |
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.
According to the official docs this resource is available in O. It would be a breaking change for them to remove it without deprecation first. Maybe the preview is missing it (in which case report an AOSP bug), I would wait until a final release before taking action.
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.
ok, removed
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'm confused, it looks like you squashed it into the commit, not reverted.
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.
my bad, pushed too soon, fixed.
77592b5
to
4e30ffc
Compare
and yes, svg is an abuse of language. |
7b37a7e
to
39fdfc9
Compare
It should be ok now :-) |
From the failing travis build: Otherwise looks good to me. Worth noting for the peanut gallery that this still won't let you call |
This allows you to use VectorDrawable with the support lib ( vectorDrawables.useSupportLibrary = true) for placeholder, error and fallback drawables. Of course, if the id points to a regular (not vector drawable) resource, the resource still inflate as usual.
My bad, I should not have added a javadoc at the last minute without running check afterwards. |
Thanks! |
Description
use the support lib in order to inflate resources.
This allows you to use the ids of VectorDrawables for placeholder, error or fallback calls.