Example usage for android.app AlertDialog.Builder dismiss

List of usage examples for android.app AlertDialog.Builder dismiss

Introduction

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

Prototype

@Override
public void dismiss() 

Source Link

Document

Dismiss this dialog, removing it from the screen.

Usage

From source file:com.guardtrax.ui.screens.SplashScreen.java

private void initialize() {
    if (locationManagerObj == null) {
        locationManagerObj = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        try {//  w ww. j av a  2  s. c  o  m
            gps_enabled = locationManagerObj.isProviderEnabled(LocationManager.GPS_PROVIDER);

            //network_enabled = locationManagerObj.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        } catch (Exception ex) {
        }
    }

    // don't start listeners if no provider is enabled - Changed to to look for both
    //if (!gps_enabled) 
    if (!gps_enabled && !network_enabled) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(SplashScreen.this);
        dialog.setTitle("Info");
        dialog.setMessage("Please enable GPS!");
        dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                System.exit(0);
            }
        });
        dialog.show();
    } else {
        Runnable showWaitDialog = new Runnable() {
            @Override
            public void run() {
                Looper.prepare();

                int i = 0;

                //if syncComplete is true already it means that we are not trying to sync, hence delay so that splash screen can close slowly
                if (syncComplete) {
                    try {
                        Thread.sleep(1000);
                    } catch (Exception e) {
                    }
                } else {
                    while (!syncComplete || i++ < 10) {
                        try {
                            Thread.sleep(1000);
                        } catch (Exception e) {
                            break;
                        }
                    }

                    //make sure background task is completed.  If not, force it closed
                    if (!syncComplete) {
                        try {
                            if (syncdb.getStatus() != AsyncTask.Status.FINISHED)
                                syncdb.cancel(true);
                        } catch (Exception e) {
                        }
                    }
                }

                //After receiving first GPS Fix dismiss the Progress Dialog
                dialog.dismiss();

                //calling the tab class causes the current tab to be displayed (set to tab(0) which is the HomeScreen)

                Intent intent = new Intent();
                intent.setClass(SplashScreen.this, HomeScreen.class);
                startActivity(intent);

                //transition from splash to main menu is slowed down to a fade by this command
                overridePendingTransition(R.anim.activityfadein, R.anim.splashfadeout);

                SplashScreen.this.finish();
            }
        };

        // Create a Dialog to let the User know that we're waiting for a GPS Fix
        dialog = ProgressDialog.show(SplashScreen.this, "Please wait", "Initializing ...", true);

        Thread t = new Thread(showWaitDialog);
        t.start();
    }
}

From source file:com.fjn.magazinereturncandidate.activities.SdmScannerActivity.java

/**
 * Show logout warning dialog//from  w  ww  .  j a  v  a2  s. c o  m
 */
private void showDialog(boolean isLogout) {
    progress.show();
    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    if (isLogout) {
        dialog.setMessage(MESSAGE_CONFIRM_LOGOUT).setCancelable(false)
                .setPositiveButton(MESSAGE_YES_JP, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        LogManagerCommon.i(TAG, Message.TAG_SCANNER_ACTIVITY + Message.MESSAGE_LOGOUT);
                        // print log end process
                        LogManagerCommon.i(TAG, Message.TAG_SCANNER_ACTIVITY + Message.MESSAGE_ACTIVITY_END);
                        // print log move screen
                        LogManagerCommon.i(TAG, String.format(Message.MESSAGE_ACTIVITY_MOVE,
                                Message.SCANNER_ACTIVITY_NAME, Message.LOGIN_ACTIVITY_NAME));
                        compressFile();
                        sendFileLog();
                    }
                }).setNegativeButton(MESSAGE_NO_JP, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        progress.dismiss();
                        btnLogout.setEnabled(true);
                        isEnableScan = true;
                        registerLicenseCommon.EnableOCROrJanCode(flagSwitchOCR, hsmDecoder);
                    }
                });
    } else {
        dialog.setMessage(Message.MESSAGE_NETWORK_ERR).setCancelable(false)
                .setPositiveButton(MESSAGE_RETRY, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        sendFileLog();
                    }
                }).setNegativeButton(MESSAGE_CANCEL, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        progress.show();
                        delete(Constants.STRING_EMPTY);
                        clearAndLogout();
                        progress.dismiss();
                    }
                });
    }
    AlertDialog alert = dialog.show();
    TextView messageText = (TextView) alert.findViewById(android.R.id.message);
    assert messageText != null;
    messageText.setGravity(Gravity.CENTER);
}

From source file:it.unipr.ce.dsg.gamidroid.activities.NAM4JAndroidActivity.java

private void showAddress(final String addressTouch) {

    Log.d(NAM4JAndroidActivity.TAG, "Tapped address: " + addressTouch);

    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setMessage("Do you want to see information about building located in " + addressTouch + " ?");
    dialog.setCancelable(true);//  ww  w  .j a  va 2  s  .c o  m
    dialog.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
            Intent intent = new Intent(NAM4JAndroidActivity.this, BuildingLookupActivity.class);

            intent.putExtra("AddressBuilding", addressTouch);
            NAM4JAndroidActivity.this.startActivity(intent);
        }
    });
    dialog.setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });

    dialog.show();
}

From source file:org.cirdles.chroni.FilePickerActivity.java

public void onNewFolderButtonClicked(View v) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(this).setMessage("Enter the new folder's name below.");

    // creates the layout for the EditText, will be added to the dialog box
    final EditText newFolderText = new EditText(this);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.setMargins(25, 10, 20, 25);/*from  w ww  .  j  a  va 2s .  c  om*/

    LinearLayout dialogLayout = new LinearLayout(this);
    dialogLayout.addView(newFolderText);
    newFolderText.setLayoutParams(params);

    dialog.setView(dialogLayout); // adds EditText to dialog box

    dialog.setPositiveButton("Create", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Editable newFolderName = newFolderText.getText();
            File newFolder = new File(mainDirectory.getAbsolutePath() + "/" + newFolderName.toString());

            // creates the folder if the length of the text is greater than 0 AND the folder does not already exist
            if (newFolderName.length() > 0 && !newFolder.exists()) {
                // creates the actual folder
                boolean createdSuccessfully = newFolder.mkdir();

                // alerts the user if the folder was not created
                if (!createdSuccessfully)
                    Toast.makeText(FilePickerActivity.this, "ERROR: Folder could not be created",
                            Toast.LENGTH_SHORT).show();

                else { // if it succeeded, updates the adapter
                    mAdapter.add(newFolder);
                    Toast.makeText(FilePickerActivity.this, "Folder Created!", Toast.LENGTH_SHORT).show();
                }

            } else
                Toast.makeText(FilePickerActivity.this, "ERROR: Invalid folder name", Toast.LENGTH_SHORT)
                        .show();

            dialog.dismiss();
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    dialog.show();
}

From source file:de.baumann.quitsmoking.fragments.FragmentNotes.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_screen_notes, container, false);

    PreferenceManager.setDefaultValues(getActivity(), R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
    setHasOptionsMenu(true);/*from  w ww  .ja va 2s  .c o  m*/

    listView = (ListView) rootView.findViewById(R.id.notes);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            @SuppressWarnings("unchecked")
            HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position);

            final String title = map.get("title");
            final String cont = map.get("cont");
            final String seqnoStr = map.get("seqno");
            final String icon = map.get("icon");
            final String attachment = map.get("attachment");
            final String create = map.get("createDate");

            final Button attachment2;
            final TextView textInput;

            LayoutInflater inflater = getActivity().getLayoutInflater();

            final ViewGroup nullParent = null;
            View dialogView = inflater.inflate(R.layout.dialog_note_show, nullParent);

            final String attName = attachment.substring(attachment.lastIndexOf("/") + 1);
            final String att = getString(R.string.note_attachment) + ": " + attName;

            attachment2 = (Button) dialogView.findViewById(R.id.button_att);
            if (attName.equals("")) {
                attachment2.setVisibility(View.GONE);
            } else {
                attachment2.setText(att);
            }
            File file2 = new File(attachment);
            if (!file2.exists()) {
                attachment2.setVisibility(View.GONE);
            }

            textInput = (TextView) dialogView.findViewById(R.id.note_text_input);
            textInput.setText(cont);

            attachment2.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    openAtt(attachment);
                }
            });

            final ImageView be = (ImageView) dialogView.findViewById(R.id.imageButtonPri);
            assert be != null;

            switch (icon) {
            case "1":
                be.setImageResource(R.drawable.emoticon_neutral);
                sharedPref.edit().putString("handleTextIcon", "1").apply();
                break;
            case "2":
                be.setImageResource(R.drawable.emoticon_happy);
                sharedPref.edit().putString("handleTextIcon", "2").apply();
                break;
            case "3":
                be.setImageResource(R.drawable.emoticon_sad);
                sharedPref.edit().putString("handleTextIcon", "3").apply();
                break;
            case "4":
                be.setImageResource(R.drawable.emoticon);
                sharedPref.edit().putString("handleTextIcon", "4").apply();
                break;
            case "5":
                be.setImageResource(R.drawable.emoticon_cool);
                sharedPref.edit().putString("handleTextIcon", "5").apply();
                break;
            case "6":
                be.setImageResource(R.drawable.emoticon_dead);
                sharedPref.edit().putString("handleTextIcon", "6").apply();
                break;
            case "7":
                be.setImageResource(R.drawable.emoticon_excited);
                sharedPref.edit().putString("handleTextIcon", "7").apply();
                break;
            case "8":
                be.setImageResource(R.drawable.emoticon_tongue);
                sharedPref.edit().putString("handleTextIcon", "8").apply();
                break;
            case "9":
                be.setImageResource(R.drawable.emoticon_devil);
                sharedPref.edit().putString("handleTextIcon", "9").apply();
                break;
            case "":
                be.setImageResource(R.drawable.emoticon_neutral);
                sharedPref.edit().putString("handleTextIcon", "").apply();
                break;
            }

            android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(getActivity())
                    .setTitle(title).setView(dialogView)
                    .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setNegativeButton(R.string.note_edit, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            sharedPref.edit().putString("handleTextTitle", title)
                                    .putString("handleTextText", cont).putString("handleTextIcon", icon)
                                    .putString("handleTextSeqno", seqnoStr)
                                    .putString("handleTextAttachment", attachment)
                                    .putString("handleTextCreate", create).apply();
                            helper_notes.editNote(getActivity());
                        }
                    });
            dialog.show();
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            @SuppressWarnings("unchecked")
            HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position);

            final String seqnoStr = map.get("seqno");
            final String title = map.get("title");
            final String cont = map.get("cont");
            final String icon = map.get("icon");
            final String attachment = map.get("attachment");
            final String create = map.get("createDate");

            final CharSequence[] options = { getString(R.string.note_edit), getString(R.string.note_share),
                    getString(R.string.note_remove_note) };
            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.goal_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.dismiss();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.note_edit))) {
                                sharedPref.edit().putString("handleTextTitle", title)
                                        .putString("handleTextText", cont).putString("handleTextIcon", icon)
                                        .putString("handleTextSeqno", seqnoStr)
                                        .putString("handleTextAttachment", attachment)
                                        .putString("handleTextAttachment", create).apply();
                                helper_notes.editNote(getActivity());
                            }

                            if (options[item].equals(getString(R.string.note_share))) {
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, cont);
                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.note_remove_note))) {
                                try {
                                    Database_Notes db = new Database_Notes(getActivity());
                                    final int count = db.getRecordCount();
                                    db.close();

                                    if (count == 1) {
                                        Snackbar snackbar = Snackbar.make(listView, R.string.note_remove_cannot,
                                                Snackbar.LENGTH_LONG);
                                        snackbar.show();

                                    } else {
                                        Snackbar snackbar = Snackbar
                                                .make(listView, R.string.note_remove_confirmation,
                                                        Snackbar.LENGTH_LONG)
                                                .setAction(R.string.yes, new View.OnClickListener() {
                                                    @Override
                                                    public void onClick(View view) {
                                                        try {
                                                            Database_Notes db = new Database_Notes(
                                                                    getActivity());
                                                            db.deleteNote(Integer.parseInt(seqnoStr));
                                                            db.close();
                                                            setNotesList();
                                                        } catch (PackageManager.NameNotFoundException e) {
                                                            e.printStackTrace();
                                                        }
                                                    }
                                                });
                                        snackbar.show();
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }).show();

            return true;
        }
    });

    setHasOptionsMenu(true);
    setNotesList();
    return rootView;
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

@Override
public void onBackPressed() {
    AlertDialog.Builder dialog = new AlertDialog.Builder(this);

    if (GTConstants.sendData) {
        dialog.setTitle("Warning");
        dialog.setMessage("You must end shift before exit!");
        dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override/*w w w  .j a  v  a 2 s.c  o m*/
            public void onClick(DialogInterface dialog, int which) {
                return;
            }
        });
        dialog.show();
    } else {
        dialog.setTitle("Exit?");
        dialog.setMessage("Are you sure you want to exit?");
        dialog.setNegativeButton(android.R.string.no, null);
        dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

                // Create a Dialog to let the User know that we're waiting for a GPS Fix
                pdialog = ProgressDialog.show(HomeScreen.this, "Please wait", "Exiting GT Android ...", true);

                Runnable showWaitDialog = new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Looper.prepare();
                            MainService.closeLocationListener(); //close out GPS

                            //only send 92 if online
                            if (Utility.isOnline(HomeScreen.this)) {
                                GTConstants.sendData = true; //allow the exit event to be sent
                                send_event("92"); //send the event
                                Utility.Sleep(4000); //give time for the event to be sent before exiting
                            }

                            stopService();

                            Utility.Sleep(1000);
                            pdialog.dismiss();
                            Utility.Sleep(1000);

                            //terminating the running threads and finishing program must be run on the main thread
                            HomeScreen.this.runOnUiThread(new Runnable() {
                                public void run() {
                                    if (pdialog.isShowing())
                                        pdialog.dismiss();
                                    HomeScreen.super.onBackPressed();
                                    android.os.Process.killProcess(android.os.Process.myPid());
                                    finish();
                                }
                            });
                        } catch (Exception e) {

                            //terminating the running threads and finishing program must be run on the main thread
                            HomeScreen.this.runOnUiThread(new Runnable() {
                                public void run() {
                                    if (pdialog.isShowing())
                                        pdialog.dismiss();
                                    HomeScreen.super.onBackPressed();
                                    android.os.Process.killProcess(android.os.Process.myPid());
                                    finish();
                                }
                            });

                        }
                    }
                };

                Thread t = new Thread(showWaitDialog);
                t.start();
            }
        });

        dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (!Utility.deviceRegistered()) {
                    //send_data = true;
                    scan_click(false);
                }
            }
        });

        dialog.show();
    }
}