Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9c1223a7 authored by Romain Guy's avatar Romain Guy
Browse files

Improve LayoutInflater's compliance.

There are standards, we should do our best to implement them
properly.

Change-Id: I83a7dc0651795d09b19d536c17b6aefc2eca5c81
parent 51d6eb7d
Loading
Loading
Loading
Loading
+78 −4
Original line number Original line Diff line number Diff line
@@ -16,6 +16,10 @@


package android.view;
package android.view;


import android.graphics.Canvas;
import android.os.Handler;
import android.os.Message;
import android.widget.FrameLayout;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserException;


@@ -83,6 +87,7 @@ public abstract class LayoutInflater {


    private static final String TAG_MERGE = "merge";
    private static final String TAG_MERGE = "merge";
    private static final String TAG_INCLUDE = "include";
    private static final String TAG_INCLUDE = "include";
    private static final String TAG_1995 = "blink";
    private static final String TAG_REQUEST_FOCUS = "requestFocus";
    private static final String TAG_REQUEST_FOCUS = "requestFocus";


    /**
    /**
@@ -454,7 +459,12 @@ public abstract class LayoutInflater {
                    rInflate(parser, root, attrs, false);
                    rInflate(parser, root, attrs, false);
                } else {
                } else {
                    // Temp is the root view that was found in the xml
                    // Temp is the root view that was found in the xml
                    View temp = createViewFromTag(root, name, attrs);
                    View temp;
                    if (TAG_1995.equals(name)) {
                        temp = new BlinkLayout(mContext, attrs);
                    } else {
                        temp = createViewFromTag(root, name, attrs);
                    }


                    ViewGroup.LayoutParams params = null;
                    ViewGroup.LayoutParams params = null;


@@ -605,10 +615,9 @@ public abstract class LayoutInflater {
     * Throw an exception because the specified class is not allowed to be inflated.
     * Throw an exception because the specified class is not allowed to be inflated.
     */
     */
    private void failNotAllowed(String name, String prefix, AttributeSet attrs) {
    private void failNotAllowed(String name, String prefix, AttributeSet attrs) {
        InflateException ie = new InflateException(attrs.getPositionDescription()
        throw new InflateException(attrs.getPositionDescription()
                + ": Class not allowed to be inflated "
                + ": Class not allowed to be inflated "
                + (prefix != null ? (prefix + name) : name));
                + (prefix != null ? (prefix + name) : name));
        throw ie;
    }
    }


    /**
    /**
@@ -720,6 +729,12 @@ public abstract class LayoutInflater {
                parseInclude(parser, parent, attrs);
                parseInclude(parser, parent, attrs);
            } else if (TAG_MERGE.equals(name)) {
            } else if (TAG_MERGE.equals(name)) {
                throw new InflateException("<merge /> must be the root element");
                throw new InflateException("<merge /> must be the root element");
            } else if (TAG_1995.equals(name)) {
                final View view = new BlinkLayout(mContext, attrs);
                final ViewGroup viewGroup = (ViewGroup) parent;
                final ViewGroup.LayoutParams params = viewGroup.generateLayoutParams(attrs);
                rInflate(parser, view, attrs, true);
                viewGroup.addView(view, params);                
            } else {
            } else {
                final View view = createViewFromTag(parent, name, attrs);
                final View view = createViewFromTag(parent, name, attrs);
                final ViewGroup viewGroup = (ViewGroup) parent;
                final ViewGroup viewGroup = (ViewGroup) parent;
@@ -848,4 +863,63 @@ public abstract class LayoutInflater {
            // Empty
            // Empty
        }
        }
    }
    }

    private static class BlinkLayout extends FrameLayout {
        private static final int MESSAGE_BLINK = 0x42;
        private static final int BLINK_DELAY = 500;

        private boolean mBlink;
        private boolean mBlinkState;
        private final Handler mHandler;

        public BlinkLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
            mHandler = new Handler(new Handler.Callback() {
                @Override
                public boolean handleMessage(Message msg) {
                    if (msg.what == MESSAGE_BLINK) {
                        if (mBlink) {
                            mBlinkState = !mBlinkState;
                            makeBlink();
                        }
                        invalidate();
                        return true;
                    }
                    return false;
                }
            });
        }

        private void makeBlink() {
            Message message = mHandler.obtainMessage(MESSAGE_BLINK);
            mHandler.sendMessageDelayed(message, BLINK_DELAY);
        }

        @Override
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();

            mBlink = true;
            mBlinkState = true;

            makeBlink();
        }

        @Override
        protected void onDetachedFromWindow() {
            super.onDetachedFromWindow();

            mBlink = false;
            mBlinkState = true;

            mHandler.removeMessages(MESSAGE_BLINK);
        }

        @Override
        protected void dispatchDraw(Canvas canvas) {
            if (mBlinkState) {
                super.dispatchDraw(canvas);
            }
        }
    }
}
}