Office Hours — Today, April 21

Tuesday, April 19

Apr 21
9:50 AM
Mark M.
has entered the room
Mark M.
turned on guest access
10:00 AM
Suzanne A.
has entered the room
Mark M.
howdy, Suzanne!
Suzanne A.
hi mark, good morning
I finished your fragments chapter, tyvm for the great work
Mark M.
you're very welcome
Suzanne A.
but someone questioned me on the orientation part, so just want to confirm with you
the paragraph I'm thinking of is on page 389, where you describe the limitation of using one layout for a config change on the same screen size
Mark M.
hold on
ok
it's an annoying limitation
what's the specific concern?
Suzanne A.
ok. so this is where we have one activity hosting several fragments, and the screen rotates on one screen size, right?
Mark M.
yes
Suzanne A.
the comment was ... dianne's blog post shows how to change orientation by selecting another fragment to display
but that's across multiple screen sizes, right?
Mark M.
Dianne is using dynamic fragments, as I recall
Suzanne A.
yes, exactly
before I argue for you, just want to be sure I have the point right
:)
Mark M.
the paragraph in question is referring to fragments in the layout resource itself
i.e., <fragment> elements
Suzanne A.
right. where I have one layout that defines several fragments, and that layout rotates
Mark M.
those have to be the same in portrait and landscape for the same screen size, based on my testing
10:05 AM
Suzanne A.
yes, I get the same result
Kathy
has entered the room
Mark M.
however, you can have different lineups of fragments in portrait and landscape, so long as the differences are all handled via FragmentTransaction
Suzanne A.
so from a ui perspective, I show two possible solutions
Mark M.
(which, BTW, is now covered in the Advanced Android book)
Suzanne A.
do you have an example of the FragmentTransaction approach?
Mark M.
(also, howdy, Kathy!)
Suzanne A.
ok, in advanced, I'll check that
Mark M.
specifically to have different rosters of fragments for portrait vs. landscape, no
FragmentTransactions in general, yes, in the book update I published yesterday
Kathy
Hello everone!
View paste
Can a listener be set up for an entire screen?  I want to create a screen that when touched anywhere on the screen another screen will be brought up. 
There would be words and photos on the screen.
Mark M.
Kathy: in Android, "screen" is not a term that is typically used
or, more accurately, it refers to the LCD itself
I am assuming that you mean "for an entire Activity"
in which case, the answer is "sorta"
touch events are handled by widgets first
if the widget does not consume the touch event, it gets passed to the Activity
TextView and ImageView do not consume touch events, normally, so if your layout is purely those widgets, I would expect that your touch events will all get to the activity via onTouchEvent()
fitz
has entered the room
fitz
morning
Mark M.
howdy, fitz!
10:10 AM
Kathy
So I could us onTouchEvent to know it was touched and then write code to do what I want to do next.
Mark M.
correct
I have an example of that here: https://github.com/commonsguy/vidtry
oh, no, wait
I think I subclassed a widget for the touch events there
hmmm...
I'm not sure that I have an example handy of onTouchEvent() at the activity level, among my open source code
Kathy
Thanks, that helps me a lot.
Suzanne A.
thanks mark, gotta run - early here. see you soon.
Mark M.
fitz: do you have a question?
Suzanne: see ya!
Kathy
I want to create buttons that are actual photographs. Where is the best place to find out info on how to do this?
Mark M.
Kathy: that depends on what you mean by "buttons that are actual photographs"
ImageButton is a true Button that allows images on the face, instead of text
it gives you the beveled edge and visibly responds to touch events with the typical orange flash
or, you can use plain ol' ImageView
no order, no orange flash
but it still responds to android:onClick or setOnClickListener()
dealing with low-level touch events typically is where you want to do gestures or other stuff
that's where onTouchEvent() comes in
10:15 AM
fitz
so did you see my email about tutorial 17, when you save the location log and lat it only saves where you are at that very moment - do you have an example that reads from the address in the record?
Kathy
What do you mean "no order" for ImageView?
Mark M.
fitz: that reads what from the address in the record?
Kathy: oops, sorry, meant "no border:
or "no border"
can't type this morning...
fitz
what I need to look for is an example that would read from lets say a contact record there address and basically get a map if requested
Mark M.
as we discussed, there is the Geocoder class in Android, but it seems to be fraught with problems
if you can settle for the standalone Maps application vs. MapView, there's a URL syntax to bring up a map on an address
but then you can't draw on it, etc.
if you need MapView *and* geocoding, either try Geocoder or find another third-party geocoding service to use
fitz
ok - so nothing that you know of yet for this problem :)
Mark M.
what specifically is "this problem"?
fitz
ok - thanks
I think mapview for now is fine - will it put a pin on map for target address location?
10:20 AM
Mark M.
MapView does nothing like that automatically
that's what the 18-Maps tutorial has code for
the built-in Maps application might put a marker there -- haven't tried launching it on an address
fitz
ok - and that uses Geocoder
Mark M.
if "that" is 18-Maps, no, it uses the location you recorded via GPS from the work you did in 17-Location
if "that" is the built-in Maps application, who knows what they use
again, I have never used Geocoder
ever
ever
ever
fitz
when you say built in - on phone? if so how does one access this function to see if it would work
Mark M.
all I see are lots and lots of complaints about it in issues, on StackOverflow, etc.
yes, I'm referring to the standard Google Maps app that's pre-installed on many Android devices (and pretty much all that have the Market)
A geo:0,0?q=my+street+address Uri in an ACTION_VIEW Intent, tossed to startActivity(), should bring up a map on that address
fitz
ok thanks - off again to look into more stuff - will stay here to observe more...
Kathy
View paste

Is ImageView affected by the different Android screen sizes?
Mark M.
that depends on what you mean by "affected"
the size of the ImageView will be dictated by however you define it in your layout, and that could be dependent upon screen size (e.g., using android:layout_weight with a LinearLayout)
Kathy
Do I need to be concerned with the different screen sizes when using ImageView?
Mark M.
generally, yes
though density is more important
it depends on how you are using the widget
if you are trying to have the image stretch or shrink to fill a particular space, screen size matters
10:25 AM
Mark M.
if you are setting the ImageView's size to wrap_content on both axes, screen size will only matter if your image is bigger than the available resolution
Kathy
I am thinking of using it more like a button.
Mark M.
that doesn't tell me much
Kathy
It would be a small button, and would not be larger that the available resolution.
Mark M.
again, the issue is whether the button is resizing to fit the image, or if the image is resizing to fit the button
fitz
Mark do you have a bunch of code at github that is not on books? is there a listing of the tools at github?
on books = in books
Mark M.
that's my list of public repositories
10:30 AM
Mark M.
cw- ones are tied to books
cwac- ones are the CommonsWare Android Components, reusable widgets and libraries and such
Suzanne A.
has left the room
fitz
nice thanks
Mark M.
the rest are a hodge-podge
Dimitri
has entered the room
Kathy
View paste
I want to create a grid of words approximately three wide and eight deep.  I would like to be able to 
 select some of the words and do a fade animation on them.  I would also like to know when a word 
has been selected.  I have been looking at TableLayout and GridView to do this.  Would one of these 
be better than the other to do this?  Is one of them more adaptable to the different screen sizes in 
Android than the other?
Mark M.
howdy, Dimitri!
Dimitri
Hi Mark,
Mark M.
Kathy: TableLayout can handle the tree wide/eight deep part
Dimitri
View paste
I want to refresh a home screen widget. My approach is to create an alarm on onEnabled() that will send a refresh_widget intent every minutes.

Questions:
1. Should I use "alarmMngr.setRepeating()", or " alarmMngr.setInexactRepeating()"?
2. My refresh may takes 10/15 secondes depending on the network connection. May this create ANR?
3. How do I disable refresh when the phone is sleeping?
Mark M.
however, it is not intrinsically "selectable", so you'd have to handle that yourself
GridView can handle the three wide/eight deep part and has selection logic
however, depending on what you mean by "fade animation", that may or may not work well with an AdapterView
either way, I think you have a bit of work to do :-)
Dimitri: #1: ideally use setInexactRepeating(), if that'll work for your use caes
er, case
#2: Yes, so please do the work in an IntentService or something
#3: don't use a _WAKEUP alarm
Kathy
I know what you mean and am thinking of trying something different. What if I just put buttons in the table or grid? wanf d
Mark M.
Kathy: Button widgets in a TableLayout are fine
Buttons inside individual pieces of an AdapterView (rows in a ListView, cells in a GridView) get tricky
10:35 AM
Dimitri
Also, I'm using a BOOT_INTENT to start an alarm that will do some file cleanup every 24hr... But how do I start the alarm after the app has been installed (should I ask the user to reboot the phone? :) )
Kathy
Would ImageViews work better in a grid? Would I know which one was selected in the grid?
Mark M.
Dmitri: just register your alarm on the first run of your app -- there's nothing to clean up before then anyway
Kathy: GridView and ImageViews work well together. You would register an OnItemSelectedListener with the GridView to find out about selection events.
Note, though, that "selection" in Android has a specific meaning and is *not* tied to the touchscreen
"selection" is for D-pad, trackball, arrow keys, etc.
Dimitri
Thanks a lot for the advices Mark! :)
Mark M.
if you really mean "click", you would find out about click events via an OnItemClickListener registered with the GridView
Kathy
Okay, using OnItemClickListener would tell me which ImageView had been clicked in the grid?
Mark M.
yes
10:40 AM
Dimitri
Mark: do you have an example in your book about IntentService?
Mark M.
Sure
several, in fact
it's covered in the services chapters of The Busy Coder's Guide to Android Development
it's also used in some of the advanced services stuff in The Busy Coder's Guide to Advanced Android Development
and it gets used in Tutorial #16 of Android Programming Tutorials
Dimitri
Thanks, I'll look into it :)
fitz
mark do you have examples of how to query the contacts in app - as in I want to see all contacts I have an a specific city I am visiting next week
Mark M.
not like that
10:45 AM
Mark M.
the Advanced Android book shows loading contacts, but not based on address
that would be difficult to do with accuracy, depending on how literal you want "a specific city" to be
(e.g., does an outlying suburb count?)
Kathy
Thanks for all of the help Mark.
Mark M.
sure!
10:55 AM
fitz
txs Mark have a great day
Mark M.
you too!
fitz
has left the room
11:00 AM
Dimitri
has left the room
Mark M.
have a pleasant day, all!
Kathy
has left the room
Mark M.
turned off guest access

Tuesday, April 19

 

Office Hours

People in this transcript

  • Dimitri
  • fitz
  • Kathy
  • Mark Murphy
  • Suzanne Alexandra