Office Hours — Today, May 12

Tuesday, May 10

Mark M.
has entered the room
Mark M.
turned on guest access
Steve S.
has entered the room
Joshua C.
has entered the room
Mark M.
hello, Steve!
Steve S.
Hi Mark, how are you!
Mark M.
and, hello, Joshua!
Joshua C.
Hello Mark, and hello Steve. :)
Steve S.
Hi Joshua!
Mark M.
Steve: you got in *just* ahead of Joshua, so you are first up -- how can I help you today?
Steve S.
I have a question about logging remote data. I'll paste it in.
View paste
I have an Android app that serves as a human-machine interface for a coffee brewer, and want to access data that it collects. I'm wondering how to do that. One possibility appears to be to use Jake Wharton's Timber logging library in conjunction with Crashlytics to display the data on the Crashlytics dashboard. If this approach is feasible, it would have the advantage of requiring adding only a couple of lines of code to the app. Is this a reasonable approach? Are there better ways to do what I want?
Mark M.
um, well, I suppose that's a question of what your end goal is
if your goal is just to be able to putter through some entries, what you describe may work
bearing in mind that I haven't used Crashlytics
May 12
7:30 PM
Steve S.
Ok. That might be adequate. Have you used Timber?
Mark M.
if your goal is to actually do something with the data, scraping it out of Crashlytics would seem like it would be a pain
I have used a logging wrapper; I forget if it is Timber or something else
Steve S.
That's true. However, for now we're looking to do something fast that could be implemented in a non-invasive way.
Ok. Are there other logging wrappers we should look at?
Mark M.
there's a whole category of 'em out on the Android Arsenal
I am using co.trikita:log
Steve S.
Great. I'll check it out.
Mark M.
but, for unstructured log-like data that you just want to eyeball, your approach is reasonable
Steve S.
We do want analyze the data, so what you said about the difficulty of getting the data out of Crashlytics could be an issue.
Mark M.
right
Steve S.
Ok. We do want to do more than eyeball it -- we'd like to get it in e.g. Excel.
Are there approaches you're aware of that would facilitate doing that?
Mark M.
then, it's a question of whether you can shoehorn your needs into some sort of analytics API, or whether you should just make Web service calls of your own server
well, I'm a control freak, so I'd write the code to send the data to my server
I'm not a huge fan of handing data over to third parties any more than is absolutely necessary
Steve S.
Right. That goes back to the other thing I said: for now, the priority is do something that we can get up and running very quickly.
We will be analyzing it ourselves.
Mark M.
well, you can't have everything :-)
7:35 PM
Steve S.
Ok. Based on what you've said so far, it sounds like there are two choices: use Crashlytics/Timber to do something quickly that won't have the optimum format, or do something more involved that would give us the appropriate format.
Mark M.
I'm sure that there are other options, but those are the two big ones
let me take a question from Joshua, and I'll be back with you in a bit
Steve S.
Great. You've pretty much answered my question then. I'll let you get on to Joshua. Thank you so much!
Mark M.
Joshua: your turn! do you have a question?
Joshua C.
Yes, though at this point... it's more of a problem that has me stumped than it is a question...
Here'
Here's what I've got... I've got a custom ViewGroup (a layout)...
Which is called "OneHandLayout"...
and inside that, I have another ViewGroup... and I am trying to access my custom attributes from inside the class and it just isn't working.
Mark M.
this doesn't really give me much to go on
Joshua C.
Yes, code coming right up...
Am straddling two computers and need to open this window in the other one to paste...
7:40 PM
Mark M.
you could post the code on the other computer to a GitHub gist, or a pastebin, or something, then put the link in here
or, perhaps, just explain a bit more what "just isn't working" means in this context
Joshua C.
Yes...
Joshua C.
has left the room
Joshua C.
has entered the room
Joshua C.
Okay, better. Now I am on a single machine...
So, I have the attributes defined as an enum....
View paste
<attr name="handed" format="enum">
            <enum name="left" value="0"/>
            <enum name="right" value="1"/>
        </attr>
in the values/attrs.xml file
View paste
more completely, 
<declare-styleable name="OneHandLayout">
        <attr name="handed" format="enum">
            <enum name="left" value="0"/>
            <enum name="right" value="1"/>
        </attr>
    </declare-styleable>
View paste
And I define the value ("handed") in the layout XML...
app:handed="left"
Which it seems to like... and then in my class, I try to simply access this data in the constructor.
View paste
 public OneHandLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        //this.DEBUG_DRAW = true;

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.OneHandLayout);
        handed = a.getInt(R.styleable.OneHandLayout_handed, 0);
        //any other attributes to extract
        Log.i("handed", String.valueOf(handed));

        a.recycle();
    }
7:45 PM
Joshua C.
And yet the only value I ever get is the one that I understood as the default value if there wasn't one, that 0 in the last paste....
I think I must be doing someone wrong in the constructor trying to access the attributes...
I can step through this in the debugger... and I should get the value 1 for handed... but I don't.
Mark M.
um, off the cuff, this seems OK
Joshua C.
Right, well, the other way.
Mark M.
have you tried calling hasValue(R.styleable.OneHandLayout_handed) to see what it returns?
(called on the TypedArray)
Joshua C.
Ooh, good question... trying now....
I'm also trying to do the SAME thing with another LayoutView subclass, called Edge, which is nested inside of the OneHandLayout.
I change the xml to app:handed="right" and I still get that same 0 value!
Mark M.
personally, I haven't used an enum custom attribute
but I thought those just turned into integers
Joshua C.
Yes, exactly... they should just turn into an int... which I am trying to extract as such...
What do I call the hasValue on?
Mark M.
the TypedArray
Joshua C.
the TypedArray I've extracted?
Mark M.
yes
7:50 PM
Joshua C.
View paste
Okay, running now with this line:
        Log.i("hasValue?", String.valueOf(a.hasValue(R.styleable.OneHandLayout_handed)));
I'm getting false.
So the value isn't reaching the TypedArray.
Mark M.
either that, or it's not liking R.styleable.OneHandLayout_handed for some reason
I haven't inspected the innards of a TypedArray in ages, but if the debugger lets you, you might try poking around in there and see if you can find a sign of your value
Joshua C.
Well, it likes it enough to autocomplete it in Android Studio...
Mark M.
you might temporarily change the integers from 0/1 to 666/1337 or something
to make it easier to see
Joshua C.
I did.
I searched and searched and that value doesn't appear to be in there anywhere.
Mark M.
OK, that implies that somewhere in the layout inflation process things are going awry
you do have the app namespace set to the .../res-auto URL, right?
let me swing back to Steve for a bit, and I'll return to you shortly
Steve: back to you! do you have another question?
Steve S.
There's nothing further unless you've thought of other fast, non-invasive approaches to remote logging.
7:55 PM
Mark M.
well, I did offer up a third avenue, though it might be the same as what you were thinking: analytics
Timber to me means "logging"
Joshua C.
View paste
Okay... and yes, this is the complete opening tag:
<com.codesolutions.onehandkeyboard.OneHandLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/com.codesolutions.onehandkeyboard"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    tools:context="com.codesolutions.onehandkeyboard.KeyboardActivity"
    app:handed="right">
Mark M.
analytics APIs can be a bit more fine grained, with counts and such
(Joshua: that's the wrong xmlns:app, I think)
Steve S.
Right, but we're doing that ourselves. I think we've covered it then. I'll let you get back to Joshua. Thank you, and have a good evening!
Mark M.
Steve: OK
Joshua: back to you!
Steve S.
has left the room
Mark M.
try changing your xmlns:app to be xmlns:app="http://schemas.android.com/apk/res-auto&quot;
Joshua C.
Great... well, that would be a nice easy place for the problem to be. :)
Okay, rerunning... I had it like that earlier, and then changed it trying to get things working... we'll see in a sec. :)
AHA!
That did it.
Mark M.
the form you had been using was replaced a few years ago
Joshua C.
Fantastic.
Very good! Well, that had been driving me crazy... and that's just the EASY part of what I'm trying to write.
8:00 PM
Joshua C.
So, now that we've got the easy one out of the way, I'm struggling with something else...
Mark M.
yeah, creating the cephalopod interface, supporting up to 8 hands, could get icky :-)
Joshua C.
grin
Well, now that I've got the basic structure in place... I have another ViewGroup I'm trying to create... so the keyboard itself (that I'm still trying to write) will have keys along each edge of the screen (So, OneHandLayout contains 4 Edge objects), and then will also have a Curve.
Now, it seems that Views can really only be defined as a rectangle... and I want to make views that are curved... so my plan was to do the work in the ViewGroup (Curve) and figure out the curve... and then the View object (a Key, inherited from View) needs to populate along the curve.
View paste
Something like this is what I'm trying to accomplish:
So to start I was just trying to define the curve and draw it... though that's not exactly my end game... at this point, I'm interested in your thoughts on the best way to accomplish a layout like this... though I want to do as much of the actual layout in XML as possible, since I'll want to fiddle with it a lot to get the layout right.
Ideally I want the keys to actually be SHAPED with rounded tops and bottoms, kinda like as shows (but perhaps more curved).
8:05 PM
Mark M.
well, as I think I have tried to point out in previous chats, this is well outside the scope of my custom view work
in the end, your statement that "Views can really only be defined as a rectangle" is somewhat off-kilter
a View *has* a rectangle
what it does in that rectangle is up to the View
it needs to render pixels, and it needs to support touch events
so your curved buttons are merely rectangular views that happen to render and respect touch input in a curved area of their rectangles
Joshua C.
Ah, good point... so I'm looking at how to render shapes... have you worked with these classes like Shape, Path, etc?
Mark M.
I know of them
I have not used them
Joshua C.
I found this post...
Mark M.
as that's lower-level than I usually get in the View system
Joshua C.
Which seems very relevant to what I'm trying to do.
Mark M.
possibly, if your curves are definable as arcs
Joshua C.
Right... and then there's this more generic Path class.
Mark M.
is this only for a single piece of hardware, or is this supposed to be for arbitrary Android devices?
Joshua C.
I'd like it to run on various newish android devices.
seems to be there from the beginning.
API level 1
Mark M.
that's not what I'm worried about
different screen sizes would need to be taken into account in your setup
8:10 PM
Mark M.
you might need somewhat different "patterns", if you will, for different screen aspect ratios
Joshua C.
Oh yes... and in fact I'll have different configurations for bigger tablets compared to smaller screens like phones.
Mark M.
(and, of course, Android N multi-window is going to make your work that much harder)
Joshua C.
I'm quite aware of that need... right now I'm just trying to get to know the tools I'm going to use... which means low level drawing.
I haven't heard of "N multi-window"
Mark M.
Android N is the next version of Android
we have the N Developer Preview 2 now
Joshua C.
Ooh.
Mark M.
it supports split-screen modes on phones and tablets, akin to what Samsung and others have had on their devices for a few years
and, there's a "freeform multi-window" option for manufacturers, which gives you a desktop OS feel, with resizeable windows
Joshua C.
Interesting... though possibly not quite relevant to this particular app... and I'm more concerned about various devices out there now and and can cross the bridge of new features when I come to it... Right now, the device I'm testing it on is android 4.4.4
And I'll install various emulators as I get further into development.
Mark M.
just making sure that you understand what you're getting into
Joshua C.
I do realize that this program is going to be very difficult to write... and is clearly a crazy one to write as my first android program. ;)
8:15 PM
Joshua C.
One more specific question I have related to this... is about the context... when I look in the debugger... the context of all the Views in my app seem to be the Activity...
How can I access the parent ViewGroup to the ViewGroup (or View) I'm in now?
Mark M.
getParent(), if I recall correctly
Joshua C.
Okay, good... a silly question...
Mark M.
Joshua C.
Well, I guess if you haven't worked with the Path and other low level drawing, I may be barking up the wrong tree for advice on how to proceed with this one....
Mark M.
yeah, I'm not going to be any good at those questions, sorry
Joshua C.
Well, that's okay... at least the code I do have works now, and I'll keep plugging away at trying to figure out low level drawing. I downloaded a million tutorials, though this subject seems a bit under represented in the books (such as yours) and tutorials. ;)
8:20 PM
Mark M.
it's a niche topic, and not a niche that I have natural skills in
Joshua C.
I must say, I really like this format, as in the book, and offering office hours, etc. :)
Mark M.
I am glad that it is working out for you
Joshua C.
Even if you don't have an answer for me, it's a good way to operate, and it helps me feel supported, to have this way to ask a question outside of the often difficult stackoverflow and forums, etc.
And now I'll get back to it... I know this is possible, so I will get it to work... ;)
Thanks for your time.
Mark M.
you are very welcome
8:30 PM
Mark M.
well, that's a wrap for today's chat
the transcript will show up on https://commonsware.com/office-hours/ shortly
the next chat is Saturday at 4pm US Eastern
have a pleasant day!
Joshua C.
has left the room
Mark M.
turned off guest access

Tuesday, May 10

 

Office Hours

People in this transcript

  • Joshua Chambers
  • Mark Murphy
  • Steve S.

Files in this transcript