Office Hours — Today, February 4

Tuesday, February 2

Feb 4
3:50 PM
Mark M.
has entered the room
Mark M.
turned on guest access
3:55 PM
Jonatan R.
has entered the room
Mark M.
hello, Jonatan!
how can I help you today?
Jonatan R.
hey Mark!
I’m working on app where we have a long list of full screen pictures in a recycler view. I would like to track exactly how long each pictures is visible on screen. If possible to also know how much of each item is visible. Do you have any suggestions how to do this?
Mark M.
for the former, I suppose it depends upon the degree of accuracy you want
a simple approach would be to track when the rows are attached and detached
Jonatan R.
ah
Mark M.
there's a callback for that
onViewAttachedToWindow()
and onViewDetachedFromWindow()
both on RecyclerView.Adapter
Gabriele
has entered the room
Jonatan R.
that's a good start for sure
Mark M.
(BTW, hello, Gabriele -- I will be with you shortly!0
er, shortly!)
Gabriele
hello
Jonatan R.
any idea on how to see how much of a view is visible?
Mark M.
Jonatan: in terms of how much of each item is visible, there's probably something with clipping rectangles that covers this, but that's way outside my area of expertise
Jonatan R.
hm, ok
Mark M.
let me take a question from Gabriele, and I will be back with you shortly
Gabriele: your turn! do you have a question?
Jonatan R.
sure, thanks
4:00 PM
Gabriele
always on the Leak, Mark: http://pastebin.com/Y4drU87v now that inside onDestroyView() I have mLastActivityAdapter = null; it seems it's not happening anymore, but I have no idea of the reason, can you take a look at mLastActivityAdapter, please? Maybe you find it easy
Mark M.
what does getNickActivities() return
?
Gabriele
it's a LinkedList<String>
Mark M.
ok, and android.R.layout.simple_dropdown_item_1line is just a TextView or something, I presume
Gabriele
yes
Mark M.
what does Command.getInstance().getCommandsList() return?
Gabriele
it's a List<String>
... return Collections.unmodifiableList(aCommands); ...
Mark M.
then I have no idea why setting that field to null would have any impact on your AutoCompleteTextView
Gabriele
oh, me neither TT
Mark M.
then again, I haven't used AutoCompleteTextView much, and I have this nagging sense that others have had strange issues with it
Gabriele
so maybe it's due to it
maybe to the fact I'm doing eInput.setAdapter(mLastActivityAdapter);
but I can't see why
Mark M.
I can recommend two courses of action, not mutually exclusive:
1. see if others have had leak issues with AutoCompleteTextView
4:05 PM
Mark M.
2. try to create a small sample project that can reproduce the leak
if you come up with the latter, I'd be interested in taking a look at it
Gabriele
ok, thank you again!
Mark M.
as I foresee AutoCompleteTextViews in my future, so I'd like to know what to avoid :-)
let me take another question from Jonatan, and I will be back with you shortly
Jonatan: your turn! do you have another question?
Gabriele
eheh, sure, I'm ok for today :)
Jonatan R.
Not right now thanks :)
Mark M.
OK, well, if either of you have a question, chime in
Gabriele
sure, thanks Mark
Jonatan R.
View paste
Found this: public void getDrawingRect (Rect outRect)

Added in API level 1
Return the visible drawing bounds of your view. Fills in the output rectangle with the values from getScrollX(), getScrollY(), getWidth(), and getHeight().
Sounds like it could be what I'm looking for
Mark M.
the key is figuring out when to call that
Jonatan R.
right, this is the next problem :)
Mark M.
I haven't looked, but I assume that RecyclerView has some OnScrollListener or the equivalent
if so, you could iterate over the RecyclerView positions at that point to see what is all visible
4:10 PM
Jonatan R.
yes
hmm
how would you track the time spent, check system millies at onAttach and again on onDetach?
Mark M.
probably
though you also have to take into account activity lifecycle stuff with all of this
Gabriele
(infact it's working even if I comment out eInput.setAdapter(mLastActivityAdapter); instead of nulling mLastActivityAdapter so I'll do a small project with it)
Mark M.
if the user switches to another activity, that affects your timing data
Jonatan R.
hmm, yes
cancel timers in onPause perhaps
Mark M.
Gabriele: in terms of leak possibilities, I am less surprised that commenting out setAdapter() clears up a leak than I am that setting that field to null clears up a leak
4:15 PM
Mark M.
Jonatan: right
similarly, if the user rotates the screen, you'll need to re-check your visible rows and stuff
Jonatan R.
yes, thankfully we don't allow rotation
all the images are formatted for portrait mode so it wouldn't make much sense
Mark M.
it would on tablets
it would depend somewhat on your UI, I guess
Jonatan R.
hmm, I guess, to be honest I haven't had the time to even look in to tablet compatibility and product owners don't care at all
Mark M.
about one Android device in six is a tablet
Jonatan R.
that's a lot of tablets
Mark M.
yup
4:20 PM
Mark M.
actually, to be fair, there's somewhat conflicting data on this
sales reports indicate that tablet sales are about 20% the size of phone sales (hence, one in six)
Google's dashboards put -large and -xlarge devices at around 13%
and that'll include some phablets
even with that, though, you're looking at 100+ million tablets, possibly closer to 200 million
and, unless you take some icky steps to avoid it, your app will be shipped to tablets
jamshaid
has entered the room
Jonatan R.
yeah, it's definitely something I will need to look in to more, and let them know
Mark M.
let me take a question from jamshaid, and I'll be back with you shortly
jamshaid: hi! how can I help you today?
Jonatan R.
sure
jamshaid
i used acra . the crashdialogactivity has a cancel button.i wanted to remove it .extending it wont work i guess as acra uses the implementation of its class...i was wondering how can one go about taking a maven project in android studio n changing source code
Mark M.
"the crashdialogactivity has a cancel button.i wanted to remove it" -- I *really* do not recommend that
Gabriele
I've reproduced it on a new project, Mark
Mark M.
your user is already angry with you for crashing
do not make them angrier by trying (and failing) to force them to supply some sort of feedback
jamshaid
but its not a user app so i awnt that this should be not possible to cancel..or better that the report is sent but user is asked to enter input
4:25 PM
Mark M.
whatever
you shouldn't need to change ACRA, though
all of these handlers are pluggable
so, create your own that is implemented how you want
oh, no, wait
never mind
I forgot, that reporting mode is not pluggable
sorry
anyway, it's a Gradle project
just clone the repo
add it as a library module to your project
replace your existing compile statement with a compile project(':acra') (or whatever you call the module)
so you pull in your local copy of ACRA instead of the published artifact
and from there, you have your own independent copy of ACRA, which you can modify as you see fit
(Gabriele: can you upload it somewhere and post a link here, or email the project to me?)
Gabriele
I've used the Android Studio's default project (the one with tabs), changed the TextView with MultiAutoCompleteTextView and added on the Fragment my old code: http://pastebin.com/FxxhwCEP (look for mLastActivityAdapter), I have a new instance of MultiAutoCompleteTextView for every time I press on different tab (about)
jamshaid
when i clone the project do i have to change any files ...normally when i use androd studio n try changes and build again nothing happens.
Gabriele
yes, sure
jamshaid
but i wil try again thanks
Gabriele
but I did only these three steps
Mark M.
jamshaid: that sounds like perhaps your build.gradle file is still using the ACRA artifact, not your local ACRA library module
4:30 PM
Mark M.
jamshaid: double-check your dependencies closure
4:30 PM
jamshaid
i created a new project using import from github for acra.then i tried to change the code in android studio and build but it does not mark even if i do something in correct by deleting some part of the code..so i was wondering if i just do a clone n import directly using github in android studio ...after that before i make changes do i have to change anything in the maven build to build the project again ?
Mark M.
"so i was wondering if i just do a clone n import directly using github in android studio" -- while that will create the library module, it will not attach it to your app
you have to modify your app's build.gradle to pull in your library module, instead of the ACRA artifact
"do i have to change anything in the maven build to build the project again ?" -- I do not know what you mean; ACRA is built by Gradle, not Maven
jamshaid
that i know but when i make changes to the module do i have to change just the source code
Mark M.
yes
jamshaid
thanks i will try again
Mark M.
Jonatan: your turn! do you have another question?
4:35 PM
Jonatan R.
I just started implementing a new signup flow in our app and decided to try a library called Pancake which is basically a simplified viewstack instead of using fragments. Have you used this or some other alternatives to fragments? What’s your preference when designing navigation?
Mark M.
I have not used Pancake
I have considered experimenting with Square's Flow and Mortar, which appear to be the most popular alternative to fragment-based UIs
Gabriele
yes, if I comment textView.setAdapter(mLastActivityAdapter); it's working in this project, too
Mark M.
I haven't had a problem with fragments, but I tend to use them very carefully
Gabriele: "it's working" meaning that you are seeing the leak?
Gabriele
I mean that if I comment it, there is no leak
if I uncomment it, there is the leak
if you have Android Studio you can try yourself, when you have time
I've used the default project so it's fast to deploy
Mark M.
um, well, I've written several book chapters about Android Studio, so... :-)
Jonatan R.
Ok. I considered Mortar and Flow but liked the simplicity of Pancake.
Gabriele
eheh :)
I've always tought Mark programming with some divine instrument
:P
Mark M.
Jonatan: I forget if I have seen Pancake before
I can see what you mean by the simplicity
plus, pancakes are much tastier
4:40 PM
Jonatan R.
haha yes
I never heard of it either, it was mentioned on the Fragmented podcast and I checked it out, seemed stable and well tested so..
we'll see how it goes
Mark M.
Gabriele: if you can get me the project, I would be interested in taking a look at it
BTW, at this point, it's "open season", so if you have a question, just ask
Gabriele
I will upload it on git then
4:50 PM
Gabriele
Mark M.
got it
I probably won't get a chance to look at this until the weekend
Gabriele
to reproduce, when built, I just click on the tabs a lot of time then I check on the Class List View, for the instances
no problem :P
I'm just curios to understand what's going on
Mark M.
I understand
I'm also interested as to why there is a discrepancy between what you were seeing with LeakCanary and what you are getting from the heap dumps
BTW, do you have the link to your Stack Overflow question on this handy?
Gabriele
yes
stackoverflow.com/questions/35153410/cant-find-the-leak-on-my-fragment-android-code
Mark M.
thanks!
Gabriele
to you :)
4:55 PM
Mark M.
Jonatan: if you don't mind my asking, with Pancake, where are you planning on putting your controller logic?
e.g., handling widget events, populating widgets with model data
I get the sense that the Pancake author does not think that such code goes in the ViewFactory
and putting it all in the activity will make for a very fat activity class
that's one of the reasons why I don't mind fragments that much: I like them as a "local controller", with activities mostly handling cross-fragment orchestration
Jonatan R.
I already have a MVP structure in my app so my plan is to have a Presenter for the activity
which connects to different services
Mark M.
but, are you decomposing the presenter into separate ones per ViewFactory?
or is it just one big presenter for everything in the activity?
Jonatan R.
I'm just starting so it's not totally clear yet but I'm thinking of just using one presenter for all the views in the signup flow
Mark M.
ah, OK
Jonatan R.
beause there's not that much going on mostly form fills
Gabriele
is there any different widget with setAdapter I could test it on, Mark? just curios
Jonatan R.
and choosing a picture
Mark M.
Gabriele: well, that adapter will work with ListView
Gabriele
curious*
Mark M.
at least, the adapter from your real app will (haven't looked at the adapter in your standalone sample yet)
Gabriele
yes, it's the same, now it's just empty
Mark M.
I suspect that you will find that there's no leak with ListView
5:00 PM
jamshaid
has left the room
Mark M.
Jonatan: yes, in that case, a single presenter seems reasonable
Jonatan R.
but I will see how it turns out I guess. But it kind of felt nice to just have one presenter for the activity
Mark M.
that depends on how complex the activity is :-)
Jonatan R.
also nice to gather all the views in this way
yes :)
Mark M.
anyway, that's a wrap for today's chat
the transcript will be posted to https://commonsware.com/office-hours/ shortly
Gabriele
thank you :)
Jonatan R.
thanks Mark, be well
Mark M.
the next chat is Saturday at 9am US Eastern
have a pleasant day!
Gabriele
yes
there is no leak
:(
Jonatan R.
has left the room
Gabriele
has left the room
Mark M.
turned off guest access

Tuesday, February 2

 

Office Hours

People in this transcript

  • Gabriele
  • jamshaid
  • Jonatan Ro
  • Mark Murphy