diff options
| author | 2011-05-17 15:06:09 -0700 | |
|---|---|---|
| committer | 2011-05-17 15:06:09 -0700 | |
| commit | 0a2ed6de7bf818a733ecafe709ff95333748dc57 (patch) | |
| tree | 3a94a4ee102b819bec37f2183d0775656ce98338 | |
| parent | 3badb0d0ca88421a44ed1d3be00a5eebbfa2fa19 (diff) | |
| parent | 9c1223a71397b565f38015c07cae57a5015a6500 (diff) | |
Merge "Improve LayoutInflater's compliance."
| -rw-r--r-- | core/java/android/view/LayoutInflater.java | 82 |
1 files changed, 78 insertions, 4 deletions
diff --git a/core/java/android/view/LayoutInflater.java b/core/java/android/view/LayoutInflater.java index 81346b4fa79f..332a0fa1b6c5 100644 --- a/core/java/android/view/LayoutInflater.java +++ b/core/java/android/view/LayoutInflater.java @@ -16,6 +16,10 @@ 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.XmlPullParserException; @@ -83,6 +87,7 @@ public abstract class LayoutInflater { private static final String TAG_MERGE = "merge"; private static final String TAG_INCLUDE = "include"; + private static final String TAG_1995 = "blink"; private static final String TAG_REQUEST_FOCUS = "requestFocus"; /** @@ -454,7 +459,12 @@ public abstract class LayoutInflater { rInflate(parser, root, attrs, false); } else { // 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; @@ -605,10 +615,9 @@ public abstract class LayoutInflater { * Throw an exception because the specified class is not allowed to be inflated. */ 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 " + (prefix != null ? (prefix + name) : name)); - throw ie; } /** @@ -720,6 +729,12 @@ public abstract class LayoutInflater { parseInclude(parser, parent, attrs); } else if (TAG_MERGE.equals(name)) { 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 { final View view = createViewFromTag(parent, name, attrs); final ViewGroup viewGroup = (ViewGroup) parent; @@ -847,5 +862,64 @@ public abstract class LayoutInflater { parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT) { // 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); + } + } + } } |