Office Hours — Today, May 17

Yesterday, May 16

May 17
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Joshua C.
has entered the room
Mark M.
hello, Joshua
how can I help you today?
Joshua C.
Hello again, Mark. :)
Well... again I seem to be having a problem getting attributes from the XML into the code... though you helped me solve this problem the other day THOSE attributes are getting through, but not the ones on my new object, the Curve...
Here is the way it's defined in attrs.xml:
View paste (2 more lines)
<declare-styleable name="Curve">
        <attr name="from_side" format="enum">
            <enum name="top" value="0"/>
            <enum name="pinkie" value="1"/>
            <enum name="bottom" value="2"/>
            <enum name="thumb" value="3"/>
        </attr>
        <attr name="to_side" format="enum">
            <enum name="top" value="0"/>
            <enum name="pinkie" value="1"/>
            <enum name="bottom" value="2"/>
            <enum name="thumb" value="3"/>
        </attr>
        <attr name="from_position" format="dimension"/>
        <attr name="to_position" format="dimension"/>
...
7:30 PM
Joshua C.
And here is the layout XML code calling it... the object is being created, my Log.i calls in the constructor are returning the default values.
View paste
<com.codesolutions.onehandkeyboard.Curve
            android:layout_width="match_parent"
            android:layout_height="50dp"
            app:from_side = "top"
            app:to_side = "thumb"
            app:from_position = "50dp"
            app:to_position = "50dp">

        </com.codesolutions.onehandkeyboard.Curve>
Here is my object's constructor:
View paste (6 more lines)
    public Curve(Context context, AttributeSet attrs) {
        super(context, attrs);

        //fetching attributes
        //note: defaults hardcoded here
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Edge);
        mRadius = a.getInt(R.styleable.Curve_radius, 50);

        mFromSide = a.getInt(R.styleable.Curve_from_side, 2);
        mToSide = a.getInt(R.styleable.Curve_to_side, 1);
        mFromPosition = a.getDimensionPixelSize(R.styleable.Curve_from_position, 33);
        mToPosition = a.getDimensionPixelSize(R.styleable.Curve_to_position, 44);

        Log.i("constructor - fromSide", String.valueOf(mFromSide));
        Log.i("constructor - toSide", String.valueOf(mToSide));
...
As you can see, the values I'm passing from the layout are different than the default values... and I am getting the default values!
Mark M.
can you show the entire layout file containing your Curve?
Joshua C.
View paste (61 more lines)
<?xml version="1.0" encoding="utf-8"?>

<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/res-auto"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.codesolutions.onehandkeyboard.KeyboardActivity"
    app:handed="right">

        <!-- top edge -->
...
Mark M.
OK, just double-checking the xmlns:app line :-)
Joshua C.
The Curve is located inside the OneHandLayout, along with some Edge objects.
Yes, of course... and the Edge objects ARE managing to get their values just fine from the XML.
I was using simple integers, which wasn't working, and now I'm trying to use dimensions (preferable), but neither seem to work.
Mark M.
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Edge);
if this is a Curve, why are you asking for R.styleable.Edge?
Joshua C.
Danmnit! You've found it!
7:35 PM
Joshua C.
I knew it had to be something little and simple... I was just missing it.
7:35 PM
Mark M.
copy/paste bug, I would guess
happens all the time
Joshua C.
Well, isn't that embarrasing... yes, definitely copy/paste bug.. I missed that one.
Okay, compiled and working now... one more little question...
it doesn't actually stop the program from working, but when I compile and run it I get this red line a bunch of times in the logcat:
E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method com.codesolutions.onehandkeyboard.Curve.access$super
View paste
along with a bunch of other lines reading:
/dalvikvm: VFY: unable to resolve virtual method ...
with various methods that are not in my app... do you know what this is? Does it matter?
7:40 PM
Mark M.
those messages are due to code (yours/framework's/library's) that refer to things that are in newer versions of Android, and you are testing on an older version of Android
Joshua C.
Yes, testing on my 4.4.4 phone.
So don't worry about it then?
Mark M.
correct
I wish they were not being flagged as errors
since they are not errors
Joshua C.
Right... well, I can ignore them. Okay... I'm starting to make real progress now, thanks to your help. :)
Mark M.
happy to be useful
Joshua C.
Thanks again, I'll get back to it. Cherio till next time. :)
Mark M.
OK
7:50 PM
Joshua C.
Okay, back again... :)
Mark M.
hi!
Joshua C.
So... in the OneHandLayout object (which is descended from ViewGroup)...
here is the onLayout...
View paste (44 more lines)
@Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        int childCount = getChildCount();

        //final int parentTop = getPaddingTop();
        //final int parentBottom = getPaddingBottom();
        int innerLeft = left;
        int innerTop = top;
        int innerRight = right;
        int innerBottom = bottom;

        for (int i = 0; i < childCount; i++) {
            View child = getChildAt(i);
            LayoutParams lp = child.getLayoutParams();

...
I include the whole thing for context...
All those Log calls produce exactly what I would expect...
Mark M.
I do not see any Log calls in that code
are you referring to the ones from the Curve constructor from before?
Joshua C.
I'm trying to get the space in the middle, between all the Edge objects (defined in the XML) and pass that to the Curve.
Oh, quite right, I didn't get to the end of the function.
View paste (57 more lines)
@Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        int childCount = getChildCount();

        //final int parentTop = getPaddingTop();
        //final int parentBottom = getPaddingBottom();
        int innerLeft = left;
        int innerTop = top;
        int innerRight = right;
        int innerBottom = bottom;

        for (int i = 0; i < childCount; i++) {
            View child = getChildAt(i);
            LayoutParams lp = child.getLayoutParams();

...
7:55 PM
Mark M.
ah, OK
Joshua C.
I start out with the complete size of the activity (the whole screen)... and layout each of the Edge's... which is working fine.
Then there near the end...
If the child is a Curve
I pass it those "inner" dimensions...
for some reason, the Curve.onLayout function is never being called.
Adding another Log inside the if with the child.layout call to be sure it's running.
and it is!
Mark M.
well, this gets into stuff that I have not worked with personally
off the cuff, I am uncertain if onLayout() is supposed to be calling layout() of the children
Joshua C.
Oh wait.
Hold on.. perhaps it is...
Adding more distinct Logs.
8:00 PM
Joshua C.
Hmm... appears I was mistaken... onLayout is running... my problem must be somewhere else.
8:20 PM
Joshua C.
has left the room
8:25 PM
arun
has entered the room
Mark M.
hello, arun
the chat is nearly over -- do you have a quick question?
arun
hi mark
no, but i see theres another one at 9am tmrw right?
Mark M.
correct
arun
ok ill be there and ask you then
Mark M.
I adjusted this week's schedule to avoid conflicts with Google I|O
OK
arun
cool, see you tmrw then
arun
has left the room
8:30 PM
Mark M.
turned off guest access

Yesterday, May 16

 

Office Hours

People in this transcript

  • arun
  • Joshua Chambers
  • Mark Murphy