Office Hours — Today, April 4

Tuesday, April 2

Apr 4
9:50 AM
Mark M.
has entered the room
9:55 AM
Mark M.
turned on guest access
10:00 AM
Sebastiano P.
has entered the room
Mark M.
hello, Sebastiano!
Sebastiano P.
Hello Mark
Mark M.
how can I help you today?
Sebastiano P.
I'm having a couple of issues, quite different from each other, to be honest
Mark M.
go ahead with your first one
Sebastiano P.
the first one is related to an app i'm developing for a custom ROM for a product i'm working on
the idea is having some sort of pre-configuration being restored on the device at each boot
because the device is going to run on public displays for people to try it
and it's going to be an unattended station
so I had the idea of getting one device configured the way we want them to be, kind of preparing a "pre-baked image"
i then got a tarball of the /data partition of the device
what i need now to do is have an app with a BOOT_COMPLETED receiver, that extracts that tarball back to /data, overwriting any other existing data
10:05 AM
Sebastiano P.
it's mostly done, but as you can imagine, the main issue here is represented by the fact that one needs root access to write on /data
Mark M.
hence, this should not be an Android SDK app function
this should be something you do in an init script or something
that runs as part of your custom ROM during the boot cycle
Sebastiano P.
being in complete control of the device (my company manifactures it) i have no problem signing the app with the platform key
that's true
i guess that's what i will have to do then... guess i was too focused on getting this to work to look at the bigger picture
anyhow, i'm left with this curiosity to satisfy
shouldn't apps that are signed with the platform key be able to perform actions as root?
Mark M.
no
signatures have nothing to do with superuser privileges
Sebastiano P.
i have a device with its su binary in place (the standard AOSP one)
no i mean i know signing does not provide su privileges per se
Mark M.
I am not aware that being signed with the firmware signing key somehow enables you to run su
then again, I have zero experience with running Android apps as rot
er, root
Sebastiano P.
i understand
yeah, got that :)
10:10 AM
Sebastiano P.
i guess i will have to ask some root guru such as chainsdd or koush about that, hoping they take the time to reply
Mark M.
XDA's forums would seem to be a likely spot to ask
Sebastiano P.
thanks for the scripting suggestion -- in fact it should be just as easy as invoking tar itself
yeah
Mark M.
make sure you do so before any processes start using files on /data
Sebastiano P.
so I can now move on to my second issue here
yes, i'm going to add it to the init script
as i was saying, i'm going to move to my second issue, which is completely unrelated to the first one
Mark M.
go right ahead -- nobody else is here :-)
Sebastiano P.
i'm developing an app (which is going to be open sourced as soon as it's beta-quality) and i'm using my own extended ImageView
to be precise, i'm using ImageViewNext, which is open-sourced as well
because it provides two key factors i need in this case
which are automatic caching of the images in byte[] form
10:15 AM
Sebastiano P.
and showing animated gifs (thus the byte[] caching: the underlying Movie object needs the byte array, not a Drawable)
so, long story short, i had some issues because i was missing some code to implement the adjustViewBounds behaviour
i have overridden the onMeasure method to take into account the gif size when relying on the Movie
luckily, i haven't changed anything of how the underlying ImageView works when using Drawables
so just copy-pasting the onMeasure method and adding a branch to an "if" for handling the Movie did work, with very few adjustments to cope with some data being private to ImageView
now i have this issue
when previewing the layout in my IDE, everything works just fine
when running on a device, i get the same behaviour i would get if adjustViewBounds was set to false
i had a debug session to determine if it was my code having bugs (unlikely, since it's basically the ImageView's own)
and i saw that it's working perfectly
10:20 AM
Sebastiano P.
it's just being called a few times, alternatively with good and bad measureSpecs
meaning, i have an image that is wide and short
it's wider than my screen is, at least in portrait
so i use the fitCenter scaling mode
this gets the image itself to the right size
so I expect to have an MEASURESPEC_EXACTLY for the width dimension, and an AT_MOST or UNSPECIFIED measure spec for the height
which i in fact get for odd layout passes
but then i get an EXACTLY measure spec on even passes, i don't know why
Mark M.
is there anything interesting in the call stacks, such as even passes being triggered by something different than the odd passes?
Sebastiano P.
with the height size set to the full image height (280 px instead of the expected 125 or so that i determine when measuring)
not that I can see
if you want I can reproduce it and copy-paste them here
Mark M.
that's worth a shot
Sebastiano P.
ok
Mark M.
I am *far* from expert on custom Views like this
you have done more work in this area than I have
Sebastiano P.
i'm launching the debugger right now
Mark M.
but, maybe I'll get lucky and see something :)
10:25 AM
Sebastiano P.
yeah but you know maybe a fresh pair of eyes can see what i can't
i've been cracking my head on this for a couple of days now, so i might be a bit biased regarding what to look at :D
ok
first calling
View paste (31 more lines)
main@830015535520, prio=5, in group 'main', status: 'RUNNING'
	  at net.frakbot.imageviewex.ImageViewEx.onMeasure(ImageViewEx.java:985)
	  at android.view.View.measure(View.java:15518)
	  at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
	  at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
	  at android.view.View.measure(View.java:15518)
	  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
	  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
	  at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
	  at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
	  at android.view.View.measure(View.java:15518)
	  at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1217)
	  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
	  at android.widget.ScrollView.onMeasure(ScrollView.java:321)
	  at android.view.View.measure(View.java:15518)
...
oh one sec
this might be the wrong imageview
i'm getting EXACTLY on both dimensions on the first pass
Carlos
has entered the room
Mark M.
hello, Carlos!
Carlos
Hi Mark
Sebastiano P.
Hi
ok this is the correct first pass
View paste (31 more lines)
main@830015535520, prio=5, in group 'main', status: 'RUNNING'
	  at net.frakbot.imageviewex.ImageViewEx.onMeasure(ImageViewEx.java:985)
	  at android.view.View.measure(View.java:15518)
	  at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
	  at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
	  at android.view.View.measure(View.java:15518)
	  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
	  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
	  at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
	  at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
	  at android.view.View.measure(View.java:15518)
	  at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1217)
	  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
	  at android.widget.ScrollView.onMeasure(ScrollView.java:321)
	  at android.view.View.measure(View.java:15518)
...
seems pretty much the same thou
View paste
widthSpecMode = 1073741824
heightSpecMode = 0
next on, second pass
here i have widthSpecMode = 1073741824 and heightSpecMode = 1073741824 (which is EXACTLY)
10:30 AM
Sebastiano P.
View paste (31 more lines)
main@830015535520, prio=5, in group 'main', status: 'RUNNING'
	  at net.frakbot.imageviewex.ImageViewEx.onMeasure(ImageViewEx.java:985)
	  at android.view.View.measure(View.java:15518)
	  at android.widget.RelativeLayout.measureChild(RelativeLayout.java:666)
	  at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:477)
	  at android.view.View.measure(View.java:15518)
	  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
	  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
	  at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
	  at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
	  at android.view.View.measure(View.java:15518)
	  at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1217)
	  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
	  at android.widget.ScrollView.onMeasure(ScrollView.java:321)
	  at android.view.View.measure(View.java:15518)
...
Mark M.
(Carlos: I will be with you shortly, once I get through this question from Sebastiano)
your second trace is slightly different
onMeasure() stems from measureChild() on RelativeLayout, versus measureChildHorizontal() on RelativeLayout in your first call stack
Sebastiano P.
third pass: widthSpecMode = 1073741824 and heightSpecMode = 0 (which is UNSPECIFIED)
that's true
on the third pass i get the same stack trace as in the first one
View paste (13 more lines)
at net.frakbot.imageviewex.ImageViewEx.onMeasure(ImageViewEx.java:985)
	  at android.view.View.measure(View.java:15518)
	  at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
	  at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
	  at android.view.View.measure(View.java:15518)
	  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
	  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
	  at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
	  at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
	  at android.view.View.measure(View.java:15518)
	  at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1217)
	  at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
	  at android.widget.ScrollView.onMeasure(ScrollView.java:321)
	  at android.view.View.measure(View.java:15518)
	  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
...
Mark M.
so, I'd look at the source for RelativeLayout and determine under what conditions it calls measureChild() instead of measureChildHorizontal()
and see what that tells you
let me take a question from Carlos, and I will be back with you shortly
Sebastiano P.
yes
Mark M.
Carlos: do you have a question?
Carlos
yes
View paste
My question is a continuation regarding pendingIntents within notifications. During normal app operation I have the following conditions:

1) In a phone, the Detail Activity/Fragment was called using a startActivityForResult from the MainActivity and once the user is done editing the data in the Detail Activity I setup the intent extras and call finish().

2) In a tablet, I remove the fragment from the back stack once the user is done with the Detail Fragment.
Sebastiano P.
i'm looking at relativelayout in the meantime
Carlos
Regarding notifications...
When the AlarmManager kicks in, I sent a notification and create a pendingIntent that will start the DetailsActivity
10:35 AM
Carlos
The problem I'm seeing is that once the user presses done in the action bar, the Detail Activity calls finish (like in normal operation), but the intent results from it are not handled by the MainActivity
Mark M.
MainActivity did not call startActivityForResult() in this code path, from what you have described -- DetailsActivity was started directly from the PendingIntent
Carlos
Yes, that's correct
how I achieve the "regular app operation" within the context of clicking on a notification
Mark M.
given your current reliance on startActivityForResult(), I do not know if that is possible
Carlos
MainActivity is the one that updates the ListFragment so I'm not getting my updated data saved to my database or the Adapter updated.
Mark M.
certainly, I have no idea how I would accomplish it
while continuing to use startActivityForResult()
however, if you switch to some other communications mechanism between the activities, you might get it to work
for example, you might try using a PendingIntent that is created by TaskStackBuilder
so that exiting the DetailsActivity will return to the MainActivity
Carlos
Any suggestions on what to use instead of Intents? I thought that was the recommended way, so I was surprised to find this bug just for pending intent
Mark M.
you will also need to figure out some other way for MainActivity to find out about the updated data
Carlos
Just to clarify, when the action bar button is press in the detail activity the app returns to the main activity, is just that main activity is started without receiving the intent data from Details Activity. Is as if the MainActivity was started from the Launcher as is just waiting for user input.
10:40 AM
Mark M.
again, that is because MainActivity did not call startActivityForResult() on DetailsActivity
startActivityForResult() is a very fragile mechanism
Carlos
So your suggestion is to use TaskStackBuilder for both regular app navigation as well as for my notification purpose. correct?
Mark M.
not necessarily -- I do not know enough about your app for that
Jose L.
has entered the room
Mark M.
however, if you are expecting BACK from DetailsActivity to return you to MainActivity, from a PendingIntent, TaskStackBuilder is probably your best option
Carlos
Hmmm. I'm just wondering how this has been done before fragments was available since TaskStackBuilder compatibility library was not available in the pre-fragment era.
Mark M.
BACK would simply return you to wherever you were before the notification was clicked
which, IMHO, is what it should be doing even today, but Google thinks otherwise
Carlos
Yeah, right now I'm not concern about the back button. Is mostly about making sure than when the user presses the notification and does edits in the detail framgment that those edits get properly reflected in the MainActivity.
Sebastiano P.
(i'm back)
Mark M.
all I can suggest is that you find some solution other than startActivityForResult(), which is really designed mostly for simple scenarios like ACTION_PICK Intents
Jose L.
Hi there guys
Mark M.
for example, you might consider using Otto's event bus, particularly with @Producer
Carlos
ok Mark. Thanks for your feedback. I'll work on this some more and file a SO question if I'm still stuck. Thanks!
Sebastiano P.
hi Jose
Mark M.
OK
10:45 AM
Mark M.
Jose: since the others have had a chance to ask a question already -- do you have a question?
Jose L.
not really, just wanted to see if I could learn something
Mark M.
OK
Sebastiano: back to you -- find anything interesting?
OK, if anyone has a question, feel free to chime in
Sebastiano P.
i found that RelativeLayout calls measureChildHorizontal from its onMeasure() to measure all children orizontally in a for cycle, and then calls measureChild() in another for cycle to measure them vertically
Mark M.
that's interesting
any idea why it is passing along different specs?
Sebastiano P.
sorry i'm a bit slow but i've got a phone call going on as well :D
Mark M.
ah, no worries
just get rid of RelativeLayout from your sample, then :-)
Sebastiano P.
it's absurd, because the RelativeLayout gets the params before calling each measureChild*(), directly from the child: LayoutParams params = (LayoutParams) child.getLayoutParams();
10:50 AM
Carlos
has left the room
Sebastiano P.
View paste
also, on top of the onMeasure method, someone has left this:
// TODO: we need to find another way to implement RelativeLayout
// This implementation cannot handle every case
:D
in the RelativeLayout code
Mark M.
yeah, there a quite a few comments like that floating around the AOSP code
Sebastiano P.
that's not really reassuring thou :)
i'm not sure i can get rid of the RelativeLayout thou
Mark M.
that was just a joke
Sebastiano P.
without having to use an awful lot of layouts :D
i'm copy-pasting my layout here
View paste (95 more lines)
<?xml version="1.0" encoding="utf-8"?>

<!--
  ~ Copyright 2013 Sebastiano Poggi and Francesco Pontillo
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
...
please consider it's still a WIP
but as you can see there's no way I can get rid of that RelativeLayout
(I'm implementing sort of a Cards UI, even if I designed way before Google launched Now)
10:55 AM
Mark M.
well, trying to make sense of the RelativeLayout two-pass measure process is about as far as I am going to be able to narrow it down for you
Sebastiano P.
this is a mockup of what i'm trying to achieve here: https://www.dropbox.com/s/b0u21rord37qz0d/05a-n...
Mark M.
with luck, that will at least help accelerate your finding a solution
Sebastiano P.
I guess I could try and ask someone in the Android team, keeping my fingers crossed for an answer
Mark M.
nice UI, though you might consider adding a profanity filter on your mockups :-)
Sebastiano P.
OR, try to implement that with some other layout, maybe a TableLayout
Jose L.
I'm sorry I got here too late but I don't know what's the problem, can you sumarize it real quick for me?
Sebastiano P.
Mark Murphy, that's the actual episode title I'm afraid :D
Mark M.
Jose: it is probably a bit difficult to summarize easily, but you will be able to read the whole chat transcript once the chat is over
Sebastiano P.
(great show, by the way)
Mark M.
Jose: all the chat transcripts are published on http://commonsware.com/office-hours/ shortly after the chat ends
Sebastiano P.
Jose, I'm having an issue with the RelativeLayout
it's doing its job of laying out the children in multiple passes
one horizontal and one vertical
for each child
the issue is that in the vertical pass it's giving me the wrong LayoutParameters
because i'd expect, given how the layout is laid out, to have the freedom to resize my extended ImageView instance for the banner as much as I want on the vertical axis
11:00 AM
Mark M.
that's a wrap for today's chat
the transcript will be posted to http://commonsware.com/office-hours/ shortly
Sebastiano P.
but when measuring the vertical size of the child, the RelativeLayout calls my ImageViewNext (http://github.com/frapontillo/imageviewex) saying it to be precisely X pixels
ok
thanks mark
Mark M.
the next chat is Tuesday at 4pm Eastern
have a pleasant day!
Jose L.
thanks!
you to
too
Sebastiano P.
especially for the first solution
bye
Sebastiano P.
has left the room
Jose L.
has left the room
Mark M.
turned off guest access

Tuesday, April 2

 

Office Hours

People in this transcript

  • Carlos
  • Jose Luis Montes
  • Mark Murphy
  • Sebastiano Poggi