Day 4: Taking Stock; Eclipse Tricks

<< Back to Tutorial Home -
< Back to Day 3 -
Forward To Day 5 >
At this point, let's quickly recap what we've done, and what we've created
that we ca re-use on other projects. Also, it's worth pointing out some
things you can do in Eclipse to make your life easier. In Day 5, we'll add
the camera images to the View screen, then wrap up.
Recap
At this point, we have a Bananas-compliant TiVo app, with multiple screens
and navigation between them. In addition, we've created a few classes that
will be useful in other projects:
- ScreenTemplate, a base class that allows us to set up a standard look
and feel for our screens (background, title, and basic navigation).
- TextItemList, which allows us to easily build a list of text items on
the screen.
- ScreenList, which allows us to build a list on the screen, where each
item in the list has its own corresponding screen.
Where Did the Tutorial Cut Corners?
As you've gone through this tutorial, you might have questions. Why did
you include that particular line of code? Why didn't you comment anything?
Most of the code (at least through Day 3) is really just copied from the
Bananas sample; I've modified it somewhat to suit our tastes, but it's beyond
the scope of this tutorial to explain all of the functions in-depth. What
I will do is explain below how you can examine the documentation yourself, and
even look at the source for Bananas and the HME SDK directly from Eclipse, which
is really nice.
As far as comments, I stripped out the comments because I didn't think the
comments that were there really added much insight to the code. All of the
methods in the classes are very short, usually only a few lines long, and it's
pretty easy to tell what's going on in there. (Sorry if you don't agree with this tactic, but I did it on purpose: the intent
of this tutorial is to explain how to get an app going, not all of the fine
details of the code.)
Debugging in Eclipse
At this point, it's worth pointing out how to get basic debugging going in
Eclipse. Turns out it's really simple. Let's say we want to set a
breakpoint in our InitialScreen, just as the list is being built. Here's
all we have to do:
Right-click in the left margin of the editor window for InitialScreen.java,
right after the super(app); call, and choose 'Toggle Breakpoint' (make
sure your mouse cursor is in the margin, where that blue bar is). You should
now see a little blue dot next to that line, indicating a
breakpoint:

Now, go to the 'Run' menu and choose 'Debug...' Pick the
'TrafficCam - Simulator' configuration, then click 'Debug'. This
will start the app in the debugger. The first time you do this, you'll get
the following dialog box:

What this means is Eclipse will change the 'Perspective', or layout of the
different tabs and windows, for debugging. This is a good thing.
Make sure the 'Remember my decision' checkbox is checked, then click 'Yes'.
Now, you'll see the Simulator partially start up, but execution stops at the
line we marked with the breakpoint. You can use the 'Step Over' button ( )
to step through, a line at a time, or just hit the 'Resume' button ( )
to continue the app like normal, since we don't have any other breakpoints
enabled. Note that in the Debug perspective, you have windows allowing you
to examine variables, change things on the fly, etc.
Once you're done debugging and you want to switch back to the normal 'Java'
perspective we've been using all along, simply click the 'Java' button in the
upper-right corner:

Eclipse Documentation
There's lots more to learn about Eclipse debugging, but I won't go into it
here. For more information, see the
Eclipse documentation. Look under 'Java Development User
Guide - Reference - Views and Editors - Debug View' as a starting point.
Viewing SDK Source in Eclipse
Sometimes, when you're trying to debug your application, you'll want to view
the source of Bananas or HME. This is a major help when trying to figure
out what's going on. In addition to debugging, the little mouse-over help
you get inside Eclipse is MUCH improved, since it shows you the actual names of
the parameters, etc. Here's how to set that up; it's easy.
Remember that we added a couple 'External JARs' to our project when we first
started. These have the binaries for the libraries we want to use, but not
the source. Fortunately, TiVo was good enough to include it for us.
Here's how to enable it:
In the Package Explorer, right-click 'hme.jar' and choose 'Properties':

Select 'Java Source Attachment', then fill in the location as shown:

Now, let's repeat those steps for Bananas. In the Package Explorer,
right-click 'bananas.jar' and choose 'Properties'. Select 'Java
Source Attachment', then fill in the location as shown:

Learning More About Eclipse
There are too many features of Eclipse to mention here, but if you're going
to spend any amount of time writing your apps in it, I'd recommend buying a
book. Here's one I've have pretty good luck with:
Eclipse Distilled. Or, if you prefer, you can stick with the (free)
Eclipse documentation.
<< Back to Tutorial Home -
< Back to Day 3 -
Forward To Day 5 >
|