ShadowView.java revision d4f5daf12f1d112cf06b8b8914437ed6c0b3a677
1a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.compackage com.xtremelabs.droidsugar.view;
2a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com
3a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.comimport android.content.Context;
4a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.comimport android.content.res.Resources;
5a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.comimport android.view.View;
6a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.comimport android.view.ViewGroup;
7a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.comimport com.xtremelabs.droidsugar.ProxyDelegatingHandler;
8a111e492b84c312a6bd5d5d9ef100dca48f4941ddjsollen@google.com
9a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.comimport java.util.ArrayList;
10a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.comimport java.util.List;
11a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com
12a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com@SuppressWarnings({"UnusedDeclaration"})
13a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.compublic class FakeView {
14a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    private View realView;
15a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com
16a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    private int id;
17a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    private List<View> children = new ArrayList<View>();
180060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    private FakeView parent;
19a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    private Context context;
20a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    private int visibility;
210060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    public boolean selected;
220060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    private View.OnClickListener onClickListener;
230060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    private Object tag;
240060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    private boolean enabled = true;
250060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    public int height;
260060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    public int width;
270060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    public int paddingLeft;
280060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    public int paddingTop;
290060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    public int paddingRight;
300060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    public int paddingBottom;
310060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    public ViewGroup.LayoutParams layoutParams;
320060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org
330060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    public FakeView(View view) {
34bc25dfc798fff225ce65355ecda19d2b85bd0e74commit-bot@chromium.org        this.realView = view;
350060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    }
360060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org
370060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    public void __constructor__(Context context) {
380060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org        this.context = context;
390060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    }
400060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org
410060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    public void setId(int id) {
420060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org        this.id = id;
430060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    }
440060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org
450060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    public int getId() {
460060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org        return id;
470060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    }
480060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org
490060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org    public View findViewById(int id) {
500060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org        if (id == this.id) {
510060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org            return realView;
520060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org        }
530060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org
540060159457453ca45a47828648c8f29d5695983ccommit-bot@chromium.org        for (View child : children) {
5595c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org            View found = child.findViewById(id);
5695c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org            if (found != null) {
5795c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org                return found;
5895c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org            }
5995c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        }
6095c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        return null;
6195c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
6295c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
6395c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public View getRootView() {
6495c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        FakeView root = this;
6595c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        while(root.parent != null) {
6695c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org            root = root.parent;
6795c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        }
6895c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        return root.realView;
6995c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
7095c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
7195c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public void addView(View child) {
7295c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        children.add(child);
7395c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        childProxy(child).parent = this;
7495c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
7595c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
7695c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    private FakeView childProxy(View child) {
7795c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        return (FakeView) ProxyDelegatingHandler.getInstance().proxyFor(child);
7895c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
7995c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
8095c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public int getChildCount() {
8195c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        return children.size();
8295c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
8395c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
8495c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public ViewGroup.LayoutParams getLayoutParams() {
8595c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        return layoutParams;
8695c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
8795c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
8895c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public View getChildAt(int index) {
8995c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        return children.get(index);
9095c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
9195c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
9295c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public void removeAllViews() {
9395c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        for (View child : children) {
9495c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org            childProxy(child).parent = null;
9595c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        }
9695c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        children.clear();
9795c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
9895c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
9995c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public final Context getContext() {
10095c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        return context;
10195c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
10295c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
10395c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public Resources getResources() {
10495c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        return context.getResources();
10595c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
10695c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
10795c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public int getVisibility() {
10895c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        return visibility;
10995c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
11095c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
11195c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public void setVisibility(int visibility) {
11295c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        this.visibility = visibility;
11395c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
11495c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
11595c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public void setSelected(boolean selected) {
11695c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        this.selected = selected;
11795c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
11895c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
11995c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public boolean isSelected() {
12095c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        return this.selected;
12195c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
12295c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
12395c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public boolean isEnabled() {
12495c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        return this.enabled;
12595c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
12695c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
12795c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public void setEnabled(boolean enabled) {
12895c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        this.enabled = enabled;
12995c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
13095c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
13195c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public void setOnClickListener(View.OnClickListener onClickListener) {
13295c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        this.onClickListener = onClickListener;
13395c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    }
13495c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org
13595c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org    public boolean performClick() {
13695c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org        if (onClickListener != null) {
13795c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org            onClickListener.onClick(realView);
13895c2e5532b094add82b007bdfcd4c64050b6b366commit-bot@chromium.org            return true;
139a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com        } else {
140a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com            return false;
141a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com        }
142a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    }
143a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com
144a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    public Object getTag() {
145efbe8e9bedda21a3e061ebf3d96431a0f250a654djsollen@google.com        return this.tag;
146fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com    }
147a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com
148a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    public void setTag(Object tag) {
149a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com        this.tag = tag;
150a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    }
151a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com
152a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    public final int getHeight() {
153a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com        return height;
154a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    }
155a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com
156a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    public final int getWidth() {
157a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com        return width;
158fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com    }
159a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com
160a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    public void setPadding(int left, int top, int right, int bottom) {
161a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com        paddingLeft = left;
162a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com        paddingTop = top;
163a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com        paddingRight = right;
164a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com        paddingBottom = bottom;
165fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com    }
166a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com
167a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    public int getPaddingTop() {
168a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com        return paddingTop;
169a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    }
170a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com
171a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    public int getPaddingLeft() {
172a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com        return paddingLeft;
173a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    }
174a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com
175a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    public int getPaddingRight() {
176a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com        return paddingRight;
177a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    }
178a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com
179a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    public int getPaddingBottom() {
180a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com        return paddingBottom;
181a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com    }
182fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com}
183a8dd1ce930811a51cc841f583424d507d95e7e78digit@google.com