133873d2b41a5cd2597b20a4e88eb8942944c0f23Tyler Schultzpackage com.xtremelabs.robolectric.shadows;
250e71a2777cae2b5f630448c5ab22be4066d4d6dChristian Williams & Ryan Richard
343d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultzimport android.R;
450e71a2777cae2b5f630448c5ab22be4066d4d6dChristian Williams & Ryan Richardimport android.app.AlertDialog;
550e71a2777cae2b5f630448c5ab22be4066d4d6dChristian Williams & Ryan Richardimport android.content.Context;
650e71a2777cae2b5f630448c5ab22be4066d4d6dChristian Williams & Ryan Richardimport android.content.DialogInterface;
750e71a2777cae2b5f630448c5ab22be4066d4d6dChristian Williams & Ryan Richardimport android.view.View;
8f1db8d709d4596bde52bcead212b396b81635123pivotalimport android.widget.Adapter;
943d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultzimport android.widget.AdapterView;
1043d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultzimport android.widget.ArrayAdapter;
11f5856a910e7581637c23b0e8568ef299be1bcd04Christian Williams & Tyler Schultzimport android.widget.Button;
12f1db8d709d4596bde52bcead212b396b81635123pivotalimport android.widget.ListAdapter;
1343d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultzimport android.widget.ListView;
14854ca0a46da43847ab5b2ed9ce4ad8f580ae5a17Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.Robolectric;
1522c22c9aa4ca68c2deac6164edc1d82bc9645310Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.Implementation;
1622c22c9aa4ca68c2deac6164edc1d82bc9645310Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.Implements;
1722c22c9aa4ca68c2deac6164edc1d82bc9645310Christian Williams & Phil Goodwinimport com.xtremelabs.robolectric.internal.RealObject;
1850e71a2777cae2b5f630448c5ab22be4066d4d6dChristian Williams & Ryan Richard
1972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwinimport java.lang.reflect.Constructor;
2072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
219c6f1b1bf3d0bb2c6bb2abbf7fe8f21a137891f3Glenn Jahnke & Phil Goodwinimport static com.xtremelabs.robolectric.Robolectric.getShadowApplication;
2272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwinimport static com.xtremelabs.robolectric.Robolectric.shadowOf;
2372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
24c1939651f1f399da668bdd59b900ad897f2b3a27pivotal@SuppressWarnings({"UnusedDeclaration"})
2550e71a2777cae2b5f630448c5ab22be4066d4d6dChristian Williams & Ryan Richard@Implements(AlertDialog.class)
26afe0a89d904a7fe2f5980b9deb26cc3240192459Christian Williamspublic class ShadowAlertDialog extends ShadowDialog {
2704d0a37ddf290c5e0543b0ebc91a3222bbe6e84cJoe Moore & Ryan Richard    @RealObject
2804d0a37ddf290c5e0543b0ebc91a3222bbe6e84cJoe Moore & Ryan Richard    private AlertDialog realAlertDialog;
2904d0a37ddf290c5e0543b0ebc91a3222bbe6e84cJoe Moore & Ryan Richard
3072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    private CharSequence[] items;
3185af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    private String message;
3272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    private DialogInterface.OnClickListener clickListener;
3372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    private boolean isMultiItem;
3472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    private boolean isSingleItem;
3572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    private DialogInterface.OnMultiChoiceClickListener multiChoiceClickListener;
3672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    private boolean[] checkedItems;
3772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    private int checkedItemIndex;
3872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    private Button positiveButton;
3972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    private Button negativeButton;
4072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    private Button neutralButton;
4157bcb4abedb50df96719d9e568fe09d06055360dLowell Kirsh    private View view;
42d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz    private View customTitleView;
4343d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz    private ListAdapter adapter;
4443d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz    private ListView listView;
4572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
4672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    /**
4772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     * Non-Android accessor.
4872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     *
4972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     * @return the most recently created {@code AlertDialog}, or null if none has been created during this test run
5072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     */
51ec07ffb13702733c07a846308de902a6f68977f2David Farber & Ryan Richard    public static AlertDialog getLatestAlertDialog() {
52ec07ffb13702733c07a846308de902a6f68977f2David Farber & Ryan Richard        ShadowAlertDialog dialog = Robolectric.getShadowApplication().getLatestAlertDialog();
535117035453920f3d4d0f3969bdab0305dcdb94baJoe Moore & Ryan Richard        return dialog == null ? null : dialog.realAlertDialog;
5472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    }
5572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
5672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    @Override
5772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    @Implementation
5872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    public View findViewById(int viewId) {
5957bcb4abedb50df96719d9e568fe09d06055360dLowell Kirsh        if(view == null) {
606a89c2aeb7fd6ad6abea8614ef54a450cb0a5211Joe Moore, Phil Goodwin & Rick Kawala            return super.findViewById(viewId);
6157bcb4abedb50df96719d9e568fe09d06055360dLowell Kirsh        }
6257bcb4abedb50df96719d9e568fe09d06055360dLowell Kirsh
6357bcb4abedb50df96719d9e568fe09d06055360dLowell Kirsh        return view.findViewById(viewId);
6457bcb4abedb50df96719d9e568fe09d06055360dLowell Kirsh    }
6557bcb4abedb50df96719d9e568fe09d06055360dLowell Kirsh
6657bcb4abedb50df96719d9e568fe09d06055360dLowell Kirsh    @Implementation
6757bcb4abedb50df96719d9e568fe09d06055360dLowell Kirsh    public void setView(View view) {
6857bcb4abedb50df96719d9e568fe09d06055360dLowell Kirsh        this.view = view;
6972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    }
7072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
7172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    /**
7272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     * Resets the tracking of the most recently created {@code AlertDialog}
7372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     */
7472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    public static void reset() {
759c6f1b1bf3d0bb2c6bb2abbf7fe8f21a137891f3Glenn Jahnke & Phil Goodwin        getShadowApplication().setLatestAlertDialog(null);
7672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    }
7772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
7872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    /**
7972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     * Simulates a click on the {@code Dialog} item indicated by {@code index}. Handles both multi- and single-choice dialogs, tracks which items are currently
8072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     * checked and calls listeners appropriately.
8172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     *
82c1939651f1f399da668bdd59b900ad897f2b3a27pivotal     * @param index the index of the item to click on
8372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     */
8472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    public void clickOnItem(int index) {
8543d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz        shadowOf(realAlertDialog.getListView()).performItemClick(index);
8672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    }
8772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
8872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    @Implementation
8972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    public Button getButton(int whichButton) {
9072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        switch (whichButton) {
91c1939651f1f399da668bdd59b900ad897f2b3a27pivotal            case AlertDialog.BUTTON_POSITIVE:
92c1939651f1f399da668bdd59b900ad897f2b3a27pivotal                return positiveButton;
93c1939651f1f399da668bdd59b900ad897f2b3a27pivotal            case AlertDialog.BUTTON_NEGATIVE:
94c1939651f1f399da668bdd59b900ad897f2b3a27pivotal                return negativeButton;
95c1939651f1f399da668bdd59b900ad897f2b3a27pivotal            case AlertDialog.BUTTON_NEUTRAL:
96c1939651f1f399da668bdd59b900ad897f2b3a27pivotal                return neutralButton;
9772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
9872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        throw new RuntimeException("Only positive, negative, or neutral button choices are recognized");
9972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    }
1006cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson
1016cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson    @Implementation
1026cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson    public void setButton(int whichButton, CharSequence text, DialogInterface.OnClickListener listener) {
1036cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson        switch (whichButton) {
1046cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson            case AlertDialog.BUTTON_POSITIVE:
1056cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson                positiveButton = createButton(context, realAlertDialog, whichButton, text, listener);
1066cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson                return;
1076cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson            case AlertDialog.BUTTON_NEGATIVE:
1086cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson                negativeButton = createButton(context, realAlertDialog, whichButton, text, listener);
1096cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson                return;
1106cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson            case AlertDialog.BUTTON_NEUTRAL:
1116cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson                neutralButton = createButton(context, realAlertDialog, whichButton, text, listener);
1126cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson                return;
1136cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson        }
1146cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson        throw new RuntimeException("Only positive, negative, or neutral button choices are recognized");
1156cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson    }
1166cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson
1176cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson    private static Button createButton(final Context context, final DialogInterface dialog, final int which, CharSequence text, final DialogInterface.OnClickListener listener) {
1186cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson        if (text == null && listener == null) {
1196cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson            return null;
1206cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson        }
1216cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson        Button button = new Button(context);
1226cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson        Robolectric.shadowOf(button).setText(text); // use shadow to skip
1236cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson                                                    // i18n-strict checking
1246cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson        button.setOnClickListener(new View.OnClickListener() {
1256cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson            @Override
1266cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson            public void onClick(View v) {
1276cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson                if (listener != null) {
1286cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson                    listener.onClick(dialog, which);
1296cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson                }
1306cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson                dialog.dismiss();
1316cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson            }
1326cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson        });
1336cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson        return button;
1346cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson    }
13572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
13643d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz    @Implementation
13743d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz    public ListView getListView() {
13843d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz        if (listView == null) {
13943d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz            listView = new ListView(context);
14043d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
14143d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz                @Override
14243d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
14343d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz                    if (isMultiItem) {
14443d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz                        checkedItems[position] = !checkedItems[position];
14543d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz                        multiChoiceClickListener.onClick(realAlertDialog, position, checkedItems[position]);
14643d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz                    } else {
14743d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz                        if (isSingleItem) {
14843d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz                            checkedItemIndex = position;
14943d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz                        }
15043d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz                        clickListener.onClick(realAlertDialog, position);
15143d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz                    }
15243d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz                }
15343d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz            });
15443d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz        }
15543d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz        return listView;
15643d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz    }
15743d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz
15872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    /**
15972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     * Non-Android accessor.
16072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     *
16172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     * @return the items that are available to be clicked on
16272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     */
16372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    public CharSequence[] getItems() {
16472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        return items;
16572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    }
166c1939651f1f399da668bdd59b900ad897f2b3a27pivotal
167f1db8d709d4596bde52bcead212b396b81635123pivotal    public Adapter getAdapter() {
168f1db8d709d4596bde52bcead212b396b81635123pivotal        return adapter;
169f1db8d709d4596bde52bcead212b396b81635123pivotal    }
170f1db8d709d4596bde52bcead212b396b81635123pivotal
17172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    /**
17272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     * Non-Android accessor.
17372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     *
17472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     * @return the message displayed in the dialog
17572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     */
17685af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    public String getMessage() {
17772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        return message;
17872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    }
17972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
18085af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    @Implementation
18185af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    public void setMessage(CharSequence message) {
18285af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        this.message = (message == null ? null : message.toString());
18385af7906879a68c99b1878dac22605fa32454f3fRich Humphrey    }
18485af7906879a68c99b1878dac22605fa32454f3fRich Humphrey
18572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    /**
18672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     * Non-Android accessor.
18772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     *
18872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     * @return an array indicating which items are and are not clicked on a multi-choice dialog
18972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     */
19072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    public boolean[] getCheckedItems() {
19172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        return checkedItems;
19272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    }
19372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
19472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    /**
1953e6fa4f57f88547cc237624a6827d14e557fcee9Rich Humphrey     * Non-Android accessor.
1963e6fa4f57f88547cc237624a6827d14e557fcee9Rich Humphrey     *
197753d062a9106040be10c39595219774ae656b8f9Mike Grafton     * @return return the index of the checked item clicked on a single-choice dialog
1983e6fa4f57f88547cc237624a6827d14e557fcee9Rich Humphrey     */
199753d062a9106040be10c39595219774ae656b8f9Mike Grafton    public int getCheckedItemIndex() {
200753d062a9106040be10c39595219774ae656b8f9Mike Grafton        return checkedItemIndex;
201753d062a9106040be10c39595219774ae656b8f9Mike Grafton    }
202753d062a9106040be10c39595219774ae656b8f9Mike Grafton
2039c6f1b1bf3d0bb2c6bb2abbf7fe8f21a137891f3Glenn Jahnke & Phil Goodwin    @Implementation
2049c6f1b1bf3d0bb2c6bb2abbf7fe8f21a137891f3Glenn Jahnke & Phil Goodwin    public void show() {
2059c6f1b1bf3d0bb2c6bb2abbf7fe8f21a137891f3Glenn Jahnke & Phil Goodwin        super.show();
20643d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz        if (items != null) {
20743d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz            adapter = new ArrayAdapter<CharSequence>(context, R.layout.simple_list_item_checked, R.id.text1, items);
20843d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz        }
20943d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz
21043d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz        if (adapter != null) {
21143d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz            getListView().setAdapter(adapter);
21243d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz        }
21343d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz
21443d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz
2159c6f1b1bf3d0bb2c6bb2abbf7fe8f21a137891f3Glenn Jahnke & Phil Goodwin        getShadowApplication().setLatestAlertDialog(this);
2163e6fa4f57f88547cc237624a6827d14e557fcee9Rich Humphrey    }
2179c6f1b1bf3d0bb2c6bb2abbf7fe8f21a137891f3Glenn Jahnke & Phil Goodwin
2183e6fa4f57f88547cc237624a6827d14e557fcee9Rich Humphrey    /**
21966ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz     * Non-Android accessor.
22066ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz     *
22166ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz     * @return return the view set with {@link ShadowAlertDialog.ShadowBuilder#setView(View)}
22266ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz     */
22366ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz    public View getView() {
22466ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz        return view;
22566ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz    }
22666ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz
22766ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz    /**
228d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz     * Non-Android accessor.
229d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz     *
230d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz     * @return return the view set with {@link ShadowAlertDialog.ShadowBuilder#setCustomTitle(View)}
231d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz     */
232d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz    public View getCustomTitleView() {
233d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz        return customTitleView;
234d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz    }
235d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz
236d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz    /**
23772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     * Shadows the {@code android.app.AlertDialog.Builder} class.
23872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin     */
23972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    @Implements(AlertDialog.Builder.class)
24072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    public static class ShadowBuilder {
24172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        @RealObject
24272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private AlertDialog.Builder realBuilder;
24372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
24472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private CharSequence[] items;
24543d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz        private ListAdapter adapter;
24672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private DialogInterface.OnClickListener clickListener;
247c1939651f1f399da668bdd59b900ad897f2b3a27pivotal        private DialogInterface.OnCancelListener cancelListener;
24872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private String title;
24972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private String message;
25072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private Context context;
25172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private boolean isMultiItem;
25272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private DialogInterface.OnMultiChoiceClickListener multiChoiceClickListener;
25372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private boolean[] checkedItems;
25472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private CharSequence positiveText;
25572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private DialogInterface.OnClickListener positiveListener;
25672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private CharSequence negativeText;
25772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private DialogInterface.OnClickListener negativeListener;
25872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private CharSequence neutralText;
25972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private DialogInterface.OnClickListener neutralListener;
26072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private boolean isCancelable;
26172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private boolean isSingleItem;
26272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        private int checkedItem;
26366ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz        private View view;
264d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz        private View customTitleView;
26572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
26672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        /**
26772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin         * just stashes the context for later use
26872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin         *
269c1939651f1f399da668bdd59b900ad897f2b3a27pivotal         * @param context the context
27072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin         */
27172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public void __constructor__(Context context) {
27272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.context = context;
27372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
27472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
27572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        /**
27672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin         * Set a list of items to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener. This should be
27772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin         * an array type i.e. R.array.foo
27872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin         *
27972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin         * @return This Builder object to allow for chaining of calls to set methods
28072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin         */
28172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        @Implementation
28272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public AlertDialog.Builder setItems(int itemsId, final DialogInterface.OnClickListener listener) {
28372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.isMultiItem = false;
28472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
28572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.items = context.getResources().getTextArray(itemsId);
28672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.clickListener = listener;
28772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            return realBuilder;
28872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
28972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
290a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi        @Implementation(i18nSafe=false)
29172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public AlertDialog.Builder setItems(CharSequence[] items, final DialogInterface.OnClickListener listener) {
29272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.isMultiItem = false;
29372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
29472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.items = items;
29572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.clickListener = listener;
29672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            return realBuilder;
29772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
29872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
299a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi        @Implementation(i18nSafe=false)
30072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public AlertDialog.Builder setSingleChoiceItems(CharSequence[] items, int checkedItem, final DialogInterface.OnClickListener listener) {
30172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.isSingleItem = true;
30272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.checkedItem = checkedItem;
30372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.items = items;
30472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.clickListener = listener;
30572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            return realBuilder;
30672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
30772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
308a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi        @Implementation(i18nSafe=false)
309f1db8d709d4596bde52bcead212b396b81635123pivotal        public AlertDialog.Builder setSingleChoiceItems(ListAdapter adapter, int checkedItem, final DialogInterface.OnClickListener listener) {
310f1db8d709d4596bde52bcead212b396b81635123pivotal            this.isSingleItem = true;
311f1db8d709d4596bde52bcead212b396b81635123pivotal            this.checkedItem = checkedItem;
312f1db8d709d4596bde52bcead212b396b81635123pivotal            this.items = null;
313f1db8d709d4596bde52bcead212b396b81635123pivotal            this.adapter = adapter;
314f1db8d709d4596bde52bcead212b396b81635123pivotal            this.clickListener = listener;
315f1db8d709d4596bde52bcead212b396b81635123pivotal            return realBuilder;
316f1db8d709d4596bde52bcead212b396b81635123pivotal        }
317f1db8d709d4596bde52bcead212b396b81635123pivotal
318f1db8d709d4596bde52bcead212b396b81635123pivotal        @Implementation(i18nSafe=false)
31972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public AlertDialog.Builder setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, final DialogInterface.OnMultiChoiceClickListener listener) {
32072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.isMultiItem = true;
32172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
32272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.items = items;
32372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.multiChoiceClickListener = listener;
32472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
32572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            if (checkedItems == null) {
32672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin                checkedItems = new boolean[items.length];
32772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            } else if (checkedItems.length != items.length) {
32872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin                throw new IllegalArgumentException("checkedItems must be the same length as items, or pass null to specify no checked items");
32972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            }
33072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.checkedItems = checkedItems;
33172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
33272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            return realBuilder;
33372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
33472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
335a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi        @Implementation(i18nSafe=false)
33672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public AlertDialog.Builder setTitle(CharSequence title) {
33772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.title = title.toString();
33872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            return realBuilder;
33972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
34072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
341d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz
342d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz        @Implementation
343d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz        public AlertDialog.Builder setCustomTitle(android.view.View customTitleView) {
344d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz            this.customTitleView = customTitleView;
345d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz            return realBuilder;
346d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz        }
347d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz
34872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        @Implementation
34972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public AlertDialog.Builder setTitle(int titleId) {
35038ee4a4da68e1faf7338f5f7124b057cbd8a6813Joe Moore            return setTitle(context.getResources().getString(titleId));
35172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
352c1939651f1f399da668bdd59b900ad897f2b3a27pivotal
353a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi        @Implementation(i18nSafe=false)
35472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public AlertDialog.Builder setMessage(CharSequence message) {
35572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.message = message.toString();
35672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            return realBuilder;
35772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
35872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
35972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        @Implementation
360b38fc2077a6ef0880426abc6bba8b10fb4a27933Yuan Mai        public AlertDialog.Builder setMessage(int messageId) {
36185af7906879a68c99b1878dac22605fa32454f3fRich Humphrey            setMessage(context.getResources().getString(messageId));
362b38fc2077a6ef0880426abc6bba8b10fb4a27933Yuan Mai            return realBuilder;
363b38fc2077a6ef0880426abc6bba8b10fb4a27933Yuan Mai        }
364b38fc2077a6ef0880426abc6bba8b10fb4a27933Yuan Mai
365b38fc2077a6ef0880426abc6bba8b10fb4a27933Yuan Mai        @Implementation
36633284708d30b1b9aa82b44afed58ca54d789bb29David Farber & Ryan Richard        public AlertDialog.Builder setIcon(int iconId) {
36733284708d30b1b9aa82b44afed58ca54d789bb29David Farber & Ryan Richard            return realBuilder;
36833284708d30b1b9aa82b44afed58ca54d789bb29David Farber & Ryan Richard        }
369c1939651f1f399da668bdd59b900ad897f2b3a27pivotal
37066ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz        @Implementation
37166ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz        public AlertDialog.Builder setView(View view) {
37266ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz            this.view = view;
37366ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz            return realBuilder;
37466ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz        }
37566ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz
376a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi        @Implementation(i18nSafe=false)
37772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public AlertDialog.Builder setPositiveButton(CharSequence text, final DialogInterface.OnClickListener listener) {
37872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.positiveText = text;
37972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.positiveListener = listener;
38072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            return realBuilder;
38172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
38272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
38372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        @Implementation
38485af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        public AlertDialog.Builder setPositiveButton(int positiveTextId, final DialogInterface.OnClickListener listener) {
385c1939651f1f399da668bdd59b900ad897f2b3a27pivotal            return setPositiveButton(context.getResources().getText(positiveTextId), listener);
3862d62e13a03392e4596cc30edd64d46f73cbc04d7Graeme Duncan        }
3872d62e13a03392e4596cc30edd64d46f73cbc04d7Graeme Duncan
388a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi        @Implementation(i18nSafe=false)
38972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public AlertDialog.Builder setNegativeButton(CharSequence text, final DialogInterface.OnClickListener listener) {
39072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.negativeText = text;
39172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.negativeListener = listener;
39272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            return realBuilder;
39372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
39472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
39572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        @Implementation
39685af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        public AlertDialog.Builder setNegativeButton(int negativeTextId, final DialogInterface.OnClickListener listener) {
397c1939651f1f399da668bdd59b900ad897f2b3a27pivotal            return setNegativeButton(context.getResources().getString(negativeTextId), listener);
3982d62e13a03392e4596cc30edd64d46f73cbc04d7Graeme Duncan        }
399c1939651f1f399da668bdd59b900ad897f2b3a27pivotal
400a11e5662854971ff223b39bae85a4854f0b6bcc5Michael Portuesi        @Implementation(i18nSafe=false)
40172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public AlertDialog.Builder setNeutralButton(CharSequence text, final DialogInterface.OnClickListener listener) {
40272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.neutralText = text;
40372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.neutralListener = listener;
40472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            return realBuilder;
40572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
40672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
40772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        @Implementation
40885af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        public AlertDialog.Builder setNeutralButton(int neutralTextId, final DialogInterface.OnClickListener listener) {
40943d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz            return setNeutralButton(context.getResources().getText(neutralTextId), listener);
41085af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        }
411c1939651f1f399da668bdd59b900ad897f2b3a27pivotal
412c1939651f1f399da668bdd59b900ad897f2b3a27pivotal
41385af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        @Implementation
41472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public AlertDialog.Builder setCancelable(boolean cancelable) {
41572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            this.isCancelable = cancelable;
41672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            return realBuilder;
41772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
418c1939651f1f399da668bdd59b900ad897f2b3a27pivotal
41985af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        @Implementation
42085af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        public AlertDialog.Builder setOnCancelListener(DialogInterface.OnCancelListener listener) {
421c1939651f1f399da668bdd59b900ad897f2b3a27pivotal            this.cancelListener = listener;
422c1939651f1f399da668bdd59b900ad897f2b3a27pivotal            return realBuilder;
42385af7906879a68c99b1878dac22605fa32454f3fRich Humphrey        }
42472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
42572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        @Implementation
42672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public AlertDialog create() {
42772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            AlertDialog realDialog;
42872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            try {
42972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin                Constructor<AlertDialog> c = AlertDialog.class.getDeclaredConstructor(Context.class);
43072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin                c.setAccessible(true);
43172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin                realDialog = c.newInstance((Context) null);
43272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            } catch (Exception e) {
43372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin                throw new RuntimeException(e);
43472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            }
43572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
43672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            ShadowAlertDialog latestAlertDialog = shadowOf(realDialog);
43772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            latestAlertDialog.context = context;
43872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            latestAlertDialog.items = items;
439f1db8d709d4596bde52bcead212b396b81635123pivotal            latestAlertDialog.adapter = adapter;
440ec07ffb13702733c07a846308de902a6f68977f2David Farber & Ryan Richard            latestAlertDialog.setTitle(title);
44172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            latestAlertDialog.message = message;
44272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            latestAlertDialog.clickListener = clickListener;
44385af7906879a68c99b1878dac22605fa32454f3fRich Humphrey            latestAlertDialog.setOnCancelListener(cancelListener);
44472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            latestAlertDialog.isMultiItem = isMultiItem;
44572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            latestAlertDialog.isSingleItem = isSingleItem;
44672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            latestAlertDialog.checkedItemIndex = checkedItem;
44772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            latestAlertDialog.multiChoiceClickListener = multiChoiceClickListener;
44872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            latestAlertDialog.checkedItems = checkedItems;
44966ab50f46c79da589f2b5419407ecce9d44c99a3Mike Mazur & Tyler Schultz            latestAlertDialog.setView(view);
4506cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson            latestAlertDialog.positiveButton = createButton(context, realDialog, AlertDialog.BUTTON_POSITIVE, positiveText, positiveListener);
4516cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson            latestAlertDialog.negativeButton = createButton(context, realDialog, AlertDialog.BUTTON_NEGATIVE, negativeText, negativeListener);
4526cb8eb7fc51d514539d865529cb849a035ab7498Levi Wilson            latestAlertDialog.neutralButton = createButton(context, realDialog, AlertDialog.BUTTON_NEUTRAL, neutralText, neutralListener);
453c1939651f1f399da668bdd59b900ad897f2b3a27pivotal            latestAlertDialog.setCancelable(isCancelable);
454d9715ea3daabfd16495e39d4af2a37b400a35150Tyler Schultz            latestAlertDialog.customTitleView = customTitleView;
45572ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            return realDialog;
45672ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
45772ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
45872ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        @Implementation
45972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        public AlertDialog show() {
46072ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            AlertDialog dialog = realBuilder.create();
46172ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            dialog.show();
46272ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin            return dialog;
46372ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin        }
46472ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin
4650bcbd37475c4774b3287f0a403ac26ca84a029efMichael Portuesi        @Implementation
4660bcbd37475c4774b3287f0a403ac26ca84a029efMichael Portuesi        public Context getContext() {
46743d4a611b7ee5c0548119b746baf4da97d8cecceTim Labeeuw & Tyler Schultz            return context;
468ef827b8c0df939367103b334ba9ae8050c6be8c0Michael Portuesi        }
46972ee6c0e205c424f0706051d89e1c7f184bf8269Phil Goodwin    }
47050e71a2777cae2b5f630448c5ab22be4066d4d6dChristian Williams & Ryan Richard}
471