SlideShare uma empresa Scribd logo
1 de 52
@glomadrian
Adrián García Lomas
Canvas al ajillo
Lo que me gustaría que me
hubieran contado sobre
Canvas y Custom Views
Los detalles importan
Adapta las vistas a las
necesidades no las
necesidades a las vistas
Un mundo diferente y
divertido
Ciclo de vida
de una vista
Constructor
onAttachedToWindow()
onMeassure()
onLayout()
dispatchDraw()
draw()
onDraw()
invalidate()
Animación de carga
public Loading(Context context) {
super(context);
initialize();
}
public Loading(Context context, AttributeSet attrs) {
super(context, attrs);
initialize();
}
public Loading(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize();
}
private void initialize() {
circlePaint = new Paint();
circlePaint.setColor(circleColor);
circlePaint.setAntiAlias(true);
circlePaint.setStyle(Paint.Style.STROKE);
circlePaint.setStrokeWidth(circleStroke);
}
¿Qué pasa con el
tamaño de la vista?
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
width = w;
height = h;
createCircle();
}
private void createCircleArea() {
int circleAreawidth = width - strokeWidth;
int circleAreaHeight = heihgt - strokeWidth;
circleArea = new RectF(strokeWidth, strokeWidth, circleAreawidth,
circleAreaHeight);
}
onDraw(Canvas canvas)
16ms (60 fps)
Evitar nuevas instancias
No usar invalidate()
X
Y
● width / 2 , height / 2
● 0 , 0
private float circleStartDegree = 0;
private float circleEndDegree = 360;
private float actualCircleEndDegree = circleEndDegree;
@Override
protected void onDraw(Canvas canvas) {
drawCircle(canvas);
}
private void drawCircle(Canvas canvas) {
canvas.drawArc(circleArea, circleStartDegree,
actualCircleEndDegree, false, circlePaint);
}
circlePaint.setPathEffect(new DashPathEffect(new float[]{dashWidth, dashSpace}, 0));
Animación
private void initializeAnimator() {
valueAnimator = ValueAnimator.ofInt(circleStartDegree, circleEndDegree);
valueAnimator.setDuration(1000);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int degreeValue = (int) valueAnimator.getAnimatedValue();
actualCircleEndDegree = degreeValue;
invalidate();
}
});
}
private void initialize() {
initializePainter();
initializeAnimator();
}
public void start(){
valueAnimator.start();
}
ValueAnimator
onUpdate
degree = value
invalidate
onDraw()
Interpolators
Acelerate
Acelerate Decelerate
BounceInterpolator
OvershootInterpolator
...
valueAnimator.setInterpolator(new BounceInterpolator());
valueAnimator.setInterpolator(new DecelateInterpolator());
blurPainter = new Paint(circlePaint);
blurPainter.setColor(Color.RED);
blurPainter.setStrokeWidth(circleStroke * 1.20F);
blurPainter.setMaskFilter(new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.NORMAL));
private void drawCircle(Canvas canvas) {
canvas.drawArc(internalCircle, circleStartDegree, circleEndDegree, false, blurPainter);
canvas.drawArc(internalCircle, circleStartDegree, circleEndDegree, false, circlePaint);
}
setLayerType(LAYER_TYPE_SOFTWARE, null);
Muerte a las vistas
cuadradas
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
width = w;
height = h;
createPath();
}
private void createPath() {
curvedPath = new Path();
curvedPath.moveTo(0, 0);
curvedPath.lineTo(width, 0);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawPath(curvedPath, pathPaint);
}
curvedPath.quadTo(x1, y1, x2, y2);
x1, y1
x2, y2
private void createPath() {
float pathCurvatureY = height / 2;
float middleX = width / 2;
curvedPath = new Path();
curvedPath.moveTo(0, 0);
curvedPath.quadTo(middleX, pathCurvatureY, width, 0);
} 0,0
middleX, pathCurvatureY
width, 0
private void createPath() {
float pathCurvatureY = height / 2;
float middleX = width / 2;
curvedPath = new Path();
curvedPath.moveTo(0, 0);
curvedPath.quadTo(middleX, pathCurvatureY, width, 0);
curvedPath.lineTo(width, height);
}
width, height
private void createPath() {
float pathCurvatureY = height / 2;
float middleX = width / 2;
curvedPath = new Path();
curvedPath.moveTo(0, 0);
curvedPath.quadTo(middleX, pathCurvatureY, width, 0);
curvedPath.lineTo(width, height);
curvedPath.lineTo(0, height);
}
0, height
private void createPath() {
float pathCurvatureY = height / 2;
float middleX = width / 2;
curvedPath = new Path();
curvedPath.moveTo(0, 0);
curvedPath.quadTo(middleX, pathCurvatureY, width, 0);
curvedPath.lineTo(width, height);
curvedPath.lineTo(0, height);
curvedPath.close();
}
pathPaint.setStyle(Paint.Style.FILL);
Interceptando
touch events
dentro de un
área
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
width = w;
height = h;
createPath();
createTouchRegion();
}
private void createTouchRegion() {
RectF pathBoundsRect = new RectF();
curvedPath.computeBounds(rectF, true);
regionToCheck = new Region(pathBoundsRect.left,
pathBoundsRect.top, pathBoundsRect.right,
pathBoundsRect.bottom);
regionToCheck.setPath(curvedPath, regionToCheck);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean result = false;
int pointX = (int) event.getX();
int pointY = (int) event.getY();
if (isPointInsidePathArea(pointX, pointY)) {
result = super.onTouchEvent(event);
}
return result;
}
private boolean isPointInsidePathArea(int x, int y) {
return regionToCheck.contains(x, y);
}
Usando path
para animar
private float[] getPathCoordinates(Path path, float fraction)
{
float aCoordinates[] = { 0f, 0f };
PathMeasure pm = new PathMeasure(path, false);
pm.getPosTan(pm.getLength() * fraction, aCoordinates, null);
return aCoordinates;
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float value = animation.getAnimatedFraction();
float[] coordinates = getPathCoordinates(infinitePath, value);
this.ballX = coordinates[0];
this.ballY = coordinates[1];
invalidate()
}
Midiendo el
rendimiento
onDraw()
Recursos
OpenGL
Espera CPU
16 ms
private void onDraw(Canvas canvas) {
heavyWork();
canvas.drawArc(internalCircle, circleStartDegree,
circleEndDegree, false, circlePaint);
}
Clean code
también en
vistas
@Override
protected void onDraw(Canvas canvas) {
if (mRunning) {
if (mShowLeftEye) {
canvas.drawCircle(mLeftEyePos[0], mLeftEyePos[1], mEyeCircleRadius,
mCirclePaint);
}
if (mShowRightEye) {
canvas.drawCircle(mRightEyePos[0], mRightEyePos[1], mEyeCircleRadius,
mCirclePaint);
}
if (mFirstStep) {
mArcPath.reset();
mArcPath.addArc(mRectF, mStartAngle, mSweepAngle);
canvas.drawPath(mArcPath, mArcPaint);
} else {
mArcPath.reset();
mArcPath.addArc(mRectF, mStartAngle, mSweepAngle);
canvas.drawPath(mArcPath, mArcPaint);
}
} else {
canvas.drawCircle(mLeftEyePos[0], mLeftEyePos[1], mEyeCircleRadius, mCirclePaint);
canvas.drawCircle(mRightEyePos[0], mRightEyePos[1], mEyeCircleRadius,mCirclePaint);
canvas.drawPath(mArcPath, mArcPaint);
}
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
externalCirclePainter.draw(canvas);
internalCirclePainter.draw(canvas);
progressPainter.draw(canvas);
iconPainter.draw(canvas);
}
¿Preguntas?

Mais conteúdo relacionado

Mais procurados

Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game ProgrammingRichard Jones
 
Writing a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 CanvasWriting a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 CanvasSteve Purkis
 
Creating custom views
Creating custom viewsCreating custom views
Creating custom viewsMu Chun Wang
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 CanvasMindy McAdams
 
Test Driven Cocos2d
Test Driven Cocos2dTest Driven Cocos2d
Test Driven Cocos2dEric Smith
 
Exploring fractals in CSS, @fronttrends, Warsaw, 2015
Exploring fractals in CSS, @fronttrends, Warsaw, 2015Exploring fractals in CSS, @fronttrends, Warsaw, 2015
Exploring fractals in CSS, @fronttrends, Warsaw, 2015pixelass
 
Test driven game development silly, stupid or inspired?
Test driven game development   silly, stupid or inspired?Test driven game development   silly, stupid or inspired?
Test driven game development silly, stupid or inspired?Eric Smith
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 CanvasHenry Osborne
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvasGary Yeh
 
刘平川:【用户行为分析】Marmot实践
刘平川:【用户行为分析】Marmot实践刘平川:【用户行为分析】Marmot实践
刘平川:【用户行为分析】Marmot实践taobao.com
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision DetectionJenchoke Tachagomain
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2MEJenchoke Tachagomain
 
Building mobile web apps with Mobello
Building mobile web apps with MobelloBuilding mobile web apps with Mobello
Building mobile web apps with MobelloJeong-Geun Kim
 
用户行为系统Marmot - D2 2011 session
用户行为系统Marmot - D2 2011 session用户行为系统Marmot - D2 2011 session
用户行为系统Marmot - D2 2011 sessionRANK LIU
 
Александр Зимин – Анимация как средство самовыражения
Александр Зимин – Анимация как средство самовыраженияАлександр Зимин – Анимация как средство самовыражения
Александр Зимин – Анимация как средство самовыраженияCocoaHeads
 
MongoDB - Introduction
MongoDB - IntroductionMongoDB - Introduction
MongoDB - IntroductionVagmi Mudumbai
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming TutorialRichard Jones
 

Mais procurados (20)

Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 
Writing a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 CanvasWriting a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 Canvas
 
Creating custom views
Creating custom viewsCreating custom views
Creating custom views
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 Canvas
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
Intro to HTML5 Canvas
Intro to HTML5 CanvasIntro to HTML5 Canvas
Intro to HTML5 Canvas
 
Test Driven Cocos2d
Test Driven Cocos2dTest Driven Cocos2d
Test Driven Cocos2d
 
Exploring fractals in CSS, @fronttrends, Warsaw, 2015
Exploring fractals in CSS, @fronttrends, Warsaw, 2015Exploring fractals in CSS, @fronttrends, Warsaw, 2015
Exploring fractals in CSS, @fronttrends, Warsaw, 2015
 
Test driven game development silly, stupid or inspired?
Test driven game development   silly, stupid or inspired?Test driven game development   silly, stupid or inspired?
Test driven game development silly, stupid or inspired?
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 Canvas
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
 
刘平川:【用户行为分析】Marmot实践
刘平川:【用户行为分析】Marmot实践刘平川:【用户行为分析】Marmot实践
刘平川:【用户行为分析】Marmot实践
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision Detection
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2ME
 
Proga 090525
Proga 090525Proga 090525
Proga 090525
 
Building mobile web apps with Mobello
Building mobile web apps with MobelloBuilding mobile web apps with Mobello
Building mobile web apps with Mobello
 
用户行为系统Marmot - D2 2011 session
用户行为系统Marmot - D2 2011 session用户行为系统Marmot - D2 2011 session
用户行为系统Marmot - D2 2011 session
 
Александр Зимин – Анимация как средство самовыражения
Александр Зимин – Анимация как средство самовыраженияАлександр Зимин – Анимация как средство самовыражения
Александр Зимин – Анимация как средство самовыражения
 
MongoDB - Introduction
MongoDB - IntroductionMongoDB - Introduction
MongoDB - Introduction
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
 

Destaque

Destaque (10)

1 redes sociais estratégias e tendencias-resumo
1 redes sociais estratégias e tendencias-resumo1 redes sociais estratégias e tendencias-resumo
1 redes sociais estratégias e tendencias-resumo
 
Ob3 Igualdade GéNero Pilar Maria
Ob3 Igualdade GéNero Pilar MariaOb3 Igualdade GéNero Pilar Maria
Ob3 Igualdade GéNero Pilar Maria
 
Revista Pronews #186
Revista Pronews #186Revista Pronews #186
Revista Pronews #186
 
Actividad postales junio 24
Actividad postales junio 24Actividad postales junio 24
Actividad postales junio 24
 
5 headlines
5 headlines5 headlines
5 headlines
 
What is Corporate Lodging?
What is Corporate Lodging? What is Corporate Lodging?
What is Corporate Lodging?
 
C.V'
C.V'C.V'
C.V'
 
Planificador de proyectos club noel
Planificador de proyectos club noelPlanificador de proyectos club noel
Planificador de proyectos club noel
 
La educación cubana
La educación cubanaLa educación cubana
La educación cubana
 
Autoestima y asertividad
Autoestima y asertividadAutoestima y asertividad
Autoestima y asertividad
 

Semelhante a Custom Views in Canvas and Performance

How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1Bitla Software
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftGiordano Scalzo
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...DroidConTLV
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfarihantmobileselepun
 
I need to create a page looks like a picture. But it looks different.pdf
I need to create a page looks like a picture. But it looks different.pdfI need to create a page looks like a picture. But it looks different.pdf
I need to create a page looks like a picture. But it looks different.pdfallurafashions98
 
need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfarcotstarsports
 
JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011Stephen Chin
 
[Ultracode Munich Meetup #7] Android view customization in a nutshell
[Ultracode Munich Meetup #7] Android view customization in a nutshell[Ultracode Munich Meetup #7] Android view customization in a nutshell
[Ultracode Munich Meetup #7] Android view customization in a nutshellBeMyApp
 
The Ring programming language version 1.6 book - Part 86 of 189
The Ring programming language version 1.6 book - Part 86 of 189The Ring programming language version 1.6 book - Part 86 of 189
The Ring programming language version 1.6 book - Part 86 of 189Mahmoud Samir Fayed
 
Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門nakamura001
 
package chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfpackage chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfKARTIKINDIA
 
The Canvas API for Rubyists
The Canvas API for RubyistsThe Canvas API for Rubyists
The Canvas API for Rubyistsdeanhudson
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3Droxlu
 
[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9Shih-Hsiang Lin
 
OL4JSF - Latinoware 2010
OL4JSF - Latinoware 2010OL4JSF - Latinoware 2010
OL4JSF - Latinoware 2010Robert Anderson
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxAhmadAbba6
 
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
Hacking JavaFX with Groovy, Clojure, Scala, and VisageHacking JavaFX with Groovy, Clojure, Scala, and Visage
Hacking JavaFX with Groovy, Clojure, Scala, and VisageStephen Chin
 
The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184Mahmoud Samir Fayed
 

Semelhante a Custom Views in Canvas and Performance (20)

How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
 
How to Clone Flappy Bird in Swift
How to Clone Flappy Bird in SwiftHow to Clone Flappy Bird in Swift
How to Clone Flappy Bird in Swift
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
 
I need to create a page looks like a picture. But it looks different.pdf
I need to create a page looks like a picture. But it looks different.pdfI need to create a page looks like a picture. But it looks different.pdf
I need to create a page looks like a picture. But it looks different.pdf
 
need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdf
 
JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011JavaFX 2.0 With Alternative Languages - JavaOne 2011
JavaFX 2.0 With Alternative Languages - JavaOne 2011
 
[Ultracode Munich Meetup #7] Android view customization in a nutshell
[Ultracode Munich Meetup #7] Android view customization in a nutshell[Ultracode Munich Meetup #7] Android view customization in a nutshell
[Ultracode Munich Meetup #7] Android view customization in a nutshell
 
Android Animation (in tamil)
Android Animation (in tamil)Android Animation (in tamil)
Android Animation (in tamil)
 
The Ring programming language version 1.6 book - Part 86 of 189
The Ring programming language version 1.6 book - Part 86 of 189The Ring programming language version 1.6 book - Part 86 of 189
The Ring programming language version 1.6 book - Part 86 of 189
 
Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門
 
package chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfpackage chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdf
 
The Canvas API for Rubyists
The Canvas API for RubyistsThe Canvas API for Rubyists
The Canvas API for Rubyists
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3D
 
[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9
 
OL4JSF - Latinoware 2010
OL4JSF - Latinoware 2010OL4JSF - Latinoware 2010
OL4JSF - Latinoware 2010
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptx
 
A More Flash Like Web?
A More Flash Like Web?A More Flash Like Web?
A More Flash Like Web?
 
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
Hacking JavaFX with Groovy, Clojure, Scala, and VisageHacking JavaFX with Groovy, Clojure, Scala, and Visage
Hacking JavaFX with Groovy, Clojure, Scala, and Visage
 
The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184
 

Último

Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 

Último (20)

Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 

Custom Views in Canvas and Performance

Notas do Editor

  1. Motivacion de la charla, introdución a la api de canvas, path, algunos trucos un poco de perfonance para ellos explicare dos pequeños ejemplos un loading y una vista que usaremos de boton
  2. Realmente no son dificiles de usar No ir siempre a buscar la solucion a GITHUB No necesitas todo lo que aporta la librearia Más control Adaptado totalmente a tus necesidades Es muy divertido programar vistas, es totalmente diferente a lo que hacemos dia a dia
  3. Ciclo de vida de una vista, por que es importante conocer por que pasos toma la vista
  4. Primero se ejecuta el contructor, que es donde crearemos los objetos necesarios que no dependan del tamaño de la vista Es llamado justo despues de que el padre hagaun addView() measure() && onMeassure() en este momento la vista aun no tiene tamaño y es aqui donde se puede definir en caso de que necesitemos modificarlo, por ejemlo aqui podemos saber si nuestra vista se encuentra dentro de un tamaño concreto, de un math_parent o de un wrap_content y actuar en consecuencia layout && onLayout() el onLayout se ejecuta por cada uno de las vistas hijas añadidas en la mayoria de los casos no es necesario
  5. dispathDraw() && draw() y onDraw() es el metodo más importante y es donde vamos a realizar todas las tareas de pintado de nuestras vistas custom una vez realizado el onDraw() la vista es mostrada y no se volvera a pintar a no ser que se llame al método invalidate() este métoco hace volver a empezar el ciclo de pintado y entonces el método onDraw() vovlera a ser ejecutado
  6. Para ilustrar mejor todo esto vamos hacer paso a paso una animación de carga parecida a esta
  7. Hablar del paint, Controla el color, el estilo los tamaños y muchas cosas más Es un objeto que necesitaremos todo el tiempo que dure la vista por lo que conviene creerlo al principio
  8. Por lo general el tamaño de una vista suele dar problemas sobretodo al principio. Por el proceso que pasa la vista el tamaño no se obtiene hasta cierto momento del ciclo de vida de la vista
  9. El método onSizeChanged es muy importante siempre se llamará cuando el tamaño cambie. Eso quiere decir que se llamara despues del onLayout Este es un buen sitio para crear todos los componentes que necesiten de tamaño. Le resto el borde para evitar que el circulo se corte RectF define un rectangulo, donde se definen las 4 posiciones x1, y1, x2, y2
  10. Método donde ocurre todo Tener en cuenta los 16MS es el tiempo que se tiene para pintar Por eso hay que evitar todos los proceso pesados en este método si se usa invalidate se entra en un bucle Canvas es el objeto donde se pinta todo, canvas provee una cantidad de metodos para el pintado entre ellos drawCircle drawPath etc
  11. explicar método circle RectF Grados desde donde empieza false / true Mejorar circulo
  12. Que es DashPathEffect pinta el stroke dash Hay más pathEffect
  13. QUe es value animator y para que sirve Como lo vamos a usar Crear animación al crear la vista Tiene dos listener importantes Vamos a usar el update listener Este listener salta cada vez que un valor se actualiza El truco consiste en setear el valor del circulo al que nos devuelve el valueAnimator y forzar el pintado Varios tipos de animator float int color
  14. Explicar lo que ha pasado y asi es como funcionan las animaciones en canvas Frame a frame
  15. Explicar que el value animator los devuelve de manera lineal y que se le puede pasar un interpolator para definir cómo deben ser devueltos Explicar que son funciones matemáticas Hay muchos
  16. Explicar que queremos mejorar el ciruclo amarillo poniendo por debajo una distorion
  17. explicar que creamos otro painter con otras propiedades en este caso Rojo con un ancho 20% más y una mascara de blur
  18. No obtenemos nada... Pregunta?
  19. Solo en vistas estaticas vistas que no esten dentro de un adapter ni sean reutilizadas No solo pasa aqui, tambien en las mascaras en canvas para imagenes etc
  20. Cambio de cuadradas - innovar no ir siempre a lo mismo Explicar lo que vamos hacer
  21. Explicar path, que es y para qué sirve Cómo funciona
  22. Explicar como funciona quadTo
  23. Paso 1
  24. Some magic
  25. Resultado, explicar lo que se puede consguir con poco
  26. Explicar el problema Pregunta como solucionar