Office Hours — Today, February 21

Tuesday, February 19

Feb 21
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
4:00 PM
Oliver
has entered the room
Mark M.
hello, Oliver!
how can I help you today?
Oliver
Hey Mark, will be just a quick(ish) one today
4:05 PM
Oliver
I have been experimenting with rounded images (ImageViews)...only I have been making them scale perfectly to make things beautiful :)
I was originally going through some horrible logic every time I needed one...which essentially was an async task which set the bitmap
today I have bundled the AsyncTask into a view
so the question is whether this is sound...I can post some code
Mark M.
I am not a big fan of views forking their own threads
IMHO, there's a "separation of concerns" issue
I would lean more towards putting the smarts inside your image cache
Oliver
interesting that you say that....because ImageView can certainly do some scale processing (and I believe some caching)
Mark M.
ImageView doesn't strictly do caching
ImageView does scaling, but not a background thread
where are the original images coming from? resource? network? file?
Oliver
local images
Mark M.
local meaning resource? file?
Oliver
I am actually using the Novoda ImageLoader...with some modifications
file
the thing is...that when other views change...I need to scale the images again
Mark M.
I'd extend their loader to do your long-running work that required the AsyncTask
Oliver
and so I go back to source....and process
4:10 PM
Mark M.
yeah, the Loader API probably isn't ideal in this case
Oliver
View paste (36 more lines)
public class Roundy extends ImageView {

    private static final boolean DEBUG = true;

    // todo: support source from attributes
    File mSource = null;
    File mCache = null;

    public Roundy(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        if (DEBUG) {
...
So I guess I could create a static utility method and pass in the ImageView
Mark M.
File mCache?
if you have to keep resizing the images, why are you persisting the resized editions?
Oliver
mCache isn't important - I have been processing and storing back to disk...but the performance is actually v.good on Nexus devices
Mark M.
OK
I'd still put the "Roundy" smarts inside ImageLoader or some other image cache
Oliver
the source images are actually ~3MiB
Mark M.
roundification is an attribute of getting you an image to work with, not an attribute of rendering the image, IMHO
but, that's just me
Oliver
:)....I was thinking that 'onLayoutChange' could trigger such funky behaviour
which I am actually doing for other use cases....
4:15 PM
Oliver
cool.....I think that Qs done...cheers.
Mark M.
ok
if you have another question, go ahead -- quiet chat today
Oliver
just a general comment on this.....with view pager....I have quite a few views. Not insane amounts....but say on one page....maybe 25 items (linear list). Things can get a little janky....any thoughts on improving that?
Mark M.
I'd run your app through Traceview and see what it comes up with
I added a chapter on detecting and removing jank in the new Version 4.6 that was released on Tuesday
Oliver
awesome...I haven't downloaded that....so will do
Mark M.
I basically walk through ThreePaneDemoBC, one of my implementations of the Gmail three-fragment problem
I had reports of jank
so I used gfxinfo and systrace to confirm the jank, following Romain Guy's recipe
4:20 PM
Mark M.
then, I used Traceview to try to figure out where the problem was
and then Chet Haase happened to chime in with the problem (trying to animate layout changes)
which confirmed what Traceview was reporting
Oliver
excellent. Sounds like it will be v.useful. I know the views that are of concern....I was thinking that maybe hiding them before loading the data might ease things when initially switching pages.
Mark M.
Traceview will help you ID logic that is on the main application thread that perhaps shouldn't be, either because it belongs on a background thread or just should not be done (e.g., animating the resize of a layout)
Oliver
ok...so your example of animating the resize of a layout should not be done?
Mark M.
yes
I was using an ObjectAnimator to change the width
Oliver
I actually have an 'expansion' button which, you guess it, shows many more views. It does get sluggish
Mark M.
thinking that this was how Gmail transitioned the wider right-hand fragment to the narrower size on the left
apparently, that's not what Gmail does
and trying to resize/re-layout the contents (a ListView) was exceeding my available time before dropping frames
hence, the jank
4:25 PM
Oliver
I see....I certainly need to check out your update then....
I haven't got any further immediate Qs - hopefully I will have most of this sorted by next time that we speak...'now with less jank' ;)
Mark M.
OK
Oliver
I am slightly surprised that there aren't lots of other folks here! I has been kinda a one on one recently...at this rate I'll be sending code for you to proof read ;)
Mark M.
it comes and goes
sometimes I have a half a dozen people here
sometimes there's nobody
Oliver
super....I'll leave it there....if you are sticking around for the whole hour then I'll stay just in case something else comes up. Else feel free to kick me :D
4:30 PM
Mark M.
oh, you are welcome to stay
if another question comes to mind, chime in
Oliver
super...thanks
4:35 PM
David
has entered the room
David
hello
Mark M.
howdy, David!
David
how are you?
Mark M.
David: do you have a question?
(besides "how are you?", that is... :-)
David
yes i have a few
thanks
Mark M.
go right ahead
(Oliver: if another question comes to mind, chime in)
David
i'm building custom views with resources, and I have a few quesitons about when I can get heights, widths, etc
Mark M.
that's not my strong suit, by any stretch of the imagination
Oliver
(Mark: thanks)
David
if the dimensions of your view do not depend on the parent, can you call measure before laying it out
Mark M.
yeah, beats me
I can do composite widgets (e.g., ColorMixer from the book)
David
ah okay
Mark M.
but you start getting into layout/measure stuff, and I'm all thumbs
David
i think I'm going to spend some time expirementing
maybe I'll let you know
Oliver
David: have you seen Romain's talk with FlowLayout as an example?
David
no
Mark M.
yes, that presentation should be a good one, though I haven't had a chance to watch it yet
Oliver
one
sec
David
i'd like to
Mark M.
I think that was a Parleys.com one, IIRC
David
i'll check them out
4:40 PM
Oliver
I have remembered a fair amount...you must call measure() on all your children 'cos it is in the contract ;)
David
can i have another question?
Mark M.
David
hmm...
Mark M.
that link in turn contains a link to the presentation, FlowLayout implementation, etc.
David
I'll read through it
Mark M.
anyway
Oliver
Mark M.
yes, you're welcome to ask more questions
David
thanks
i had a project where I was using actionbar sherlock, and the version 11 of the v4 support library
i had a lot of problems with the childFragmentManager
I finally got it working, it seems that you can't retain an instance of the fragment that it is in
Mark M.
yeah, that's not shocking
David
because its 'stuck' with the old activity
Mark M.
that's a bit surprising -- I haven't tried that scenario
David
i was using it with a viewpager
i got a whole multitide of different errors, from a 'No Activity" error
to an illegalstateException error that I had to remove a childs view from a parent
Mark M.
I get the impression that the child FragmentManager stuff is designed to work in narrow cases but isn't necessarily as general-purpose as the regular FragmentManager
that's based on other questions/issues I've seen floating around with it
4:45 PM
David
after about a day of expirementing I found that I had to destroy activity in configuration changes, and save the fragment in all other cases for it to work
i wanted to ask if you knew how it worked
Mark M.
what is "it"?
David
the fragment the viewpager was in
Mark M.
I have only used a child FragmentManager once, for the book sample of putting fragments in a ViewPager
which was a fairly basic sample
personally, I am still trying to avoid the child FragmentManager in general, as I am unconvinced that it is "fully baked", as it were
David
i didn't know it was in the latest book...
Mark M.
actually, that popped into 4.5, and the current is 4.6
David
i have to for this project, or else create an activity for one screen
which would break the architecture completely
Mark M.
you can use a custom view (composite-style) for the pages in the ViewPager, instead of fragments, in many cases
David
really?
Mark M.
sure
David
that would work very well in my case
Mark M.
in many ways, that's all a fragment is
David
what kind of adapter do you use?
Mark M.
custom implementation of PagerAdapter
I show one in my ViewPager coverage of showing multiple pages at a time, in the Large Screen chapter
David
great!
i will go with that
...even though I got the stupid thing working...after lots of pain :)
that answers my question
4:50 PM
Oliver
David, you are welcome to take my notes regarding Romain's talk https://docs.google.com/presentation/d/1uMM_wfC...
David
thank you
Oliver
(probably not a huge amount)
I would guess that you need to get the sizes on the layout pass
or after
David
i would want to get the sizes on the layout pass, and then call setMeasuredDimension again on the container
the container has to grow by a factor of one of the child views
Mark M.
that could get messy
David
and then set the dimensions of that new part in onSizeChanged
Oliver
I think setMeasuredDimension has to occur at the end of onMeasure
Mark M.
the general Android model is that the container dictates the size of the children, not the other way around
David
yeah....
Mark M.
are you sure that the container that depends on the child size *has* to contain that child? or could they be peers?
David
they could be peers
Mark M.
off the cuff, that might be more reliable
David
the container could sit ontop of the child
hmm...
so I could layout the component first, then figure out how large the container would have to be, and the rest to container afterwards
Mark M.
right
David
ok cool
Oliver
I think the presentation will explain a lot
4:55 PM
Oliver
if you press S I have typed some notes
David
i'll go over it
Oliver
sure
David
thanks
if I have some spare time I'll try out the first implementation as well
if it works it has some useful purposes
i find whenever I make custom views, i have to hard code a dimension or get it from somewhere, and it never ends up looking good on all form factors
Mark M.
dimension resources provide some flexibility, but they are not a universal solution either
David
i have thought of building something to get pixels from a percentage or scale
using the DisplayManager
but it ends up adding a lot of extra work
trying to find out how much space the components occupy
Mark M.
you are probably better off calculating from the size of the parent container, not the size of the screen
see LinearLayout and layout_weight, for example
David
you can get that from onLayout
i have an image of a 'card'
with a logo on it
5:00 PM
David
and on small devices it looks terrible beacause it takes up half the screen
even when you adjust for density
Mark M.
well, that's a wrap for today's chat
David
outside of getting multiple resources for this image, that is really a background image, I'm not sure how to get it looking good on smaller phones
thank you Mark & Oliver
...sorry if i monopolized the chat
Mark M.
the transcript will be posted shortly at http://commonsware.com/office-hours/ and the next chat is Wednesday at 10am
not a problem -- Oliver had questions before you arrived
have a pleasant day, all!
Oliver
super...thanks for today Mark
bye
David
:)
Oliver
has left the room
David
has left the room
Mark M.
turned off guest access

Tuesday, February 19

 

Office Hours

People in this transcript

  • David
  • Mark Murphy
  • Oliver