Coder Social home page Coder Social logo

Comments (6)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 2, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 2, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 2, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 2, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 2, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 2, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.