X

Download Android graphics PowerPoint Presentation

SlidesFinder-Advertising-Design.jpg

Login   OR  Register
X


Iframe embed code :



Presentation url :

Home / Science & Technology / Science & Technology Presentations / Android graphics PowerPoint Presentation

Android graphics PowerPoint Presentation

Ppt Presentation Embed Code   Zoom Ppt Presentation

PowerPoint is the world's most popular presentation software which can let you create professional Android graphics powerpoint presentation easily and in no time. This helps you give your presentation on Android graphics in a conference, a school lecture, a business proposal, in a webinar and business and professional representations.

The uploader spent his/her valuable time to create this Android graphics powerpoint presentation slides, to share his/her useful content with the world. This ppt presentation uploaded by onlinesearch in Science & Technology ppt presentation category is available for free download,and can be used according to your industries like finance, marketing, education, health and many more.

About This Presentation

Android graphics Presentation Transcript

Slide 1 - Basic 2D Graphics in Android
Slide 2 - Android Graphics There are many ways to do graphics programming in Android 2D vs. 3D static vs. dynamic Many of them require knowledge of underlying graphics libraries, e.g. OpenGL We will look at very simple 2D graphics
Slide 3 - Views Recall that Views are the visible components in the user interface You can create your own View class and override its onDraw method, which is automatically called by Android to render the View Android passes a Canvas object to onDraw, which you can use to draw shapes
Slide 4 - 1 public class MyShapeView extends View { 2 3 // You must implement these constructors!! 4 public MyShapeView(Context c) { 5 super(c); 6 init(); // more on this in a second! 7 } 8 public MyShapeView(Context c, AttributeSet a) { 9 super(c, a); 10 init(); 11 } ... to be continued! Create a custom View class
Slide 5 - Shapes and ShapeDrawables Android has built-in Shape classes to represent 2D shapes, e.g. RectShape, OvalShape, etc. From a Shape, you can create a ShapeDrawable object, which has methods for drawing itself A ShapeDrawable has a Paint object that is the “paintbrush”: color, transparency, stroke, etc. ShapeDrawables have a “bounding area” using an x-y coordinate system with (0,0) in top left corner
Slide 6 - Still in the MyShapeView class... 12 protected ShapeDrawable square; 13 protected ShapeDrawable circle; 14 15 protected void init() { 16 17 // blue 60x60 square at 80, 120 18 square = new ShapeDrawable(new RectShape()); 19 // set the color 20 square.getPaint().setColor(Color.BLUE); 21 // position it 22 square.setBounds(80, 120, 80+60, 120+60); 23 24 // greenish circle at 230, 220 25 circle = new ShapeDrawable(new OvalShape()); 26 // set the color using opacity + RGB 27 circle.getPaint().setColor(0xff74AC23); 28 // give it a white shadow 29 // arguments are blur radius, x-offset, y-offset 30 circle.getPaint().setShadowLayer(10, 15, 15, Color.WHITE); 31 // position it 32 circle.setBounds(230, 220, 230+80, 220+80); 33 34 } // end of init method
Slide 7 - Still in the MyShapeView class... 35 // this is automatically called by Android 36 // EVERY time this View is rendered 37 protected void onDraw(Canvas canvas) { 38 39 // draw the square 40 square.draw(canvas); 41 42 // draw the circle 43 circle.draw(canvas); 44 45 } // end of onDraw method
Slide 8 - Placing the View in the Activity If you want the entire Activity to be filled with your custom View, pass an instance to setContentView In your Activity class: 1 public void onCreate(Bundle savedInstanceState) { 2 3 // always do this first! 4 super.onCreate(savedInstanceState); 5 6 // set the View in the Activity (not using XML here) 7 setContentView(new MyShapeView(this)); 8 9 } // end of onCreate method
Slide 9 - Placing the View in the Activity Alternatively, you can put it in the XML file 1 2 8 13 14 18
Slide 10 - rectangle oval shadow layer MyShapeView 1. Create a View class 2. Create ShapeDrawables 3. Override onDraw 4. Add View to Activity
Slide 11 - Drawing Lines In the onDraw method, you can create a Paint object and draw right on the Canvas The Canvas has a drawLine method that you can use to draw a line segment between two points In your View's onDraw method: 1 // create a Paint object 2 Paint p = new Paint(); 3 // set its color 4 p.setColor(Color.RED); 5 // set the stroke width 6 p.setStrokeWidth(10); 7 8 // draw a line from (40, 20) to (60, 50) 9 canvas.drawLine(40, 20, 60, 50, p);
Slide 12 - Drawing Text The Canvas also has a drawText method that will make text appear on the screen In your View's onDraw method: 1 // create a Paint object 2 Paint p = new Paint(); 3 // set its color 4 p.setColor(Color.WHITE); 5 // set the alignment 6 p.setTextAlign(Paint.Align.LEFT); 7 // set the typeface (font) 8 p.setTypeface(Typeface.SANS_SERIF); 9 // set the size 10 p.setTextSize(20); 11 12 // draw the text at (180, 120) 13 canvas.drawText(“Hello”, 180, 120, p);
Slide 13 - Handling User Interaction When the user interacts with the View, Android invokes its onTouchEvent method Android passes a MotionEvent object, which includes: the type of Action (down, up/release, move) the location (x-y coordinate) the time at which it occurred To force the View to redraw, call invalidate( )
Slide 14 - This is the revised MyShapeView class... 1 protected ShapeDrawable square; 2 protected int squareColor = Color.BLUE; 3 4 protected void init() { 5 square = new ShapeDrawable(new RectShape()); 6 square.setBounds(80, 120, 80+60, 120+60); 7 } 8 9 protected void onDraw(Canvas canvas) { 10 square.getPaint().setColor(squareColor); // use variable 11 square.draw(canvas); 12 } 13 14 public boolean onTouchEvent(MotionEvent e) { 15 if (e.getAction() == MotionEvent.ACTION_DOWN) { 16 int x = (int)event.getX(); int y = (int)event.getY(); 17 if (x > 80 && x < 140 && y > 120 && y < 180) { 18 squareColor = Color.RED; 19 invalidate(); // force redraw 20 return true; 21 } 22 } 23 return false; 24 }