Office Hours — Today, October 17

Tuesday, October 15

Oct 17
9:50 AM
Mark M.
has entered the room
9:55 AM
Mark M.
turned on guest access
EGHDK
has entered the room
Mark M.
hello, EGHDK
how can I help you today?
10:00 AM
EGHDK
View paste
Hey Mark, so I was still working on my chat bubble, trying to do it in a LayerDrawable. I haven't been able to get it to work quite right, but I found a question on SO posted yesterday that is my problem EXACTLY. I'm even coding it the same. Can you take a look?
http://stackoverflow.com/questions/19410967/filling-a-draw9patch-image-with-a-solid-color?noredirect=1#comment28776866_19410967
Mark M.
hmmmm...
that's disappointing
EGHDK
So am I stuck creating a custom view?
Mark M.
how many colors can the user choose from?
EGHDK
Ideally... all of the colors of the rainbow.
(And every color in between).
Mark M.
then a custom view will probably be the answer
you could look at the other similar bubble implementations, like the one I pointed you to last time, and see how they approached it
EGHDK
If you take another look at this link I sent you:
10:05 AM
Mark M.
they may not have the color concept, but they may spark ideas
EGHDK
They have to be doing that "cookie cutter" effect on that picture somehow...
Custom view is your best guess though?
Mark M.
use uiautomatorviewer to see what they're doing
EGHDK
?
Mark M.
uiautomatorviewer is reminiscent of Hierarchy View, but it works on production devices
it does not give all the information that Hierarchy View does, but it comes fairly close
since it can be applied to production apps running on production devices, you can use it to inspect the UI of some production app, like whatever it was that resulted in the screenshot you linked to, to see what they do
EGHDK
Gotcha. I've user Hierarchy viewer before.
Before I go into that though. You opinion (as of right now) is to build a custom view?
Mark M.
my opinion is to see what others do, by looking at existing implementations (e.g., the map bubbles that I pointed you to yesterday) and using uiautomatorviewer
my *guess* is that you will wind up with a custom view, rendered using the Canvas drawing primitives
10:10 AM
EGHDK
Okay. The map yesterday was done with 9 patches.
I'm trying uiautomatorviewer, but when I type it in terminal it says "command not found"
Mark M.
do you have $ANDROID_SDK/tools in your PATH? (where $ANDROID_SDK is wherever you have the SDK installed)
Jose L.
has entered the room
EGHDK
Yeah
Mark M.
then your tools are 12+ months out of date
uiautomatorviewer was released late last year
Jose L.
hello everyone, don't have questions so far, just curious :)
Mark M.
Jose: OK -- if you come up with a question, let me know
EGHDK
When I do ls in /tools, it shows uiautomatorviewer though.
Mark M.
EGHDK: then tools/ must not be in your PATH
regardless, you can switch to the tools/ directory and run it from there
EGHDK
I'm in the tools directory?
10:15 AM
Mark M.
sorry, but I do not understand that question
EGHDK
pwd returns ../android-sdk-macosx/tools
Mark M.
on OS X and Linux, to run a program in the current working directory, use ./ as a prefix
so ./uiautomatorviewer
EGHDK
oh...
That worked =)
Mark M.
if either of you have a question, chime in
10:20 AM
EGHDK
Trying to get whatsapp to launch... not working for some reason. I will try uiautomatorviewer later.
So how would I go about creating a custom view..?
Mark M.
create a subclass of View
EGHDK
Just "View"? Not textView or something?
Mark M.
override methods like onDraw()
well, only if you want to inherit TextView behavior
Jose L.
I'm still struggling with gradle in a multiproject configuration but we already talked about that in a previous chat office hour
10:25 AM
Mark M.
Jose: I doubt that I will be of much help with that at the present time
Jose L.
yeah... I didn't want to ask <again> the same question ;)
Mark M.
EGHDK
The only behavior I need built in is to be able to call match_parent or wrap_content
Mark M.
is this going to be an empty bubble, then?
EGHDK
Nope. I just need it to scale width wise.
Mark M.
then you are going to need more than "to be able to call match_parent or wrap_content", then
do you want your custom view to be a container (so the contents are handled by some other existing widget)?
or do you want your custom view to render the contents as well?
10:30 AM
EGHDK
I just want the bubble to be able to grow in width when I write more stuff in the bubble.
But the bubble will have to hold about 2 textView inside of it.
One for the persons phone number, and one for the persons actual message.
Mark M.
OK, so that means you want the bubble to be a container, so it can "hold about 2 textView inside of it"
if there is a specific existing container class, like LinearLayout, that implements the rules you want, subclass it as the basis for your custom view
EGHDK
Yeah!
Luca L.
has entered the room
Mark M.
otherwise, you will need to subclass ViewGroup, and cook up your own rules, which can get complicated
Luca L.
hi all
EGHDK
I guess I would want to extend relative layout?
Mark M.
EGHDK: let me take a question from Luca, and I will be back with you in a bit
EGHDK
Yeah, I want to do that.
Mark M.
Luca: do you have a question?
EGHDK
Okay.
10:35 AM
Mark M.
Luca: if you come up with a question, let me know
EGHDK: if RelativeLayout would be how you want to organize the children, then, yes, you could subclass RelativeLayout
Luca L.
yes
I'm using a WakefulIntentService with startForeground inside onCreate and stopForeground inside onDestroy, i have noticed that if i close the app from recent apps onDestroy will never be called for my service. Is it a normal behaviour?
Mark M.
Luca: onDestroy() is never guaranteed to be called
in a WakefulIntentService, call startForeground() and stopForeground() inside doWakefulWork()
(at the beginning and end, respectively)
Luca L.
ok thank you
EGHDK
Okay so I want to subclass relative layout... cool, but does it also have an onDraw method to override?
Mark M.
everything that inherits from View has onDraw()
which includes everything that inherits from ViewGroup
which therefore includes RelativeLayout
though you will need to call setWillNotDraw(false); somewhere, probably in the constructor
EGHDK
Gotcha. So last question I guess is... in onDraw is where I will need to make my chages to make a bubble. How will I go about drawing it? Using Shapes or Paint or..? I've never tried drawing to the screen before.
Mark M.
please read the documentation at the links I provided earlier in the chat
Jose L.
I might have understood wrong the problem, but I think that for holding two textviews and make the container grow to always wrap the two textviews the only thing you need is to use a normal layout with wrap_content for both width and height
Mark M.
Jose L.
if you use background resources, they will grow
10:40 AM
Jose L.
along with the content
Mark M.
Jose: he wants a map-balloon-style caret
with a colored fill
which does not appear to be readily doable using simple resources
(unfortunately)
without the fill, a nine-patch PNG would suffice
EGHDK
Okay, looks like I will start reading!
Luca L.
tell me when can i ask other questions
Mark M.
Luca: go ahead
EGHDK
Go for it Luca
Luca L.
when using fragments onActivityCreated for what operations is reccommended to be used?
Mark M.
that is difficult to answer in the abstract, sorry
10:45 AM
Luca L.
in some example i have noticed that adapters are created and setted inside onActivityCreated instead of onCreateView, why?
Mark M.
with a ListFragment, the ListView is itself created in onCreateView()
hence, you either need to call super.onCreateView() first (before calling setListAdapter()), or delay the setListAdapter() call to some lifecycle method that will occur after onCreateView()
Luca L.
ok so in custom fragments there is no reason to move code to onActivityCreated unless you need to get something from the activity?
Jose L.
View paste
EGHDK -> http://i.imgur.com/wFrDjUu.jpg

you'd need to play a lot with the dimensions for the padding and margins and such and 9 patches for that tend to give lots of trouble but... you might want to give that a try
just trying to help
Mark M.
Luca: I suppose
IMHO, you put the code where it works :-)
10:50 AM
Mark M.
Jose: again, the problem is that the bubble needs a color fill, for an arbitrary user-selected color
I had suggested last time a LayerDrawable consisting of the nine-patch and a ColorDrawable
Jose L.
ah... oh, I missed that part
sorry
Mark M.
Luca L.
ok thank you, i need to start an internal activity and pass some objects by reference without using parcelable, currently i'm using something like "getApplication().setActiveItems(items)" and "getApplication().getActiveItems()" there are better alternatives?
Mark M.
Luca: well, I do not recommend using Application, as it usually adds no value over your own singleton
and, of course, any static data is a memory leak risk
10:55 AM
Mark M.
plus, since this sounds like model data, make sure that you are only treating the singleton as a static data cache, with the real data being persistet
er, persisted
Luca L.
yes real data is already persisted i need only to pass these objects for read only, so is better to use something like ItemsCache.getInstance().get()/set()?
Mark M.
yes, because you can have as many singletons as you wish, for organizing different data sets
there can be only one custom Application subclass
11:00 AM
Mark M.
and that is a wrap for today's chat
the transcript will be posted to http://commonsware.com/office-hours/ shortly
Luca L.
ok thank you, bye
Mark M.
the next chat will be tomorrow at 4pm Eastern
have a pleasant day!
EGHDK
has left the room
Jose L.
has left the room
Luca L.
has left the room
Mark M.
turned off guest access

Tuesday, October 15

 

Office Hours

People in this transcript

  • EGHDK
  • Jose Luis
  • Luca Looz
  • Mark Murphy