Example usage for android.app AlertDialog setMessage

List of usage examples for android.app AlertDialog setMessage

Introduction

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

Prototype

public void setMessage(CharSequence message) 

Source Link

Usage

From source file:com.linkbubble.util.YouTubeEmbedHelper.java

AlertDialog getEmbedResultsDialog() {
    if (mEmbedInfo.size() > 0) {
        ListView listView = new ListView(mContext);
        listView.setAdapter(new EmbedItemAdapter());

        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setView(listView);//w w  w .  j  av a 2 s . co  m
        builder.setIcon(mYouTubeResolveInfo.loadIcon(mContext.getPackageManager()));
        builder.setTitle(R.string.title_youtube_embed_to_load);

        final AlertDialog alertDialog = builder.create();
        alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                EmbedInfo embedInfo = (EmbedInfo) view.getTag();
                if (embedInfo != null) {
                    loadYouTubeVideo(embedInfo.mId);
                }
                alertDialog.dismiss();
            }
        });

        return alertDialog;
    } else {
        final AlertDialog alertDialog = new AlertDialog.Builder(mContext).create();
        alertDialog.setTitle(R.string.youtube_embed_error_title);
        alertDialog.setMessage(mContext.getString(R.string.youtube_embed_error_summary));
        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE,
                mContext.getResources().getString(R.string.action_ok), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        alertDialog.dismiss();
                    }

                });
        alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        return alertDialog;
    }
}

From source file:com.ushahidi.android.app.ui.phone.AddReportActivity.java

/**
 * Create various dialog/*  ww  w .ja v  a 2s.c  om*/
 */
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ERROR_NETWORK: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.network_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }
    case DIALOG_ERROR_SAVING: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.file_system_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_CHOOSE_IMAGE_METHOD: {

        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.choose_method));
        dialog.setMessage(getString(R.string.how_to_select_pic));
        dialog.setButton(getString(R.string.gallery_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_PICK);
                intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, REQUEST_CODE_IMAGE);
                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.cancel), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setButton3(getString(R.string.camera_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT,
                        PhotoUtils.getPhotoUri(photoName, AddReportActivity.this));
                startActivityForResult(intent, REQUEST_CODE_CAMERA);
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_MULTIPLE_CATEGORY: {
        if (showCategories() != null) {
            return new AlertDialog.Builder(this).setTitle(R.string.choose_categories)
                    .setMultiChoiceItems(showCategories(), setCheckedCategories(),
                            new DialogInterface.OnMultiChoiceClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton,
                                        boolean isChecked) {
                                    // see if categories have previously

                                    if (isChecked) {
                                        mVectorCategories.add(mCategoriesId.get(whichButton));

                                        mError = false;
                                    } else {
                                        mVectorCategories.remove(mCategoriesId.get(whichButton));
                                    }

                                    setSelectedCategories(mVectorCategories);
                                }
                            })
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {

                            /* User clicked Yes so do some stuff */
                        }
                    }).create();
        }
    }

    case TIME_DIALOG_ID:
        return new TimePickerDialog(this, mTimeSetListener, mCalendar.get(Calendar.HOUR),
                mCalendar.get(Calendar.MINUTE), false);

    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, mDateSetListener, mCalendar.get(Calendar.YEAR),
                mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));

    case DIALOG_SHOW_MESSAGE:
        AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this);
        messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showDialog = messageBuilder.create();
        showDialog.show();
        break;

    case DIALOG_SHOW_REQUIRED:
        AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this);
        requiredBuilder.setTitle(R.string.required_fields);
        requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showRequiredDialog = requiredBuilder.create();
        showRequiredDialog.show();
        break;

    // prompt for unsaved changes
    case DIALOG_SHOW_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.unsaved_changes));
        dialog.setMessage(getString(R.string.want_to_cancel));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    // prompt for report deletion
    case DIALOG_SHOW_DELETE_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.delete_report));
        dialog.setMessage(getString(R.string.want_to_delete));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // delete report
                deleteReport();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    }
    return null;
}

From source file:ch.bfh.instacircle.NetworkActiveActivity.java

/**
 * Writes an NFC Tag//w w w .ja v a2s  .c o m
 * 
 * @param tag
 *            The reference to the tag
 * @param message
 *            the message which should be writen on the message
 * @return true if successful, false otherwise
 */
public boolean writeTag(Tag tag, NdefMessage message) {

    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("InstaCircle - write NFC Tag failed");
    alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    try {
        // see if tag is already NDEF formatted
        Ndef ndef = Ndef.get(tag);
        if (ndef != null) {
            ndef.connect();
            if (!ndef.isWritable()) {
                Log.d(TAG, "This tag is read only.");
                alertDialog.setMessage("This tag is read only.");
                alertDialog.show();
                return false;
            }

            // work out how much space we need for the data
            int size = message.toByteArray().length;
            if (ndef.getMaxSize() < size) {
                Log.d(TAG, "Tag doesn't have enough free space.");
                alertDialog.setMessage("Tag doesn't have enough free space.");
                alertDialog.show();
                return false;
            }

            ndef.writeNdefMessage(message);
            Log.d(TAG, "Tag written successfully.");

        } else {
            // attempt to format tag
            NdefFormatable format = NdefFormatable.get(tag);
            if (format != null) {
                try {
                    format.connect();
                    format.format(message);
                    Log.d(TAG, "Tag written successfully!");
                } catch (IOException e) {
                    alertDialog.setMessage("Unable to format tag to NDEF.");
                    alertDialog.show();
                    Log.d(TAG, "Unable to format tag to NDEF.");
                    return false;

                }
            } else {
                Log.d(TAG, "Tag doesn't appear to support NDEF format.");
                alertDialog.setMessage("Tag doesn't appear to support NDEF format.");
                alertDialog.show();
                return false;
            }
        }
    } catch (Exception e) {
        Log.d(TAG, "Failed to write tag");
        return false;
    }
    alertDialog.setTitle("InstaCircle");
    alertDialog.setMessage("NFC Tag written successfully.");
    alertDialog.show();
    return true;
}

From source file:info.zamojski.soft.towercollector.MainActivity.java

private void displayUploadResultDialog(Bundle extras) {
    int descriptionId = extras.getInt(UploaderService.INTENT_KEY_RESULT_DESCRIPTION);
    try {//from w ww  .j  a  v a2 s.  com
        String descriptionContent = getString(descriptionId);
        Log.d("displayUploadResultDialog(): Received extras: %s", descriptionId);
        // display dialog
        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setCanceledOnTouchOutside(true);
        alertDialog.setCancelable(true);
        alertDialog.setTitle(R.string.uploader_result_dialog_title);
        alertDialog.setMessage(descriptionContent);
        alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        alertDialog.show();
    } catch (NotFoundException ex) {
        Log.w("displayUploadResultDialog(): Invalid string id received with intent extras: %s", descriptionId);
        MyApplication.getAnalytics().sendException(ex, Boolean.FALSE);
        ACRA.getErrorReporter().handleSilentException(ex);
    }
}

From source file:info.zamojski.soft.towercollector.MainActivity.java

private boolean displayInAirplaneModeDialog() {
    // check if in airplane mode
    boolean inAirplaneMode = NetworkUtils.isInAirplaneMode(getApplication());
    if (inAirplaneMode) {
        Log.d("displayInAirplaneModeDialog(): Device is in airplane mode");
        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setCanceledOnTouchOutside(true);
        alertDialog.setCancelable(true);
        alertDialog.setTitle(R.string.main_dialog_in_airplane_mode_title);
        alertDialog.setMessage(getString(R.string.main_dialog_in_airplane_mode_message));
        alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    }/*  w ww.  ja  v  a2  s . c om*/
                });
        alertDialog.show();
    }
    return inAirplaneMode;
}

From source file:com.awrtechnologies.carbudgetsales.MainActivity.java

/**
 * Function to display simple Alert Dialog
 *
 * @param context - application context//  ww w  .j  av a2s.  com
 * @param title   - alert dialog title
 * @param message - alert message
 * @param status  - success/failure (used to set icon)
 */
public void showAlertDialog(Context context, String title, String message, Boolean status) {
    AlertDialog alertDialog = new AlertDialog.Builder(context).create();

    // Setting Dialog Title
    alertDialog.setTitle(title);

    // Setting Dialog Message
    alertDialog.setMessage(message);

    // Setting alert dialog icon
    alertDialog.setIcon((status) ? R.drawable.transparentlogo : R.drawable.transparentlogo);

    // Setting OK Button
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            MainActivity.this.finish();
            dialog.dismiss();

        }
    });

    // Showing Alert Message
    alertDialog.show();
}

From source file:foam.littlej.android.app.ui.phone.AddReportActivity.java

/**
 * Create various dialog// w  ww.  j a  v  a  2  s. c o m
 */
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ERROR_NETWORK: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.network_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }
    case DIALOG_ERROR_SAVING: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.file_system_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_CHOOSE_IMAGE_METHOD: {

        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.choose_method));
        dialog.setMessage(getString(R.string.how_to_select_pic));
        dialog.setButton(getString(R.string.gallery_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_PICK);
                intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, REQUEST_CODE_IMAGE);
                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.cancel), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setButton3(getString(R.string.camera_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT,
                        PhotoUtils.getPhotoUri(photoName, AddReportActivity.this));
                startActivityForResult(intent, REQUEST_CODE_CAMERA);
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_MULTIPLE_CATEGORY: {
        if (showCategories() != null) {
            return new AlertDialog.Builder(this).setTitle(R.string.choose_categories)
                    .setMultiChoiceItems(showCategories(), setCheckedCategories(),
                            new DialogInterface.OnMultiChoiceClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton,
                                        boolean isChecked) {
                                    // see if categories have previously

                                    if (isChecked) {
                                        mVectorCategories.add(mCategoriesId.get(whichButton));

                                        mError = false;
                                    } else {
                                        mVectorCategories.remove(mCategoriesId.get(whichButton));
                                    }

                                    setSelectedCategories(mVectorCategories);
                                }
                            })
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {

                            /* User clicked Yes so do some stuff */
                        }
                    }).create();
        }
    }

    case TIME_DIALOG_ID:
        return new TimePickerDialog(this, mTimeSetListener, mCalendar.get(Calendar.HOUR),
                mCalendar.get(Calendar.MINUTE), false);

    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, mDateSetListener, mCalendar.get(Calendar.YEAR),
                mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));

    case DIALOG_SHOW_MESSAGE:
        AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this);
        messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showDialog = messageBuilder.create();
        showDialog.show();
        break;

    case DIALOG_SHOW_REQUIRED:
        AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this);
        requiredBuilder.setTitle(R.string.required_fields);
        requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showRequiredDialog = requiredBuilder.create();
        showRequiredDialog.show();
        break;

    // prompt for unsaved changes
    case DIALOG_SHOW_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.unsaved_changes));
        dialog.setMessage(getString(R.string.want_to_cancel));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                new DiscardTask(AddReportActivity.this).execute((String) null);
                finish();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    // prompt for report deletion
    case DIALOG_SHOW_DELETE_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.delete_report));
        dialog.setMessage(getString(R.string.want_to_delete));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // delete report
                deleteReport();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    }
    return null;
}

From source file:com.xperia64.rompatcher.MainActivity.java

private void patchCheck() {
    // Just try to interpret the following if statement. I dare you.
    if (new File(Globals.fileToPatch + ".bak").exists()
            || (Globals.fileToPatch.toLowerCase(Locale.US).endsWith(".ecm") && new File(
                    Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('.'))).exists())
            || new File(Globals.fileToPatch + ".new").exists()
            || (new File(Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('/') + 1)
                    + ed.getText().toString()
                    + ((e.isChecked())//from   w ww  .j av a  2  s  .co m
                            ? ((Globals.fileToPatch.lastIndexOf('.') > -1) ? Globals.fileToPatch.substring(
                                    Globals.fileToPatch.lastIndexOf('.'), Globals.fileToPatch.length()) : "")
                            : "")).exists()
                    && d.isChecked() && c.isChecked())) {

        System.out.println("bad");
        AlertDialog dialog2 = new AlertDialog.Builder(staticThis).create();
        dialog2.setTitle(getResources().getString(R.string.warning));
        dialog2.setMessage(getResources().getString(R.string.warning_desc));
        dialog2.setCancelable(false);
        dialog2.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.yes),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int buttonId) {
                        new File(Globals.fileToPatch + ".bak").delete();
                        new File(Globals.fileToPatch + ".new").delete();
                        if (Globals.fileToPatch.toLowerCase(Locale.US).endsWith(".ecm"))
                            new File(Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('.')))
                                    .delete();
                        new File(Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('/') + 1)
                                + ed.getText().toString()
                                + ((e.isChecked()) ? ((Globals.fileToPatch.lastIndexOf('.') > -1)
                                        ? Globals.fileToPatch.substring(Globals.fileToPatch.lastIndexOf('.'),
                                                Globals.fileToPatch.length())
                                        : "") : "")).delete();
                        if (d.isChecked() && c.isChecked() && e.isChecked()
                                && Globals.fileToPatch.lastIndexOf('.') > -1) {
                            ed.setText(ed.getText() + Globals.fileToPatch.substring(
                                    Globals.fileToPatch.lastIndexOf('.'), Globals.fileToPatch.length()));
                        }
                        patch(c.isChecked(), d.isChecked(), r.isChecked(), ed.getText().toString());
                    }
                });
        dialog2.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.cancel),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int buttonId) {
                        Toast t = Toast.makeText(staticThis, getResources().getString(R.string.nopatch),
                                Toast.LENGTH_SHORT);
                        t.show();
                    }
                });
        dialog2.show();
    } else {
        if (d.isChecked() && c.isChecked() && e.isChecked() && Globals.fileToPatch.lastIndexOf('.') > -1) {
            ed.setText(ed.getText() + Globals.fileToPatch.substring(Globals.fileToPatch.lastIndexOf('.'),
                    Globals.fileToPatch.length()));
        }
        patch(c.isChecked(), d.isChecked(), r.isChecked(), ed.getText().toString());
    }

}

From source file:info.zamojski.soft.towercollector.MainActivity.java

private void startUploaderServiceWithCheck() {
    String runningTaskClassName = MyApplication.getBackgroundTaskName();
    if (runningTaskClassName != null) {
        Log.d("startUploaderService(): Another task is running in background: %s", runningTaskClassName);
        backgroundTaskHelper.showTaskRunningMessage(runningTaskClassName);
        return;//from   ww w . jav  a  2  s.  co  m
    }
    // check API key
    String apiKey = MyApplication.getPreferencesProvider().getApiKey();
    if (!Validator.isOpenCellIdApiKeyValid(apiKey)) {
        final String apiKeyLocal = apiKey;
        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setCanceledOnTouchOutside(true);
        alertDialog.setCancelable(true);
        if (StringUtils.isNullEmptyOrWhitespace(apiKey)) {
            alertDialog.setTitle(R.string.main_dialog_api_key_empty_title);
            alertDialog.setMessage(getString(R.string.main_dialog_api_key_empty_message));
            alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_register),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            try {
                                Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                                        Uri.parse(getString(R.string.preferences_opencellid_org_sign_up_link)));
                                startActivity(browserIntent);
                            } catch (ActivityNotFoundException ex) {
                                Toast.makeText(getApplication(), R.string.web_browser_missing,
                                        Toast.LENGTH_LONG).show();
                            }
                        }
                    });
        } else {
            alertDialog.setTitle(R.string.main_dialog_api_key_invalid_title);
            alertDialog.setMessage(getString(R.string.main_dialog_api_key_invalid_message));
            alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_upload),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            startUploaderService(apiKeyLocal);
                        }
                    });
        }
        alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.dialog_enter_api_key),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        startPreferencesActivity();
                    }
                });
        alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.dialog_cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        alertDialog.show();
        return;
    } else {
        startUploaderService(apiKey);
    }
}

From source file:com.xperia64.timidityae.PlayerFragment.java

@SuppressLint("InflateParams")
public void showMidiDialog() {
    AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
    View v = getActivity().getLayoutInflater().inflate(R.layout.midi_options, null);
    Button speedUp = (Button) v.findViewById(R.id.speedUp);
    Button slowDown = (Button) v.findViewById(R.id.slowDown);
    Button keyUp = (Button) v.findViewById(R.id.keyUp);
    Button keyDown = (Button) v.findViewById(R.id.keyDown);
    Button vplus = (Button) v.findViewById(R.id.vplus);
    Button vminus = (Button) v.findViewById(R.id.vminus);
    Button export = (Button) v.findViewById(R.id.exportButton);
    Button saveCfg = (Button) v.findViewById(R.id.saveCfg);
    Button loadCfg = (Button) v.findViewById(R.id.loadCfg);
    Button savedefCfg = (Button) v.findViewById(R.id.savedefCfg);
    final Button deldefCfg = (Button) v.findViewById(R.id.deldefCfg);
    deldefCfg.setEnabled(new File(mActivity.currSongName + ".def.tcf").exists()
            || new File(mActivity.currSongName + ".def.tzf").exists());
    tempo = (TextView) v.findViewById(R.id.tempoText);
    pitch = (TextView) v.findViewById(R.id.pitchText);
    voices = (TextView) v.findViewById(R.id.voiceText);

    tempo.setText(String.format(getResources().getString(R.string.mop_tempo), JNIHandler.ttr,
            (int) (500000 / (double) JNIHandler.tt * 120 * (double) JNIHandler.ttr / 100 + 0.5)));
    pitch.setText(String.format(getResources().getString(R.string.mop_pitch),
            ((JNIHandler.koffset > 0) ? "+" : "") + Integer.toString(JNIHandler.koffset)));
    voices.setText(/*from   ww w .  j  a  va2 s. c o m*/
            String.format(getResources().getString(R.string.mop_voice), JNIHandler.voice, JNIHandler.maxvoice));
    speedUp.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            JNIHandler.controlTimidity(17, 1);
            JNIHandler.waitUntilReady();
            JNIHandler.tb++;
        }

    });
    slowDown.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            JNIHandler.controlTimidity(18, 1);
            JNIHandler.waitUntilReady();
            JNIHandler.tb--;
        }

    });
    keyUp.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            JNIHandler.controlTimidity(15, 1);
            JNIHandler.waitUntilReady();
        }

    });
    keyDown.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            JNIHandler.controlTimidity(16, -1);
            JNIHandler.waitUntilReady();
        }

    });
    vplus.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            JNIHandler.controlTimidity(19, 5);
            JNIHandler.waitUntilReady();
        }

    });
    vminus.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            JNIHandler.controlTimidity(20, 5);
            JNIHandler.waitUntilReady();
        }

    });
    export.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            mActivity.dynExport();
        }

    });
    saveCfg.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            mActivity.saveCfg();
        }

    });
    loadCfg.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            mActivity.loadCfg();
        }

    });
    savedefCfg.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            String value1;
            String value2;
            boolean alreadyExists = (new File(mActivity.currSongName + ".def.tcf").exists()
                    || new File(mActivity.currSongName + ".def.tzf").exists());
            boolean aWrite = true;
            String needRename1 = null;
            String needRename2 = null;
            String probablyTheRoot = "";
            String probablyTheDirectory = "";
            try {
                if (Globals.compressCfg)
                    new FileOutputStream(mActivity.currSongName + ".def.tzf", true).close();
                else
                    new FileOutputStream(mActivity.currSongName + ".def.tcf", true).close();
            } catch (FileNotFoundException e) {
                aWrite = false;
            } catch (IOException e) {
                e.printStackTrace();
            }
            final boolean canWrite = aWrite;
            if (!alreadyExists && canWrite) {
                new File(mActivity.currSongName + ".def.tcf").delete();
                new File(mActivity.currSongName + ".def.tzf").delete();
            }

            if (canWrite && new File(mActivity.currSongName).canWrite()) {
                value1 = mActivity.currSongName + (Globals.compressCfg ? ".def.tzf" : ".def.tcf");
                value2 = mActivity.currSongName + (Globals.compressCfg ? ".def.tcf" : ".def.tzf");
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null) {
                //TODO
                // Write the file to getExternalFilesDir, then move it with the Uri
                // We need to tell JNIHandler that movement is needed.
                // This is pretty much done now?
                String[] tmp = Globals.getDocFilePaths(getActivity(), mActivity.currSongName);
                probablyTheDirectory = tmp[0];
                probablyTheRoot = tmp[1];
                if (probablyTheDirectory.length() > 1) {
                    needRename1 = (mActivity.currSongName).substring(
                            mActivity.currSongName.indexOf(probablyTheRoot) + probablyTheRoot.length())
                            + (Globals.compressCfg ? ".def.tzf" : ".def.tcf");
                    needRename2 = (mActivity.currSongName).substring(
                            mActivity.currSongName.indexOf(probablyTheRoot) + probablyTheRoot.length())
                            + (Globals.compressCfg ? ".def.tcf" : ".def.tzf");
                    value1 = probablyTheDirectory
                            + mActivity.currSongName.substring(mActivity.currSongName.lastIndexOf('/'))
                            + (Globals.compressCfg ? ".def.tzf" : ".def.tcf");
                    value2 = probablyTheDirectory
                            + mActivity.currSongName.substring(mActivity.currSongName.lastIndexOf('/'))
                            + (Globals.compressCfg ? ".def.tcf" : ".def.tzf");
                } else {
                    Toast.makeText(getActivity(),
                            "Could not write config file. Did you give Timidity write access to the root of your external sd card?",
                            Toast.LENGTH_SHORT).show();
                    return;
                }
            } else {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    Toast.makeText(getActivity(),
                            "Could not write config file. Did you give Timidity write access to the root of your external sd card?",
                            Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getActivity(), "Could not write config file. Permission denied.",
                            Toast.LENGTH_SHORT).show();
                }
                return;
            }
            final String finalval1 = value1;
            final String finalval2 = value2;
            final String needToRename1 = needRename1;
            final String needToRename2 = needRename2;
            final String probRoot = probablyTheRoot;
            if (alreadyExists) {
                AlertDialog dialog = new AlertDialog.Builder(mActivity).create();
                dialog.setTitle("Warning");
                dialog.setMessage("Overwrite default config file?");
                dialog.setCancelable(false);
                dialog.setButton(DialogInterface.BUTTON_POSITIVE,
                        getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int buttonId) {
                                if (!canWrite && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                    if (needToRename1 != null) {
                                        Globals.tryToDeleteFile(getActivity(), probRoot + needToRename1);
                                        Globals.tryToDeleteFile(getActivity(), finalval1);
                                        Globals.tryToDeleteFile(getActivity(), probRoot + needToRename2);
                                        Globals.tryToDeleteFile(getActivity(), finalval2);
                                    } else {
                                        Globals.tryToDeleteFile(getActivity(), finalval1);
                                        Globals.tryToDeleteFile(getActivity(), finalval2);
                                    }
                                } else {
                                    new File(mActivity.currSongName + ".def.tcf").delete();
                                    new File(mActivity.currSongName + ".def.tzf").delete();
                                }
                                mActivity.localfinished = false;
                                mActivity.saveCfgPart2(finalval1, needToRename1);
                                deldefCfg.setEnabled(true);
                                /*Intent new_intent = new Intent();
                                new_intent.setAction(getResources().getString(R.string.msrv_rec));
                                new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 16);
                                new_intent.putExtra(getResources().getString(R.string.msrv_outfile), mActivity.currSongName+".def.tcf");
                                getActivity().sendBroadcast(new_intent);
                                deldefCfg.setEnabled(true);*/
                            }
                        });
                dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.no),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int buttonId) {

                            }
                        });
                dialog.show();

            } else {
                /*Intent new_intent = new Intent();
                 new_intent.setAction(getResources().getString(R.string.msrv_rec));
                 new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 16);
                 new_intent.putExtra(getResources().getString(R.string.msrv_outfile), mActivity.currSongName+".def.tcf");
                 getActivity().sendBroadcast(new_intent);
                 deldefCfg.setEnabled(true);*/
                mActivity.localfinished = false;
                mActivity.saveCfgPart2(finalval1, needToRename1);
                deldefCfg.setEnabled(true);
            }
        }

    });

    deldefCfg.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            if (new File(mActivity.currSongName + ".def.tcf").exists()
                    || new File(mActivity.currSongName + ".def.tzf").exists()) {
                boolean aWrite = true;
                try {
                    if (Globals.compressCfg)
                        new FileOutputStream(mActivity.currSongName + ".def.tzf", true).close();
                    else
                        new FileOutputStream(mActivity.currSongName + ".def.tcf", true).close();
                } catch (FileNotFoundException e) {
                    aWrite = false;
                } catch (IOException e) {
                    e.printStackTrace();
                }
                final boolean canWrite = aWrite;
                AlertDialog dialog = new AlertDialog.Builder(mActivity).create();
                dialog.setTitle("Warning");
                dialog.setMessage("Really delete default config file?");
                dialog.setCancelable(false);
                dialog.setButton(DialogInterface.BUTTON_POSITIVE,
                        getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int buttonId) {

                                if (!canWrite && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                    Globals.tryToDeleteFile(getActivity(), mActivity.currSongName + ".def.tzf");
                                    Globals.tryToDeleteFile(getActivity(), mActivity.currSongName + ".def.tcf");
                                } else {
                                    new File(mActivity.currSongName + ".def.tcf").delete();
                                    new File(mActivity.currSongName + ".def.tzf").delete();
                                }
                                deldefCfg.setEnabled(false);
                            }
                        });
                dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.no),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int buttonId) {

                            }
                        });
                dialog.show();

            }
        }

    });

    final Spinner x = (Spinner) v.findViewById(R.id.resampSpinner);
    List<String> arrayAdapter = new ArrayList<String>();
    for (String yyy : Globals.sampls)
        arrayAdapter.add(yyy);
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, arrayAdapter);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    x.setAdapter(dataAdapter);
    firstSelection = true;
    x.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int pos, long id) {
            if (firstSelection)
                firstSelection = false;
            else {
                JNIHandler.setResampleTimidity(JNIHandler.currsamp = pos);
                JNIHandler.seekTo(JNIHandler.currTime);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {

        }

    });
    x.setSelection(JNIHandler.currsamp);
    if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        v.setBackgroundColor(Globals.theme == 1 ? Color.WHITE : Color.BLACK);

    b.setView(v);
    b.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    b.setTitle(getActivity().getResources().getString(R.string.mop));
    ddd = b.create();
    ddd.show();

}