+ All Categories
Home > Documents > Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation...

Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation...

Date post: 05-Oct-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
65
Build beer Android apps, with vector assets @LukeSleeman (Itty Bitty Apps) @MarcEdwards (Bjango)
Transcript
Page 1: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Build better Android apps,with vector assets

@LukeSleeman (Itty Bitty Apps)

@MarcEdwards(Bjango)

Page 2: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

OutlineWhat are vector assets?

Creating and exporting SVGs

Converting SVGs to VectorDrawables

Using VectorDrawables in your apps

The Marc and Luke 4 step plan

Questions?

Page 3: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

What are vector assets?Vector Bitmap

Page 4: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

What are the benefits of vector assets?Smaller files and faster loading.

One file for all pixel densities.

Dynamic colours, and other dynamic drawing.

Did we mention smaller files?

Smaller files!*

Page 5: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

What are the drawbacks?Vector assets can have performance issues.

Can use a lot of memory while rendering.

Can only be used for certain things.

Choose wisely!

Page 6: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

What are SVGs?Scalable Vector Graphics files.

XML files, containing shapes, paths and styling data.

Initially released in 2001, but increasingly popular.

SVG 2.0 is in flux right now.

Pronounced with a hard G.

Page 7: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

What are Vector Drawables?Android specific vector format.

Subset of SVG:Supports group, path, clipPath, and transforms.

Quicker and easier to render than SVG.

This image is pretty ugly and blurry. If its quick and easy to do re-draw it, otherwise we will just live with it

Page 8: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Example Vector Drawable

Page 9: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Example Vector Drawable

Page 10: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Example Vector Drawable

Page 11: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Example Vector Drawable

Page 12: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

When should you use vector assets?

Yes! Maybe? 🤔 No way.

Page 13: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

223.1 MB

Page 14: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Creating vector assets

Illustrator Photoshop Sketch Affinity Designer

Page 15: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Best practices for creating vector assetsCreate using a 1dp grid.

“Flatten” or combine boolean operations.

If you use text, outline it.

Remove redundant points.

Page 16: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Create using a 1dp grid

Page 17: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

“Flatten” or combine boolean operations

Page 18: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

“Flatten” or combine boolean operations

Page 19: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Outline text

Page 20: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Remove redundant points

Page 21: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Remove redundant points

😲

Page 22: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Exporting SVGsAs automated as possible.

Faster, and less mistakes.

Less effort to make changes.

Page 23: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

iStat Menus prefs app export document

Page 24: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Exporting SVGs from IllustratorCreate artwork on artboards.

Export with Export for Screens.

100 artboard limit? 1000 artboards!

Page 25: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Exporting SVGs from PhotoshopCreate artwork on artboards or in groups.

Export with Export As or Generator.

Don’t use Photoshop? Or use Photoshop + PaintCode!

Page 26: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Exporting SVGs from SketchCreate artwork on artboards or in groups.

Export with Make Exportable.

Slices are good!

Page 27: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Exporting SVGs from AffinityCreate artwork on artboards or in groups.

Export with Export Persona.

Slices are good!

Page 28: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp
Page 29: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

We have ✨SVG’s✨

🤔

Now how to get VectorDrawables?

Converting SVGs to VectorDrawables

Page 30: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

What do you mean ‘complex’?Features that cause problems:

clip paths

Inner and outer strokes

gradient fill (7.0, SDK 24+)

fill rule - evenodd, etc (7.0 SDK 24+)

transforms

<defs>

It would be nice if we could somehow visually show what these things are. I think it may be a bit to much work to draw up examples of each of them though

Page 31: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

4 Ways of converting1. Android Studio import

2. http://inloop.github.io/svg2android/

3. http://a-student.github.io/SvgToVectorDrawableConverter.Web/

4. PaintCode

Page 32: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

#1 - Android Studio

Page 33: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

#2 - SVG2Android

http://inloop.github.io/svg2android/

Page 34: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

#3 - SvgToVectorDrawableConverter.Web

http://a-student.github.io/SvgToVectorDrawableConverter.Web/

Page 35: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

#4 - PaintCode

If you have a more relevant screenshot of paint code go for it - this was just from their website

Page 36: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Lets put them to the test!

TransformFill ruleGradientInner strokeClip paths

<Defs>

Page 37: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

This turned out to be a lot of work …

Page 38: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

The results!

Page 39: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Recommendation:

PaintCode SVG2Android a close second

also Keep checking Android Studio for updates: https://

issuetracker.google.com/issues/37092389

Page 40: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Now to use them in the app

Easy right? 😅

Page 41: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Again - lots of options!1. Native vector drawable generation

2. Native for 5.0 and up, PNG generation through gradle for backwards compatibility

3. support-vector-drawable library

Page 42: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Native Vector Drawable supportAdd your vector drawable xml file to res/drawable/

Reference it like any other drawable

API 21 (Android 5.0) has native support

API 24 (Android 7) has better support - Fill types (even-odd), gradient fill

Other misc bugs in android 5.0 and 6.0

Page 43: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Cool feature - can reference colours.xml

Page 44: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Vectors aren’t always sharp 😳

Page 45: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp
Page 46: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

100dp

100dp

Page 47: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp
Page 48: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Native SVG - PNG Generation

Set minSdkVersion < 21, eg below android 5.0

No build changes required at all - just drop in Vector Drawable to project!

Only supports limited set of elements

Cant reference colours.xml from xml

Page 49: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

PNG GenerationAPK contents:

Page 50: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

PNG GenerationAPK contents:

Page 51: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

PNG GenerationAPK contents:

Page 52: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Backwards compatibility library support-vector-drawable

Backwards compatibility library which extends Drawable to create VectorDrawableCompat

Uses VectorDrawableCompat when running below API 24 (Android 7). API 24+ it uses native implementation

Allows you to get vector drawable features only supported in API 24

Vectors are Sharp on all API levels!

Can use colors.xml values

Page 53: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Backwards compatibility library support-vector-drawable - gradle changes

Page 54: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Backwards compatibility library support-vector-drawable - gradle changes

Page 55: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Backwards compatibility library support-vector-drawable - gradle changes

Page 56: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Backwards compatibility library support-vector-drawable - Code changes

Page 57: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Backwards compatibility library support-vector-drawable - Code changes

Page 58: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

The magical setting to turn on

Page 59: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Recommendation:

support-vector-drawable

Perhaps native if your are targeting API 23 (Android 6.0) and up

Page 60: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

The Marc and Luke 4 step plan1. Create clean artwork

2. Export like this

3. Converting to VectorDrawable

4. Displaying VectorDrawables

Page 61: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

1. Create clean artworkCreate using a 1dp grid.

“Flatten” or combine boolean operations.

If you use text, outline it.

Remove redundant points.

Page 62: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

2. Export like thisIllustrator, using artboards and Export for Screens

Sketch, using Make Exportable

Affinity Designer, using Slices

Photoshop, by importing into PaintCode

Page 63: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

3. Converting to VectorDrawable Use PaintCode

If you cant use that - try SVG2Andoid

Keep checking for those Android Studio updates …

Page 64: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

4. Displaying VectorDrawablesUse support-vector-drawable

If you are only supporting the latest versions of Android, perhaps native will work

Page 65: Build be er Android apps, with vector assets...(Android 7). API 24+ it uses native implementation Allows you to get vector drawable features only supported in API 24 Vectors are Sharp

Questions?

@MarcEdwards(Bjango)

@LukeSleeman (Itty Bitty Apps)


Recommended