133873d2b41a5cd2597b20a4e88eb8942944c0f23Tyler Schultzpackage com.xtremelabs.robolectric.shadows;
26eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
320a4d94c942081c83c7d270680df40e73b8896b5Ryan Richard & Tyler Schultzimport android.app.Activity;
4490535650f83cedb8fdd58aa3c4a928ce843e794Harry Ugol & Ian Fisherimport android.app.Application;
585af7906879a68c99b1878dac22605fa32454f3fRich Humphreyimport android.app.Dialog;
685af7906879a68c99b1878dac22605fa32454f3fRich Humphreyimport android.content.Context;
777e577374c759ae8ecbe8b63b9d42088992a1d50Joe Moore & Tyler Schultzimport android.content.Intent;
896bd436ce2e84a30747574ce2b7e4ef5e61bc3d0Valtteri Virtanenimport android.content.SharedPreferences;
9e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chenimport android.database.Cursor;
1085af7906879a68c99b1878dac22605fa32454f3fRich Humphreyimport android.os.Bundle;
118e3b1f6515f98cbaad5809be132e3914973bb9a2Aaron VonderHaar & Amrit Thakurimport android.view.*;
12297cc102ff285524a4109025ecd2c9c6ef051ce5Jan Berkelimport android.widget.FrameLayout;
13345fb6b77303f0d3c98cf748fefa0136183bdc79Christian Williamsimport com.xtremelabs.robolectric.Robolectric;
1422c22c9aa4ca68c2deac6164edc1d82bc9645310Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.Implementation;
1522c22c9aa4ca68c2deac6164edc1d82bc9645310Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.Implements;
1622c22c9aa4ca68c2deac6164edc1d82bc9645310Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.RealObject;
172cdde11355e7c249e83a8b7aaabae5977bbc3e49Phil Goodwinimport com.xtremelabs.robolectric.tester.android.view.TestWindow;
18a8486da7c7a0b6a10e943c55992f34d9c256456dChristian Williams
19b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williamsimport java.lang.reflect.InvocationTargetException;
20b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williamsimport java.lang.reflect.Method;
2140c6251719cccc0a84ae99c976d2836b14374ce6Christian Williamsimport java.util.ArrayList;
22b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williamsimport java.util.HashMap;
2340c6251719cccc0a84ae99c976d2836b14374ce6Christian Williamsimport java.util.List;
24b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williamsimport java.util.Map;
25b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williams
26e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chenimport javassist.bytecode.Mnemonic;
27e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen
28a8486da7c7a0b6a10e943c55992f34d9c256456dChristian Williamsimport static com.xtremelabs.robolectric.Robolectric.shadowOf;
296eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
306a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin
316eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz@SuppressWarnings({"UnusedDeclaration"})
320b378afcde0200166e546c46a7642015accfce49Christian Williams & Ian Fisher@Implements(Activity.class)
33afe0a89d904a7fe2f5980b9deb26cc3240192459Christian Williamspublic class ShadowActivity extends ShadowContextWrapper {
3485af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    @RealObject
356b92d0bcbd859dbd8f4d14b65f633d3b694a449cJan Berkel    protected Activity realActivity;
364a7b7902404d0c3743f96c043e3cc6b9069cf438Christian Williams
37e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz    private Intent intent;
384e3b6432e36c8d7e95cee1066bd71a511f7c7b88Chris Perry & Phil Goodwin    private FrameLayout contentViewContainer;
394e3b6432e36c8d7e95cee1066bd71a511f7c7b88Chris Perry & Phil Goodwin    private View contentView;
40c6526af59ebcc818c95680ac6f8efe83a0b65644adriancowham    private int orientation;
41de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin    private int resultCode;
42de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin    private Intent resultIntent;
43de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin    private Activity parent;
446d32429ccdfb0cb8ce602093e915ac51b7dda901Christian Williams & Joe Moore    private boolean finishWasCalled;
4538c16130a7d0b2709049b010bbb14336e1d25d2dPhil Goodwin & Ryan Richard    private TestWindow window;
46256949ba5562873047aecf1bf47533e5ae1cd933Phil Goodwin & Phil Plante
474c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi    private List<IntentForResult> startedActivitiesForResults = new ArrayList<IntentForResult>();
48f33e228a6f3eed1c97488df2ca30da315324aa1eHarry Ugol
49b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williams    private Map<Intent, Integer> intentRequestCodeMap = new HashMap<Intent, Integer>();
5085af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    private int requestedOrientation = -1;
5185af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    private View currentFocus;
5285af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    private Integer lastShownDialogId = null;
53b2bf0f618dcabd9e1340f2ec255821b8fd461a93Lowell Kirsh & Ryan Richard    private int pendingTransitionEnterAnimResId = -1;
54b2bf0f618dcabd9e1340f2ec255821b8fd461a93Lowell Kirsh & Ryan Richard    private int pendingTransitionExitAnimResId = -1;
5507e6c6574361950efbc98100729ccc2646c60000Chris Heisterkamp & Ryan Richard    private Object lastNonConfigurationInstance;
56256949ba5562873047aecf1bf47533e5ae1cd933Phil Goodwin & Phil Plante    private Map<Integer, Dialog> dialogForId = new HashMap<Integer, Dialog>();
57a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi    private CharSequence title;
5805d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard    private boolean onKeyUpWasCalled;
59e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen    private ArrayList<Cursor> managedCusors = new ArrayList<Cursor>();
60b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williams
61de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
62490535650f83cedb8fdd58aa3c4a928ce843e794Harry Ugol & Ian Fisher    public final Application getApplication() {
63345fb6b77303f0d3c98cf748fefa0136183bdc79Christian Williams        return Robolectric.application;
64490535650f83cedb8fdd58aa3c4a928ce843e794Harry Ugol & Ian Fisher    }
656eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
6685af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    @Override
6785af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    @Implementation
68a7e263ae4add03982ef3fe294d72ae43102ce52eChristian Williams    public final Application getApplicationContext() {
69a7e263ae4add03982ef3fe294d72ae43102ce52eChristian Williams        return getApplication();
70a7e263ae4add03982ef3fe294d72ae43102ce52eChristian Williams    }
71a7e263ae4add03982ef3fe294d72ae43102ce52eChristian Williams
72a7e263ae4add03982ef3fe294d72ae43102ce52eChristian Williams    @Implementation
73e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz    public void setIntent(Intent intent) {
74e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz        this.intent = intent;
75e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz    }
76e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz
77de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
78e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz    public Intent getIntent() {
79e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz        return intent;
80e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz    }
8105d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard
8205d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard    @Implementation(i18nSafe = false)
83a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi    public void setTitle(CharSequence title) {
8405d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard        this.title = title;
85a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi    }
8605d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard
87a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi    @Implementation
88a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi    public void setTitle(int titleId) {
8905d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard        this.title = this.getResources().getString(titleId);
90a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi    }
9105d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard
92a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi    @Implementation
93a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi    public CharSequence getTitle() {
9405d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard        return title;
95a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi    }
9605d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard
976a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin    /**
986a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * Sets the {@code contentView} for this {@code Activity} by invoking the
996a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * {@link android.view.LayoutInflater}
1006a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     *
1016a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * @param layoutResID ID of the layout to inflate
1026a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * @see #getContentView()
1036a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     */
104de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
105e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz    public void setContentView(int layoutResID) {
106297cc102ff285524a4109025ecd2c9c6ef051ce5Jan Berkel        contentView = getLayoutInflater().inflate(layoutResID, new FrameLayout(realActivity));
107966bbed22d63d7eb0f481bfbd54b860c3607153eCristian        realActivity.onContentChanged();
108e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz    }
1096eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz
110de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
111b9f02c365280d0ffd0a516243ebbebdd59dbc48aHarry    public void setContentView(View view) {
112b9f02c365280d0ffd0a516243ebbebdd59dbc48aHarry        contentView = view;
113966bbed22d63d7eb0f481bfbd54b860c3607153eCristian        realActivity.onContentChanged();
114b9f02c365280d0ffd0a516243ebbebdd59dbc48aHarry    }
115b9f02c365280d0ffd0a516243ebbebdd59dbc48aHarry
116de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
1178d051375a72a04d241756de2cc1df69d4bad30c6Joe Moore & Tyler Schultz    public final void setResult(int resultCode) {
1188d051375a72a04d241756de2cc1df69d4bad30c6Joe Moore & Tyler Schultz        this.resultCode = resultCode;
1198d051375a72a04d241756de2cc1df69d4bad30c6Joe Moore & Tyler Schultz    }
1208d051375a72a04d241756de2cc1df69d4bad30c6Joe Moore & Tyler Schultz
121de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
12277e577374c759ae8ecbe8b63b9d42088992a1d50Joe Moore & Tyler Schultz    public final void setResult(int resultCode, Intent data) {
12377e577374c759ae8ecbe8b63b9d42088992a1d50Joe Moore & Tyler Schultz        this.resultCode = resultCode;
1246a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin        this.resultIntent = data;
12577e577374c759ae8ecbe8b63b9d42088992a1d50Joe Moore & Tyler Schultz    }
12677e577374c759ae8ecbe8b63b9d42088992a1d50Joe Moore & Tyler Schultz
127de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
128b9f02c365280d0ffd0a516243ebbebdd59dbc48aHarry    public LayoutInflater getLayoutInflater() {
12986335af816f048e32aad504aed0af63a73097a5fChristian Williams & Ryan Richard        return LayoutInflater.from(realActivity);
130b9f02c365280d0ffd0a516243ebbebdd59dbc48aHarry    }
131b9f02c365280d0ffd0a516243ebbebdd59dbc48aHarry
132323c0d5f6b7280968122e3984ed5dc00978c2467Tom Parker    @Implementation
133323c0d5f6b7280968122e3984ed5dc00978c2467Tom Parker    public MenuInflater getMenuInflater() {
134323c0d5f6b7280968122e3984ed5dc00978c2467Tom Parker        return new MenuInflater(realActivity);
135323c0d5f6b7280968122e3984ed5dc00978c2467Tom Parker    }
136323c0d5f6b7280968122e3984ed5dc00978c2467Tom Parker
1376a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin    /**
1386a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * Checks to ensure that the{@code contentView} has been set
1396a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     *
1406a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * @param id ID of the view to find
1416a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * @return the view
1426a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * @throws RuntimeException if the {@code contentView} has not been called first
1436a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     */
144de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
145e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz    public View findViewById(int id) {
1464e3b6432e36c8d7e95cee1066bd71a511f7c7b88Chris Perry & Phil Goodwin        if (id == android.R.id.content) {
1474e3b6432e36c8d7e95cee1066bd71a511f7c7b88Chris Perry & Phil Goodwin            return getContentViewContainer();
1484e3b6432e36c8d7e95cee1066bd71a511f7c7b88Chris Perry & Phil Goodwin        }
149e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz        if (contentView != null) {
150e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz            return contentView.findViewById(id);
151e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz        } else {
152793f1b31caba17266599fcb55485ae7231082d5cChristian Williams            System.out.println("WARNING: you probably should have called setContentView() first");
15391ec6eaa1421596efd53caa7044b17f7d7fb5981Rich Humphrey            Thread.dumpStack();
154793f1b31caba17266599fcb55485ae7231082d5cChristian Williams            return null;
155e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz        }
156e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz    }
157e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz
1584e3b6432e36c8d7e95cee1066bd71a511f7c7b88Chris Perry & Phil Goodwin    private View getContentViewContainer() {
1594e3b6432e36c8d7e95cee1066bd71a511f7c7b88Chris Perry & Phil Goodwin        if (contentViewContainer == null) {
1604e3b6432e36c8d7e95cee1066bd71a511f7c7b88Chris Perry & Phil Goodwin            contentViewContainer = new FrameLayout(realActivity);
1614e3b6432e36c8d7e95cee1066bd71a511f7c7b88Chris Perry & Phil Goodwin        }
1624e3b6432e36c8d7e95cee1066bd71a511f7c7b88Chris Perry & Phil Goodwin        contentViewContainer.addView(contentView, 0);
1634e3b6432e36c8d7e95cee1066bd71a511f7c7b88Chris Perry & Phil Goodwin        return contentViewContainer;
1644e3b6432e36c8d7e95cee1066bd71a511f7c7b88Chris Perry & Phil Goodwin    }
1654e3b6432e36c8d7e95cee1066bd71a511f7c7b88Chris Perry & Phil Goodwin
166de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
16720a4d94c942081c83c7d270680df40e73b8896b5Ryan Richard & Tyler Schultz    public final Activity getParent() {
16820a4d94c942081c83c7d270680df40e73b8896b5Ryan Richard & Tyler Schultz        return parent;
16920a4d94c942081c83c7d270680df40e73b8896b5Ryan Richard & Tyler Schultz    }
17020a4d94c942081c83c7d270680df40e73b8896b5Ryan Richard & Tyler Schultz
171de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
17285af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    public void onBackPressed() {
17385af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        finish();
17485af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    }
17585af7906879a68c99b1878dac22605fa32454f3fRich Humphrey
17685af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    @Implementation
177e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz    public void finish() {
178e617325bfe357b73644421064cae37e0a033eed7Christian Williams & Tyler Schulz        finishWasCalled = true;
1796eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz    }
18040c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams
181db9bbf49c96c3a9d1e61d17ba60610661d8ed2caAaron VonderHaar & Amrit Thakur    public void resetIsFinishing() {
182db9bbf49c96c3a9d1e61d17ba60610661d8ed2caAaron VonderHaar & Amrit Thakur        finishWasCalled = false;
183db9bbf49c96c3a9d1e61d17ba60610661d8ed2caAaron VonderHaar & Amrit Thakur    }
184db9bbf49c96c3a9d1e61d17ba60610661d8ed2caAaron VonderHaar & Amrit Thakur
1856a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin    /**
1866a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * @return whether {@link #finish()} was called
1876a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     */
188de9feed5ddf1d91a3e76cbc71712c36a7652201eChristian Williams    @Implementation
1896d32429ccdfb0cb8ce602093e915ac51b7dda901Christian Williams & Joe Moore    public boolean isFinishing() {
1906d32429ccdfb0cb8ce602093e915ac51b7dda901Christian Williams & Joe Moore        return finishWasCalled;
1916d32429ccdfb0cb8ce602093e915ac51b7dda901Christian Williams & Joe Moore    }
1926a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin
1936a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin    /**
1942cdde11355e7c249e83a8b7aaabae5977bbc3e49Phil Goodwin     * Constructs a new Window (a {@link com.xtremelabs.robolectric.tester.android.view.TestWindow}) if no window has previously been
1956a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * set.
196adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams     *
1976a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * @return the window associated with this Activity
1986a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     */
1996d32429ccdfb0cb8ce602093e915ac51b7dda901Christian Williams & Joe Moore    @Implementation
200964491a5d5046523f1ca8e9a3b30779420d79034Ryan Richard    public Window getWindow() {
201adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams        if (window == null) {
202964491a5d5046523f1ca8e9a3b30779420d79034Ryan Richard            window = new TestWindow(realActivity);
203964491a5d5046523f1ca8e9a3b30779420d79034Ryan Richard        }
204964491a5d5046523f1ca8e9a3b30779420d79034Ryan Richard        return window;
205964491a5d5046523f1ca8e9a3b30779420d79034Ryan Richard    }
2060add4ea006647573fc11fac463c87842f2dcc403Christian Williams
2073fc6cac3677cd2ca3958dfb5d4598728d304db4fWenhui Yao    public void setWindow(TestWindow wind){
2083fc6cac3677cd2ca3958dfb5d4598728d304db4fWenhui Yao    	window = wind;
2093fc6cac3677cd2ca3958dfb5d4598728d304db4fWenhui Yao    }
2103fc6cac3677cd2ca3958dfb5d4598728d304db4fWenhui Yao
211a4f7d50f8e6f12d541421383544fe16c185e4bbcPhil Goodwin & Tyler Schultz    @Implementation
212a4f7d50f8e6f12d541421383544fe16c185e4bbcPhil Goodwin & Tyler Schultz    public void runOnUiThread(Runnable action) {
213f64d95f87eb9715622e3f77eb0b369d60270054cChristian Williams & Phil Goodwin        Robolectric.getUiThreadScheduler().post(action);
214a4f7d50f8e6f12d541421383544fe16c185e4bbcPhil Goodwin & Tyler Schultz    }
215a4f7d50f8e6f12d541421383544fe16c185e4bbcPhil Goodwin & Tyler Schultz
2163bbad72d54226c0899e42fe657958a31694980cfRyan Richard    @Implementation
2173bbad72d54226c0899e42fe657958a31694980cfRyan Richard    public void onCreate(Bundle bundle) {
2183bbad72d54226c0899e42fe657958a31694980cfRyan Richard
2193bbad72d54226c0899e42fe657958a31694980cfRyan Richard    }
2203bbad72d54226c0899e42fe657958a31694980cfRyan Richard
2216a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin    /**
2226a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * Checks to see if {@code BroadcastListener}s are still registered.
223adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams     *
2246a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * @throws RuntimeException if any listeners are still registered
225adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams     * @see #assertNoBroadcastListenersRegistered()
2266a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     */
2270add4ea006647573fc11fac463c87842f2dcc403Christian Williams    @Implementation
2280add4ea006647573fc11fac463c87842f2dcc403Christian Williams    public void onDestroy() {
2290add4ea006647573fc11fac463c87842f2dcc403Christian Williams        assertNoBroadcastListenersRegistered();
2300add4ea006647573fc11fac463c87842f2dcc403Christian Williams    }
23140c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams
23285af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    @Implementation
23385af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    public WindowManager getWindowManager() {
23485af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        return (WindowManager) Robolectric.application.getSystemService(Context.WINDOW_SERVICE);
23585af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    }
23685af7906879a68c99b1878dac22605fa32454f3fRich Humphrey
23785af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    @Implementation
23885af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    public void setRequestedOrientation(int requestedOrientation) {
23985af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        this.requestedOrientation = requestedOrientation;
24085af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    }
24185af7906879a68c99b1878dac22605fa32454f3fRich Humphrey
24285af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    @Implementation
24385af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    public int getRequestedOrientation() {
24485af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        return requestedOrientation;
24585af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    }
246521cabb44ef11199544abf17cfc1b7fb84019914Jon Boekenoogen
24796bd436ce2e84a30747574ce2b7e4ef5e61bc3d0Valtteri Virtanen    @Implementation
24896bd436ce2e84a30747574ce2b7e4ef5e61bc3d0Valtteri Virtanen    public SharedPreferences getPreferences(int mode) {
2494e38d69f092a879f1a8ba5cc8dce8526da47851aTyler Schultz    	return ShadowPreferenceManager.getDefaultSharedPreferences(getApplicationContext());
25096bd436ce2e84a30747574ce2b7e4ef5e61bc3d0Valtteri Virtanen    }
25185af7906879a68c99b1878dac22605fa32454f3fRich Humphrey
2526a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin    /**
2536a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * Checks the {@code ApplicationContext} to see if {@code BroadcastListener}s are still registered.
254adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams     *
2556a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * @throws RuntimeException if any listeners are still registered
256adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams     * @see ShadowApplication#assertNoBroadcastListenersRegistered(android.content.Context, String)
2576a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     */
2580add4ea006647573fc11fac463c87842f2dcc403Christian Williams    public void assertNoBroadcastListenersRegistered() {
259793f1b31caba17266599fcb55485ae7231082d5cChristian Williams        shadowOf(getApplicationContext()).assertNoBroadcastListenersRegistered(realActivity, "Activity");
2600add4ea006647573fc11fac463c87842f2dcc403Christian Williams    }
261de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin
2626a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin    /**
263adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams     * Non-Android accessor.
264adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams     *
2656a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * @return the {@code contentView} set by one of the {@code setContentView()} methods
2666a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     */
267de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin    public View getContentView() {
268de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin        return contentView;
269de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin    }
270de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin
2716a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin    /**
272adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams     * Non-Android accessor.
273adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams     *
2746a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * @return the {@code resultCode} set by one of the {@code setResult()} methods
2756a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     */
276de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin    public int getResultCode() {
277de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin        return resultCode;
278de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin    }
279de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin
2806a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin    /**
281adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams     * Non-Android accessor.
282adfaceabbda4c8c51f24a0def8926075bd7306adChristian Williams     *
2836a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     * @return the {@code Intent} set by {@link #setResult(int, android.content.Intent)}
2846a3415646e4410abf4766e5e7fad273a2bd042acPhil Goodwin     */
285de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin    public Intent getResultIntent() {
286de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin        return resultIntent;
287de22c4308f53c746aed662ca08c9df02ec87bed3Christian Williams & Phil Goodwin    }
28840c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams
2894c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi    /**
2904c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi     * Non-Android accessor consumes and returns the next {@code Intent} on the
2914c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi     * started activities for results stack.
2924c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi     *
2934e4c8a7fa80af5449f4e5ec4df9a56e3713a7a6eMichael Portuesi     * @return the next started {@code Intent} for an activity, wrapped in
29440c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams     *         an {@link ShadowActivity.IntentForResult} object
2954c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi     */
2964c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi    public IntentForResult getNextStartedActivityForResult() {
2974c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi        if (startedActivitiesForResults.isEmpty()) {
29840c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams            return null;
2994c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi        } else {
30040c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams            return startedActivitiesForResults.remove(0);
3014c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi        }
3024c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi    }
30340c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams
3044c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi    /**
3054c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi     * Non-Android accessor returns the most recent {@code Intent} started by
30640c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams     * {@link #startActivityForResult(android.content.Intent, int)} without
3074c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi     * consuming it.
3084c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi     *
3094e4c8a7fa80af5449f4e5ec4df9a56e3713a7a6eMichael Portuesi     * @return the most recently started {@code Intent}, wrapped in
31040c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams     *         an {@link ShadowActivity.IntentForResult} object
3114c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi     */
3124c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi    public IntentForResult peekNextStartedActivityForResult() {
3134c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi        if (startedActivitiesForResults.isEmpty()) {
3144c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi            return null;
3154c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi        } else {
3164c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi            return startedActivitiesForResults.get(0);
3174c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi        }
3184c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi    }
31940c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams
32007e6c6574361950efbc98100729ccc2646c60000Chris Heisterkamp & Ryan Richard    @Implementation
32107e6c6574361950efbc98100729ccc2646c60000Chris Heisterkamp & Ryan Richard    public Object getLastNonConfigurationInstance() {
32207e6c6574361950efbc98100729ccc2646c60000Chris Heisterkamp & Ryan Richard        return lastNonConfigurationInstance;
32307e6c6574361950efbc98100729ccc2646c60000Chris Heisterkamp & Ryan Richard    }
32407e6c6574361950efbc98100729ccc2646c60000Chris Heisterkamp & Ryan Richard
32507e6c6574361950efbc98100729ccc2646c60000Chris Heisterkamp & Ryan Richard    public void setLastNonConfigurationInstance(Object lastNonConfigurationInstance) {
32607e6c6574361950efbc98100729ccc2646c60000Chris Heisterkamp & Ryan Richard        this.lastNonConfigurationInstance = lastNonConfigurationInstance;
32707e6c6574361950efbc98100729ccc2646c60000Chris Heisterkamp & Ryan Richard    }
32807e6c6574361950efbc98100729ccc2646c60000Chris Heisterkamp & Ryan Richard
3294c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi    /**
33085af7906879a68c99b1878dac22605fa32454f3fRich Humphrey     * Non-Android accessor Sets the {@code View} for this {@code Activity}
33185af7906879a68c99b1878dac22605fa32454f3fRich Humphrey     *
33285af7906879a68c99b1878dac22605fa32454f3fRich Humphrey     * @param view
33385af7906879a68c99b1878dac22605fa32454f3fRich Humphrey     */
33485af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    public void setCurrentFocus(View view) {
33585af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        currentFocus = view;
33685af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    }
33785af7906879a68c99b1878dac22605fa32454f3fRich Humphrey
33885af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    @Implementation
33985af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    public View getCurrentFocus() {
34010afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias        if (currentFocus != null) {
34110afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias            return currentFocus;
34210afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias        } else if (contentView != null) {
34310afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias            return contentView.findFocus();
34410afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias        } else {
34510afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias            return null;
34610afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias        }
34710afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias    }
34810afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias
34910afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias    public void clearFocus() {
35010afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias        currentFocus = null;
35110afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias        if (contentView != null) {
35210afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias            contentView.clearFocus();
35310afa627a8dc3aba930189ee6b15d1aa99531ec8Cristian Esquivias        }
35485af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    }
35585af7906879a68c99b1878dac22605fa32454f3fRich Humphrey
35605d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard    @Implementation
35705d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard    public boolean onKeyUp(int keyCode, KeyEvent event) {
35805d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard        onKeyUpWasCalled = true;
35905d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard        if (keyCode == KeyEvent.KEYCODE_BACK) {
36005d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard            onBackPressed();
36105d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard            return true;
36205d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard        }
36305d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard        return false;
36405d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard    }
36505d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard
36605d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard    public boolean onKeyUpWasCalled() {
36705d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard        return onKeyUpWasCalled;
36805d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard    }
36905d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard
37005d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard    public void resetKeyUpWasCalled() {
37105d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard        onKeyUpWasCalled = false;
37205d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard    }
37305d5fa490c39eae46684f666a66acb8edf42661cPhil Goodwin & Ryan Richard
37485af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    /**
3754c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi     * Container object to hold an Intent, together with the requestCode used
3764c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi     * in a call to {@code Activity#startActivityForResult(Intent, int)}
3774c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi     */
3784c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi    public class IntentForResult {
37940c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams        public Intent intent;
38040c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams        public int requestCode;
38140c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams
38240c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams        public IntentForResult(Intent intent, int requestCode) {
38340c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams            this.intent = intent;
38440c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams            this.requestCode = requestCode;
38540c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams        }
3864c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi    }
3874c183658bf1ab87148cfdc61d7669c2ab670fbcbMichael Portuesi
388b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williams    @Implementation
389b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williams    public void startActivityForResult(Intent intent, int requestCode) {
390b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williams        intentRequestCodeMap.put(intent, requestCode);
39140c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams        startedActivitiesForResults.add(new IntentForResult(intent, requestCode));
39240c6251719cccc0a84ae99c976d2836b14374ce6Christian Williams        getApplicationContext().startActivity(intent);
393b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williams    }
394b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williams
395b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williams    public void receiveResult(Intent requestIntent, int resultCode, Intent resultIntent) {
396b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williams        Integer requestCode = intentRequestCodeMap.get(requestIntent);
397b76cabccd9f35b57fe486faf7d5763952c07c1a9Josh Lauer & Christian Williams        if (requestCode == null) {
398b01474a3329222965d31068f5c33e59c6e6aa6a4Josh Lauer & Christian Williams            throw new RuntimeException("No intent matches " + requestIntent + " among " + intentRequestCodeMap.keySet());
399b76cabccd9f35b57fe486faf7d5763952c07c1a9Josh Lauer & Christian Williams        }
4006439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson
4016439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        final ActivityInvoker invoker = new ActivityInvoker();
4026439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        invoker.call("onActivityResult", Integer.TYPE, Integer.TYPE, Intent.class)
4036439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            .with(requestCode, resultCode, resultIntent);
404b832a2815d03667cbe1415bfcfd596292cb76f85Josh Lauer & Christian Williams    }
40585af7906879a68c99b1878dac22605fa32454f3fRich Humphrey
40688a7b3c27c736843e69e6ec12c1d7c7397c14d1cRich Humphrey    @Implementation
40785af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    public final void showDialog(int id) {
40885af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        showDialog(id, null);
40988a7b3c27c736843e69e6ec12c1d7c7397c14d1cRich Humphrey    }
4108e3b1f6515f98cbaad5809be132e3914973bb9a2Aaron VonderHaar & Amrit Thakur
4116c243b00fee6298c384d10f2cf97508d24237633Matthias Kiefer    @Implementation
412943730659b697ae049fe203b2a51d75113c49cb5Chuck Greb    public final void dismissDialog(int id) {
413943730659b697ae049fe203b2a51d75113c49cb5Chuck Greb        final Dialog dialog = dialogForId.get(id);
414943730659b697ae049fe203b2a51d75113c49cb5Chuck Greb        if (dialog == null) {
415943730659b697ae049fe203b2a51d75113c49cb5Chuck Greb            throw new IllegalArgumentException();
416943730659b697ae049fe203b2a51d75113c49cb5Chuck Greb        }
417943730659b697ae049fe203b2a51d75113c49cb5Chuck Greb
418943730659b697ae049fe203b2a51d75113c49cb5Chuck Greb        dialog.dismiss();
419943730659b697ae049fe203b2a51d75113c49cb5Chuck Greb    }
420943730659b697ae049fe203b2a51d75113c49cb5Chuck Greb
421943730659b697ae049fe203b2a51d75113c49cb5Chuck Greb    @Implementation
4226c243b00fee6298c384d10f2cf97508d24237633Matthias Kiefer    public final void removeDialog(int id) {
4236c243b00fee6298c384d10f2cf97508d24237633Matthias Kiefer        dialogForId.remove(id);
4246c243b00fee6298c384d10f2cf97508d24237633Matthias Kiefer    }
42585af7906879a68c99b1878dac22605fa32454f3fRich Humphrey
4266d2daa795cd59a43fbebc4e10e0a314a5440bb59Rich Humphrey    @Implementation
42785af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    public final boolean showDialog(int id, Bundle bundle) {
42885af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        Dialog dialog = null;
42985af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        this.lastShownDialogId = id;
43085af7906879a68c99b1878dac22605fa32454f3fRich Humphrey
431256949ba5562873047aecf1bf47533e5ae1cd933Phil Goodwin & Phil Plante        dialog = dialogForId.get(id);
432256949ba5562873047aecf1bf47533e5ae1cd933Phil Goodwin & Phil Plante
433256949ba5562873047aecf1bf47533e5ae1cd933Phil Goodwin & Phil Plante        if (dialog == null) {
4346439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            final ActivityInvoker invoker = new ActivityInvoker();
4356439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            dialog = (Dialog) invoker.call("onCreateDialog", Integer.TYPE).with(id);
4366439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson
4376439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            if (bundle == null) {
4386439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson                invoker.call("onPrepareDialog", Integer.TYPE, Dialog.class)
4396439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson                    .with(id, dialog);
4406439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            } else {
4416439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson                invoker.call("onPrepareDialog", Integer.TYPE, Dialog.class, Bundle.class)
4426439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson                    .with(id, dialog, bundle);
44385af7906879a68c99b1878dac22605fa32454f3fRich Humphrey            }
444256949ba5562873047aecf1bf47533e5ae1cd933Phil Goodwin & Phil Plante
445256949ba5562873047aecf1bf47533e5ae1cd933Phil Goodwin & Phil Plante            dialogForId.put(id, dialog);
4466d2daa795cd59a43fbebc4e10e0a314a5440bb59Rich Humphrey        }
44785af7906879a68c99b1878dac22605fa32454f3fRich Humphrey
44885af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        dialog.show();
44985af7906879a68c99b1878dac22605fa32454f3fRich Humphrey
45085af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        return true;
4516d2daa795cd59a43fbebc4e10e0a314a5440bb59Rich Humphrey    }
45285af7906879a68c99b1878dac22605fa32454f3fRich Humphrey
45385af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    /**
45485af7906879a68c99b1878dac22605fa32454f3fRich Humphrey     * Non-Android accessor
45585af7906879a68c99b1878dac22605fa32454f3fRich Humphrey     *
45685af7906879a68c99b1878dac22605fa32454f3fRich Humphrey     * @return the dialog resource id passed into
45785af7906879a68c99b1878dac22605fa32454f3fRich Humphrey     *         {@code Activity#showDialog(int, Bundle)} or {@code Activity#showDialog(int)}
45885af7906879a68c99b1878dac22605fa32454f3fRich Humphrey     */
45985af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    public Integer getLastShownDialogId() {
46085af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        return lastShownDialogId;
46188a7b3c27c736843e69e6ec12c1d7c7397c14d1cRich Humphrey    }
462256949ba5562873047aecf1bf47533e5ae1cd933Phil Goodwin & Phil Plante
463b2bf0f618dcabd9e1340f2ec255821b8fd461a93Lowell Kirsh & Ryan Richard    public boolean hasCancelledPendingTransitions() {
464b2bf0f618dcabd9e1340f2ec255821b8fd461a93Lowell Kirsh & Ryan Richard        return pendingTransitionEnterAnimResId == 0 && pendingTransitionExitAnimResId == 0;
465f2d58029c81a9729d0e640254762fc99a2a8924dLowell Kirsh & Ryan Richard    }
466f2d58029c81a9729d0e640254762fc99a2a8924dLowell Kirsh & Ryan Richard
467f2d58029c81a9729d0e640254762fc99a2a8924dLowell Kirsh & Ryan Richard    @Implementation
468f2d58029c81a9729d0e640254762fc99a2a8924dLowell Kirsh & Ryan Richard    public void overridePendingTransition(int enterAnim, int exitAnim) {
469b2bf0f618dcabd9e1340f2ec255821b8fd461a93Lowell Kirsh & Ryan Richard        pendingTransitionEnterAnimResId = enterAnim;
470b2bf0f618dcabd9e1340f2ec255821b8fd461a93Lowell Kirsh & Ryan Richard        pendingTransitionExitAnimResId = exitAnim;
471f2d58029c81a9729d0e640254762fc99a2a8924dLowell Kirsh & Ryan Richard    }
4728e3b1f6515f98cbaad5809be132e3914973bb9a2Aaron VonderHaar & Amrit Thakur
473731e10cf870a791a5730a7d3a92a0735d6739bc8Jessica Chen    public Dialog getDialogById(int dialogId) {
4748e3b1f6515f98cbaad5809be132e3914973bb9a2Aaron VonderHaar & Amrit Thakur        return dialogForId.get(dialogId);
4758e3b1f6515f98cbaad5809be132e3914973bb9a2Aaron VonderHaar & Amrit Thakur    }
476521cabb44ef11199544abf17cfc1b7fb84019914Jon Boekenoogen
477f9fae237b421f257e8fcc2316d8fcfde81762537Levi Wilson    public void create() {
4786439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        final ActivityInvoker invoker = new ActivityInvoker();
4796439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson
4806439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        final Bundle noInstanceState = null;
4816439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        invoker.call("onCreate", Bundle.class).with(noInstanceState);
4826439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        invoker.call("onStart").withNothing();
4836439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        invoker.call("onPostCreate", Bundle.class).with(noInstanceState);
4846439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        invoker.call("onResume").withNothing();
485f9fae237b421f257e8fcc2316d8fcfde81762537Levi Wilson    }
486f9fae237b421f257e8fcc2316d8fcfde81762537Levi Wilson
4870bcbd37475c4774b3287f0a403ac26ca84a029efMichael Portuesi    @Implementation
488521cabb44ef11199544abf17cfc1b7fb84019914Jon Boekenoogen    public void recreate() {
4896439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        Bundle outState = new Bundle();
4906439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        final ActivityInvoker invoker = new ActivityInvoker();
4916439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson
4926439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        invoker.call("onSaveInstanceState", Bundle.class).with(outState);
4936439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        invoker.call("onPause").withNothing();
4946439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        invoker.call("onStop").withNothing();
4956439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson
4966439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        Object nonConfigInstance = invoker.call("onRetainNonConfigurationInstance").withNothing();
4976439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        setLastNonConfigurationInstance(nonConfigInstance);
4986439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson
4996439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        invoker.call("onDestroy").withNothing();
5006439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        invoker.call("onCreate", Bundle.class).with(outState);
5016439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        invoker.call("onStart").withNothing();
5026439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        invoker.call("onRestoreInstanceState", Bundle.class).with(outState);
5036439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        invoker.call("onResume").withNothing();
5046439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson    }
505e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen
506e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen    @Implementation
507e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen    public void startManagingCursor(Cursor c) {
508e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen    	managedCusors.add(c);
509e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen    }
5106439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson
511e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen    @Implementation
512e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen    public void stopManagingCursor(Cursor c) {
513e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen    	managedCusors.remove(c);
514e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen    }
515e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen
516e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen    public List<Cursor> getManagedCursors() {
517e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen    	return managedCusors;
518e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen    }
519e1fc833767e4f78b1fc6d17d21b15bad3986260fJessica Chen
5206439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson    private final class ActivityInvoker {
5216439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        private Method method;
5226439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson
5236439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        public ActivityInvoker call(final String methodName, final Class ...argumentClasses) {
5246439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            try {
5256439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson                method = Activity.class.getDeclaredMethod(methodName, argumentClasses);
5266439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson                method.setAccessible(true);
5276439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson                return this;
5286439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            } catch(NoSuchMethodException e) {
5296439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson                throw new RuntimeException(e);
5306439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            }
5316439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        }
5326439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson
5336439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        public Object withNothing() {
5346439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            return with();
5356439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        }
5366439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson
5376439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson        public Object with(final Object ...parameters) {
5386439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            try {
5396439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson                return method.invoke(realActivity, parameters);
5406439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            } catch(IllegalAccessException e) {
5416439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson                throw new RuntimeException(e);
5426439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            } catch(IllegalArgumentException e) {
5436439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson                throw new RuntimeException(e);
5446439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            } catch(InvocationTargetException e) {
5456439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson                throw new RuntimeException(e);
5466439c8aedb81ba816d7a7d386fa85a045c4329f7Levi Wilson            }
547521cabb44ef11199544abf17cfc1b7fb84019914Jon Boekenoogen        }
548521cabb44ef11199544abf17cfc1b7fb84019914Jon Boekenoogen    }
5496eedf728138e6f79fa898ff3e31bf61c9b1151dChristian Williams & Tyler Schulz}
550