Example usage for android.app AlertDialog dismiss

List of usage examples for android.app AlertDialog dismiss

Introduction

In this page you can find the example usage for android.app AlertDialog dismiss.

Prototype

@Override
public void dismiss() 

Source Link

Document

Dismiss this dialog, removing it from the screen.

Usage

From source file:org.dpadgett.timer.WorldClockFragment.java

private void newClockDialog(final int position) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(context.getString(R.string.world_clock_select_timezone));
    final Map<String, String> timezoneNameToId = new HashMap<String, String>();
    final Set<Integer> timezones = new TreeSet<Integer>();
    final Map<Integer, List<String>> offsetToName = new HashMap<Integer, List<String>>();
    final long currentTime = System.currentTimeMillis();

    for (final String timezone : TimeZone.getAvailableIDs()) {
        final TimeZone tz = TimeZone.getTimeZone(timezone);
        final boolean isDaylight = tz.useDaylightTime();
        final String timezoneName = tz.getDisplayName(isDaylight, TimeZone.LONG, Locale.getDefault());
        if (timezoneNameToId.containsKey(timezoneName)) {
            continue;
        }//w  w  w  .  j a  v a 2 s .  co  m
        final int millisOffset = tz.getOffset(currentTime);
        timezones.add(millisOffset);
        if (!offsetToName.containsKey(millisOffset)) {
            offsetToName.put(millisOffset, new ArrayList<String>());
        }
        offsetToName.get(millisOffset).add(timezoneName);
        timezoneNameToId.put(timezoneName, timezone);
    }
    for (final List<String> names : offsetToName.values()) {
        Collections.sort(names);
    }
    if (position > -1) {
        builder.setPositiveButton(context.getString(R.string.world_clock_button_remove),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        clockList.remove(position);
                        clocksListAdapter.notifyDataSetChanged();

                        final SharedPreferences.Editor prefs = context
                                .getSharedPreferences("WorldClocks", Context.MODE_PRIVATE).edit();
                        prefs.putInt("numClocks", clockList.size());
                        int idx;
                        for (idx = position; idx < clockList.size(); idx++) {
                            prefs.putString("clock" + idx, clockList.get(idx));
                        }
                        prefs.remove("clock" + idx);
                        prefs.commit();
                    }
                });
    }
    final LinearLayout tzView = (LinearLayout) LayoutInflater.from(context)
            .inflate(R.layout.timezone_picker_dialog, (ViewGroup) finder.findViewById(R.id.layout_root));

    final List<String> initialItems = new ArrayList<String>();
    initialItems.add(context.getString(R.string.world_clock_timezone_gmt));
    initialItems.add(context.getString(R.string.world_clock_timezone_utc));
    final ArrayAdapter<String> adapter = ArrayAdapter.newArrayAdapter(context,
            R.layout.timezone_dialog_list_item, initialItems);
    final ListView timezoneList = (ListView) tzView.findViewById(R.id.timezoneList);
    timezoneList.setAdapter(adapter);

    final TextView sliderView = (TextView) tzView.findViewById(R.id.timezoneLabel);

    final SeekBar timezoneSeeker = (SeekBar) tzView.findViewById(R.id.timezoneSeeker);
    final List<Integer> timezonesList = new ArrayList<Integer>(timezones);
    timezoneSeeker.setMax(timezonesList.size() - 1);
    if (position > -1) {
        final int offset = TimeZone.getTimeZone(clockList.get(position)).getOffset(currentTime);
        timezoneSeeker.setProgress(timezonesList.indexOf(offset));
    } else {
        timezoneSeeker.setProgress(timezonesList.indexOf(0));
    }
    timezoneSeeker.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        // initialize the timezoneSeeker
        {
            onProgressChanged(timezoneSeeker, timezoneSeeker.getProgress(), false);
        }

        @Override
        public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
            adapter.clear();
            adapter.addAll(offsetToName.get(timezonesList.get(progress)));
            final int millisOffset = timezonesList.get(progress);
            String offset = String.format("%02d:%02d", Math.abs(millisOffset / 1000 / 60 / 60),
                    Math.abs(millisOffset / 1000 / 60) % 60);
            if (millisOffset / 1000 / 60 / 60 < 0) {
                offset = "-" + offset;
            } else {
                offset = "+" + offset;
            }
            sliderView.setText(context.getString(R.string.world_clock_timezone_label) + offset);
        }

        @Override
        public void onStartTrackingTouch(final SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(final SeekBar seekBar) {
        }
    });
    builder.setView(tzView);
    final AlertDialog alert = builder.create();

    timezoneList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, final int selectedPosition,
                final long id) {
            final String timezoneName = adapter.getItem(selectedPosition);
            final String timezone = timezoneNameToId.get(timezoneName);
            addNewClock(timezone, position);
            alert.dismiss();
        }
    });

    alert.show();
}

From source file:com.iklimov.alexandria.fragments.NoInternet.java

@Override
public void onStart() {
    super.onStart();
    final AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
        Button positiveButton = d.getButton(AlertDialog.BUTTON_POSITIVE);
        positiveButton.setOnClickListener(new View.OnClickListener() {
            @Override/*from  w  w  w. j  a va2 s . c o  m*/
            public void onClick(View v) {
                ConnectivityManager systemService = (ConnectivityManager) getActivity()
                        .getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo activeNetworkInfo = systemService.getActiveNetworkInfo();
                if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
                    if (getTag().equals("1")) {
                        ((SignInActivity) getActivity()).new SyncFavorites().execute();
                    }
                    d.dismiss();
                }
            }
        });
    }
}

From source file:com.esri.arcgisruntime.generateofflinemapoverrides.MainActivity.java

/**
 * Creates parameters dialog and handles processing of input to generateOfflineMap(...) when Start Job button is clicked.
 *///from ww  w . jav  a  2s. c om
private void showParametersDialog() {

    View overrideParametersView = getLayoutInflater().inflate(R.layout.override_parameters_dialog, null);

    // min and max seek bars
    TextView currMinScaleTextView = overrideParametersView.findViewById(R.id.currMinScaleTextView);
    TextView currMaxScaleTextView = overrideParametersView.findViewById(R.id.currMaxScaleTextview);

    SeekBar minScaleSeekBar = buildSeekBar(overrideParametersView.findViewById(R.id.minScaleSeekBar),
            currMinScaleTextView, 22, 15);
    SeekBar maxScaleSeekBar = buildSeekBar(overrideParametersView.findViewById(R.id.maxScaleSeekBar),
            currMaxScaleTextView, 23, 20);
    minScaleSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            currMinScaleTextView.setText(String.valueOf(progress));
            if (progress >= maxScaleSeekBar.getProgress()) {
                // set max to 1 more than min value (since max must always be greater than min)
                currMaxScaleTextView.setText(String.valueOf(progress + 1));
                maxScaleSeekBar.setProgress(progress + 1);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    maxScaleSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            currMaxScaleTextView.setText(String.valueOf(progress));
            if (progress <= minScaleSeekBar.getProgress()) {
                // set min to 1 less than max value (since min must always be less than max)
                currMinScaleTextView.setText(String.valueOf(progress - 1));
                minScaleSeekBar.setProgress(progress - 1);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    // extent buffer seek bar
    SeekBar extentBufferDistanceSeekBar = buildSeekBar(
            overrideParametersView.findViewById(R.id.extentBufferDistanceSeekBar),
            overrideParametersView.findViewById(R.id.currExtentBufferDistanceTextView), 500, 300);

    // include layers checkboxes
    CheckBox systemValves = overrideParametersView.findViewById(R.id.systemValvesCheckBox);
    CheckBox serviceConnections = overrideParametersView.findViewById(R.id.serviceConnectionsCheckBox);

    // min hydrant flow rate seek bar
    SeekBar minHydrantFlowRateSeekBar = buildSeekBar(
            overrideParametersView.findViewById(R.id.minHydrantFlowRateSeekBar),
            overrideParametersView.findViewById(R.id.currMinHydrantFlowRateTextView), 2000, 500);

    // crop layer to extent checkbox
    CheckBox waterPipes = overrideParametersView.findViewById(R.id.waterPipesCheckBox);

    // setup dialog
    AlertDialog.Builder overrideParametersDialogBuilder = new AlertDialog.Builder(this);
    AlertDialog overrideParametersDialog = overrideParametersDialogBuilder.create();
    overrideParametersDialogBuilder.setView(overrideParametersView).setTitle("Override Parameters")
            .setCancelable(true)
            .setNegativeButton("Cancel", (dialog, which) -> overrideParametersDialog.dismiss())
            .setPositiveButton("Start Job", (dialog, which) -> {
                // re-create download area geometry in case user hasn't changed the Viewpoint
                mDownloadArea.setGeometry(createDownloadAreaGeometry());
                defineParameters(minScaleSeekBar.getProgress(), maxScaleSeekBar.getProgress(),
                        extentBufferDistanceSeekBar.getProgress(), systemValves.isChecked(),
                        serviceConnections.isChecked(), minHydrantFlowRateSeekBar.getProgress(),
                        waterPipes.isChecked());
            }).show();
}

From source file:org.mythdroid.activities.Main.java

private Dialog createGuideDialog() {

    final AlertDialog d = new AlertDialog.Builder(ctx).setItems(new String[] {}, null)
            .setIcon(drawable.ic_menu_upload_you_tube).setTitle(R.string.dispGuide).create();

    d.getListView().setOnItemClickListener(new OnItemClickListener() {
        @Override/*w  ww .j av  a  2s  .c  o  m*/
        public void onItemClick(AdapterView<?> av, View v, int pos, long id) {

            String item = (String) av.getItemAtPosition(pos);
            d.dismiss();

            if (item.equals(Messages.getString("MDActivity.0"))) { //$NON-NLS-1$
                // Here
                startActivity(new Intent().setClass(ctx, Guide.class));
                return;
            }

            else if (item.equals(Messages.getString("MythDroid.23"))) { //$NON-NLS-1$
                // Choose frontend
                nextActivity = NavRemote.class;
                setExtra(Extras.GUIDE.toString());
                showDialog(FRONTEND_CHOOSER);
                return;
            }

            else {
                startActivity(
                        new Intent().putExtra(Extras.GUIDE.toString(), true).setClass(ctx, NavRemote.class));
                return;
            }

        }
    });

    return d;
}

From source file:org.ale.openwatch.feeds.RemoteRecordingsListFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Log.i(TAG, "Item clicked: " + id);
    try {/*from  w w w  .  ja v a 2s  .  com*/
        final int model_id = (Integer) v.getTag(R.id.list_item_model);
        final OWServerObject server_object = OWServerObject
                .objects(getActivity().getApplicationContext(), OWServerObject.class).get(model_id);

        if (v.getTag(R.id.subView) != null && v.getTag(R.id.subView).toString().compareTo("menu") == 0) {
            Log.i(TAG, "menu click!");
            final Context c = getActivity();
            LayoutInflater inflater = (LayoutInflater) parentActivity
                    .getSystemService(parentActivity.LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.media_menu_popup,
                    (ViewGroup) getActivity().findViewById(R.id.content_frame), false);
            final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setView(layout).create();
            layout.findViewById(R.id.shareButton).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    Share.showShareDialogWithInfo(c, getString(R.string.share_video), server_object.getTitle(c),
                            OWUtils.urlForOWServerObject(server_object, c));
                    OWServiceRequests.increaseHitCount(c, server_object.getServerId(c), model_id,
                            server_object.getContentType(c), Constants.HIT_TYPE.CLICK);
                }
            });
            if (((OWServerObjectInterface) server_object.getChildObject(c)).getLat(c) != 0.0) {
                layout.findViewById(R.id.mapButton).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                        Intent i = new Intent(getActivity(), MapActivity.class);
                        i.putExtra(Constants.INTERNAL_DB_ID, model_id);
                        startActivity(i);
                    }
                });
            } else
                layout.findViewById(R.id.mapButton).setVisibility(View.GONE);
            layout.findViewById(R.id.reportButton).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    OWServiceRequests.flagOWServerObjet(getActivity().getApplicationContext(), server_object);
                }
            });
            dialog.show();
            return;
        } else
            Log.i(TAG, "non menu click!");

        Intent i = null;
        switch (server_object.getContentType(getActivity().getApplicationContext())) {
        case INVESTIGATION:
            //TODO: InvestigationViewActivity
            i = new Intent(this.getActivity(), OWInvestigationViewActivity.class);
            break;
        case VIDEO:
            // play video inline
            v.findViewById(R.id.playButton).setVisibility(View.GONE);

            parentActivity.removeVideoView(); // remove prior VideoView if it exists

            LayoutInflater layoutInflater = (LayoutInflater) getActivity()
                    .getSystemService(parentActivity.LAYOUT_INFLATER_SERVICE);
            //videoViewParent = (ViewGroup) v;
            parentActivity.videoViewHostCell = (ViewGroup) v;
            parentActivity.videoViewParent = (ViewGroup) layoutInflater.inflate(R.layout.feed_video_view,
                    (ViewGroup) v, true);
            parentActivity.videoView = (VideoView) parentActivity.videoViewParent.findViewById(R.id.videoView);

            if (Build.VERSION.SDK_INT >= 11)
                parentActivity.videoView.setAlpha(0);
            parentActivity.progressBar = (ProgressBar) parentActivity.videoViewParent
                    .findViewById(R.id.videoProgress);
            parentActivity.progressBar.setVisibility(View.VISIBLE);

            //Log.i(TAG, progressBar.toString());
            //RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)videoView.getLayoutParams();
            String url = ((OWVideoRecording) server_object
                    .getChildObject(getActivity().getApplicationContext()))
                            .getMediaFilepath(getActivity().getApplicationContext());
            OWUtils.setupVideoView(getActivity(), parentActivity.videoView, url, videoViewCallback,
                    parentActivity.progressBar);
            Log.i(TAG, "created VideoView");
            parentActivity.videoViewListIndex = position;
            break;
        case AUDIO:
        case PHOTO:
            i = new Intent(this.getActivity(), OWMediaObjectViewActivity.class);
            break;
        case MISSION:
            i = new Intent(this.getActivity(), OWMissionViewActivity.class);
        }

        if (i != null) {
            i.putExtra(Constants.INTERNAL_DB_ID, (Integer) v.getTag(R.id.list_item_model));
            startActivity(i);
        }
    } catch (Exception e) {
        Log.e(TAG, "failed to load list item model tag");
        e.printStackTrace();
        return;
    }

}

From source file:com.github.mobile.ui.repo.RepositoryListFragment.java

@Override
public boolean onListItemLongClick(ListView list, View v, int position, long itemId) {
    if (!isUsable())
        return false;

    final Repository repo = (Repository) list.getItemAtPosition(position);
    if (repo == null)
        return false;

    final AlertDialog dialog = LightAlertDialog.create(getActivity());
    dialog.setCanceledOnTouchOutside(true);

    dialog.setTitle(repo.generateId());// w w  w . j ava 2s  .  c  o  m

    View view = getActivity().getLayoutInflater().inflate(layout.repo_dialog, null);
    ViewFinder finder = new ViewFinder(view);

    final User owner = repo.getOwner();
    avatars.bind(finder.imageView(id.iv_owner_avatar), owner);
    finder.setText(id.tv_owner_name, getString(string.navigate_to_user, owner.getLogin()));
    finder.onClick(id.ll_owner_area, new OnClickListener() {

        public void onClick(View v) {
            dialog.dismiss();

            viewUser(owner);
        }
    });

    if ((recentRepos != null) && (recentRepos.contains(repo))) {
        finder.find(id.divider).setVisibility(View.VISIBLE);
        finder.find(id.ll_recent_repo_area).setVisibility(View.VISIBLE);
        finder.onClick(id.ll_recent_repo_area, new OnClickListener() {

            public void onClick(View v) {
                dialog.dismiss();

                recentRepos.remove(repo);
                refresh();
            }
        });
    }

    dialog.setView(view);
    dialog.show();

    return true;
}

From source file:com.janela.mobile.ui.repo.RepositoryListFragment.java

@Override
public boolean onListItemLongClick(ListView list, View v, int position, long itemId) {
    if (!isUsable())
        return false;

    final Repository repo = (Repository) list.getItemAtPosition(position);
    if (repo == null)
        return false;

    final AlertDialog dialog = LightAlertDialog.create(getActivity());
    dialog.setCanceledOnTouchOutside(true);

    dialog.setTitle(repo.generateId());//from   w w  w. j a  v a  2 s  .c  o m

    View view = getActivity().getLayoutInflater().inflate(R.layout.repo_dialog, null);
    ViewFinder finder = new ViewFinder(view);

    final User owner = repo.getOwner();
    avatars.bind(finder.imageView(R.id.iv_owner_avatar), owner);
    finder.setText(R.id.tv_owner_name, getString(R.string.navigate_to_user, owner.getLogin()));
    finder.onClick(R.id.ll_owner_area, new OnClickListener() {

        public void onClick(View v) {
            dialog.dismiss();

            viewUser(owner);
        }
    });

    if ((recentRepos != null) && (recentRepos.contains(repo))) {
        finder.find(R.id.divider).setVisibility(View.VISIBLE);
        finder.find(R.id.ll_recent_repo_area).setVisibility(View.VISIBLE);
        finder.onClick(R.id.ll_recent_repo_area, new OnClickListener() {

            public void onClick(View v) {
                dialog.dismiss();

                recentRepos.remove(repo);
                refresh();
            }
        });
    }

    dialog.setView(view);
    dialog.show();

    return true;
}

From source file:com.github.pockethub.ui.repo.RepositoryListFragment.java

@Override
public boolean onListItemLongClick(ListView list, View v, int position, long itemId) {
    if (!isUsable())
        return false;

    final Repo repo = (Repo) list.getItemAtPosition(position);
    if (repo == null)
        return false;

    final AlertDialog dialog = LightAlertDialog.create(getActivity());
    dialog.setCanceledOnTouchOutside(true);

    dialog.setTitle(InfoUtils.createRepoId(repo));

    View view = getActivity().getLayoutInflater().inflate(R.layout.repo_dialog, null);
    ViewFinder finder = new ViewFinder(view);

    final User owner = repo.owner;
    avatars.bind(finder.imageView(R.id.iv_owner_avatar), owner);
    finder.setText(R.id.tv_owner_name, getString(R.string.navigate_to_user, owner.login));
    finder.onClick(R.id.ll_owner_area, new OnClickListener() {

        public void onClick(View v) {
            dialog.dismiss();

            viewUser(owner);//from  ww w  . j ava 2  s .  c om
        }
    });

    if ((recentRepos != null) && (recentRepos.contains(repo))) {
        finder.find(R.id.divider).setVisibility(View.VISIBLE);
        finder.find(R.id.ll_recent_repo_area).setVisibility(View.VISIBLE);
        finder.onClick(R.id.ll_recent_repo_area, new OnClickListener() {

            public void onClick(View v) {
                dialog.dismiss();

                recentRepos.remove(repo);
                refresh();
            }
        });
    }

    dialog.setView(view);
    dialog.show();

    return true;
}

From source file:com.jwork.spycamera.MainFragment.java

private void showHelp() {
    AlertDialog dialog = new AlertDialog.Builder(activity).create();
    dialog.setTitle(this.getString(R.string.help));

    WebView wv = new WebView(activity);
    wv.loadData(this.getString(R.string.help_html), "text/html", "utf-8");
    wv.setScrollContainer(true);//from w  ww. j a  v a2  s  .  co m
    dialog.setView(wv);

    dialog.setButton(AlertDialog.BUTTON_NEGATIVE, this.getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Rate It", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Uri uri = Uri.parse("market://details?id=" + activity.getPackageName());
            Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
            try {
                activity.startActivity(myAppLinkToMarket);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(activity, "Failed to find Market application", Toast.LENGTH_LONG).show();
            }
        }
    });
    dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Share It", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Utility.shareIt(activity);
        }
    });
    dialog.show();
}

From source file:org.loon.framework.android.game.LGameActivity.java

/**
 * ??Alter//from ww  w  .jav  a  2s  .co m
 * 
 * @param message
 */
public void showAndroidAlert(final String title, final String message) {
    Runnable showAlert = new Runnable() {
        public void run() {
            final AlertDialog alert = new AlertDialog.Builder(LGameActivity.this).create();
            alert.setTitle(title);
            alert.setMessage(message);
            alert.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    alert.dismiss();
                }
            });
            alert.show();
        }
    };
    runOnUiThread(showAlert);
}