Office Hours — Today, April 18

Yesterday, April 17

Apr 18
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
4:00 PM
Tamir
has entered the room
Tamir
hi
Mark M.
hello, Tamir
how can I help you today?
Spleak
has entered the room
Tamir
View paste
hi again 
i have a viewpager with one page that contains a list (fragment A).
i want to allow the user to press an item on the list and as a response i want that a new fragment(B) with some information will be loaded on the same tab . i have managed to do all of that using transection manager to load the fragmenet that i want to be see. 
my problem is like that: i am extending ShelockFragment and i am using addToBackStack when i am loading the Second fragment (by replace) in order to restore fragment A when back button is pressed, but still the back button exits from my app ..
Mark M.
I doubt that you can safely change the contents of a ViewPager that way
ViewPager is designed to allow horizontal swiping between peer content
Spleak
Hi
Mark M.
(Spleak: hi! I will be with you shortly!)
Tamir
but still i cant load a new fragment in the same tab ?
i am using some farame layer
Mark M.
Tamir: you can call notifyDataSetChanged() and perhaps return a different fragment
however, I will be surprised if addToBackStack() will work
because you should not be executing the FragmentTransaction -- your adapter will
it is conceivable that you could create your own PagerAdapter implementation that can handle this scenario better
since I really really really dislike the navigation pattern you are proposing, I have not given this much thought
4:05 PM
Mark M.
let me take a question from Spleak, and I will be back with you in a bit
Spleak: do you have a question?
Tamir
ok thanks
Spleak
Yes I do
View paste
So I'm currently developing an app that will work as a "room booker". It will hang on tablets outside rooms, and tell the user the status of the room, and let him/her book the room if it's available.

It syncs with Google Apps (using Google's Calendar API). 
Most things now work, and I'm currently working on a "schedule" for the room, which will be shown to the left on the screen, residing in a Fragment.
(just pasting it all)
View paste (2 more lines)
That schedule will not be interactive except for scrolling up and down on it. It will display like a "dayview" calendar going from 00.00 AM to 11.59 PM. In this schedule I want to print up all bookings for the room graphically so the user sees which times are available and not.

That is if a room is booked from 09.53 AM to 11.00 AM I want an orange box or something similar stretch out from 09.53 to 11.00 and more boxes for other times the room is booked, much like it does in Android own calendar app in dayview.

I dont need events/meetings to overlap, as it is only for one room, and thus the times can't/shouldn't "crash".

Now I don't really know how I should go about implementing this. I first thought about using a ListFragment and having 24 "items" in the adapter populating it, and then coloring the adapter item based on if the time (position) is "busy" or not. But that way if a room is booked only like 10 minutes the whole hour gets filled, also it's a little tricky to get it to look good.

So I think I'm in the wrong path, and simply wonder if you have any suggestions on what to use to create this schedule? Dynamically create a HTML-page in a webview somehow? Use ListView (but 
...
Mark M.
I'd look to see how iosched does it
Spleak
Also I can wait for an answer, just write here if it takes long you can help Tamir
Mark M.
iosched is the Google I|O conference app
Spleak
Hmm okay :O
Mark M.
it has a calendar akin to what you are proposing, though a bit more complex (shows all rooms, not just one)
the HTML approach could work
you could hack something together using a TextView with a nine-patch PNG file for the background (for a variable-size bubble) and appropriate margins
Spleak
Is it the "my agenda" part of the IO app you are talking about?
Mark M.
(in a vertical LinearLayout, wrapped in a ScrollView)
yes
well, sorta
4:10 PM
Mark M.
there's also a separate view for the conference agenda
not shown in the screenshots
it's been nearly a year since I looked at it, so my memory is fuzzy
Spleak
Ah, downloading the app and looking right now
The "Textview"-hack, how exactly do you mean? Still use a ListFragment?
Mark M.
no
have one TextView per event
size the TextView vertically in accordance with its duration
using the nine-patch PNG to give you the rounded-rectangle "bubble" for the event
use margins for the spacing between events, sized in accordance with the duration of the gaps
using a vertical LinearLayout for the whole thing
wrapped in a ScrollView so that it is scrollable
Spleak
Ahh I understand. That actually sounds pretty good
Mark M.
getting the sizing and margins right may get a bit tricky
another variation on the theme would use a FrameLayout instead of a vertical LinearLayout, using the top margin to offset the TextView to the right spot
Spleak
Ye. Especially since I want it to scale for many screensizes.
Mark M.
go that route if you find that you are progressively getting further off due to calculation issues compounded as you append more and more events
you could even create your own ViewGroup with this sort of model in mind
so, there are lots of possibilities
4:15 PM
Spleak
Figured so. :) Thanks for the great tips. I will try to find how Google did with their IO thing (still can't find it).
Mark M.
let me swing back to Tamir, and I'll be with you again in a bit
Tamir: do you have another question?
Spleak
sure
Mark M.
OK
Tamir
yes .. one more
Mark M.
go ahead
Tamir
i thought to try and catch the on press Back button event and the activity
on the main activity
can i tell which fragment is running when the event happend?
Mark M.
all of your fragments are "running"
for any conventional definition of "running"
what do *you* mean by "running"?
Tamir
the one that user use just before he pressed the back button
Mark M.
I have no idea what you are talking about
4:20 PM
Mark M.
what does "that user use" mean?
Tamir
never mind thanks for the help
let say that i use the fragment manager and just replaced a fragment
Mark M.
...and... ?
Tamir
and than the user pressed back
and i want for the replaced fragment to handle this event
Mark M.
you will have to track that yourself
again, you will have to track that yourself
Tamir
thanks
thanks for your help
Mark M.
Spleak: do you have another question?
Spleak
Hmm. Well not anything I can't read myself to I think. Still can't find where in the IO app the schedule is though. :)
Mark M.
it's possible I was thinking of the 2011 edition
4:25 PM
Mark M.
then if either of you has a question, chime in
Spleak
Will do, thanks for the help! Just gonna hang around here
4:35 PM
Spleak
Just one quick question. Trying your "textview"-method. You mean set the 9-patch png as the background for the textview right?
(probably silly question)
Tamir
bye and have a good day
Mark M.
correct, whatever you want the event background to look like
Tamir
has left the room
Mark M.
you'll need to set the height and width to whatever makes sense (height based on duration, width presumably match_parent)
Spleak
ya. and I can only set the height in Java right?
Mark M.
in your case, yes, because you do not know the duration of the event at compile time
Spleak
exactly. :) Also, how should I do to print out the "times"? I want there to be like 24 "lines" with each hour, which the bubbles are then placed "on top" of if you get what I mean
Mark M.
that will probably require you to go the FrameLayout route and use margins to "push down" each bubble/line from the top
Spleak
or perhaps that's not needed.. hmm
Mark M.
(or roll your own ViewGroup)
4:40 PM
Spleak
Okay. Never used FrameLayout before. So I still go the same route with making a TextView+background, just use the FrameLayout to position it instead, modifying the margin according to the time they are (and ofc heigh or the textview for how long)?
height of*
Mark M.
yes
FrameLayout is a fairly simplistic container, that puts everything in the upper-left corner by default, and stacks on the Z axis (later children float over earlier children)
if you want lines, with events floating over them, you need a container that has Z axis support, and LinearLayout does not
Spleak
hmm okay. So I should make a new element, representing a "line with time" and add those as a child, and then add my textviews?
Mark M.
yes
actually, 24 elements, each representing a "line with time"
(where 24 = however many hours you are showing, and adjust if you are showing time divisions other than an hour)
Spleak
Ah. And how do I do to position the "bubbles" over them? Won't they just push the lines further down?
if I get what you wrote earlier correctly
Mark M.
no, because children in FrameLayout are independent of each other on the X/Y plane, unlike with LinearLayout
you set the top margin for each child to be how far from the top you want it to appear
and you order them, in terms of when you add them as a child, to determine the Z-axis stacking
Spleak
so I can for example add 1 element and set the margin to like. 50? and then another and set it to 50 also, then they will overlap each other?
Mark M.
yes
Spleak
Ah, fantastic :)
can I rearrange the child-elements however I want?
Mark M.
yes, by adding and removing them
there is no setZAxisOrder() or equivalent method
4:45 PM
Mark M.
if you mean rearrange in terms of the chronology, that's a matter of adjusting the LayoutParams of the widget at runtime
Spleak
ah great, think this is exactly what I'm looking for
the "line with time" element could be a textview with a drawable? (sorry for the newbie questions, still learning android)
Mark M.
conceivably -- haven't tried that for this scenario
if not, a LinearLayout with a TextView and a View as children
(View, given a background color, is good for lines or boxes)
Spleak
there is no equivalent to <hr> in android? :)
Mark M.
yes, a View with a width of match_parent, a height of whatever-you-want, and a background color of whatever-you-want
Spleak
ah nice. then combine that with a textview in a linearlayout?
Mark M.
that would work, yes
4:50 PM
Mark M.
the compound drawable technique with TextView is a tad more efficient, though that probably won't matter here
4:50 PM
Spleak
okay, thanks again =)
if I want the height (for example for the line) to be a little bigger for screens with higher densities, I use "dp" as unit right0
?
Mark M.
right
Spleak
great
Mark M.
1dp = 1px at medium density (~160dpi)
1dp = 2px at xhdpi
and so on
4:55 PM
Spleak
the framelayout should be wrapped in a scrollview right?
Mark M.
yes
5:00 PM
Mark M.
well, that's a wrap for today's chat
the transcript will be posted shortly to http://commonsware.com/office-hours/
next chat is Tuesday at 7:30pm Eastern
have a pleasant day!
Spleak
thanks! you too
Spleak
has left the room
Mark M.
turned off guest access

Yesterday, April 17

 

Office Hours

People in this transcript

  • Mark Murphy
  • Spleak
  • Tamir