Example usage for android.app Dialog setOnDismissListener

List of usage examples for android.app Dialog setOnDismissListener

Introduction

In this page you can find the example usage for android.app Dialog setOnDismissListener.

Prototype

public void setOnDismissListener(@Nullable OnDismissListener listener) 

Source Link

Document

Set a listener to be invoked when the dialog is dismissed.

Usage

From source file:com.adithya321.sharesanalysis.fragments.SalesShareFragment.java

@Nullable
@Override//w  w  w  . j av  a2  s . c  o m
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_share_sales, container, false);

    databaseHandler = new DatabaseHandler(getContext());
    salesRecyclerView = (RecyclerView) root.findViewById(R.id.sales_recycler_view);
    setRecyclerViewAdapter();

    FloatingActionButton sellShareFab = (FloatingActionButton) root.findViewById(R.id.sell_share_fab);
    sellShareFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Dialog dialog = new Dialog(getContext());
            dialog.setTitle("Sell Share Holdings");
            dialog.setContentView(R.layout.dialog_sell_share_holdings);
            dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.WRAP_CONTENT);
            dialog.show();

            final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner);

            ArrayList<String> shares = new ArrayList<>();
            for (Share share : sharesList) {
                shares.add(share.getName());
            }
            ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(),
                    android.R.layout.simple_spinner_item, shares);
            spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(spinnerAdapter);

            Calendar calendar = Calendar.getInstance();
            year_start = calendar.get(Calendar.YEAR);
            month_start = calendar.get(Calendar.MONTH) + 1;
            day_start = calendar.get(Calendar.DAY_OF_MONTH);
            final Button selectDate = (Button) dialog.findViewById(R.id.select_date);
            selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/")
                    .append(year_start));
            selectDate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Dialog dialog = new DatePickerDialog(getActivity(), onDateSetListener, year_start,
                            month_start - 1, day_start);
                    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            selectDate.setText(new StringBuilder().append(day_start).append("/")
                                    .append(month_start).append("/").append(year_start));
                        }
                    });
                    dialog.show();
                }
            });

            Button sellShareBtn = (Button) dialog.findViewById(R.id.sell_share_btn);
            sellShareBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Purchase purchase = new Purchase();
                    purchase.setId(databaseHandler.getNextKey("purchase"));
                    purchase.setName(spinner.getSelectedItem().toString());

                    String stringStartDate = year_start + " " + month_start + " " + day_start;
                    DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH);
                    try {
                        Date date = format.parse(stringStartDate);
                        purchase.setDate(date);
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares);
                    try {
                        purchase.setQuantity(Integer.parseInt(quantity.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    EditText price = (EditText) dialog.findViewById(R.id.selling_price);
                    try {
                        purchase.setPrice(Double.parseDouble(price.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Selling Price", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    purchase.setType("sell");
                    databaseHandler.addPurchase(spinner.getSelectedItem().toString(), purchase);
                    setRecyclerViewAdapter();
                    dialog.dismiss();
                }
            });
        }
    });

    return root;
}

From source file:org.sufficientlysecure.keychain.ui.linked.LinkedIdCreateGithubFragment.java

public void oAuthRequest(String hostAndPath, String clientId, String scope) {

    Activity activity = getActivity();/*from  www.j  a v  a2 s .  c o  m*/
    if (activity == null) {
        return;
    }

    byte[] buf = new byte[16];
    new Random().nextBytes(buf);
    mOAuthState = new String(Hex.encode(buf));
    mOAuthCode = null;

    final Dialog auth_dialog = new Dialog(activity);
    auth_dialog.setContentView(R.layout.oauth_webview);
    WebView web = (WebView) auth_dialog.findViewById(R.id.web_view);
    web.getSettings().setSaveFormData(false);
    web.getSettings().setUserAgentString("OpenKeychain " + BuildConfig.VERSION_NAME);
    web.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Uri uri = Uri.parse(url);
            if ("oauth-openkeychain".equals(uri.getScheme())) {

                if (mOAuthCode != null) {
                    return true;
                }

                if (uri.getQueryParameter("error") != null) {
                    Log.i(Constants.TAG, "got oauth error: " + uri.getQueryParameter("error"));
                    auth_dialog.dismiss();
                    return true;
                }

                // check if mOAuthState == queryParam[state]
                mOAuthCode = uri.getQueryParameter("code");

                auth_dialog.dismiss();
                return true;
            }
            // don't surf away from github!
            if (!"github.com".equals(uri.getHost())) {
                auth_dialog.dismiss();
                return true;
            }
            return false;
        }

    });

    auth_dialog.setTitle(R.string.linked_webview_title_github);
    auth_dialog.setCancelable(true);
    auth_dialog.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            step1GetOAuthToken();
        }
    });
    auth_dialog.show();

    web.loadUrl("https://" + hostAndPath + "?client_id=" + clientId + "&scope=" + scope
            + "&redirect_uri=oauth-openkeychain://linked/" + "&state=" + mOAuthState);

}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Prompt the user to rate the app.//from w  w w.j  a  v a2s. c  o m
 * 
 * @param context
 */
public static void displayRating(final Launcher context) {
    SharedPreferences prefs = context.getSharedPreferences(Launcher.PREFERENCES_NAME, Activity.MODE_PRIVATE);

    if (prefs.getBoolean(DONT_SHOW_RATING_AGAIN, false)) {
        return;
    }

    final SharedPreferences.Editor editor = prefs.edit();

    // Get date of first launch
    Long date_firstLaunch = prefs.getLong(DATE_FIRST_LAUNCHED, 0);
    if (date_firstLaunch == 0) {
        date_firstLaunch = System.currentTimeMillis();
        editor.putLong(DATE_FIRST_LAUNCHED, date_firstLaunch);
    }

    // Wait at least n days before opening
    if (System.currentTimeMillis() >= date_firstLaunch + (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
        final Dialog dialog = new Dialog(context);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.confirmation);

        TextView confirmationTextView = (TextView) dialog.findViewById(R.id.confirmationText);
        confirmationTextView.setText(context.getString(R.string.rating_message));
        Button buttonYes = (Button) dialog.findViewById(R.id.button1);
        buttonYes.setText(context.getString(R.string.dialog_yes));
        buttonYes.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("market://details?id=com.entertailion.android.launcher"));
                context.startActivity(intent);
                if (editor != null) {
                    editor.putBoolean(DONT_SHOW_RATING_AGAIN, true);
                    editor.commit();
                }
                Analytics.logEvent(Analytics.RATING_YES);
                context.showCover(false);
                dialog.dismiss();
            }

        });
        Button buttonNo = (Button) dialog.findViewById(R.id.button2);
        buttonNo.setText(context.getString(R.string.dialog_no));
        buttonNo.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (editor != null) {
                    editor.putBoolean(DONT_SHOW_RATING_AGAIN, true);
                    editor.commit();
                }
                Analytics.logEvent(Analytics.RATING_NO);
                context.showCover(false);
                dialog.dismiss();
            }

        });
        dialog.setOnDismissListener(new OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {
                context.showCover(false);
            }

        });
        context.showCover(true);
        dialog.show();
    }

    editor.commit();
}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Display a grid of all installed apps + virtual apps. Allow user to launch
 * apps./*from www  .j a  v  a2s .c o  m*/
 * 
 * @param context
 * @param applications
 */
public static void displayAllApps(final Launcher context, final ArrayList<ApplicationInfo> applications) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.apps_grid);

    final GridView gridView = (GridView) dialog.findViewById(R.id.grid);
    gridView.setAdapter(new AllItemAdapter(context, getApplications(context, applications, false)));
    gridView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ItemInfo itemInfo = (ItemInfo) parent.getAdapter().getItem(position);
            itemInfo.invoke(context);
            context.showCover(false);
            dialog.dismiss();
            if (itemInfo instanceof ApplicationInfo) {
                ApplicationInfo applicationInfo = (ApplicationInfo) itemInfo;
                RecentAppsTable.persistRecentApp(context, applicationInfo);
            }
        }

    });
    gridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> gridView, View view, int pos, long arg3) {
            ItemInfo itemInfo = (ItemInfo) gridView.getAdapter().getItem(pos);
            if (itemInfo instanceof ApplicationInfo) {
                Uri packageURI = Uri.parse("package:" + itemInfo.getIntent().getComponent().getPackageName());
                Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
                context.startActivity(uninstallIntent);
                context.showCover(false);
                dialog.dismiss();
                Analytics.logEvent(Analytics.UNINSTALL_APP);
            }

            return false;
        }

    });
    gridView.setDrawingCacheEnabled(true);
    gridView.setOnKeyListener(onKeyListener);
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
        }

    });
    context.showCover(true);
    dialog.show();
    Analytics.logEvent(Analytics.DIALOG_ALL_APPS);
}

From source file:androidVNC.VncCanvasActivity.java

private void selectColorModel() {
    // Stop repainting the desktop
    // because the display is composited!
    vncCanvas.disableRepaints();//  w w  w .  j a va  2  s .  c  o  m

    String[] choices = new String[COLORMODEL.values().length];
    int currentSelection = -1;
    for (int i = 0; i < choices.length; i++) {
        COLORMODEL cm = COLORMODEL.values()[i];
        choices[i] = cm.toString();
        if (vncCanvas.isColorModel(cm))
            currentSelection = i;
    }

    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    ListView list = new ListView(this);
    list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, choices));
    list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    list.setItemChecked(currentSelection, true);
    list.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            dialog.dismiss();
            COLORMODEL cm = COLORMODEL.values()[arg2];
            vncCanvas.setColorModel(cm);
            connection.setColorModel(cm.nameString());
            connection.save(database.getWritableDatabase());
            //Toast.makeText(VncCanvasActivity.this,"Updating Color Model to " + cm.toString(), Toast.LENGTH_SHORT).show();
        }
    });
    dialog.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface arg0) {
            Log.i(TAG, "Color Model Selector dismissed");
            // Restore desktop repaints
            vncCanvas.enableRepaints();
        }
    });
    dialog.setContentView(list);
    dialog.show();
}

From source file:org.de.jmg.learn.MainActivity.java

private boolean saveVokAsync(boolean dontPrompt, final boolean blnAsync) throws Exception {
    fPA.fragMain.EndEdit(true);/*from ww  w .  j a va2 s  . co m*/
    if (vok.aend) {
        if (!dontPrompt) {

            AlertDialog.Builder A = new AlertDialog.Builder(context);
            A.setPositiveButton(getString(R.string.yes), new AlertDialog.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        if (libString.IsNullOrEmpty(vok.getFileName()) && vok.getURI() == null) {
                            SaveVokAs(true, false);
                        } else {
                            if (blnAsync
                                    || (libString.IsNullOrEmpty(vok.getFileName()) && vok.getURI() != null)) {
                                vok.SaveCurrentFileAsync();
                            } else {
                                vok.SaveFile(vok.getFileName(), vok.getURI(), vok.getUniCode(), false);
                            }
                            vok.aend = false;
                            saveFilePrefs(false);
                        }

                    } catch (Exception e) {
                        try {
                            SaveVokAs(true, false);
                        } catch (Exception e1) {

                            e1.printStackTrace();
                            lib.ShowException(MainActivity.this, e1);
                        }
                    }
                }
            });
            A.setNegativeButton(getString(R.string.no), new AlertDialog.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            });
            A.setMessage(getString(R.string.Save));
            A.setTitle(getString(R.string.question));
            Dialog dlg = A.create();
            dlg.show();
            dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    lib.ShowToast(MainActivity.this, MainActivity.this.getString(R.string.PressBackAgain));
                    _backPressed += 1;
                    handlerbackpressed.postDelayed(rSetBackPressedFalse, 10000);
                }
            });
            if (_backPressed > 0) {
                return true;
            }
        }

        if (dontPrompt) {
            try {
                if (libString.IsNullOrEmpty(vok.getFileName()) && vok.getURI() == null) {
                    SaveVokAs(true, false);
                } else {
                    if (blnAsync || (libString.IsNullOrEmpty(vok.getFileName()) && vok.getURI() != null)) {
                        vok.SaveCurrentFileAsync();
                    } else {
                        vok.SaveFile(vok.getFileName(), vok.getURI(), vok.getUniCode(), true);
                    }
                    vok.aend = false;
                    saveFilePrefs(false);
                }
                _backPressed += 1;
                handlerbackpressed.postDelayed(rSetBackPressedFalse, 10000);

            } catch (Exception e) {
                lib.ShowException(this, e);
            }
        }
        return false;
    } else {
        return true;
    }

}

From source file:nl.sogeti.android.gpstracker.actions.NameTrack.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog = null;
    LayoutInflater factory = null;/*from  w  w w . ja  va 2  s.c  om*/
    View view = null;
    Builder builder = null;
    switch (id) {
    case DIALOG_TRACKNAME:
        builder = new AlertDialog.Builder(this);
        factory = LayoutInflater.from(this);
        view = factory.inflate(R.layout.namedialog, null);
        mTrackNameView = (EditText) view.findViewById(R.id.nameField);
        mHelmetRadioGroup = (RadioGroup) view.findViewById(R.id.helmetRadioGroup);
        mServiceRatingBar = (RatingBar) view.findViewById(R.id.serviceRatingBar);
        mOriginReasonSpinner = (Spinner) view.findViewById(R.id.originReasonSpinner);
        mDestinationReasonSpinner = (Spinner) view.findViewById(R.id.destinationReasonSpinner);
        mReasonAdapter = ArrayAdapter.createFromResource(this, R.array.Reason_choices,
                android.R.layout.simple_spinner_item);
        mReasonAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        mOriginReasonSpinner.setAdapter(mReasonAdapter);
        mDestinationReasonSpinner.setAdapter(mReasonAdapter);

        mStartStationAutoCompleteTextView = (AutoCompleteTextView) view
                .findViewById(R.id.startStationAutocomplete);

        mStartStationAutoCompleteTextView.setAdapter(mStartStationSimpleCursorAdapter);
        mStartStationAutoCompleteTextView.addTextChangedListener(this);
        mStartStationAutoCompleteTextView.addTextChangedListener(mStartStationTextWatcher);

        mEndStationAutoCompleteTextView = (AutoCompleteTextView) view.findViewById(R.id.endStationAutocomplete);

        mEndStationAutoCompleteTextView.setAdapter(mEndStationSimpleCursorAdapter);
        mEndStationAutoCompleteTextView.addTextChangedListener(this);
        mEndStationAutoCompleteTextView.addTextChangedListener(mEndStationTextWatcher);

        builder.setTitle(R.string.dialog_routename_title)
                //.setMessage( R.string.dialog_routename_message )
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setPositiveButton(R.string.btn_okay, mTrackNameDialogListener)
                .setNeutralButton(R.string.btn_skip, mTrackNameDialogListener)
                .setNegativeButton(R.string.btn_cancel, mTrackNameDialogListener).setView(view);
        dialog = builder.create();
        dialog.setOnDismissListener(new OnDismissListener() {
            public void onDismiss(DialogInterface dialog) {
                if (!paused) {
                    finish();
                }
            }
        });
        return dialog;
    default:
        return super.onCreateDialog(id);
    }
}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Display dialog to allow user to add an app to a row. The user can add the
 * app to an existing row or a new row.// www. j a  v  a2  s .com
 * 
 * @param context
 * @param applications
 */
public static void displayAddApps(final Launcher context, final ArrayList<ApplicationInfo> applications) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.add_apps_grid);

    final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName);
    final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio);
    currentRadioButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // hide the row name edit field if the current row radio button
            // is selected
            nameEditText.setVisibility(View.GONE);
        }

    });
    final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio);
    newRadioButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // show the row name edit field if the new radio button is
            // selected
            nameEditText.setVisibility(View.VISIBLE);
            nameEditText.requestFocus();
        }

    });
    final GridView gridView = (GridView) dialog.findViewById(R.id.grid);
    gridView.setAdapter(new AllItemAdapter(context, getApplications(context, applications, true)));
    gridView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // if the new row radio button is selected, the user must enter
            // a name for the new row
            String name = nameEditText.getText().toString().trim();
            if (newRadioButton.isChecked() && name.length() == 0) {
                nameEditText.requestFocus();
                displayAlert(context, context.getString(R.string.dialog_new_row_name_alert));
                return;
            }
            ItemInfo itemInfo = (ItemInfo) parent.getAdapter().getItem(position);
            boolean currentRow = !newRadioButton.isChecked();
            context.addItem(itemInfo, currentRow ? null : name);
            context.showCover(false);
            dialog.dismiss();
            if (currentRow) {
                Analytics.logEvent(Analytics.DIALOG_ADD_APP);
            } else {
                Analytics.logEvent(Analytics.ADD_APP_WITH_ROW);
            }
        }

    });
    gridView.setDrawingCacheEnabled(true);
    gridView.setOnKeyListener(onKeyListener);
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
        }

    });
    context.showCover(true);
    dialog.show();
    Analytics.logEvent(Analytics.DIALOG_ADD_APP);
}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Display dialog to the user for the Spotlight web apps:
 * https://www.google.com/tv/spotlight-gallery.html Allow the user to add a
 * web app to an existing row or a new row.
 * /*www .  j a v a 2  s  . c om*/
 * @param context
 */
public static void displayAddSpotlight(final Launcher context) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.add_apps_grid);

    final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName);
    final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio);
    currentRadioButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // hide the row name edit field if the current row radio button
            // is selected
            nameEditText.setVisibility(View.GONE);
        }

    });
    final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio);
    newRadioButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // show the row name edit field if the new radio button is
            // selected
            nameEditText.setVisibility(View.VISIBLE);
            nameEditText.requestFocus();
        }

    });
    final GridView gridView = (GridView) dialog.findViewById(R.id.grid);
    final ArrayList<SpotlightInfo> spotlights = SpotlightTable.getAllSpotlights(context);
    gridView.setAdapter(new AllSpotlightAdapter(context, spotlights));
    gridView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // if the new row radio button is selected, the user must enter
            // a name for the new row
            String name = nameEditText.getText().toString().trim();
            if (newRadioButton.isChecked() && name.length() == 0) {
                nameEditText.requestFocus();
                displayAlert(context, context.getString(R.string.dialog_new_row_name_alert));
                return;
            }
            ItemInfo itemInfo = (ItemInfo) parent.getAdapter().getItem(position);
            boolean currentRow = !newRadioButton.isChecked();
            context.addItem(itemInfo, currentRow ? null : name);
            context.showCover(false);
            dialog.dismiss();
            if (currentRow) {
                Analytics.logEvent(Analytics.ADD_SPOTLIGHT_WEB_APP);
            } else {
                Analytics.logEvent(Analytics.ADD_SPOTLIGHT_WEB_APP_WITH_ROW);
            }
        }

    });
    gridView.setDrawingCacheEnabled(true);
    gridView.setOnKeyListener(onKeyListener);
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
        }

    });
    context.showCover(true);
    dialog.show();
    Analytics.logEvent(Analytics.DIALOG_ADD_SPOTLIGHT_WEB_APP);
}

From source file:dev.memento.MementoBrowser.java

@Override
protected Dialog onCreateDialog(int id) {

    Dialog dialog = null;
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    switch (id) {
    case DIALOG_DATE:
        dialog = new DatePickerDialog(this, mDateSetListener, mDateChosen.getYear(), mDateChosen.getMonth() - 1,
                mDateChosen.getDay());//w  ww .j ava 2  s .co  m
        break;

    case DIALOG_ERROR:
        builder = new AlertDialog.Builder(this);
        builder.setMessage("error message").setCancelable(false).setPositiveButton("OK", null);
        dialog = builder.create();
        break;

    case DIALOG_MEMENTO_YEARS:
        builder = new AlertDialog.Builder(this);
        final CharSequence[] years = mMementos.getAllYears();

        // Select the year of the Memento currently displayed
        int selectedYear = -1;

        for (int i = 0; i < years.length; i++) {
            if (mDateDisplayed.getYear() == Integer.parseInt(years[i].toString())) {
                selectedYear = i;
                break;
            }
        }

        builder.setSingleChoiceItems(years, selectedYear, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                dialog.dismiss();

                mSelectedYear = Integer.parseInt(years[item].toString());
                showDialog(DIALOG_MEMENTO_DATES);
            }
        });

        dialog = builder.create();

        // Cause the dialog to be freed whenever it is dismissed.
        // This is necessary because the items are dynamic.  
        dialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface arg0) {
                removeDialog(DIALOG_MEMENTO_YEARS);
            }
        });

        break;

    case DIALOG_MEMENTO_DATES:
        builder = new AlertDialog.Builder(this);

        final CharSequence[] dates;

        if (mSelectedYear == 0)
            dates = mMementos.getAllDates();
        else
            dates = mMementos.getDatesForYear(mSelectedYear);

        Log.d(LOG_TAG, "Number of dates = " + dates.length);

        // This shouldn't happen, but just in case.
        if (dates.length == 0) {
            showToast("No Mementos to select from.");
            return null;
        }

        int selected = -1;

        // Select the radio button for the current Memento if it's in the selected year.
        if (mSelectedYear == 0 || mSelectedYear == mDateDisplayed.getYear()) {

            int index = mMementos.getIndex(mDateDisplayed);
            if (index < 0)
                Log.d(LOG_TAG, "Could not find Memento in the list with date " + mDateDisplayed);
            else
                mMementos.setCurrentIndex(index);

            Memento m = mMementos.getCurrent();
            if (m != null) {
                for (int i = 0; i < dates.length; i++) {
                    if (m.getDateTime().dateAndTimeFormatted().equals(dates[i])) {
                        selected = i;
                        break;
                    }
                }
            } else
                Log.d(LOG_TAG, "There is no current Memento");
        }

        Log.d(LOG_TAG, "Selected index = " + selected);

        builder.setSingleChoiceItems(dates, selected, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                dialog.dismiss();

                int index = mMementos.getIndex(dates[item].toString());
                Memento m = mMementos.get(index);
                if (m == null) {
                    Log.e(LOG_TAG, "Could not find Memento with date " + mDateChosen + ".");
                    displayError("The date selected could not be accessed. Please select another.");
                } else {
                    // Display this Memento

                    Log.d(LOG_TAG, "index for [" + dates[item] + "] is " + index);

                    SimpleDateTime d = m.getDateTime();
                    setChosenDate(d);

                    if (index == mMementos.getCurrentIndex()) {
                        showToast("Memento is already displayed.");
                    } else {
                        mMementos.setCurrentIndex(index);
                        showToast("Time travelling to " + mDateChosen.dateFormatted());

                        // Find the Memento URL for the selected date                      

                        mDateDisplayed = new SimpleDateTime(mDateChosen);
                        String redirectUrl = m.getUrl();
                        Log.d(LOG_TAG, "Sending browser to " + redirectUrl);
                        mWebview.loadUrl(redirectUrl);

                        setEnableForNextPrevButtons();
                    }
                }
            }
        });

        dialog = builder.create();

        // Cause the dialog to be freed whenever it is dismissed.
        // This is necessary because the items are dynamic.  I couldn't find
        // a better way to solve this problem.
        dialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface arg0) {
                removeDialog(DIALOG_MEMENTO_DATES);
            }
        });

        break;

    case DIALOG_HELP:

        Context context = getApplicationContext();
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.about_dialog, null);
        builder.setView(layout);
        builder.setPositiveButton("OK", null);
        dialog = builder.create();
        break;
    }

    return dialog;
}