ShadowView.java revision b551a870eb9fb9acae0f8a6632fefea12a5f8598
133873d2b41a5cd2597b20a4e88eb8942944c0f23Tyler Schultzpackage com.xtremelabs.robolectric.shadows;
26eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
36eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulzimport android.content.Context;
46eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulzimport android.content.res.Resources;
5ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williamsimport android.graphics.Bitmap;
6a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultzimport android.graphics.Point;
7a075f94a84c6dd3493700d0c752fc545642e44d5Mike Grafton & Tyler Schultzimport android.graphics.drawable.ColorDrawable;
8a075f94a84c6dd3493700d0c752fc545642e44d5Mike Grafton & Tyler Schultzimport android.graphics.drawable.Drawable;
9684ccc2fc5a1c79aa45af22b95c37f7c509a00c1Christian Williamsimport android.util.AttributeSet;
10445ec52f595fdb5eeb9111056651c79e46e29941Aaron VonderHaar & Phil Goodwinimport android.view.*;
113f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesiimport android.view.animation.Animation;
12ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williamsimport com.xtremelabs.robolectric.Robolectric;
1322c22c9aa4ca68c2deac6164edc1d82bc9645310Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.Implementation;
1422c22c9aa4ca68c2deac6164edc1d82bc9645310Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.Implements;
1522c22c9aa4ca68c2deac6164edc1d82bc9645310Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.RealObject;
166eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
1786e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williamsimport java.io.PrintStream;
186c887826366610c9e44c21a9fec6020219226283Gautier Hayounimport java.lang.reflect.InvocationTargetException;
196c887826366610c9e44c21a9fec6020219226283Gautier Hayounimport java.lang.reflect.Method;
2051fe0b279e9f5568683d9ef67921f922a51c05d5Christian Williams & Tyler Schultzimport java.util.HashMap;
2151fe0b279e9f5568683d9ef67921f922a51c05d5Christian Williams & Tyler Schultzimport java.util.Map;
22c6f46aeb970c9111e2e79b806451f63b4853950bIan Fisher & Tyler Schultz
23f5850efa8da26855e1e60ab7497b78da56b1a5baAmrit Thakur & Ryan Richardimport static com.xtremelabs.robolectric.Robolectric.Reflection.newInstanceOf;
2486e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williamsimport static com.xtremelabs.robolectric.Robolectric.shadowOf;
2586e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams
26ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin/**
276c887826366610c9e44c21a9fec6020219226283Gautier Hayoun * Shadow implementation of {@code View} that simulates the behavior of this
286c887826366610c9e44c21a9fec6020219226283Gautier Hayoun * class.
29d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz * <p/>
306c887826366610c9e44c21a9fec6020219226283Gautier Hayoun * Supports listeners, focusability (but not focus order), resource loading,
316c887826366610c9e44c21a9fec6020219226283Gautier Hayoun * visibility, onclick, tags, and tracks the size and shape of the view.
32ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin */
33198b49fe81283e340891361045a8bdeb01f35e04Tyler Schultz@SuppressWarnings({"UnusedDeclaration"})
340b378afcde0200166e546c46a7642015accfce49Christian Williams & Ian Fisher@Implements(View.class)
35afe0a89d904a7fe2f5980b9deb26cc3240192459Christian Williamspublic class ShadowView {
36d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz    @RealObject
37d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz    protected View realView;
386eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
396eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    private int id;
40afe0a89d904a7fe2f5980b9deb26cc3240192459Christian Williams    ShadowView parent;
4170e43520d16dba344ad0f2f96e5d9300880153ffPhil Goodwin & Tyler Schultz    protected Context context;
424d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    private boolean selected;
43810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore    private View.OnClickListener onClickListener;
44d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz    private View.OnLongClickListener onLongClickListener;
45c6f46aeb970c9111e2e79b806451f63b4853950bIan Fisher & Tyler Schultz    private Object tag;
46775ccf7ae53d9b4c77d3adf2514f26747cebd89cIan Fisher & Ryan Richard    private boolean enabled = true;
474d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    private int visibility = View.VISIBLE;
484d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    int left;
494d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    int top;
504d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    int right;
514d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    int bottom;
524d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    private int paddingLeft;
534d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    private int paddingTop;
544d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    private int paddingRight;
554d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    private int paddingBottom;
564d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    private ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(0, 0);
5744ade170c5bc611222ed25d5b1f8e7745104057dChristian Williams    private Map<Integer, Object> tags = new HashMap<Integer, Object>();
584d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    private boolean clickable;
59254044cea0df7e6aef3ce33c98a5003a6eba0512Christian Williams & Phil Goodwin    protected boolean focusable;
609729911f8638b6bb4d55b3d67e6d68a6b3f19dc7Phil Goodwin    boolean focusableInTouchMode;
614d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    private int backgroundResourceId = -1;
621f4067d01d9e2907f2d926b17d378cb40a379dcaRich Humphrey    private int backgroundColor;
635411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams    protected View.OnKeyListener onKeyListener;
644d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    private boolean isFocused;
655411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams    private View.OnFocusChangeListener onFocusChangeListener;
664d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    private boolean wasInvalidated;
67924f851cb0ec279b6974744ce623f25bdc657551Ryan Richard    private View.OnTouchListener onTouchListener;
68a2dd5bb88b4bfe0cbe77cfc3581ce42745509760Phil Goodwin & Tyler Schultz    protected AttributeSet attributeSet;
69ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williams    private boolean drawingCacheEnabled;
70a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    public Point scrollToCoordinates;
714241c0d59435626c1858d15e5e3612674a666ec0Lowell Kirsh & Ryan Richard    private boolean didRequestLayout;
72a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    private Drawable background;
733f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesi    private Animation animation;
74f5850efa8da26855e1e60ab7497b78da56b1a5baAmrit Thakur & Ryan Richard    private ViewTreeObserver viewTreeObserver;
75840b7de2b17a13dc045a278cd8f2a05c2d6ef609Rick Kawala & Wei Wu    private MotionEvent lastTouchEvent;
767cd4fd403867d4e7e6ee944a07ad6fb6c537f3ecRyan Richard    private int nextFocusDownId = View.NO_ID;
77cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella    private CharSequence contentDescription = null;
786eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
796eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    public void __constructor__(Context context) {
803c5249864cabd318d8b3f551f2f4ab7af7434f8bChristian Williams        __constructor__(context, null);
816eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    }
826eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
835189dc7b67bf8426200b68a998442ba821a27222Phil Goodwin & Tyler Schultz    public void __constructor__(Context context, AttributeSet attributeSet) {
843c5249864cabd318d8b3f551f2f4ab7af7434f8bChristian Williams        __constructor__(context, attributeSet, 0);
853c5249864cabd318d8b3f551f2f4ab7af7434f8bChristian Williams    }
863c5249864cabd318d8b3f551f2f4ab7af7434f8bChristian Williams
873c5249864cabd318d8b3f551f2f4ab7af7434f8bChristian Williams    public void __constructor__(Context context, AttributeSet attributeSet, int defStyle) {
883c5249864cabd318d8b3f551f2f4ab7af7434f8bChristian Williams        this.context = context;
895189dc7b67bf8426200b68a998442ba821a27222Phil Goodwin & Tyler Schultz        this.attributeSet = attributeSet;
903c5249864cabd318d8b3f551f2f4ab7af7434f8bChristian Williams
913c5249864cabd318d8b3f551f2f4ab7af7434f8bChristian Williams        if (attributeSet != null) {
923c5249864cabd318d8b3f551f2f4ab7af7434f8bChristian Williams            applyAttributes();
933c5249864cabd318d8b3f551f2f4ab7af7434f8bChristian Williams        }
943c5249864cabd318d8b3f551f2f4ab7af7434f8bChristian Williams    }
953c5249864cabd318d8b3f551f2f4ab7af7434f8bChristian Williams
963c5249864cabd318d8b3f551f2f4ab7af7434f8bChristian Williams    public void applyAttributes() {
975189dc7b67bf8426200b68a998442ba821a27222Phil Goodwin & Tyler Schultz        applyIdAttribute();
986be1495845e002cf1888bf1fe6b2ef1f43a0198dPhil Goodwin & Tyler Schultz        applyVisibilityAttribute();
9949e04b12550327c269ed8b826c71b1affe503336Phil Goodwin & Tyler Schultz        applyEnabledAttribute();
1004cee28dd02fadbaec9b236f04ff15057fd866077Phil Goodwin & Tyler Schultz        applyBackgroundAttribute();
101b53a662c0c9502e86039aa5d0c3fb7fb3f22e6bbChris Van Vranken        applyTagAttribute();
1026c887826366610c9e44c21a9fec6020219226283Gautier Hayoun        applyOnClickAttribute();
103cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella        applyContentDescriptionAttribute();
104684ccc2fc5a1c79aa45af22b95c37f7c509a00c1Christian Williams    }
105684ccc2fc5a1c79aa45af22b95c37f7c509a00c1Christian Williams
106de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
1076eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    public void setId(int id) {
1086eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz        this.id = id;
1096eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    }
1106eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
111de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
112cc4bd26d94f6eba2a0dc3dae0065c8df2296a95eIan Fisher & Tyler Schultz    public void setClickable(boolean clickable) {
113cc4bd26d94f6eba2a0dc3dae0065c8df2296a95eIan Fisher & Tyler Schultz        this.clickable = clickable;
114cc4bd26d94f6eba2a0dc3dae0065c8df2296a95eIan Fisher & Tyler Schultz    }
115cc4bd26d94f6eba2a0dc3dae0065c8df2296a95eIan Fisher & Tyler Schultz
116ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
117ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * Also sets focusable in touch mode to false if {@code focusable} is false, which is the Android behavior.
118ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     *
119ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * @param focusable the new status of the {@code View}'s focusability
120ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
121de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
122cc4bd26d94f6eba2a0dc3dae0065c8df2296a95eIan Fisher & Tyler Schultz    public void setFocusable(boolean focusable) {
123cc4bd26d94f6eba2a0dc3dae0065c8df2296a95eIan Fisher & Tyler Schultz        this.focusable = focusable;
124adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams        if (!focusable) {
125415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard            setFocusableInTouchMode(false);
126415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard        }
127415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard    }
128415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard
129415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard    @Implementation
130415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard    public final boolean isFocusableInTouchMode() {
131415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard        return focusableInTouchMode;
132415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard    }
133415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard
134ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
135ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * Also sets focusable to true if {@code focusableInTouchMode} is true, which is the Android behavior.
136ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     *
137ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * @param focusableInTouchMode the new status of the {@code View}'s touch mode focusability
138ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
139415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard    @Implementation
140415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard    public void setFocusableInTouchMode(boolean focusableInTouchMode) {
141415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard        this.focusableInTouchMode = focusableInTouchMode;
142adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams        if (focusableInTouchMode) {
143415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard            setFocusable(true);
144415f3fdab8162ece7185268f71b577f7faa0ba38Phil Goodwin & Ryan Richard        }
145cc4bd26d94f6eba2a0dc3dae0065c8df2296a95eIan Fisher & Tyler Schultz    }
146cc4bd26d94f6eba2a0dc3dae0065c8df2296a95eIan Fisher & Tyler Schultz
147cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella    @Implementation(i18nSafe = false)
148cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella    public void setContentDescription(CharSequence contentDescription) {
149cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella        this.contentDescription = contentDescription;
150cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella    }
151cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella
152de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
153254044cea0df7e6aef3ce33c98a5003a6eba0512Christian Williams & Phil Goodwin    public boolean isFocusable() {
154254044cea0df7e6aef3ce33c98a5003a6eba0512Christian Williams & Phil Goodwin        return focusable;
155254044cea0df7e6aef3ce33c98a5003a6eba0512Christian Williams & Phil Goodwin    }
156254044cea0df7e6aef3ce33c98a5003a6eba0512Christian Williams & Phil Goodwin
157254044cea0df7e6aef3ce33c98a5003a6eba0512Christian Williams & Phil Goodwin    @Implementation
1586eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    public int getId() {
1596eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz        return id;
1606eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    }
1616eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
162cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella    @Implementation
163cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella    public CharSequence getContentDescription() {
164cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella        return contentDescription;
165cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella    }
166cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella
167ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
168ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * Simulates the inflating of the requested resource.
169ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     *
1708de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz     * @param context  the context from which to obtain a layout inflater
171ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * @param resource the ID of the resource to inflate
1728de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz     * @param root     the {@code ViewGroup} to add the inflated {@code View} to
173ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * @return the inflated View
174ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
175de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
176a66c979cb64d406c1646a0909bd9a0b6b6ccd802Ian Fisher & Tyler Schultz    public static View inflate(Context context, int resource, ViewGroup root) {
17740c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams        return ShadowLayoutInflater.from(context).inflate(resource, root);
178a66c979cb64d406c1646a0909bd9a0b6b6ccd802Ian Fisher & Tyler Schultz    }
179a66c979cb64d406c1646a0909bd9a0b6b6ccd802Ian Fisher & Tyler Schultz
180ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
181ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * Finds this {@code View} if it's ID is passed in, returns {@code null} otherwise
182ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     *
183ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * @param id the id of the {@code View} to find
184ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * @return the {@code View}, if found, {@code null} otherwise
185ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
186de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
1876eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    public View findViewById(int id) {
188e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz        if (id == this.id) {
189e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz            return realView;
190e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz        }
1916eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
1926eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz        return null;
1936eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    }
194f5850efa8da26855e1e60ab7497b78da56b1a5baAmrit Thakur & Ryan Richard
195593543dfecc0d06e016c66504f24cd361b353a44Chris Van Vranken    @Implementation
196593543dfecc0d06e016c66504f24cd361b353a44Chris Van Vranken    public View findViewWithTag(Object obj) {
197b551a870eb9fb9acae0f8a6632fefea12a5f8598Ryan Richard & Tyler Schultz        if (obj.equals(realView.getTag())) {
198593543dfecc0d06e016c66504f24cd361b353a44Chris Van Vranken            return realView;
199593543dfecc0d06e016c66504f24cd361b353a44Chris Van Vranken        }
200593543dfecc0d06e016c66504f24cd361b353a44Chris Van Vranken
201593543dfecc0d06e016c66504f24cd361b353a44Chris Van Vranken        return null;
202593543dfecc0d06e016c66504f24cd361b353a44Chris Van Vranken    }
2036eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
204de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
2050c40acb66824054e469b3afbc3609ba39bbdac1cChristian Williams & Harry Ugol    public View getRootView() {
206afe0a89d904a7fe2f5980b9deb26cc3240192459Christian Williams        ShadowView root = this;
207adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams        while (root.parent != null) {
2080c40acb66824054e469b3afbc3609ba39bbdac1cChristian Williams & Harry Ugol            root = root.parent;
2090c40acb66824054e469b3afbc3609ba39bbdac1cChristian Williams & Harry Ugol        }
2100c40acb66824054e469b3afbc3609ba39bbdac1cChristian Williams & Harry Ugol        return root.realView;
2110c40acb66824054e469b3afbc3609ba39bbdac1cChristian Williams & Harry Ugol    }
2120c40acb66824054e469b3afbc3609ba39bbdac1cChristian Williams & Harry Ugol
213de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
214d4f5daf12f1d112cf06b8b8914437ed6c0b3a677Ryan Richard & Tyler Schultz    public ViewGroup.LayoutParams getLayoutParams() {
215d4f5daf12f1d112cf06b8b8914437ed6c0b3a677Ryan Richard & Tyler Schultz        return layoutParams;
216d4f5daf12f1d112cf06b8b8914437ed6c0b3a677Ryan Richard & Tyler Schultz    }
217d4f5daf12f1d112cf06b8b8914437ed6c0b3a677Ryan Richard & Tyler Schultz
218de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
219b0336c5991d124b6b157b9dc976ade56d00cba3eChristian Williams & Ryan Richard    public void setLayoutParams(ViewGroup.LayoutParams params) {
220b0336c5991d124b6b157b9dc976ade56d00cba3eChristian Williams & Ryan Richard        layoutParams = params;
221b0336c5991d124b6b157b9dc976ade56d00cba3eChristian Williams & Ryan Richard    }
222b0336c5991d124b6b157b9dc976ade56d00cba3eChristian Williams & Ryan Richard
223de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
2245411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams    public final ViewParent getParent() {
225a89236397e869467b3fc6f7208f551da61235795Christian Williams & Tyler Schultz        return parent == null ? null : (ViewParent) parent.realView;
2265411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams    }
2275411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams
228de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
2296eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    public final Context getContext() {
2306eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz        return context;
2316eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    }
2326eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
233de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
2346eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    public Resources getResources() {
2356eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz        return context.getResources();
2366eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    }
2376eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
238de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
2394d4b979c716f731be80852e7c04fdbe9862be3f0Ian Fisher & Phil Goodwin    public void setBackgroundResource(int backgroundResourceId) {
2404d4b979c716f731be80852e7c04fdbe9862be3f0Ian Fisher & Phil Goodwin        this.backgroundResourceId = backgroundResourceId;
241a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz        setBackgroundDrawable(getResources().getDrawable(backgroundResourceId));
242a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    }
243a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz
244a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    /**
245a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz     * Non-Android accessor.
246a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz     *
247a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz     * @return the resource ID of this views background
248a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz     */
249a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    public int getBackgroundResourceId() {
250a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz        return backgroundResourceId;
251a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    }
252a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz
253a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    @Implementation
254a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    public void setBackgroundColor(int color) {
255a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz        backgroundColor = color;
256a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz        setBackgroundDrawable(new ColorDrawable(getResources().getColor(color)));
257a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    }
258a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz
259a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    /**
260a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz     * Non-Android accessor.
261a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz     *
262a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz     * @return the resource color ID of this views background
263a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz     */
264a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    public int getBackgroundColor() {
265a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz        return backgroundColor;
266a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    }
267a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz
268a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    @Implementation
269a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    public void setBackgroundDrawable(Drawable d) {
270a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz        this.background = d;
271a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    }
272a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz
273a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    @Implementation
274a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    public Drawable getBackground() {
275a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz        return background;
2764d4b979c716f731be80852e7c04fdbe9862be3f0Ian Fisher & Phil Goodwin    }
2774d4b979c716f731be80852e7c04fdbe9862be3f0Ian Fisher & Phil Goodwin
278de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
2796eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    public int getVisibility() {
2806eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz        return visibility;
2816eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    }
2826eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
283de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
2846eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    public void setVisibility(int visibility) {
2856eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz        this.visibility = visibility;
2866eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    }
287eaadc83b187e31670dec8837d0851c0646522987Joe Moore & Tyler Schultz
288de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
289eaadc83b187e31670dec8837d0851c0646522987Joe Moore & Tyler Schultz    public void setSelected(boolean selected) {
290eaadc83b187e31670dec8837d0851c0646522987Joe Moore & Tyler Schultz        this.selected = selected;
291eaadc83b187e31670dec8837d0851c0646522987Joe Moore & Tyler Schultz    }
292810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore
293de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
294acb084f15b3b6e2496136ee8449b5d64ccb54939Ryan Richard & Tyler Schultz    public boolean isSelected() {
295acb084f15b3b6e2496136ee8449b5d64ccb54939Ryan Richard & Tyler Schultz        return this.selected;
296acb084f15b3b6e2496136ee8449b5d64ccb54939Ryan Richard & Tyler Schultz    }
297acb084f15b3b6e2496136ee8449b5d64ccb54939Ryan Richard & Tyler Schultz
298de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
299775ccf7ae53d9b4c77d3adf2514f26747cebd89cIan Fisher & Ryan Richard    public boolean isEnabled() {
300775ccf7ae53d9b4c77d3adf2514f26747cebd89cIan Fisher & Ryan Richard        return this.enabled;
301775ccf7ae53d9b4c77d3adf2514f26747cebd89cIan Fisher & Ryan Richard    }
302adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams
303de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
304775ccf7ae53d9b4c77d3adf2514f26747cebd89cIan Fisher & Ryan Richard    public void setEnabled(boolean enabled) {
305775ccf7ae53d9b4c77d3adf2514f26747cebd89cIan Fisher & Ryan Richard        this.enabled = enabled;
306775ccf7ae53d9b4c77d3adf2514f26747cebd89cIan Fisher & Ryan Richard    }
307775ccf7ae53d9b4c77d3adf2514f26747cebd89cIan Fisher & Ryan Richard
308de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
309810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore    public void setOnClickListener(View.OnClickListener onClickListener) {
310810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore        this.onClickListener = onClickListener;
311810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore    }
312810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore
313de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
314810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore    public boolean performClick() {
315810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore        if (onClickListener != null) {
316810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore            onClickListener.onClick(realView);
317810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore            return true;
318810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore        } else {
319810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore            return false;
320810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore        }
321810ca4e6f0dc6d69504b3e03ef61155f10083fbeChristian Williams & Joe Moore    }
322c6f46aeb970c9111e2e79b806451f63b4853950bIan Fisher & Tyler Schultz
323de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
324d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz    public void setOnLongClickListener(View.OnLongClickListener onLongClickListener) {
325d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        this.onLongClickListener = onLongClickListener;
326d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz    }
327d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz
328d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz    @Implementation
329d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz    public boolean performLongClick() {
330d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        if (onLongClickListener != null) {
331d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz            onLongClickListener.onLongClick(realView);
332d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz            return true;
333d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        } else {
334d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz            return false;
335d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        }
336d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz    }
337d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz
338d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz    @Implementation
3395411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams    public void setOnKeyListener(View.OnKeyListener onKeyListener) {
3405411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams        this.onKeyListener = onKeyListener;
3415411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams    }
3425411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams
343de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
344c6f46aeb970c9111e2e79b806451f63b4853950bIan Fisher & Tyler Schultz    public Object getTag() {
345c6f46aeb970c9111e2e79b806451f63b4853950bIan Fisher & Tyler Schultz        return this.tag;
346c6f46aeb970c9111e2e79b806451f63b4853950bIan Fisher & Tyler Schultz    }
347c6f46aeb970c9111e2e79b806451f63b4853950bIan Fisher & Tyler Schultz
348de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
349c6f46aeb970c9111e2e79b806451f63b4853950bIan Fisher & Tyler Schultz    public void setTag(Object tag) {
350c6f46aeb970c9111e2e79b806451f63b4853950bIan Fisher & Tyler Schultz        this.tag = tag;
351c6f46aeb970c9111e2e79b806451f63b4853950bIan Fisher & Tyler Schultz    }
35218141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard
353de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
35418141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    public final int getHeight() {
355a1ef7deaed03310ed6ec51621125f69bb16ac8fcChristian Williams & Ryan Richard        return bottom - top;
35618141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    }
35718141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard
358de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
35918141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    public final int getWidth() {
360a1ef7deaed03310ed6ec51621125f69bb16ac8fcChristian Williams & Ryan Richard        return right - left;
36118141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    }
36218141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard
363de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
364924f851cb0ec279b6974744ce623f25bdc657551Ryan Richard    public final int getMeasuredWidth() {
365a1ef7deaed03310ed6ec51621125f69bb16ac8fcChristian Williams & Ryan Richard        return getWidth();
366a1ef7deaed03310ed6ec51621125f69bb16ac8fcChristian Williams & Ryan Richard    }
367a1ef7deaed03310ed6ec51621125f69bb16ac8fcChristian Williams & Ryan Richard
368de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
3692b03c587c2f87875d4e70e77df53c7ea912414bcAaron VonderHaar & Amrit Thakur    public final int getMeasuredHeight() {
3702b03c587c2f87875d4e70e77df53c7ea912414bcAaron VonderHaar & Amrit Thakur        return getHeight();
3712b03c587c2f87875d4e70e77df53c7ea912414bcAaron VonderHaar & Amrit Thakur    }
3722b03c587c2f87875d4e70e77df53c7ea912414bcAaron VonderHaar & Amrit Thakur
3732b03c587c2f87875d4e70e77df53c7ea912414bcAaron VonderHaar & Amrit Thakur    @Implementation
374a1ef7deaed03310ed6ec51621125f69bb16ac8fcChristian Williams & Ryan Richard    public final void layout(int l, int t, int r, int b) {
375a1ef7deaed03310ed6ec51621125f69bb16ac8fcChristian Williams & Ryan Richard        left = l;
376a1ef7deaed03310ed6ec51621125f69bb16ac8fcChristian Williams & Ryan Richard        top = t;
377a1ef7deaed03310ed6ec51621125f69bb16ac8fcChristian Williams & Ryan Richard        right = r;
378a1ef7deaed03310ed6ec51621125f69bb16ac8fcChristian Williams & Ryan Richard        bottom = b;
379a1ef7deaed03310ed6ec51621125f69bb16ac8fcChristian Williams & Ryan Richard
380a1ef7deaed03310ed6ec51621125f69bb16ac8fcChristian Williams & Ryan Richard// todo:       realView.onLayout();
381924f851cb0ec279b6974744ce623f25bdc657551Ryan Richard    }
382adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams
383de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
38418141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    public void setPadding(int left, int top, int right, int bottom) {
38518141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard        paddingLeft = left;
38618141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard        paddingTop = top;
38718141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard        paddingRight = right;
38818141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard        paddingBottom = bottom;
38918141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    }
39018141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard
391de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
39218141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    public int getPaddingTop() {
39318141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard        return paddingTop;
39418141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    }
39518141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard
396de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
39718141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    public int getPaddingLeft() {
39818141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard        return paddingLeft;
39918141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    }
40018141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard
401de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
40218141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    public int getPaddingRight() {
40318141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard        return paddingRight;
40418141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    }
40518141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard
406de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
40718141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    public int getPaddingBottom() {
40818141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard        return paddingBottom;
40918141e608f2e60c866a9b7729909e9ce3b9eb588Ian Fisher & Ryan Richard    }
41051fe0b279e9f5568683d9ef67921f922a51c05d5Christian Williams & Tyler Schultz
411de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
41244ade170c5bc611222ed25d5b1f8e7745104057dChristian Williams    public Object getTag(int key) {
41344ade170c5bc611222ed25d5b1f8e7745104057dChristian Williams        return tags.get(key);
41444ade170c5bc611222ed25d5b1f8e7745104057dChristian Williams    }
41544ade170c5bc611222ed25d5b1f8e7745104057dChristian Williams
416de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
41744ade170c5bc611222ed25d5b1f8e7745104057dChristian Williams    public void setTag(int key, Object value) {
41844ade170c5bc611222ed25d5b1f8e7745104057dChristian Williams        tags.put(key, value);
41944ade170c5bc611222ed25d5b1f8e7745104057dChristian Williams    }
4205411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams
42165e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams    @Implementation
4224241c0d59435626c1858d15e5e3612674a666ec0Lowell Kirsh & Ryan Richard    public void requestLayout() {
4234241c0d59435626c1858d15e5e3612674a666ec0Lowell Kirsh & Ryan Richard        didRequestLayout = true;
4244241c0d59435626c1858d15e5e3612674a666ec0Lowell Kirsh & Ryan Richard    }
4254241c0d59435626c1858d15e5e3612674a666ec0Lowell Kirsh & Ryan Richard
4264241c0d59435626c1858d15e5e3612674a666ec0Lowell Kirsh & Ryan Richard    public boolean didRequestLayout() {
4274241c0d59435626c1858d15e5e3612674a666ec0Lowell Kirsh & Ryan Richard        return didRequestLayout;
4284241c0d59435626c1858d15e5e3612674a666ec0Lowell Kirsh & Ryan Richard    }
4294241c0d59435626c1858d15e5e3612674a666ec0Lowell Kirsh & Ryan Richard
4304241c0d59435626c1858d15e5e3612674a666ec0Lowell Kirsh & Ryan Richard    @Implementation
43165e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams    public final boolean requestFocus() {
43265e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams        return requestFocus(View.FOCUS_DOWN);
43365e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams    }
43465e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams
43565e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams    @Implementation
43665e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams    public final boolean requestFocus(int direction) {
43765e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams        setViewFocus(true);
43865e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams        return true;
43965e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams    }
44065e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams
4415411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams    public void setViewFocus(boolean hasFocus) {
4429729911f8638b6bb4d55b3d67e6d68a6b3f19dc7Phil Goodwin        this.isFocused = hasFocus;
4435411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams        if (onFocusChangeListener != null) {
4445411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams            onFocusChangeListener.onFocusChange(realView, hasFocus);
4455411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams        }
4465411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams    }
4475411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams
448de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
4497cd4fd403867d4e7e6ee944a07ad6fb6c537f3ecRyan Richard    public int getNextFocusDownId() {
4507cd4fd403867d4e7e6ee944a07ad6fb6c537f3ecRyan Richard        return nextFocusDownId;
4517cd4fd403867d4e7e6ee944a07ad6fb6c537f3ecRyan Richard    }
4527cd4fd403867d4e7e6ee944a07ad6fb6c537f3ecRyan Richard
4537cd4fd403867d4e7e6ee944a07ad6fb6c537f3ecRyan Richard    @Implementation
4547cd4fd403867d4e7e6ee944a07ad6fb6c537f3ecRyan Richard    public void setNextFocusDownId(int nextFocusDownId) {
4557cd4fd403867d4e7e6ee944a07ad6fb6c537f3ecRyan Richard        this.nextFocusDownId = nextFocusDownId;
4567cd4fd403867d4e7e6ee944a07ad6fb6c537f3ecRyan Richard    }
4577cd4fd403867d4e7e6ee944a07ad6fb6c537f3ecRyan Richard
4587cd4fd403867d4e7e6ee944a07ad6fb6c537f3ecRyan Richard    @Implementation
45965e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams    public boolean isFocused() {
4609729911f8638b6bb4d55b3d67e6d68a6b3f19dc7Phil Goodwin        return isFocused;
46165e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams    }
46265e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams
46365e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams    @Implementation
4645411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams    public boolean hasFocus() {
4659729911f8638b6bb4d55b3d67e6d68a6b3f19dc7Phil Goodwin        return isFocused;
4665411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams    }
4675411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams
468de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
46965e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams    public void clearFocus() {
47065e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams        setViewFocus(false);
47165e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams    }
47265e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams
47365e90b1b9829e83cac5cdcf8836b9706aa67c072Christian Williams    @Implementation
4745411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams    public void setOnFocusChangeListener(View.OnFocusChangeListener listener) {
4755411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams        onFocusChangeListener = listener;
4765411bf7cde998b5c2e70b69fe3d7227b6783ab7cChristian Williams    }
477f5850efa8da26855e1e60ab7497b78da56b1a5baAmrit Thakur & Ryan Richard
4780a780446a9b9384ec3e1ffa2d47c132dbaa8e63cRobert Taylor    @Implementation
4792b03c587c2f87875d4e70e77df53c7ea912414bcAaron VonderHaar & Amrit Thakur    public View.OnFocusChangeListener getOnFocusChangeListener() {
4800a780446a9b9384ec3e1ffa2d47c132dbaa8e63cRobert Taylor        return onFocusChangeListener;
4810a780446a9b9384ec3e1ffa2d47c132dbaa8e63cRobert Taylor    }
4821c46c94a5affe7beeb8c6bfcb5ec0ed509e5fdbdRyan Richard
483de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
4841c46c94a5affe7beeb8c6bfcb5ec0ed509e5fdbdRyan Richard    public void invalidate() {
4851c46c94a5affe7beeb8c6bfcb5ec0ed509e5fdbdRyan Richard        wasInvalidated = true;
4861c46c94a5affe7beeb8c6bfcb5ec0ed509e5fdbdRyan Richard    }
487924f851cb0ec279b6974744ce623f25bdc657551Ryan Richard
488de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
4891e17997177f9683996d07a7c88cbc9a938116e73Rick Kawala & Wei Wu    public boolean onTouchEvent(MotionEvent event) {
490840b7de2b17a13dc045a278cd8f2a05c2d6ef609Rick Kawala & Wei Wu        lastTouchEvent = event;
491840b7de2b17a13dc045a278cd8f2a05c2d6ef609Rick Kawala & Wei Wu        return false;
4921e17997177f9683996d07a7c88cbc9a938116e73Rick Kawala & Wei Wu    }
4931e17997177f9683996d07a7c88cbc9a938116e73Rick Kawala & Wei Wu
4941e17997177f9683996d07a7c88cbc9a938116e73Rick Kawala & Wei Wu    @Implementation
495924f851cb0ec279b6974744ce623f25bdc657551Ryan Richard    public void setOnTouchListener(View.OnTouchListener onTouchListener) {
496924f851cb0ec279b6974744ce623f25bdc657551Ryan Richard        this.onTouchListener = onTouchListener;
497924f851cb0ec279b6974744ce623f25bdc657551Ryan Richard    }
498924f851cb0ec279b6974744ce623f25bdc657551Ryan Richard
499de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
500924f851cb0ec279b6974744ce623f25bdc657551Ryan Richard    public boolean dispatchTouchEvent(MotionEvent event) {
5017bffa835922296fdd6ad995c8b28a735739cb839Andrew Dai & Rick Kawala        if (onTouchListener != null && onTouchListener.onTouch(realView, event)) {
5027bffa835922296fdd6ad995c8b28a735739cb839Andrew Dai & Rick Kawala            return true;
503924f851cb0ec279b6974744ce623f25bdc657551Ryan Richard        }
504840b7de2b17a13dc045a278cd8f2a05c2d6ef609Rick Kawala & Wei Wu        return realView.onTouchEvent(event);
505840b7de2b17a13dc045a278cd8f2a05c2d6ef609Rick Kawala & Wei Wu    }
506840b7de2b17a13dc045a278cd8f2a05c2d6ef609Rick Kawala & Wei Wu
507840b7de2b17a13dc045a278cd8f2a05c2d6ef609Rick Kawala & Wei Wu    public MotionEvent getLastTouchEvent() {
508840b7de2b17a13dc045a278cd8f2a05c2d6ef609Rick Kawala & Wei Wu        return lastTouchEvent;
509924f851cb0ec279b6974744ce623f25bdc657551Ryan Richard    }
5102ff94a9e4df5b0d3eb21bda70793b27d9f1f353cChristian Williams & Phil Goodwin
511445ec52f595fdb5eeb9111056651c79e46e29941Aaron VonderHaar & Phil Goodwin    @Implementation
5122b03c587c2f87875d4e70e77df53c7ea912414bcAaron VonderHaar & Amrit Thakur    public boolean dispatchKeyEvent(KeyEvent event) {
513445ec52f595fdb5eeb9111056651c79e46e29941Aaron VonderHaar & Phil Goodwin        if (onKeyListener != null) {
514445ec52f595fdb5eeb9111056651c79e46e29941Aaron VonderHaar & Phil Goodwin            return onKeyListener.onKey(realView, event.getKeyCode(), event);
515445ec52f595fdb5eeb9111056651c79e46e29941Aaron VonderHaar & Phil Goodwin        }
516445ec52f595fdb5eeb9111056651c79e46e29941Aaron VonderHaar & Phil Goodwin        return false;
517445ec52f595fdb5eeb9111056651c79e46e29941Aaron VonderHaar & Phil Goodwin    }
518445ec52f595fdb5eeb9111056651c79e46e29941Aaron VonderHaar & Phil Goodwin
519ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
520da9cd404c0db2ebcef4ecfb50836de00b56622f1Christian Williams     * Returns a string representation of this {@code View}. Unless overridden, it will be an empty string.
52140c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams     * <p/>
522da9cd404c0db2ebcef4ecfb50836de00b56622f1Christian Williams     * Robolectric extension.
523ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
5242ff94a9e4df5b0d3eb21bda70793b27d9f1f353cChristian Williams & Phil Goodwin    public String innerText() {
5252ff94a9e4df5b0d3eb21bda70793b27d9f1f353cChristian Williams & Phil Goodwin        return "";
5262ff94a9e4df5b0d3eb21bda70793b27d9f1f353cChristian Williams & Phil Goodwin    }
52786e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams
528ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
529ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * Dumps the status of this {@code View} to {@code System.out}
530ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
53186e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams    public void dump() {
53286e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams        dump(System.out, 0);
53386e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams    }
53486e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams
535ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
536ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * Dumps the status of this {@code View} to {@code System.out} at the given indentation level
537ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
53886e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams    public void dump(PrintStream out, int indent) {
53986e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams        dumpFirstPart(out, indent);
54086e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams        out.println("/>");
54186e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams    }
54286e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams
54386e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams    protected void dumpFirstPart(PrintStream out, int indent) {
54486e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams        dumpIndent(out, indent);
54586e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams
54686e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams        out.print("<" + realView.getClass().getSimpleName());
54786e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams        if (id > 0) {
54886e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams            out.print(" id=\"" + shadowOf(context).getResourceLoader().getNameForId(id) + "\"");
54986e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams        }
55086e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams    }
55186e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams
55286e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams    protected void dumpIndent(PrintStream out, int indent) {
55386e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams        for (int i = 0; i < indent; i++) out.print(" ");
55486e98619f5f1b5f6b1fd5742ba911d7ebc83c2ddChristian Williams    }
5554d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
556ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
557ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * @return left side of the view
558ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
559bbf6ae3d37d2303d8463094096ef0bb9906fd658Christian Williams    @Implementation
5604d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public int getLeft() {
5614d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        return left;
5624d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
5634d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
564ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
565ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * @return top coordinate of the view
566ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
567bbf6ae3d37d2303d8463094096ef0bb9906fd658Christian Williams    @Implementation
5684d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public int getTop() {
5694d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        return top;
5704d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
5714d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
572ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
573ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * @return right side of the view
574ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
575bbf6ae3d37d2303d8463094096ef0bb9906fd658Christian Williams    @Implementation
5764d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public int getRight() {
5774d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        return right;
5784d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
5794d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
580ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
581ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * @return bottom coordinate of the view
582ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
583bbf6ae3d37d2303d8463094096ef0bb9906fd658Christian Williams    @Implementation
5844d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public int getBottom() {
5854d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        return bottom;
5864d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
5874d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
588ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
589ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * @return whether the view is clickable
590ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
591bbf6ae3d37d2303d8463094096ef0bb9906fd658Christian Williams    @Implementation
5924d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public boolean isClickable() {
5934d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        return clickable;
5944d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
5954d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
596ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
597de2143a1bef92c4ef270d3391b9201e8b8af7051Christian Williams     * Non-Android accessor.
598ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     *
599ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * @return whether or not {@link #invalidate()} has been called
600ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
6014d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public boolean wasInvalidated() {
6024d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        return wasInvalidated;
6034d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
6044d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
605ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
606ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     * Clears the wasInvalidated flag
607ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
6084d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public void clearWasInvalidated() {
6094d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        wasInvalidated = false;
6104d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
6114d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
612ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
613de2143a1bef92c4ef270d3391b9201e8b8af7051Christian Williams     * Non-Android accessor.
614ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
6154d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public void setLeft(int left) {
6164d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        this.left = left;
6174d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
6184d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
619ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
620de2143a1bef92c4ef270d3391b9201e8b8af7051Christian Williams     * Non-Android accessor.
621ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
6224d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public void setTop(int top) {
6234d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        this.top = top;
6244d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
6254d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
626ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
627de2143a1bef92c4ef270d3391b9201e8b8af7051Christian Williams     * Non-Android accessor.
628ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
6294d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public void setRight(int right) {
6304d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        this.right = right;
6314d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
6324d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
633ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
634de2143a1bef92c4ef270d3391b9201e8b8af7051Christian Williams     * Non-Android accessor.
635ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
6364d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public void setBottom(int bottom) {
6374d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        this.bottom = bottom;
6384d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
6394d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
640ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
641de2143a1bef92c4ef270d3391b9201e8b8af7051Christian Williams     * Non-Android accessor.
642ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
6434d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public void setPaddingLeft(int paddingLeft) {
6444d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        this.paddingLeft = paddingLeft;
6454d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
6464d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
647ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
648de2143a1bef92c4ef270d3391b9201e8b8af7051Christian Williams     * Non-Android accessor.
649ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
6504d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public void setPaddingTop(int paddingTop) {
6514d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        this.paddingTop = paddingTop;
6524d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
6534d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
654ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
655de2143a1bef92c4ef270d3391b9201e8b8af7051Christian Williams     * Non-Android accessor.
656ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
6574d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public void setPaddingRight(int paddingRight) {
6584d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        this.paddingRight = paddingRight;
6594d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
6604d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
661ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
662de2143a1bef92c4ef270d3391b9201e8b8af7051Christian Williams     * Non-Android accessor.
663ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
6644d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public void setPaddingBottom(int paddingBottom) {
6654d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        this.paddingBottom = paddingBottom;
6664d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
6674d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin
668ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin    /**
669de2143a1bef92c4ef270d3391b9201e8b8af7051Christian Williams     * Non-Android accessor.
670ac58b328bde3c77d1d9687408e547faad3b77e2bPhil Goodwin     */
6714d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    public void setFocused(boolean focused) {
6724d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin        isFocused = focused;
6734d709f74a8a630e677915cff8fba5e8b4888800fChristian Williams & Phil Goodwin    }
6748de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz
6758de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz    /**
6768de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz     * Non-Android accessor.
6778de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz     *
6788de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz     * @return true if this object and all of its ancestors are {@code View.VISIBLE}, returns false if this or
6798de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz     *         any ancestor is not {@code View.VISIBLE}
6808de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz     */
6818de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz    public boolean derivedIsVisible() {
6828de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz        View parent = realView;
6838de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz        while (parent != null) {
6848de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz            if (parent.getVisibility() != View.VISIBLE) {
6858de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz                return false;
6868de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz            }
6878de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz            parent = (View) parent.getParent();
6888de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz        }
6898de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz        return true;
6908de53d85207b90879fd242796941d526277b1245Phil Goodwin & Tyler Schultz    }
691c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz
692c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz    /**
693c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz     * Utility method for clicking on views exposing testing scenarios that are not possible when using the actual app.
694c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz     *
695c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz     * @throws RuntimeException if the view is disabled or if the view or any of its parents are not visible.
696c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz     */
697c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz    public boolean checkedPerformClick() {
698c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz        if (!derivedIsVisible()) {
699c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz            throw new RuntimeException("View is not visible and cannot be clicked");
700c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz        }
701c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz        if (!realView.isEnabled()) {
702c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz            throw new RuntimeException("View is not enabled and cannot be clicked");
703c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz        }
704c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz
705c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz        return realView.performClick();
706c140c89564a145280adf65188f25303e850d3a9cPhil Goodwin & Tyler Schultz    }
7075101cf6874bcc7ceef92354819497ea9cea04c22Phil Goodwin & Tyler Schultz
70806dfb798c2833348ed593991759fb581f7c7b20dPhil Goodwin & Tyler Schultz    public void applyFocus() {
70906dfb798c2833348ed593991759fb581f7c7b20dPhil Goodwin & Tyler Schultz        if (noParentHasFocus(realView)) {
71006dfb798c2833348ed593991759fb581f7c7b20dPhil Goodwin & Tyler Schultz            Boolean focusRequested = attributeSet.getAttributeBooleanValue("android", "focus", false);
71106dfb798c2833348ed593991759fb581f7c7b20dPhil Goodwin & Tyler Schultz            if (focusRequested || realView.isFocusableInTouchMode()) {
71206dfb798c2833348ed593991759fb581f7c7b20dPhil Goodwin & Tyler Schultz                realView.requestFocus();
71306dfb798c2833348ed593991759fb581f7c7b20dPhil Goodwin & Tyler Schultz            }
71406dfb798c2833348ed593991759fb581f7c7b20dPhil Goodwin & Tyler Schultz        }
7155101cf6874bcc7ceef92354819497ea9cea04c22Phil Goodwin & Tyler Schultz    }
7165101cf6874bcc7ceef92354819497ea9cea04c22Phil Goodwin & Tyler Schultz
7175189dc7b67bf8426200b68a998442ba821a27222Phil Goodwin & Tyler Schultz    private void applyIdAttribute() {
7185189dc7b67bf8426200b68a998442ba821a27222Phil Goodwin & Tyler Schultz        Integer id = attributeSet.getAttributeResourceValue("android", "id", 0);
7195189dc7b67bf8426200b68a998442ba821a27222Phil Goodwin & Tyler Schultz        if (getId() == 0) {
7205189dc7b67bf8426200b68a998442ba821a27222Phil Goodwin & Tyler Schultz            setId(id);
7212bc51e5a1e4d54158f7ff81af442d306fcd9a449Phil Goodwin & Tyler Schultz        }
7222bc51e5a1e4d54158f7ff81af442d306fcd9a449Phil Goodwin & Tyler Schultz    }
723d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz
724b53a662c0c9502e86039aa5d0c3fb7fb3f22e6bbChris Van Vranken    private void applyTagAttribute() {
725d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        Object tag = attributeSet.getAttributeValue("android", "tag");
726d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        if (tag != null) {
727d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz            setTag(tag);
728d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        }
729d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz    }
7302bc51e5a1e4d54158f7ff81af442d306fcd9a449Phil Goodwin & Tyler Schultz
7316be1495845e002cf1888bf1fe6b2ef1f43a0198dPhil Goodwin & Tyler Schultz    private void applyVisibilityAttribute() {
7326be1495845e002cf1888bf1fe6b2ef1f43a0198dPhil Goodwin & Tyler Schultz        String visibility = attributeSet.getAttributeValue("android", "visibility");
7335101cf6874bcc7ceef92354819497ea9cea04c22Phil Goodwin & Tyler Schultz        if (visibility != null) {
7345101cf6874bcc7ceef92354819497ea9cea04c22Phil Goodwin & Tyler Schultz            if (visibility.equals("gone")) {
7355101cf6874bcc7ceef92354819497ea9cea04c22Phil Goodwin & Tyler Schultz                setVisibility(View.GONE);
7365101cf6874bcc7ceef92354819497ea9cea04c22Phil Goodwin & Tyler Schultz            } else if (visibility.equals("invisible")) {
7375101cf6874bcc7ceef92354819497ea9cea04c22Phil Goodwin & Tyler Schultz                setVisibility(View.INVISIBLE);
7385101cf6874bcc7ceef92354819497ea9cea04c22Phil Goodwin & Tyler Schultz            }
7395101cf6874bcc7ceef92354819497ea9cea04c22Phil Goodwin & Tyler Schultz        }
7405101cf6874bcc7ceef92354819497ea9cea04c22Phil Goodwin & Tyler Schultz    }
7415101cf6874bcc7ceef92354819497ea9cea04c22Phil Goodwin & Tyler Schultz
74249e04b12550327c269ed8b826c71b1affe503336Phil Goodwin & Tyler Schultz    private void applyEnabledAttribute() {
74349e04b12550327c269ed8b826c71b1affe503336Phil Goodwin & Tyler Schultz        setEnabled(attributeSet.getAttributeBooleanValue("android", "enabled", true));
7445101cf6874bcc7ceef92354819497ea9cea04c22Phil Goodwin & Tyler Schultz    }
74519d90b633936ae8dacbc7b09a8e44b2ad90be497Phil Goodwin & Tyler Schultz
7464cee28dd02fadbaec9b236f04ff15057fd866077Phil Goodwin & Tyler Schultz    private void applyBackgroundAttribute() {
74740c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams        String source = attributeSet.getAttributeValue("android", "background");
74840c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams        if (source != null) {
74940c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams            if (source.startsWith("@drawable/")) {
75040c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams                setBackgroundResource(attributeSet.getAttributeResourceValue("android", "background", 0));
75140c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams            }
75240c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams        }
7536d2ed84f8604e5022dd0576567bf3a0bd0e22403Macarse    }
7546d2ed84f8604e5022dd0576567bf3a0bd0e22403Macarse
7556c887826366610c9e44c21a9fec6020219226283Gautier Hayoun    private void applyOnClickAttribute() {
7566c887826366610c9e44c21a9fec6020219226283Gautier Hayoun        final String handlerName = attributeSet.getAttributeValue("android",
757d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz                "onClick");
7586c887826366610c9e44c21a9fec6020219226283Gautier Hayoun        if (handlerName == null) {
7596c887826366610c9e44c21a9fec6020219226283Gautier Hayoun            return;
7606c887826366610c9e44c21a9fec6020219226283Gautier Hayoun        }
7616c887826366610c9e44c21a9fec6020219226283Gautier Hayoun
7626c887826366610c9e44c21a9fec6020219226283Gautier Hayoun        /* good part of following code has been directly copied from original
7636c887826366610c9e44c21a9fec6020219226283Gautier Hayoun         * android source */
7646c887826366610c9e44c21a9fec6020219226283Gautier Hayoun        setOnClickListener(new View.OnClickListener() {
7656c887826366610c9e44c21a9fec6020219226283Gautier Hayoun            public void onClick(View v) {
7666c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                Method mHandler;
7676c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                try {
7686c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                    mHandler = getContext().getClass().getMethod(handlerName,
769d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz                            View.class);
7706c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                } catch (NoSuchMethodException e) {
7716c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                    int id = getId();
7726c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                    String idText = id == View.NO_ID ? "" : " with id '"
7736c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                            + shadowOf(context).getResourceLoader()
774d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz                            .getNameForId(id) + "'";
7756c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                    throw new IllegalStateException("Could not find a method " +
7766c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                            handlerName + "(View) in the activity "
7776c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                            + getContext().getClass() + " for onClick handler"
7786c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                            + " on view " + realView.getClass() + idText, e);
7796c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                }
7806c887826366610c9e44c21a9fec6020219226283Gautier Hayoun
7816c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                try {
7826c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                    mHandler.invoke(getContext(), realView);
7836c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                } catch (IllegalAccessException e) {
7846c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                    throw new IllegalStateException("Could not execute non "
7856c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                            + "public method of the activity", e);
7866c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                } catch (InvocationTargetException e) {
7876c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                    throw new IllegalStateException("Could not execute "
7886c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                            + "method of the activity", e);
7896c887826366610c9e44c21a9fec6020219226283Gautier Hayoun                }
7906c887826366610c9e44c21a9fec6020219226283Gautier Hayoun            }
7916c887826366610c9e44c21a9fec6020219226283Gautier Hayoun        });
7926c887826366610c9e44c21a9fec6020219226283Gautier Hayoun    }
7936c887826366610c9e44c21a9fec6020219226283Gautier Hayoun
794cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella    private void applyContentDescriptionAttribute() {
795cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella        String contentDescription = attributeSet.getAttributeValue("android", "contentDescription");
796cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella        if (contentDescription != null) {
797cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella            if (contentDescription.startsWith("@string/")) {
798cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella                int resId = attributeSet.getAttributeResourceValue("android", "contentDescription", 0);
799cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella                contentDescription = context.getResources().getString(resId);
800cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella            }
801cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella            setContentDescription(contentDescription);
802cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella        }
803cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella    }
804cd6a55965421b7a1bcea900058a98c464c157319Matteo Panella
80506dfb798c2833348ed593991759fb581f7c7b20dPhil Goodwin & Tyler Schultz    private boolean noParentHasFocus(View view) {
80619d90b633936ae8dacbc7b09a8e44b2ad90be497Phil Goodwin & Tyler Schultz        while (view != null) {
80706dfb798c2833348ed593991759fb581f7c7b20dPhil Goodwin & Tyler Schultz            if (view.hasFocus()) return false;
80819d90b633936ae8dacbc7b09a8e44b2ad90be497Phil Goodwin & Tyler Schultz            view = (View) view.getParent();
80919d90b633936ae8dacbc7b09a8e44b2ad90be497Phil Goodwin & Tyler Schultz        }
81006dfb798c2833348ed593991759fb581f7c7b20dPhil Goodwin & Tyler Schultz        return true;
81119d90b633936ae8dacbc7b09a8e44b2ad90be497Phil Goodwin & Tyler Schultz    }
812d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz
8130ed02e080ff9f471642662ba0678db1d42221343Michael Portuesi    /**
8140ed02e080ff9f471642662ba0678db1d42221343Michael Portuesi     * Non-android accessor.  Returns touch listener, if set.
815d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz     *
8160ed02e080ff9f471642662ba0678db1d42221343Michael Portuesi     * @return
8170ed02e080ff9f471642662ba0678db1d42221343Michael Portuesi     */
8180ed02e080ff9f471642662ba0678db1d42221343Michael Portuesi    public View.OnTouchListener getOnTouchListener() {
819d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        return onTouchListener;
8200ed02e080ff9f471642662ba0678db1d42221343Michael Portuesi    }
821d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz
82246309a9995c013790cbc40ae207f10973350b14fMichael Portuesi    /**
82346309a9995c013790cbc40ae207f10973350b14fMichael Portuesi     * Non-android accessor.  Returns click listener, if set.
824d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz     *
82546309a9995c013790cbc40ae207f10973350b14fMichael Portuesi     * @return
82646309a9995c013790cbc40ae207f10973350b14fMichael Portuesi     */
82746309a9995c013790cbc40ae207f10973350b14fMichael Portuesi    public View.OnClickListener getOnClickListener() {
828d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        return onClickListener;
82946309a9995c013790cbc40ae207f10973350b14fMichael Portuesi    }
830ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williams
831b76cabccd9f35b57fe486faf7d5763952c07c1a9Josh Lauer & Christian Williams    @Implementation
832ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williams    public void setDrawingCacheEnabled(boolean drawingCacheEnabled) {
833ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williams        this.drawingCacheEnabled = drawingCacheEnabled;
834ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williams    }
835ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williams
836b76cabccd9f35b57fe486faf7d5763952c07c1a9Josh Lauer & Christian Williams    @Implementation
837ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williams    public boolean isDrawingCacheEnabled() {
838ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williams        return drawingCacheEnabled;
839ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williams    }
840ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williams
841b76cabccd9f35b57fe486faf7d5763952c07c1a9Josh Lauer & Christian Williams    @Implementation
842ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williams    public Bitmap getDrawingCache() {
843ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williams        return Robolectric.newInstanceOf(Bitmap.class);
844ae26238c7d01caef84ceddd8ffb42c32306918d6Josh Lauer & Christian Williams    }
84540c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams
84634f3d7cb9f41c9480d7b7b4e03be6df4c1c8021fRich Humphrey    @Implementation
84734f3d7cb9f41c9480d7b7b4e03be6df4c1c8021fRich Humphrey    public void post(Runnable action) {
84834f3d7cb9f41c9480d7b7b4e03be6df4c1c8021fRich Humphrey        Robolectric.getUiThreadScheduler().post(action);
84934f3d7cb9f41c9480d7b7b4e03be6df4c1c8021fRich Humphrey    }
850b020d9a038a8d1274806e1cccbc015f559396f05Christian Williams
851b020d9a038a8d1274806e1cccbc015f559396f05Christian Williams    @Implementation
852b020d9a038a8d1274806e1cccbc015f559396f05Christian Williams    public void postDelayed(Runnable action, long delayMills) {
853b020d9a038a8d1274806e1cccbc015f559396f05Christian Williams        Robolectric.getUiThreadScheduler().postDelayed(action, delayMills);
854b020d9a038a8d1274806e1cccbc015f559396f05Christian Williams    }
855289938e9153024d2146a7130de98fdc16efd5aa2Tim Labeeuw & Tyler Schultz
856289938e9153024d2146a7130de98fdc16efd5aa2Tim Labeeuw & Tyler Schultz    @Implementation
857289938e9153024d2146a7130de98fdc16efd5aa2Tim Labeeuw & Tyler Schultz    public void postInvalidateDelayed(long delayMilliseconds) {
858289938e9153024d2146a7130de98fdc16efd5aa2Tim Labeeuw & Tyler Schultz        Robolectric.getUiThreadScheduler().postDelayed(new Runnable() {
859289938e9153024d2146a7130de98fdc16efd5aa2Tim Labeeuw & Tyler Schultz            @Override
860289938e9153024d2146a7130de98fdc16efd5aa2Tim Labeeuw & Tyler Schultz            public void run() {
861289938e9153024d2146a7130de98fdc16efd5aa2Tim Labeeuw & Tyler Schultz                realView.invalidate();
862289938e9153024d2146a7130de98fdc16efd5aa2Tim Labeeuw & Tyler Schultz            }
863289938e9153024d2146a7130de98fdc16efd5aa2Tim Labeeuw & Tyler Schultz        }, delayMilliseconds);
864289938e9153024d2146a7130de98fdc16efd5aa2Tim Labeeuw & Tyler Schultz    }
865d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz
8663f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesi    @Implementation
8673f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesi    public Animation getAnimation() {
868d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        return animation;
8693f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesi    }
870d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz
8713f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesi    @Implementation
8723f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesi    public void setAnimation(Animation anim) {
873d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        animation = anim;
8743f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesi    }
875d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz
8763f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesi    @Implementation
8773f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesi    public void startAnimation(Animation anim) {
878d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        setAnimation(anim);
879d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        animation.start();
8803f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesi    }
881d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz
8823f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesi    @Implementation
8833f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesi    public void clearAnimation() {
884d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        if (animation != null) {
885d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz            animation.cancel();
886d723e05df54299b88daa5b626c460d733d9bcf6dLenny Turetsky & Tyler Schultz        }
8873f78da998ce73c1c7c25798a7e7e4f19287eff23Michael Portuesi    }
888a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz
889a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    @Implementation
890a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    public void scrollTo(int x, int y) {
891a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz        this.scrollToCoordinates = new Point(x, y);
892a739b57a6b1a99f14d586f609f0f62f48b8e2284Ian Fisher & Tyler Schultz    }
893f5850efa8da26855e1e60ab7497b78da56b1a5baAmrit Thakur & Ryan Richard
894cf952a3ce2fd0bf7d9236ea7b909924e6091cf09Phil Goodwin & Ryan Richard    @Implementation
895cf952a3ce2fd0bf7d9236ea7b909924e6091cf09Phil Goodwin & Ryan Richard    public int getScrollX() {
896cf952a3ce2fd0bf7d9236ea7b909924e6091cf09Phil Goodwin & Ryan Richard        return scrollToCoordinates != null ? scrollToCoordinates.x : 0;
897cf952a3ce2fd0bf7d9236ea7b909924e6091cf09Phil Goodwin & Ryan Richard    }
898cf952a3ce2fd0bf7d9236ea7b909924e6091cf09Phil Goodwin & Ryan Richard
899cf952a3ce2fd0bf7d9236ea7b909924e6091cf09Phil Goodwin & Ryan Richard    @Implementation
900cf952a3ce2fd0bf7d9236ea7b909924e6091cf09Phil Goodwin & Ryan Richard    public int getScrollY() {
901cf952a3ce2fd0bf7d9236ea7b909924e6091cf09Phil Goodwin & Ryan Richard        return scrollToCoordinates != null ? scrollToCoordinates.y : 0;
902cf952a3ce2fd0bf7d9236ea7b909924e6091cf09Phil Goodwin & Ryan Richard    }
903f5850efa8da26855e1e60ab7497b78da56b1a5baAmrit Thakur & Ryan Richard
904f5850efa8da26855e1e60ab7497b78da56b1a5baAmrit Thakur & Ryan Richard    @Implementation
905f5850efa8da26855e1e60ab7497b78da56b1a5baAmrit Thakur & Ryan Richard    public ViewTreeObserver getViewTreeObserver() {
906f5850efa8da26855e1e60ab7497b78da56b1a5baAmrit Thakur & Ryan Richard        if (viewTreeObserver == null) {
907f5850efa8da26855e1e60ab7497b78da56b1a5baAmrit Thakur & Ryan Richard            viewTreeObserver = newInstanceOf(ViewTreeObserver.class);
908f5850efa8da26855e1e60ab7497b78da56b1a5baAmrit Thakur & Ryan Richard        }
909f5850efa8da26855e1e60ab7497b78da56b1a5baAmrit Thakur & Ryan Richard        return viewTreeObserver;
910f5850efa8da26855e1e60ab7497b78da56b1a5baAmrit Thakur & Ryan Richard    }
9110c428886526fc277d3b47d08b1fce79c89920a92Amrit Thakur & Rick Kawala
9120c428886526fc277d3b47d08b1fce79c89920a92Amrit Thakur & Rick Kawala    @Implementation
9130c428886526fc277d3b47d08b1fce79c89920a92Amrit Thakur & Rick Kawala    public void onAnimationEnd() {
9140c428886526fc277d3b47d08b1fce79c89920a92Amrit Thakur & Rick Kawala    }
9150c428886526fc277d3b47d08b1fce79c89920a92Amrit Thakur & Rick Kawala
9160c428886526fc277d3b47d08b1fce79c89920a92Amrit Thakur & Rick Kawala    /*
9170c428886526fc277d3b47d08b1fce79c89920a92Amrit Thakur & Rick Kawala     * Non-Android accessor.
9180c428886526fc277d3b47d08b1fce79c89920a92Amrit Thakur & Rick Kawala     */
9190c428886526fc277d3b47d08b1fce79c89920a92Amrit Thakur & Rick Kawala    public void finishedAnimation() {
92023da7c64347b46b8fccf281c5d9894299cfb7622Amrit Thakur & Rick Kawala        try {
92123da7c64347b46b8fccf281c5d9894299cfb7622Amrit Thakur & Rick Kawala            Method onAnimationEnd = realView.getClass().getDeclaredMethod("onAnimationEnd", new Class[0]);
92223da7c64347b46b8fccf281c5d9894299cfb7622Amrit Thakur & Rick Kawala            onAnimationEnd.setAccessible(true);
92323da7c64347b46b8fccf281c5d9894299cfb7622Amrit Thakur & Rick Kawala            onAnimationEnd.invoke(realView);
92423da7c64347b46b8fccf281c5d9894299cfb7622Amrit Thakur & Rick Kawala        } catch (Exception e) {
92523da7c64347b46b8fccf281c5d9894299cfb7622Amrit Thakur & Rick Kawala            throw new RuntimeException(e);
92623da7c64347b46b8fccf281c5d9894299cfb7622Amrit Thakur & Rick Kawala        }
9270c428886526fc277d3b47d08b1fce79c89920a92Amrit Thakur & Rick Kawala    }
9286eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz}
929