beautiful android
play

Beautiful Android by Eric Burke Square Inc. Friday, October 7, - PowerPoint PPT Presentation

Beautiful Android by Eric Burke Square Inc. Friday, October 7, 2011 Android Developers? Friday, October 7, 2011 Friday, October 7, 2011 Friday, October 7, 2011 Friday, October 7, 2011 Friday, October 7, 2011 Friday, October 7, 2011 Time


  1. Beautiful Android by Eric Burke Square Inc. Friday, October 7, 2011

  2. Android Developers? Friday, October 7, 2011

  3. Friday, October 7, 2011

  4. Friday, October 7, 2011

  5. Friday, October 7, 2011

  6. Friday, October 7, 2011

  7. Friday, October 7, 2011

  8. Time for Code Friday, October 7, 2011

  9. Keep it Square public class EditablePhoto extends View { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int measuredWidth = getDefaultSize( getSuggestedMinimumWidth(), widthMeasureSpec); int measuredHeight = getDefaultSize( getSuggestedMinimumHeight(), heightMeasureSpec); // Ensure this view is always square. int min = Math.min(measuredHeight, measuredWidth); setMeasuredDimension(min, min); } } Friday, October 7, 2011

  10. Keep it Square public class EditablePhoto extends View { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int measuredWidth = getDefaultSize( getSuggestedMinimumWidth(), widthMeasureSpec); int measuredHeight = getDefaultSize( getSuggestedMinimumHeight(), heightMeasureSpec); // Ensure this view is always square. int min = Math.min(measuredHeight, measuredWidth); setMeasuredDimension(min, min); } } Friday, October 7, 2011

  11. Keep it Square public class EditablePhoto extends View { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int measuredWidth = getDefaultSize( getSuggestedMinimumWidth(), widthMeasureSpec); int measuredHeight = getDefaultSize( getSuggestedMinimumHeight(), heightMeasureSpec); // Ensure this view is always square. int min = Math.min(measuredHeight, measuredWidth); setMeasuredDimension(min, min); } } Friday, October 7, 2011

  12. Friday, October 7, 2011

  13. Let’s round these corners. Friday, October 7, 2011

  14. Don’t Do This. Path clip = new Path(); clip.addRoundRect(...); canvas.clipPath(clip); canvas.drawBitmap(photo, 0, 0, null); canvas.restore(); Friday, October 7, 2011

  15. Ugly Corners Friday, October 7, 2011

  16. Lazy Bitmap public class EditablePhoto extends View { private Bitmap image; private Drawable placeholder; private Bitmap framedPhoto; ... @Override protected void onDraw(Canvas canvas) { if (placeholder == null && image == null) return; if (framedPhoto == null) { createFramedPhoto(Math.min(getWidth(), getHeight())); } canvas.drawBitmap(framedPhoto, 0, 0, null); } ... Friday, October 7, 2011

  17. Lazy Bitmap public class EditablePhoto extends View { private Bitmap image; private Drawable placeholder; private Bitmap framedPhoto; ... @Override protected void onDraw(Canvas canvas) { if (placeholder == null && image == null) return; if (framedPhoto == null) { createFramedPhoto(Math.min(getWidth(), getHeight())); } canvas.drawBitmap(framedPhoto, 0, 0, null); } ... Friday, October 7, 2011

  18. Lazy Bitmap public class EditablePhoto extends View { private Bitmap image; private Drawable placeholder; private Bitmap framedPhoto; ... @Override protected void onDraw(Canvas canvas) { if (placeholder == null && image == null) return; if (framedPhoto == null) { createFramedPhoto(Math.min(getWidth(), getHeight())); } canvas.drawBitmap(framedPhoto, 0, 0, null); } ... Friday, October 7, 2011

  19. Lazy Bitmap public class EditablePhoto extends View { private Bitmap image; private Drawable placeholder; private Bitmap framedPhoto; ... @Override protected void onDraw(Canvas canvas) { if (placeholder == null && image == null) return; if (framedPhoto == null) { createFramedPhoto(Math.min(getWidth(), getHeight())); } canvas.drawBitmap(framedPhoto, 0, 0, null); } ... Friday, October 7, 2011

  20. Alpha Compositing Source: http://en.wikipedia.org/wiki/Alpha_compositing Friday, October 7, 2011

  21. Offscreen Bitmap private void createFramedPhoto(int size) { // Start with either the placeholder or the image. Drawable imageDrawable = (image != null) ? new BitmapDrawable(image) : placeholder; Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); RectF outerRect = new RectF(0, 0, size, size); float outerRadius = size / 18f; Friday, October 7, 2011

  22. Offscreen Bitmap private void createFramedPhoto(int size) { // Start with either the placeholder or the image. Drawable imageDrawable = (image != null) ? new BitmapDrawable(image) : placeholder; Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); RectF outerRect = new RectF(0, 0, size, size); float outerRadius = size / 18f; Friday, October 7, 2011

  23. Offscreen Bitmap private void createFramedPhoto(int size) { // Start with either the placeholder or the image. Drawable imageDrawable = (image != null) ? new BitmapDrawable(image) : placeholder; Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); RectF outerRect = new RectF(0, 0, size, size); float outerRadius = size / 18f; Friday, October 7, 2011

  24. Offscreen Bitmap private void createFramedPhoto(int size) { // Start with either the placeholder or the image. Drawable imageDrawable = (image != null) ? new BitmapDrawable(image) : placeholder; Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); RectF outerRect = new RectF(0, 0, size, size); float outerRadius = size / 18f; Friday, October 7, 2011

  25. Draw a Red Rectangle Paint paint = new Paint( Paint.ANTI_ALIAS_FLAG ); paint.setColor(Color.RED); canvas.drawRoundRect (outerRect, outerRadius, outerRadius, paint); Friday, October 7, 2011

  26. paint.setXfermode(new PorterDuffXfermode( PorterDuff.Mode.SRC_IN)); Transparent Corners Friday, October 7, 2011

  27. Composing the Image // Compose the image with the red rectangle. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); imageDrawable.setBounds(0, 0, size, size); // Save the layer to apply the paint. canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG); imageDrawable.draw(canvas); canvas.restore(); Friday, October 7, 2011

  28. Composing the Image // Compose the image with the red rectangle. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); imageDrawable.setBounds(0, 0, size, size); // Save the layer to apply the paint. canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG); imageDrawable.draw(canvas); canvas.restore(); Friday, October 7, 2011

  29. Composing the Image // Compose the image with the red rectangle. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); imageDrawable.setBounds(0, 0, size, size); // Save the layer to apply the paint. canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG); imageDrawable.draw(canvas); canvas.restore(); Friday, October 7, 2011

  30. Composing the Image // Compose the image with the red rectangle. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); imageDrawable.setBounds(0, 0, size, size); // Save the layer to apply the paint. canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG); imageDrawable.draw(canvas); canvas.restore(); Drawing over the red rectangle. Friday, October 7, 2011

  31. Composing the Image // Compose the image with the red rectangle. paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); imageDrawable.setBounds(0, 0, size, size); // Save the layer to apply the paint. canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG); imageDrawable.draw(canvas); canvas.restore(); Friday, October 7, 2011

  32. Rounded Corners Friday, October 7, 2011

  33. Framing the Photo 1. Create offscreen bitmap. Friday, October 7, 2011

  34. Framing the Photo 2. Draw an opaque rounded rectangle. Friday, October 7, 2011

  35. Framing the Photo paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); 3. Set the Porter Duff mode. Friday, October 7, 2011

  36. Framing the Photo Transparent center viewport. 4. Draw a translucent rounded rectangle. Friday, October 7, 2011

  37. Friday, October 7, 2011

  38. Friday, October 7, 2011

  39. Friday, October 7, 2011

  40. plastic_background.xml res/drawable/plastic_background.xml <shape xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Nearly white at the top, light gray at the bottom. --> <gradient android:startColor="#fff7f7f7" android:endColor="#ffe2e3e5" android:angle="270"/> </shape> Friday, October 7, 2011

  41. PlasticLinearLayout public class PlasticLinearLayout extends LinearLayout { public PlasticLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); // The subtle gradient draws behind everything. setBackgroundResource(R.drawable.plastic_window_background); } } Friday, October 7, 2011

  42. Friday, October 7, 2011

  43. Friday, October 7, 2011

  44. Triangular Shine private void createShinePath() { int width = getWidth(); int height = (int) (0.85 * getHeight()); shinePath = new Path(); shinePath.moveTo(0, 0); shinePath.lineTo(width, 0); shinePath.lineTo(width, height); shinePath.close(); shinePaint.setShader(new LinearGradient(0, 0, 0, height, 0x66ffffff, 0x10ffffff, CLAMP)); } Friday, October 7, 2011

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend