Oct 10 | 9:50 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Oct 10 | 10:00 AM |
Zaur A. | has entered the room |
Zaur A. |
Hello, Mark!
|
Mark M. |
hello, Zaur!
|
Mark M. |
how can I help you today?
|
Zaur A. |
oh, I have tons of questions :)
|
Zaur A. |
just a min
|
Oct 10 | 10:05 AM |
Zaur A. |
first question is about sliding menu and activities
|
Zaur A. |
I am using SlidingMenu library by Jeremy Feinstein
|
Zaur A. |
and this library assumes that you have one main activity
|
Zaur A. |
and sliding menu just switches fragments
|
Zaur A. |
is this a right approach of using fragments?
|
Mark M. |
there's nothing wrong with it
|
Mark M. |
DrawerLayout also works best when a navigation drawer entry does not switch to another activity
|
Mark M. |
you *can* switch to another activity, but the effect will be a bit more jarring
|
Zaur A. |
I already asked a question on SO about using fragments, can you please check it out: http://stackoverflow.com/questions/15611886/am-...
|
Oct 10 | 10:10 AM |
Mark M. |
again, there is nothing intrinsically wrong with what you are doing
|
Mark M. |
it will make configuration changes perhaps a bit more interesting, to ensure that when the user rotates the screen, they wind up with the right fragment showing
|
Mark M. |
it may also make the BACK button a bit more challenging, to determine what is the right thing to do there
|
Zaur A. |
yes, the second question is about config changes...
|
Zaur A. |
what I've done before - I used this bad trick with android:configChanges
|
Zaur A. |
now I want to do everything right
|
Zaur A. |
for example,
|
Zaur A. |
I have feeds fragment
|
Zaur A. |
with endless adapter
|
Zaur A. |
when I rotate the device, I want to preserve scroll state and all the data in adapter
|
Zaur A. |
and if there is networking in progress, I don't want it to reset
|
Zaur A. |
I understand how to save simple data in Bundles
|
Zaur A. |
example: I have an Activity with FeedFragment
|
Oct 10 | 10:15 AM |
Zaur A. |
FeedFragment is a ListFragment, with EndlessAdapter of objects that implement Parcelable interface
|
Zaur A. |
fragment is saved into backstack, so you can't use setRetainInstance(true)
|
Zaur A. |
how can I save listview scroll position and all data in adapter?
|
Zaur A. |
so I can restore it after screen rotation or other config change
|
Mark M. |
I am not aware of a limitation on setRetainInstance(true) regarding the back stack
|
Mark M. |
your data presumably should be somewhere outside the activity entirely (e.g., singleton cache of persistent data store)
|
Mark M. |
your scroll position can be saved via onSaveInstanceState()
|
Zaur A. |
Android documentation says so: "Control whether a fragment instance is retained across Activity re-creation (such as from a configuration change). This can only be used with fragments not in the back stack."
|
Mark M. |
OK
|
Mark M. |
it does not much matter
|
Mark M. |
again, your data presumably should not be owned by your activity, and a scroll position is a simple int, which works well with onSaveInstanceState(0
|
Mark M. |
er, onSaveInstanceState()
|
Zaur A. |
data is owned by fragment
|
Oct 10 | 10:20 AM |
Mark M. |
hopefully not
|
Zaur A. | |
Mark M. |
I would really hope that an app that shows "feeds" persists its data
|
Mark M. |
now, if you want a fragment to be a local in-memory cache of that data, that's fine
|
Mark M. |
you can always go with the model fragment pattern
|
Mark M. |
as I did in the tutorials in the book
|
Mark M. |
a model fragment is a fragment with no UI, just there as a data maintainer across configuration changes
|
Mark M. |
it also would manage any tactical background operations for loading that data (e.g., file or database I/O)
|
Mark M. |
since it has no UI, it would not be on your back stack, and therefore can be retained
|
Zaur A. |
so I can change adapter data to this fragment, and the restore after FeedFragment recreation, right?
|
Zaur A. |
change == save
|
Zaur A. |
sorry)
|
Mark M. |
the data that your adapter adapts would be managed by the model fragment
|
Mark M. |
your ListFragment(?) that has the ListAdapter would retrieve its data model from the fragment, either directly or by way of the hosting activity
|
Zaur A. |
ah, now I got it.
|
Oct 10 | 10:25 AM |
Zaur A. |
and how the architecture will look like if I want to persist feeds data?
|
Mark M. |
I have no good way to answer that completely, in the abstract
|
Mark M. |
your in-memory data cache should be scoped to who all needs the data
|
Mark M. |
a model fragment is fine when a single activity needs the data
|
Mark M. |
if multiple activities need the data, you probably will want some sort of singleton cache, reachable from those activities
|
Oct 10 | 10:30 AM |
Zaur A. |
ok. I need to read that in your book.
|
Zaur A. |
one more question:
|
Zaur A. |
regarding scrollbars in ListView
|
Zaur A. |
if you have items with different height, scrollbar's size is jumping up and down
|
Zaur A. |
is there a way to avoid this?
|
Mark M. |
not really
|
Mark M. |
the scrollbar height is an estimate
|
Mark M. |
your results may not match the estimate
|
Zaur A. |
because I have seen some apps, that don't have this annoying feature...
|
Mark M. |
I know of no way to affect the scrollbar height calculations
|
Mark M. |
that does not mean that there is no means to do it, just that I cannot think of one
|
Zaur A. |
maybe there is another custom AdapterView
|
Zaur A. |
that can estimate the height more accurately? :)
|
Zaur A. |
as I have seen, Facebook app doesn't have scrollbars at all
|
Zaur A. |
when watching my newsfeed
|
Mark M. |
neither do you
|
Mark M. |
scrollbars, by default, only appear while scrolling
|
Mark M. |
unless you specifically arrange for them to show up persistently
|
Oct 10 | 10:35 AM |
Zaur A. |
even if I scroll, facebook is hiding scrollbars
|
Mark M. |
then they disabled them, perhaps using android:scrollbars
|
Zaur A. |
ok, next question is about Horizontal AdapterView
|
Zaur A. |
as far as I know, HorizontalScrollView does not recycle views
|
Zaur A. |
so app may fail with OutOfMemory error
|
Mark M. |
correct, as it is not an AdapterView
|
Zaur A. |
is there any good AdapterView with horizontal scrolling?
|
Zaur A. |
I want to create scrolling photo-feed
|
Mark M. |
the only currently-maintained one from Google is ViewPager (which, while not an AdapterView, allows you to do more memory management)
|
Mark M. |
there's a third-party horizontal ListView floating around somewhere
|
Zaur A. |
but you can't use ViewPager inside ListView
|
Zaur A. |
and I need to do that)
|
Zaur A. | |
Zaur A. |
I need photos to be scrolled horizontally
|
Zaur A. |
inside ListView
|
Mark M. |
to be honest, I detest that UI structure, and so I have done zero research as to how Pulse, etc. pull it off
|
Oct 10 | 10:40 AM |
Mark M. |
if you find apps that have it, use uiautomatorviewer to see what widgets they are using
|
Andrea | has entered the room |
Mark M. |
hello, Andrea!
|
Zaur A. |
ok, got it.
|
Andrea |
hello
|
Mark M. |
Zaur: let me take a question from Andrea, and I will be back with you shortly
|
Mark M. |
Andrea: do you have a question?
|
Andrea |
yes
|
Andrea |
I have a problem with content providers
|
Mark M. |
um, could you be more specific? :-)
|
Andrea |
I have two tables (one for the subject and one for the notes). I am loading the subject list through a content provider. Then I would like that when the user clicks on a subject it displays just the notes of that specific subject. That means I need to join the two tables right? When should I join them?
|
Mark M. |
"That means I need to join the two tables right?" -- not necessarily
|
Mark M. |
ignoring the provider for the moment, in plain SQL you would be doing something like SELECT note,related,columns FROM notes WHERE subject_id=?
|
Andrea |
yes
|
Oct 10 | 10:45 AM |
Andrea |
View paste
|
Mark M. |
there does not necessarily have to be a JOIN there, unless you specifically want to return some columns from the subject table
|
Mark M. |
since you already have moduleName and moduleNumber, you need noteTitle
|
Mark M. |
so the SQL is SELECT noteTitle FROM notes WHERE moduleNumber=?
|
Mark M. |
with no JOIN
|
Andrea |
at the moment I was keeping the moduleNumber (in the note table) as a foreign key, is that they right way?
|
Andrea |
ohh right
|
Mark M. |
if I understand your schema correctly, that seems correct
|
Andrea |
I already got the moduleNumber when a user clicks on the subject
|
Andrea |
and using a content provider can I do a raw sql?
|
Mark M. |
the provider can; the client cannot
|
Andrea |
mm
|
Mark M. |
in this case, the client could be providing the moduleNumber=? bit
|
Andrea |
I don't really get it
|
Mark M. |
query(CONTENT_URI, PROJECTION, "moduleNumber=?", args)
|
Andrea |
could I obtain it using a cursor loader?
|
Oct 10 | 10:50 AM |
Mark M. |
sure
|
Mark M. |
set up the CursorLoader with "moduleNumber=?"
|
Andrea |
amazing
|
Andrea |
thanks so much
|
Andrea |
I need to go, but once again you solved it
|
Mark M. |
happy to be useful
|
Andrea |
I'll more at the documentaion
|
Andrea |
:)
|
Andrea |
Have a nice day
|
Mark M. |
you too!
|
Mark M. |
Zaur: do you have another question?
|
Zaur A. |
yes
|
Zaur A. |
I wanted to ask about mockups resolutions
|
Zaur A. |
what resolutions should a designer use?
|
Zaur A. |
to draw a design for handsets
|
Mark M. |
I would argue that the answer is "none" or "it does not matter"
|
Zaur A. |
ooh, not again :)
|
Mark M. |
designs need to be fluid, to handle modest changes in screen physical size and density
|
Zaur A. |
I haven't seen a plain answer to this question
|
Mark M. |
well, it's akin to asking "what browser resolution should a Web designer use?"
|
Mark M. |
a Web designer needs to ensure that the design works across a range of reasonable sizes
|
Zaur A. |
for iOS it is much simpler :)
|
Oct 10 | 10:55 AM |
Mark M. |
saying that the browser must be exactly 1024x768, and the design fails for 1023x769, is a #fail
|
Mark M. |
you design for Android much like you design for the Web
|
Zaur A. |
ok, I got the idea. but when I design for web, I can think like this:
|
Mark M. |
now, for the purposes of pure mockups, I'd aim at common resolutions, like WVGA800, WXGA800, 720p, 1080p, etc.
|
Zaur A. |
most displays have resolution at least 1024 pixels wide
|
Mark M. |
however, the *design* should not be thinking in those terms
|
Zaur A. |
so let's make it 1000 pixels wide
|
Zaur A. |
yes, that's what I want to hear
|
Zaur A. |
what are the most common and popular resolutions
|
Mark M. |
off the cuff, I'd say the ones that I listed
|
Zaur A. |
ok, I got it
|
Zaur A. |
thank you, Mark
|
Mark M. |
you are very welcome
|
Mark M. |
that wraps up today's chat
|
Mark M. |
the transcript will be posted at http://commonsware.com/office-hours/ shortly
|
Mark M. |
the next chat is tomorrow, 7:30pm Eastern
|
Mark M. |
have a pleasant day!
|
Oct 10 | 11:00 AM |
Zaur A. | has left the room |
Andrea | has left the room |
Mark M. | turned off guest access |