Office Hours — Today, February 3

Tuesday, February 1

Feb 3
9:50 AM
Mark M.
has entered the room
Mark M.
turned off guest access
Mark M.
turned on guest access
10:00 AM
Prasanna P.
has entered the room
Mark M.
howdy, Prasanna!
Prasanna P.
Hi Mark, Quick qestion
Would you use preferences to keep track of something in a situation
where you want this piece of information ...
each time a service is invoked inside of the service?
Mark M.
I am completely lost
first, what is "each time a service is invoked inside of the service?"
Prasanna P.
sorry
10:05 AM
Prasanna P.
ok. basically using a preference from inside of a service ...
this preference say 'last_update_date' would be updated from the service ...
then next time the service is running, the service would want to look at this same ...
preference 'last_update_date' to find out its value. Then update this.
So that the next time the service is running ...
you can get this updated value again?
does this make sense?
Mark M.
yes, it now makes sense
can you use SharedPreferences? yes
would *I* use SharedPreferences? no
I reserve SharedPreferences for things collected from the user via a PreferenceActivity
everything else that fits goes in SQLite
simply for transactional integrity
in your case, I would go with a static data member backed up by some persistent store -- that way, if the process sticks around, you can skip the flash read operationg
er, operation
10:10 AM
Prasanna P.
by 'by some persistent store' you mean sqlite?
Mark M.
again, that's what I would use
if you wanted to use SharedPreferences or a flat file, you could
Prasanna P.
one more qs
to call a remote service that I create, I can use startService(Intent). Right?
Mark M.
um
Prasanna P.
No need of the binding stuff right?
Mark M.
you can send a command to a service via startService()
Prasanna P.
If I do not want a strong bind
Mark M.
whether it is "remote" or not depends on whether it is in a separate app
whether you use the command (startService()) or binding (bindService()) pattern for any given service implementation is up to you
10:15 AM
Alexander K.
has entered the room
Prasanna P.
so if you want to start a service by command (startService()) ...
and it is a remote service ...
Mark M.
(btw, howdy, Alexander!)
Prasanna P.
would you implement it like a local service ...
Alexander K.
hello Mark, hello Prasanna
Prasanna P.
ie the same code but in a different app
?
hi Alexander
Mark M.
the service implementation for the command pattern is generally ignorant of whether the client is in the same app or a different app
your onStartCommand() gets an Intent just the same
Prasanna P.
ok. got it. Thanks! Heading out. Enjoy the rest of the day.
Mark M.
the only big difference is that you will need to add an <intent-filter> with a custom action, to name the service
Prasanna P.
oh ok. still here ...
Mark M.
that is what clients will use in their Intents to identify which service to send the command to
also, it allows the service to be used from another app; without an <intent-filter>, by default, the service is not exported
Prasanna P.
got it.
10:20 AM
Prasanna P.
Thanks again Mark for your help.
fitz
has entered the room
Mark M.
no problme
er, problem
howdy, fitz!
Alexander: do you have a question?
Alexander K.
I do
fitz
morning - just learning so no specific questions
Alexander K.
hi fitz
I created a custom component, trying to reproduce iPhone's UIPicker
that seems like an ideal match for the task at hand: to have a meter with a variable number of dials.
The component is based on a LinearLayout, to which the dials are added at run time
I add the component to the layout like this:
View paste
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:id="@+id/layout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<com.test.Meter 
	android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|center_horizontal"
	/>
</LinearLayout>
It works fine on 2.2 and 2.3 SDK but on anything earlier the component remains invisible
Mark M.
what has Hierarchy Viewer indicated?
10:25 AM
Alexander K.
My guess is that Android notices that this is a LinearLayout and it doesn't have any children so it doesn't bother to display it
Hierarchy Viewer?
Mark M.
though note that the docs are somewhat out of date relative to new tools releases
I cover it in The Busy Coder's Guide to Android Development
Alexander K.
haven't looked at it yet
Mark M.
it allows you to inspect a running activity to see the various widgets and their properties at runtime
Alexander K.
great, will have a look
Mark M.
I'd use it to figure out where your widget is winding up
most likely, the android:layout_height="wrap_content" is your problem
if you have no content, you have no height
Alexander K.
I manage to get the component visible by adding a 1px by 1px view inside the layout
Mark M.
you are probably going to need a requirement of at least one wheel or something
Alexander K.
Here is the code of the component, not very verbose:
well, just a part of it
View paste (16 more lines)
@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		
		int width = MeasureSpec.getSize(widthMeasureSpec);
		dialWidth = width / NUMBER_OF_DIALS;
	}
	
	protected void dispatchDraw (Canvas canvas) {
		super.dispatchDraw(canvas);
		
		for (Dial d : dials) {
			d.draw(canvas);
		}
	}
...
fitz
Does DDMS in Eclipse do the same thing as Hierarchy Viewer?
Mark M.
fitz: no, but newer editions of the tools has a Hierarchy View perspective in Eclipse
Alexander K.
the dispatchDraw is needed to make the component visible with the 1x1 view in it on 1.6
10:30 AM
Mark M.
Alexander: I don't see where you are qualifying the height
10:30 AM
Mark M.
bear in mind that I haven't written a custom component with custom onMeasure() and such, so I may be misunderstanding things
regardless, I'd start with Hierarchy View
Alexander K.
well, this is my first experience :)
ok, will try to see what Hierarchy View shows
the thing is: everything works fine on 2.2 and 2.3 platforms
all right, thanks Mark
and thank you for the books, they are a great help
Mark M.
glad you like them!
Alexander K.
has left the room
Mark M.
anyone have any questions?
10:35 AM
fitz
Quick one - you mentioned in books that PNG is a nine-patch bitmap - so does this mean PNG's are best to use or use something like ISO's
Mark M.
um
first, nine-patch bitmaps are PNGs; not all PNGs are nine-patch bitmaps
fitz
for graphic buttons
Mark M.
second, ISO is a CD/DVD disk image, not an image from the standpoint of graphics
I would recommend PNGs and JPEGs for your images
fitz
sorry ment ICO's
Mark M.
Android does not support the ICO image format
fitz
ok so png and make them nine-patch?
Mark M.
whether or not you make a PNG be nine-patch depends on how you want to use it
for the face of a button, no
fitz
ya you can tell I am from .net c# mentality :)
Mark M.
for the background of a button (i.e., what makes a button a button), yes
though in that case you need several .9.png files, one per relevant state (normal, focused, pressed, etc.)
fitz
ok - will just do PNG's - see simple questions :)
Mark M.
bear in mind that a PNG is what you will want in your project
however, given different screen densities, it helps if your actual original artwork is in some vector format (e.g., SVG)
so you can save the image at various resolutions for use at various screen densitiies
er, densities
10:40 AM
Prasanna P.
has left the room
fitz
hmm - ok so get into final format of SVG?
Mark M.
I would describe it as your initial format is SVG, exported to PNGs
though the actual vector format is up to the tools you are using for the graphics
e.g., Adobe Illustrator might use AI files instead of SVGs
SVG is the open standard for vector art, but not all tools support it equally well
fitz
ok great - do you have an example in books on how to scan emails to pull out data? keyword search etc.
Mark M.
well, you don't really have access to emails, unless you are using JavaMail or something
so, no, I have nothing in the books on that
fitz
would this be the case as well - no access to contacts or calendar
Mark M.
contacts are part of the SDK -- see android.provider.ContactsContract
chapter on it in The Busy Coder's Guide to Advanced Android Development
icky subject
fitz
those are the 3 components we are looking to get data from
Mark M.
there is no SDK support for calendar or email
mostly because there is no OS concept of calendar or email
those are just apps
they can be replaced
they can be changed
10:45 AM
fitz
Advanced book is not updated yet to 2.3 right - does it change a ton - if so I will focus on other to-do's till it is out
Mark M.
Advanced book will not be updated now until after Honeycomb ships and I get my grubby little hands on a XOOM or something
little *changed* (i.e., is now wrong) in the book due to 2.3
the camera chapter is updated with better samples, including front-facing camera support using 2.3
those samples are out in the GitHub repo, if you need them
fitz
ok - great thanks
Mark M.
otherwise, looking over my notes, there's nothing much 2.3-specific in the Advanced book
fitz
I am last one here so I will let you go thanks
Mark M.
lots of other improvements, and definitely some Honeycomb stuff
fitz
ok so you like honeycomb?
Mark M.
um
I have grave concerns over fragments
fitz
it looks like everyone will have to review code to make sure all looks ok
Mark M.
and, yes, it will require a fair bit of testing
and the whole Honeycomb-on-phones area is murky
otherwise, it seems fine
fitz
ya that way an interesting concept - wonder why they are focusing on this - gives us flexibility....
Mark M.
oh, we need that sort of flexibility
10:50 AM
Mark M.
however, their backwards-incompatible implementation is a mistake, IMHO
as a result, I have a pile of work ahead of me to write up ways of solving the problem that *will* be backwards-compatible
at least until 2013 and Honeycomb-on-up are 90+% of the market
fitz
ya so the chrome OS is for laptops - honeycome for tablets and android for cells - interesting - I know tablets and cell use android but you almost have to code to each with a different mind set
Mark M.
don't forget Google TV
fitz
ya so you like me thinking honeycomb will kick some royal apple A**
oh ya TV ahhhhhh
Mark M.
unlikely
Apple's power is less in the OS than it is in the marketing juggernaut
Android has to get to 200-300% of the capability of iOS for the iOS-is-superior attitude to change
HC isn't there yet
and Android may never get there, since Apple keeps innovating
fitz
most android developers also do IPhone etc?
Mark M.
don't know about "most"
some certainly do
fitz
ya well we are betting on Android for now
10:55 AM
fitz
ok cya thanks for chat
fitz
has left the room
Mark M.
see ya!
11:00 AM
Mark M.
turned off guest access

Tuesday, February 1

 

Office Hours

People in this transcript

  • Alexander Kolesnikov
  • fitz
  • Mark Murphy
  • Prasanna Perera