Comments (6)
I just noticed another point against the current solution: you can simply use
getField(...).getInt(null) to get a static field's value, no need to create a
new View(getContext()).
Original comment by papp.robert.s
on 7 Dec 2014 at 9:31
from androidsvg.
Thanks for that. I didn't know that ViewCompat had that method. However I
should have updated that answer with the other new way of doing it.
I've updated the answer now.
I've kept the old-style way in the FAQ just in case anyone is still using an
old build environment.
Thanks again Robert.
Original comment by [email protected]
on 8 Dec 2014 at 11:35
- Changed state: Fixed
from androidsvg.
Ahaa, I didn't know the @TargetApi was added in 16 :)
Still the SDK_INT was added in API 4 and I don't think anyone is targeting less
than that... so even if @TargetApi is not available because of old target the
Build.VERSION method works.
@TargetApi is only used to silence lint, like @SuppressLint("NewApi") which is
API 16 too. I guess before API 16 the lint.xml was used to make it shut up when
SDK_INT is used to make stuff compatible.
Original comment by papp.robert.s
on 8 Dec 2014 at 11:55
from androidsvg.
Yeah you are right. That section made no sense. I think I have fixed it now.
:)
Original comment by [email protected]
on 8 Dec 2014 at 12:26
from androidsvg.
Some of the numbers and terminology is still strange, here're the paragraphs
fixed to my best knowledge:
If you are using the v4 support library in your project (also included with
latest v7 appcompat library), compatibility will be taken care of for you:
If you are targeting API 4 or later, you can use the constants in the
android.os.Build class to prevent setLayerType() being invoked when it is not
available on the user's device.
Please note that the @TargetApi annotation was added in API 16, so if your
target is between API 11 and API 15 and your minSdkVersion is less than API 11
you'll have to find another way to suppress the lint warning about
setLayerType() not being available.
In almost all cases you will be able to use one of the first two approaches. We
recommend you use one of them if you can. However some people may be forced for
some reason to use Java reflection to call the setLayerType() method if it is
available.
private void setSoftwareLayerType() {
try {
Method setLayerTypeMethod = View.class.getMethod("setLayerType", Integer.TYPE, Paint.class);
int LAYER_TYPE_SOFTWARE = View.class.getField("LAYER_TYPE_SOFTWARE").getInt(null);
setLayerTypeMethod.invoke(this, LAYER_TYPE_SOFTWARE, null);
} catch (NoSuchMethodException e) {
// Android platform too old, no setLayerType
} catch (NoSuchFieldException e) {
// Android platform too old, no LAYER_TYPE_SOFTWARE
} catch (Exception e) {
Log.w("MySVGView", "Unexpected failure calling setLayerType", e);
}
}
Original comment by papp.robert.s
on 8 Dec 2014 at 12:50
from androidsvg.
Thanks. I have incorporated your suggestions.
> If you are targeting API 4 or later, you can use the constants...
Yes, the constants are available in API 4, but you can't use
View.setLayerType() till API 11.
Original comment by [email protected]
on 8 Dec 2014 at 1:29
from androidsvg.
Related Issues (20)
- SVGAndroidRenderer.processMaskBitmaps is very slow HOT 1
- SVGParser is not thread-safe [with fix] (SVG parse error: Invalid colour keyword: white) HOT 2
- Feature request: replace text HOT 6
- Image references missing SVG support. HOT 3
- Canvas changed after renderToCanvas HOT 1
- Position of Rectf ignored when renderToCanvas HOT 1
- Support for hardware acceleration
- Android version support HOT 1
- Android version support HOT 1
- Pattern fills are rendered with visible grid HOT 4
- Provide copy constructor or allow rendering to multiple viewBox at once HOT 3
- migrate the repository HOT 3
- Move project to Github HOT 1
- NullPointerException in 1.2.2-beta1 when parsing SVG document HOT 4
- SVGImageView crashes on Android 5.0 and higher HOT 5
- Proguard breaks reflective CSS selectors HOT 1
- java.lang.ArrayIndexOutOfBoundsException: length=0; index=-2 in SVGAndroidRenderer.arcTo(SourceFile:2572) HOT 1
- Incorrect rendering of SVG image HOT 5
- Unable to execute dex: Multiple dex files define HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from androidsvg.