Office Hours — Today, January 25

Thursday, January 14

Jan 25
6:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Terry S.
has entered the room
Terry S.
Greetings oh wise one.
Mark M.
Howdy!
Dan
has entered the room
Mike Q.
has entered the room
Mark M.
Howdy all!
Dan
Hi
Jan 25
6:30 PM
Mike Q.
Hi Mark
Mark M.
Um, anybody got any Android development questions?
Mike Q.
Yes, I do.
Mark M.
Fire away!
Mike Q.
Question regarding SurfaceView...
Mike Q.
Using this to try to capture a user drawing on the screen....
Mark M.
Oy
Mike Q.
I wanted to add a background that was a drawable....
Rick J.
has entered the room
Rick J.
Hi
Mark M.
Hi, Rick!
Mike Q.
So doing the drawing was bad enough but adding the background image basically disabled the drawing area.
Rick J.
Hi Mark
Mark M.
Mike: what does a SurfaceView have to do with user drawing?
Mark M.
When I think "SurfaceView", I think of video output or OpenGL.
Mike Q.
That's just the widget I extended to make the drawing area.
Mark M.
Unless there's something specific about SurfaceView you need, that's the last choice I'd make.
Mark M.
SurfaceView is designed for the innards of Android to get direct access to the screen.
Mike Q.
Ok, I'm all ears for another option!!!
Jan 25
6:35 PM
Mark M.
:: shrug :: How about a plain View?
Mike Q.
Can a user draw on that?
Mark M.
You can put a <View> in your layouts, that takes up space and has a background, but otherwise does not have any specific functionality.
Mark M.
However you are capturing user motions on the SurfaceView should work on a View, AFAIK
Mike Q.
And add a Canvas to that for drawing?
Mark M.
Um, now you're getting into 2D graphics, which is an area of Android I have little experience in
Mark M.
AFAIK, though, yes.
Mike Q.
Ok.
Mark M.
Give that a shot and see if your problem is SurfaceView-isms
Mike Q.
Will do.
Mark M.
Anybody else have an Android development question?
Terry S.
Ready for another?
Mark M.
Go ahead, Terry!
Terry S.
View paste
C:\Android\HeadFirst>javac -classpath "C:\Android\AndroidSDK\android-sdk-windows
\commons-io-1.4" RecursiveDirectories.java
RecursiveDirectories.java:1: package org.apache.commons.io does not exist
import org.apache.commons.io.FileUtils;
                            ^
RecursiveDirectories.java:22: cannot find symbol
symbol  : variable FileUtils
location: class RecursiveDirectories
            Collection files = FileUtils.listFiles(root, extensions, recursive);

                               ^
2 errors
Terry S.
I cannot figure out why it doesn't work.
Terry S.
FileUtils is in the Jar in the right place or so it seems to me.
Mark M.
Umm
Mark M.
You forgot the .jar on the path to the JAR, for one
Terry S.
I just need to add the jar name?
Mark M.
Yes
Terry S.
OK, thanks.
Mark M.
-classpath takes a list of directories (of *classes*) and JARs
Jan 25
6:40 PM
Mark M.
Of course, in an Android project, you drop the JAR into libs/, and add it to your Eclipse build path (if applicable), and the build process handles your classpath for you
Terry S.
I said you were brilliant. LOL
Mark M.
That's just the lights shining off my bald pate.
Rick J.
I resemble that remark
Terry S.
OK,I downloaded a zip file that had the whole structure in it.
Terry S.
I just need to move the jars to the proper lib directory then.
Terry S.
I thought I tried that.
Mark M.
Rick: my sincere condolences for your former follicles
Terry S.
View paste
It apparently doesn't work if you just put the jar in the current directory.
I think I tried that.
Mark M.
If by "current directory", you mean the base project directory, yes, that won't work.
Terry S.
OK
Mark M.
If you are building via Ant, all you need to do is drop it in libs/ (along with any dependencies) and you're set -- ant install will pick it up automagically
Terry S.
Great
Mark M.
BTW, before I forget, in case you missed the announcement, EPUB editions of the books are being generated now
Mark M.
It's taking longer than I expected to generate
Mark M.
Most people will have them by 11am Eastern tomorrow
Mark M.
20-25% will be delayed another 18 hours or so
Rick J.
Ready for another Q?
Dan
My question is a bit more basic. I have a simple app that has a EditText and two buttons. One button is accepts the user input in the EditText and the other clears it. If the phone setting "Audible selection" is set to true, there is an audible key click. The problem is when the user enters a value in the EditText using the soft keyboard and then hits the "Done" button, I want to make the same key click sound (to be consistent). Is there an easy way to do this?
Mark M.
Go right ahead!
Rick J.
Here's one I posted on stack overflow
Jan 25
6:45 PM
Rick J.
I am having issues accessing buttons from JUnit into Android
Rick J.
I can query simple things like relative position, visibility, etc
Rick J.
but when I attempt to exercise controls exceptions are thrown
Rick J.
CalledFromWrongThreadException
Mark M.
Rick: Define "exercise controls"
Rick J.
android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. at android.view.ViewRoot.checkThread(ViewRoot.java:2683) at android.view.ViewRoot.playSoundEffect(ViewRoot.java:2472) at android.view.View.playSoundEffect(View.java:8307) at android.view.View.performClick(View.java:2363) at com.android.tigerslair.demo1.test.GoTest.setUp(GoTest.java:49) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
Rick J.
Well, in this case perform a click of a button
Mark M.
OK, so you're calling performClick()
Rick J.
which in turn is playing a sound effect
Mark M.
You're probably going to need to use UiThreadTest for that test method, or runTestOnUiThread()
Mark M.
Dan: I'll get to your question when we're done with Rick's, sorry.
Rick J.
sorry, am I out of order?
Rick J.
I can wait
Dan
no worries
Mark M.
Rick: You and Dan asked questions at the same time
Mark M.
Rick: keep rolling
Mark M.
(pun lightly intended)
Rick J.
Maybe I'm done
Rick J.
not familiar with UIThreadTest
Rick J.
I'll look into it
Rick J.
well, there was a second part
Mark M.
Basically, tests are run on a non-UI thread, so you need to do something to execute tests on the UI thread
Rick J.
why is it so hard to find anything about TDD with android?
Rick J.
any pointers?
Rick J.
I've found one blog entry from more than a year ago, but that's about it
Mark M.
Hold on
Jan 25
6:50 PM
Mark M.
Hmmmm...
Mark M.
Thought I Evernoted something on that
Mark M.
Anyway, I took a shot at creating a Cucumber-based code generator for TDD, because TDD with JUnit would make me claw my eyes out
Rick J.
:)
Mark M.
Unfortunately, Cucumber's regex-based language parser and I didn't get along
Rick J.
Could be another authoring opportunity...:)
Mark M.
I seem to recall somebody else debuting a similar sort of test framework, designed to simplify test writing
Mark M.
Unfortunately, I seem to have lost the link.
Rick J.
OK
Mark M.
OK, back to Dan's question
Mark M.
Dan: are you looking for the sound on every soft keyboard tap, or just when the whole thing is done?
Rick J.
thx
Dan
just when the user hits the "done" button
Dan
I call the same logic when that happens as when they hit the "set" button without the soft keyboard
Mark M.
That shouldn't be too bad. Give me a minute while I dredge up some code.
Dan
thanks
Jan 25
6:55 PM
Mark M.
Step #1: call setOnEditorActionListener() on your EditText, supplying a TextView.OnEditorActionListener
Mark M.
Step #2: Specify an android:imeActionId in the XML layout for that EditText
Mark M.
Step #3: In your OnEditorActionListener, play the sound (MediaPlayer or SoundPool or something)
Mark M.
Actually, AsyncPlayer might be the best choice, though I haven't played with that yet
Dan
ok...then I will check that out. thanks
Mark M.
Basically, steps #1 and #2 will get you control when they press the action button (lower right corner of the IME); step #3 just plays whatever click sound you want.
Dan
I have the #1 and #2 down now. Just did not know the best solution for #3
Mark M.
Ah, OK
Mark M.
AsyncPlayer saves you the trouble of forking your own background thread
Mark M.
since playing the click isn't something you probably want tying up the UI flow
Dan
I agree...simple is what I need ;')
Jan 25
7:00 PM
Dan
I will look at AsyncPlayer-thanks
Mark M.
Any other questions?
Terry S.
I found a reference to a package that mapped Oracle (ANSI99) functions directly in Java. Have any idea where I could actually find it?
Mark M.
I have nary a clue
Terry S.
OK, thanks.
Mark M.
I am completely clue-free
Dan
Another quick question?
Mike Q.
I have another question.
Dan
sorry Mike Q - go ahead
Mark M.
Mike: go ahead, then we'll roll back to Dan
Mike Q.
Why don't you do, mine is a little more complicated.
Dan
go ahead Mike Q
Mike Q.
Ok....I have a ListView I want to select something in the list (touch or otherwise) and have it highlight and then perform an action on the highlighted list item.
Mike Q.
Even when I can highlight the item, I can't capture the selection.
Jan 25
7:05 PM
Mark M.
The clicked-on item will be passed to you in your listener
Mark M.
If this is part of a ListActivity, you can get the item _ID and/or position in onListItemClick(). If not, use setOnItemClickListener() on the ListView itself, and you get the same data.
Mike Q.
Yea, clicked on does but the clicked on listener does something else like takes me to another Activity.
Mark M.
It does whatever you implement
Mark M.
If you want the listener to start another activity, craft an appropriate Intent in the listener and call startActivity()
Mark M.
You can see this pattern in _Android Programming Tutorials_ in the implementation of the LunchList application
Mike Q.
Ok, but I want to the click to do one thing (take me to another screen) and that's ok. And when I select an item in the list, hold that item until I press a button to act on the selected item but I can't get the state of that item.
Mark M.
ListViews don't work that way.
Jan 25
7:10 PM
Mark M.
Use a context menu (displayed on a long-tap of the list item) instead
Mike Q.
Yes, that was one thing I was thinking of. Changes the flow of what they wanted but if that's all we can do.....
Mark M.
ListViews are not stateful, in that when they are used in touch mode, the ListView does not track the selection, other than to pass it to the listener.
Mark M.
In non-touch mode, you could do what you want, but then users will get frustrated when they tap the screen.
Mike Q.
Understood. Could I force it to non-touch mode though?
Mark M.
Nope.
Mark M.
Non-touch mode requires the user to use the D-pad/trackball/whatever.
Mike Q.
Ok. Well that answers my question. Thanks. Dan, you're up....
Dan
this is about testing prior to releasing to the market
Jan 25
7:15 PM
Mark M.
OK
Dan
how good are the emulators...I am testing on a droid, but can I reply on the emulators for testing of other screen sizes?
Mark M.
Specifically in terms of screen sizes, the emulators should be fine.
Dan
ok - thanks for your help tonight!
Mark M.
You may want to experiment both in normal mode (one emulator pixel = one pixel on your monitor) and scaled model (one emulator inch = one monitor inch)
Mark M.
Oops, that should have been "scaled mode"
Dan
got it
Dan
i wish I could test on all real devices to be sure
Mark M.
There's always DeviceAnywhere
Mark M.
though that's not exactly cheap
Mark M.
Other questions?
Dan
has left the room
Jan 25
7:20 PM
Terry S.
How can you get a list of where the accessible jars, etc. are other than the classpath variable?
Mike Q.
I actually have one more.
Mark M.
Terry: what do you mean by "accessible jars"?
Terry S.
If I try to do an import, how would I know the file that needs to be accessed is in a place ANT, etc would look for it?
Mark M.
Simple: look in libs/
Mark M.
If it's not there, and it's not built into Android, Ant won't find it
Terry S.
Great.
Terry S.
Thanks.
Mark M.
Mike: go ahead
Mike Q.
For supporting layouts for different screen sizes or resolutions, I saw post (of yours) that described putting different layouts in different resource directories...
Mark M.
Yes
Mark M.
You'll see this covered in greater detail in a chapter in _The Busy Coder's Guide to Android Development_
Mike Q.
Is this the best practice for doing this? I'm concerned that I'll have several layouts for certain screens and it seems that it could become a bit of a maintenance issue.
Mark M.
Well, that depends on the layouts.
Mike Q.
How so?
Mark M.
For example, consider the LunchList application from the _Tutorials_
Mike Q.
Yes...
Mark M.
By the end, there are two activities of significance: one for the list of restaurants and the detail form for an individual restaurant
Mark M.
The list of restaurants would not need a different layout for different screen sizes, because its current design should scale up and down fairly nicely (main activity plus the rows)
Mark M.
The detail form, though, is probably too big for a QVGA screen
Mark M.
It already uses two layouts, one portrait and one landscape, just for HVGA on up
Mike Q.
Understood.
Jan 25
7:25 PM
Mark M.
If you want to support QVGA, you'd probably need another pair of layouts for that size, doing...something...to make it all fit
Mark M.
In an ideal world, your activities won't need separate layouts in separate resource sets
Mark M.
RelativeLayout and density-independent dimensions and stuff would cover it all
Mark M.
In reality, there's probably some layouts that will need greater tweaking
Mike Q.
Yes, I'm finding that already.
Mike Q.
Thanks for your help tonight. So, when are your next office hours?? :)
Terry S.
Yes, thanks loads!
Mark M.
I tossed in another hour next week, Tuesday, 9pm Eastern.
Terry S.
Great! Thanks!
Mark M.
Unfortunately, I am in week #2 of a four-week stint of delivering live Android training, so I have less time for office hours
Mark M.
Things should improve in the second half of February
Jan 25
7:30 PM
Mike Q.
Sounds good. Thanks again.
Terry S.
Great for you!
Mark M.
OK, that's a wrap for today. I'll be posting the transcript on [cw-android], per usual.
Mark M.
Have a delightful week!
Terry S.
You too!
Mike Q.
has left the room
Terry S.
has left the room
Rick J.
has left the room
Mark M.
turned off guest access

Thursday, January 14

 

Office Hours

People in this transcript

  • Dan
  • Mark Murphy
  • Mike Quaranto
  • Rick Jones
  • Terry Stough