Office Hours — Today, March 23

Tuesday, March 20

Mark M.
has entered the room
Mark M.
turned on guest access
Mar 23
10:05 AM
somethingclever77@gmail.com
has entered the room
Mark M.
howdy, ummm...
somethingclever77@gmail.com
Hi
Mark M.
can I call you Clever?
:-)
how can I help you today?
10:10 AM
somethingclever77@gmail.com
sure...but it's just a name, I'm not really that clever
if i was i would've actually come up with something clever
I have a few questions I'd like to go over today
Mark M.
fire away
somethingclever77@gmail.com
First and foremost, I'd like to know how to create a gradient background
Mark M.
background for what?
somethingclever77@gmail.com
I have to make a splash activity with a background gradient from white to a light grey
it's for a window background
Mark M.
I'd use a ShapeDrawable
somethingclever77@gmail.com
Can you define it in your layout.xml file
Ok
Is that in one of the books
?
Mark M.
ShapeDrawable is, yes
it's lightly covered in the Advanced Android book
somethingclever77@gmail.com
Thanks
Mark M.
in the discussion of custom ListView selectors
somethingclever77@gmail.com
What exactly is a View focus?
Mark M.
well, focus in Android is not significantly different than focus in any other OS
it is the individual widget to which key events will be delivered
focused widgets usually have a different background (e.g., orange border)
somethingclever77@gmail.com
can a container with no clickable elements maintain a focus?
I've run into problems where one element 'steals
10:15 AM
somethingclever77@gmail.com
the focus for the window
10:15 AM
Mark M.
you can apply android:focusable and android:focusableInTouchMode on any View
even ones that are not naturally focusable
somethingclever77@gmail.com
and it seems the solution is either to define the widget as not focusable, or to block descendents from taking the focsu from their paretn
Mark M.
just make sure you don't screw up the use of D-pads, trackballs, arrow keys, and the like
somethingclever77@gmail.com
how do each of those parameters work?
Mark M.
they take a boolean
you might consider just using the <requestFocus> element in your layout to manually assign the focus to some more appropriate widget
somethingclever77@gmail.com
I mean how do they work, what do they mean?
okay cool, I've seen that before
Mark M.
um, android:focusable makes a widget focusable (true) or not focusable (false)
somethingclever77@gmail.com
I would just add it inside the tags for any widget?
Mark M.
yes
e.g., <Button ...><requestFocus></Button>
somethingclever77@gmail.com
so if a widget is not-focusable it can't be clicked, but you can change that programmatically right?
Mark M.
focusable and clickable are independent properties
somethingclever77@gmail.com
ah okay
Mark M.
usually clickable widgets are focusable
but that doesn't have to be the case
though it should be for decent navigation sans touchscreen
somethingclever77@gmail.com
if a parent widget has the 'focus', and a user clicks on one its children, will the child register the click event?
Mark M.
beats me
10:20 AM
somethingclever77@gmail.com
Also, I have a post on stack overflow for a google-tv app that I'm having a problem with...do you think you could take a look at it?
Mark M.
got a link?
somethingclever77@gmail.com
Mark M.
try adding android:nextFocusLeft to your WebView, identifying the thingy you want to get the focus
WebView is a little odd with these sorts of events, so that may not help, but it is worth trying
somethingclever77@gmail.com
it doesn't work
it's not a big deal
Mark M.
you could try WebViewClient and shouldOverrideKeyEvent() and manually force the focus
somethingclever77@gmail.com
how do you manually force the focus?
Mark M.
call requestFocus() on the widget that you would like to have the focus, IIRC
yes, that's right
somethingclever77@gmail.com
ah... cool
so I can use requestFocus() on any widget and it will take the focus, right?
10:25 AM
Mark M.
well, with the verb being "request", I don't think it's a rock-solid guarantee
but, yes, that's the theory
somethingclever77@gmail.com
Have you had problems with the graphical layout editor constantly crashing eclipse?
Mark M.
no
I have never had the layout editor crash Eclipse
somethingclever77@gmail.com
I found some other ppl who had this problem on stack overflow
Mark M.
if you can consistently reproduce it, file a bug on b.android.com
somethingclever77@gmail.com
I will do that
Frank
has entered the room
somethingclever77@gmail.com
where in eclipse would you set up the java sdk that you build your project on?
Frank
Hello!
somethingclever77@gmail.com
Hi Frank
Mark M.
Clever: either Project > Properties or the overall Preferences, depending on whether you want it to affect one project or all
howdy, Frank!
Frank: do you have a question?
10:30 AM
Frank
yes, but It will take a couple of minutes to prepare...
I'll let you know
Mark M.
OK
Clever: do you have another question?
Frank
Actually I'm ready
Mark M.
Frank: minutes must be shorter where you are :-)
anyway, go ahead
Frank
I want to control the layout when a multi-line textedit is entered. In particular to add buttons
E.g. a "done" button.
I'm afraid some users won't know that they should use the back button.
Mark M.
why isn't the "done" button there all the time?
Frank
Which "done" button? The one on the soft keyboard?
Mark M.
I have no idea
you said you wanted to "add buttons... E.g., a "done" button"
I am merely using your words
Frank
Scenario: a users selects an multiline textedit
10:35 AM
Frank
android open softkeyboard
users types
then he has to hit back to return to the normal layout
I would like to give the user a visible solution, instead of relying on him knowing that he has to use the back button.
Mark M.
so, you are *not* trying to "control the layout" (as you wrote), but rather put a Done button in the input method editor
right?
Frank
The button was just a solution that I imagined to solving this UI "problem". Other elegant solutions are welcome ;-)
Mark M.
OK
you can ask the input method editor to have a "Done" action button, traditionally in the lower right corner
add android:imeOptions="actionDone" to your EditText
Frank
Isn't that being used in this case as the enter key for multi-line text?
Mark M.
ah, yes
now I understand
honestly, users will know to use BACK in that situation
otherwise, they can't do much with their devices
Frank
Just looked at Google+ App. :)
10:40 AM
Mark M.
if you want an action that does something with the results of what they typed in, having a Button or something for that makes sense
and saying you aren't going to enable that button until you have valid input makes sense
somethingclever77@gmail.com
I do find it annoying myself that you have to click back to get out a text editor
Frank
They put the send button in the Action bar so it is always visible.
Mark M.
right
the button or action bar item is to process what's in the EditText, not so much to dismiss the keyboard
though usually it does that too
if anyone has another question, chime in
Frank
Well in my case it's a Save button, and there is another field that the user can change. I guess I'd really like to customize the layout the user sees when the softkeyboard is open...
Mark M.
personally, I doubt that will be very user-friendly
er, otherwise
that being said, you are welcome to change the visibility of a button or something, showing it when the user is in the EditText and hiding it othewise
10:45 AM
Frank
Well Google+ and Plume a Twitter client do things like that, and I consider them well designed.
Mark M.
to each their own
regardless, it tends to be easier to hide and show things that should be visible conditionally, as opposed to adding and removing them
Frank
So I'd just capture the onClick event and do whatever needs to be done layoutwise?
Mark M.
probably not onClick()
probably when it gets the focus
Frank
onFocus, or
yes
OK, thanks I'll give it a shot
Mark M.
yeah, setOnFocusChangeListener(), defined on View
Frank
any questions clever? Or should I go on?
Mark M.
either of you can ask questions when you have them, particularly since we're running out of chat time
10:50 AM
Frank
I'm wondering what you consider are best practices for sharing code between different activities?
Mark M.
what sort of code?
Frank
Actually scratch that. What about DB access from several threads.
Mark M.
if you are using the same SQLiteDatabase object, it will serialize the operations
Frank
I've had some exceptions because of conflicts.
OK so you suggest I only use one SQLiteDatabase. How would you implement that?
Mark M.
from what I've seen, that typically arises when you have multiple SQLiteDatabase objects
ContentProvider or your own singleton
David O.
has entered the room
Mark M.
depending on how much of a fan of the ContentProvider facade you like
er, you are
David O.
Hi..I'm back
Mark M.
howdy, David!
David O.
I'm somethingclever..I had a network issue
Mark M.
David: the chat is ending in ~7 minutes -- do you have a question?
Frank
I haven't done ContentProvider yet, so I'll take Singleton as a first approach.
Mark M.
ah, OK
David O.
I actually have a question about ContentProviders...I don't know If understand the benefit of them vs just accessing a database
10:55 AM
Frank
Great transition!
Mark M.
1. they provide an abstraction layer, to try to insulate clients from changes in the DB structure
David O.
ok
Mark M.
2. they handle inter-process scenarios nicely, which otherwise would require a lot of work
David O.
ok
Mark M.
3. they give you the ContentObserver change-monitoring framework
however, on the downside:
A. they are exported by default, meaning any app can read/write data with impunity
David O.
ok
Mark M.
B. their interface dumbs things down (e.g., you can't do a JOIN, GROUP BY, etc. directly)
David O.
ok
Mark M.
C. you can't ever close your database (which is supposed to be OK, but bugs me)
D. your output is limited to Cursors and streams (for file access)
David O.
ok
Mark M.
on the whole, I tend to use ContentProvider only where necessary
however, "necessary" is increasing in scope
David O.
what about using adapters as ContentObservers?
Mark M.
what about it?
David O.
can't you get the same functionality with an Adapter, calling notifyDataSetChanged() or some method like that?
11:00 AM
David O.
if you call that method (I might have the name wrong) I believe the adapter will re-query your dataabase
Mark M.
ContentProviders, via ContentObservers, tell you when the data has changed
proactively
vs. a polling model
David O.
ah okay
Mark M.
you still have to requery the provider to get the results
well, that's a wrap for today's chat
next one is Tuesday, 4pm Eastern
Frank
Thanks Mark!
Mark M.
have a pleasant day!
David O.
Thanks
somethingclever77@gmail.com
has left the room
Frank
has left the room
David O.
has left the room
Mark M.
turned off guest access

Tuesday, March 20

 

Office Hours

People in this transcript

  • David Ozersky
  • Frank
  • Mark Murphy
  • somethingclever77@gmail.com