Wrox Programmer Forums
|
BOOK: Professional Android 2 Application Development
This is the forum to discuss the Wrox book Professional Android 2 Application Development, 2nd Edition by Reto Meier; ISBN: 978-0-470-56552-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 2 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 13th, 2010, 11:54 AM
Registered User
 
Join Date: Jun 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 4 questions

Hi - I am a beginning programmer, and I am on Chapter 4 now. There are some concepts that I still am not so clear on but I decided to venture on and hope that later chapters will cover these issues on my mind.

But by the time the book introduces Layouts, compound controls (or compound views... are they the same things?) and custom views, there are simply too many lines in code that I do not understand.

1. Context

ex.
Code:
 public ClearableEditText(Context context)
I have no idea what Context class is, as well as why it needs to be passed into a View class such as ClearableEditText. Do I need to know this now or will it be introduced and explained in detail later?

2. onDraw & Canvas

ex. P. 93
Code:
@Override
Public void onDraw(Canvas canvas){
... }
is onDraw a method much like onCreate() where Android will automatically call for the class it is in (such as MyTextView)? do I assume that it is called immediately when the object is instantiated?

is Canvas a view? like Frame? or will it be introduced later in the book?

3. init() and Paint objects
ex. P. 95
Code:
private Paint marginPaint;
private Paint linePaint;
prviate int paperColor;
private float margin;

private void init()
//Get a reference to our resource table.
Resources myResources = getResources();

//Create the paint brushes we will use in the onDraw method.
marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

marginPaint.setColor(myResources.getColor(R.color.notepad_lines));
linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
linePaint.setColor(myResources.getColor(R.color.notepad_lines));

//Get the paper background color and the margin width.
paperColor = myResources.getColor(R.color.notepad_paper);
margin = myResources.getDimension(R.dimen.notepad_margin);
}
Why do margin and line need the Paint class and papercolor and margin don't?
Where do I learn about the Paint class itself? Where is the init() method called when instantiating? Do you somehow indicate that method to be called in the TodoListItemView.java file?



Any help would be GREATLY appreciated. Thanks.
 
Old June 14th, 2010, 04:24 PM
Authorized User
 
Join Date: Jun 2010
Posts: 18
Thanks: 0
Thanked 6 Times in 3 Posts
Default

Quote:
Originally Posted by sidneyyin View Post
Hi - I am a beginning programmer, and I am on Chapter 4 now. There are some concepts that I still am not so clear on but I decided to venture on and hope that later chapters will cover these issues on my mind.

But by the time the book introduces Layouts, compound controls (or compound views... are they the same things?) and custom views, there are simply too many lines in code that I do not understand.

1. Context

ex.
Code:
 public ClearableEditText(Context context)
I have no idea what Context class is, as well as why it needs to be passed into a View class such as ClearableEditText. Do I need to know this now or will it be introduced and explained in detail later?
Try not to get too caught up in the details. One of the key ideas behind object-oriented development is detail abstraction. You don't need to know all the details about everything up front. Wait until you're actually doing something with the context (e.g., calling a method on it), then worry about those details.

Quote:
Originally Posted by sidneyyin View Post
2. onDraw & Canvas

ex. P. 93
Code:
@Override
Public void onDraw(Canvas canvas){
... }
is onDraw a method much like onCreate() where Android will automatically call for the class it is in (such as MyTextView)? do I assume that it is called immediately when the object is instantiated?

is Canvas a view? like Frame? or will it be introduced later in the book?
Yes, onDraw() is similar to onCreate() in that Android will automatically call it on your activity when it needs to be drawn. If you are familiar with Swing, think of it like paintComponent().

Quote:
Originally Posted by sidneyyin View Post
3. init() and Paint objects
ex. P. 95
Code:
private Paint marginPaint;
private Paint linePaint;
prviate int paperColor;
private float margin;

private void init()
//Get a reference to our resource table.
Resources myResources = getResources();

//Create the paint brushes we will use in the onDraw method.
marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

marginPaint.setColor(myResources.getColor(R.color.notepad_lines));
linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
linePaint.setColor(myResources.getColor(R.color.notepad_lines));

//Get the paper background color and the margin width.
paperColor = myResources.getColor(R.color.notepad_paper);
margin = myResources.getDimension(R.dimen.notepad_margin);
}
Why do margin and line need the Paint class and papercolor and margin don't?
Where do I learn about the Paint class itself? Where is the init() method called when instantiating? Do you somehow indicate that method to be called in the TodoListItemView.java file?



Any help would be GREATLY appreciated. Thanks.
The papercolor is simply the background color. The other entities are used to paint on the view.





Similar Threads
Thread Thread Starter Forum Replies Last Post
More Chapter 3 Method questions. wbrco BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7 3 February 17th, 2009 12:14 AM
Chapter 1 - Two questions mikener BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 6 March 17th, 2008 03:59 PM
Two Chapter 3 Questions psychonet BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 6 April 13th, 2007 11:39 PM
Comments and Questions for Chapter 2 nguyendh BOOK: Ivor Horton's Beginning Visual C++ 2005 0 June 24th, 2006 07:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.