diff options
author | Steve Kondik <steve@cyngn.com> | 2016-03-11 03:47:09 -0800 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2016-03-11 16:58:39 -0800 |
commit | 0e1dbed9194839a90755670d8fdf9046a75b85f7 (patch) | |
tree | 010372762ddc617295da2862f7d61813da9e3586 /tools/layoutlib/bridge/src/com/android/layoutlib/bridge/MockView.java | |
parent | 564f10b8f05ddf4d9ea2c0e64f1b113fe6dad4b8 (diff) | |
parent | e342181a4a8d8177b3b87ffe141777565fe98f15 (diff) | |
download | frameworks_base-0e1dbed9194839a90755670d8fdf9046a75b85f7.zip frameworks_base-0e1dbed9194839a90755670d8fdf9046a75b85f7.tar.gz frameworks_base-0e1dbed9194839a90755670d8fdf9046a75b85f7.tar.bz2 |
Merge tag 'android-6.0.1_r22' of https://android.googlesource.com/platform/frameworks/base into cm-13.0
Android 6.0.1 release 22
Change-Id: I0d31899b234156a91accb61e0a7fb3d8d16d5062
Diffstat (limited to 'tools/layoutlib/bridge/src/com/android/layoutlib/bridge/MockView.java')
-rw-r--r-- | tools/layoutlib/bridge/src/com/android/layoutlib/bridge/MockView.java | 77 |
1 files changed, 64 insertions, 13 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/MockView.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/MockView.java index 44a9aad..d392f21 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/MockView.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/MockView.java @@ -17,39 +17,90 @@ package com.android.layoutlib.bridge; import android.content.Context; -import android.graphics.Canvas; import android.util.AttributeSet; import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; import android.widget.TextView; /** * Base class for mocked views. - * - * TODO: implement onDraw and draw a rectangle in a random color with the name of the class - * (or better the id of the view). + * <p/> + * FrameLayout with a single TextView. Doesn't allow adding any other views to itself. */ -public class MockView extends TextView { +public class MockView extends FrameLayout { + + private final TextView mView; + + public MockView(Context context) { + this(context, null); + } public MockView(Context context, AttributeSet attrs) { this(context, attrs, 0); } - public MockView(Context context, AttributeSet attrs, int defStyle) { - this(context, attrs, defStyle, 0); + public MockView(Context context, AttributeSet attrs, int defStyleAttr) { + this(context, attrs, defStyleAttr, 0); } public MockView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); - - setText(this.getClass().getSimpleName()); - setTextColor(0xFF000000); + mView = new TextView(context, attrs); + mView.setTextColor(0xFF000000); setGravity(Gravity.CENTER); + setText(getClass().getSimpleName()); + addView(mView); + setBackgroundColor(0xFF7F7F7F); + } + + // Only allow adding one TextView. + @Override + public void addView(View child) { + if (child == mView) { + super.addView(child); + } + } + + @Override + public void addView(View child, int index) { + if (child == mView) { + super.addView(child, index); + } } @Override - public void onDraw(Canvas canvas) { - canvas.drawARGB(0xFF, 0x7F, 0x7F, 0x7F); + public void addView(View child, int width, int height) { + if (child == mView) { + super.addView(child, width, height); + } + } + + @Override + public void addView(View child, ViewGroup.LayoutParams params) { + if (child == mView) { + super.addView(child, params); + } + } + + @Override + public void addView(View child, int index, ViewGroup.LayoutParams params) { + if (child == mView) { + super.addView(child, index, params); + } + } + + // The following methods are called by the IDE via reflection, and should be considered part + // of the API. + // Historically, MockView used to be a textView and had these methods. Now, we simply delegate + // them to the contained textView. + + public void setText(CharSequence text) { + mView.setText(text); + } - super.onDraw(canvas); + public void setGravity(int gravity) { + mView.setGravity(gravity); } } |