Example usage for android.app AlertDialog setButton

List of usage examples for android.app AlertDialog setButton

Introduction

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

Prototype

public void setButton(int whichButton, CharSequence text, OnClickListener listener) 

Source Link

Document

Set a listener to be invoked when the positive button of the dialog is pressed.

Usage

From source file:es.uja.photofirma.android.CameraActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.camera_activity);

    logger.appendLog(100, "login usuario satisfactorio");

    //Definicin de elementos visuales involucrados
    lycpt = (ImageView) findViewById(R.id.cameraActivityCameraPhotoTap);
    lyerr = (LinearLayout) findViewById(R.id.cameraActivityErrorHeader);
    lysuc = (LinearLayout) findViewById(R.id.cameraActivitySuccessHeaderTextView);
    lycan = (LinearLayout) findViewById(R.id.cameraActivityCancelHeader);
    lyinf = (LinearLayout) findViewById(R.id.cameraActivityInfoHeader);
    lyupl = (LinearLayout) findViewById(R.id.cameraActivityUploadingHeader);
    lyudone = (LinearLayout) findViewById(R.id.cameraActivitySuccesUploadHeader);
    lyuerr = (LinearLayout) findViewById(R.id.cameraActivityErrorUploadHeader);
    errorText = (TextView) findViewById(R.id.cameraActivityErrorTextView);

    //gestor de servicios de telefonia, para la obtencin del IMEI del terminal
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    if (telephonyManager == null) {
        imeiNumber = getString(R.string.no_imei_available);
    } else {/*from  www  .  jav  a2  s .  c om*/
        imeiNumber = telephonyManager.getDeviceId();
    }

    //Deteccin de los parametros necesarios tras un login exitoso
    if (getIntent().hasExtra("userName") && getIntent().hasExtra("userId")
            && getIntent().hasExtra("userEmail")) {
        userName = getIntent().getExtras().getString("userName");
        userId = getIntent().getExtras().getInt("userId");
        userEmail = getIntent().getExtras().getString("userEmail");
    } else {
        Toast.makeText(getApplicationContext(), getString(R.string.no_user_data_found), Toast.LENGTH_LONG)
                .show();
    }

    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Aviso de privacidad");
    alertDialog.setMessage(getString(R.string.privacy_alert));
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {

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

    SharedPreferences prefs = getSharedPreferences("prefsfile", Context.MODE_PRIVATE);
    String myPrefServerIp = prefs.getString("prefIpAddress", "10.0.3.2");
    URL_CONTENT_UPLOAD = "https://" + myPrefServerIp + "/photo@firmaServices/content_upload.php";
}

From source file:org.apps8os.motivator.ui.MoodHistoryActivity.java

/**
 * Actions for the menu items./*from   w  w w . j  a v  a 2  s .  com*/
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    MoodHistoryWeekFragment weekFragment;
    switch (item.getItemId()) {
    // Search functionality for the search button
    case R.id.mood_history_search:
        // Spawn a dialog fragment so that the user can select a day.
        DialogFragment dialog = new DatePickerFragment();
        dialog.show(getFragmentManager(), "datePicker");
        return true;
    case R.id.mood_history_attribute_drinking:
        // Setting the selected attribute in landscape view.
        mSelectedAttribute = DayInHistory.AMOUNT_OF_DRINKS;
        weekFragment = mPagerAdapterWeek.getWeekFragment(mViewPager.getCurrentItem());
        weekFragment.updateSelectedAttribute(DayInHistory.AMOUNT_OF_DRINKS, false);
        return true;
    case R.id.mood_history_attribute_moods:
        mSelectedAttribute = DayInHistory.MOODS;
        weekFragment = mPagerAdapterWeek.getWeekFragment(mViewPager.getCurrentItem());
        weekFragment.updateSelectedAttribute(DayInHistory.MOODS, false);
        return true;
    case R.id.mood_history_change_sprint:
        // Spawn a dialog where the user can select the sprint depicted in this history.
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final Sprint[] sprints = new SprintDataHandler(this).getSprints();

        // Get the string representations of the sprints.
        String[] sprintsAsString = new String[sprints.length];
        for (int i = 0; i < sprints.length; i++) {
            sprintsAsString[i] = sprints[i].getSprintTitle() + " " + sprints[i].getStartTimeInString(this);
        }
        builder.setTitle(getString(R.string.select_sprint)).setSingleChoiceItems(sprintsAsString,
                sprints.length - 1, null);
        final AlertDialog alertDialog = builder.create();
        final Activity thisActivity = this;
        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok),
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Start this activity again with the selected sprint as the passed Parcelable Sprint.
                        // This is done so that the activity can update itself to the selected sprint.
                        mCurrentSprint = sprints[alertDialog.getListView().getCheckedItemPosition()];
                        Intent intent = new Intent(thisActivity, MoodHistoryActivity.class);
                        intent.putExtra(Sprint.CURRENT_SPRINT, mCurrentSprint);
                        startActivity(intent);
                        alertDialog.dismiss();
                        thisActivity.finish();
                    }
                });
        alertDialog.show();
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:nl.nikhef.eduroam.WiFiEduroam.java

private void alert(String title, String message) {
    AlertDialog alertBox = new AlertDialog.Builder(this).create();
    alertBox.setTitle(title);//  ww  w  .  j a  v a 2s.c o m
    alertBox.setMessage(message);
    alertBox.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            onActivityResult(2, RESULT_OK, null);
        }
    });
    alertBox.show();
}

From source file:com.prof.youtubeparser.example.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    if (id == R.id.action_settings) {

        android.support.v7.app.AlertDialog alertDialog = new android.support.v7.app.AlertDialog.Builder(
                MainActivity.this).create();
        alertDialog.setTitle(R.string.app_name);
        alertDialog.setMessage(Html.fromHtml(MainActivity.this.getString(R.string.info_text)
                + " <a href='http://github.com/prof18/YoutubeParser'>GitHub.</a>"
                + MainActivity.this.getString(R.string.author)));
        alertDialog.setButton(android.support.v7.app.AlertDialog.BUTTON_NEUTRAL, "OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }/*from   w w w  .  j  ava  2  s  .c om*/
                });
        alertDialog.show();
        ((TextView) alertDialog.findViewById(android.R.id.message))
                .setMovementMethod(LinkMovementMethod.getInstance());
    }

    return super.onOptionsItemSelected(item);
}

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  w w .  ja v  a  2 s.c  o 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.iota.wallet.ui.fragment.NewTransferFragment.java

@OnClick(R.id.new_transfer_send_fab_button)
public void onNewTransferSendFabClick(FloatingActionButton fab) {
    inputManager.hideSoftInputFromWindow(fab.getWindowToken(), 0);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());

    addressEditTextInputLayout.setError(null);
    amountEditTextInputLayout.setError(null);

    //noinspection StatementWithEmptyBody
    if (!isValidAddress()) {

    } else if (getAmount().isEmpty() || getAmount().equals("0")) {
        amountEditTextInputLayout.setError(getString(R.string.messages_enter_amount));

    } else if (prefs.getLong(Constants.PREFERENCES_CURRENT_IOTA_BALANCE, 0) < Long
            .parseLong(amountInSelectedUnit())) {
        amountEditTextInputLayout.setError(getString(R.string.messages_not_enough_balance));

    } else {/*w w  w .  j a va2  s.  com*/
        AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
                .setMessage(R.string.message_confirm_transfer).setCancelable(false)
                .setPositiveButton(R.string.buttons_ok, null).setNegativeButton(R.string.buttons_cancel, null)
                .create();

        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.buttons_ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        SendTransferRequest tir = new SendTransferRequest(getAddress(), amountInSelectedUnit(),
                                getMessage(), getTaG());

                        TaskManager rt = new TaskManager(getActivity());
                        rt.startNewRequestTask(tir);

                        getActivity().onBackPressed();
                    }
                });

        alertDialog.show();
    }
}

From source file:com.LMO.capstone.KnoWITHerbalMain.java

private void resolver() throws XmlPullParserException, IOException {
    if (!new File(Config.dbPath(getApplicationContext())).exists()) { //no DB, no Folder
        HowToUseFragment howto = new HowToUseFragment();
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.frame_content, howto);
        ft.addToBackStack("help");
        ft.commit();/*  w w  w . j  a v a 2s.co  m*/
        if (util.isNetworkAvailable())
            util.PrepareFileForDatabase();
    } else {
        File appDir = new File(Config.externalDirectory);
        if (!appDir.exists())
            appDir.mkdir();

        FileFilter filter = new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                // TODO Auto-generated method stub
                return pathname.toString().toLowerCase(Locale.getDefault()).contains(".jpg")
                        || pathname.toString().toLowerCase(Locale.getDefault()).contains(".png")
                        || pathname.toString().toLowerCase(Locale.getDefault()).contains(".bmp")
                        || pathname.toString().toLowerCase(Locale.getDefault()).contains(".gif")
                        || pathname.toString().toLowerCase(Locale.getDefault()).contains(".jpeg");
            }
        };
        File[] files = appDir.listFiles(filter);
        dbHelper = new DatabaseHelper(this);
        int imageEntryCount = Queries.getImageEntryCount(sqliteDB, dbHelper);

        if (files.length == 1 || (files.length + 1) < imageEntryCount) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            AlertDialog dialog = builder.create();
            dialog.setTitle("Oops!");
            dialog.setMessage("It seems your data is invalid!\nRe-download now?");
            dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    if (util.isNetworkAvailable())
                        Queries.truncateDatabase(sqliteDB, dbHelper, getApplicationContext());
                    util.PrepareFileForDatabase();
                }
            });
            dialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Maybe later", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    dialog.dismiss();
                }
            });
            dialog.show();
        }
    }
}

From source file:no.digipost.android.gui.content.ThreadPerTaskExecutor.java

/**
 * Called when the activity is first created.
 *///  ww  w  . ja v a 2 s . c  om
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pdf);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    toolbar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showInformationDialog();
        }
    });
    ((DigipostApplication) getApplication()).getTracker(DigipostApplication.TrackerName.APP_TRACKER);
    selectActionModeCallback = new SelectActionModeCallback();
    mAlertBuilder = new AlertDialog.Builder(this);
    intent = getIntent();
    String openFilepath = intent.getStringExtra(ACTION_OPEN_FILEPATH);
    if (openFilepath != null) {
        setActionBar(FilenameUtils.getName(openFilepath));
        core = openFile(openFilepath);
        SearchTaskResult.set(null);
    } else if (core == null && DocumentContentStore.getDocumentContent() != null) {
        setActionBar(DocumentContentStore.getDocumentAttachment().getSubject());

        byte buffer[] = DocumentContentStore.getDocumentContent();

        if (buffer != null) {
            core = openBuffer(buffer);
        }

        SearchTaskResult.set(null);
    }

    if (core == null) {
        AlertDialog alert = mAlertBuilder.create();
        alert.setTitle(R.string.pdf_open_failed);
        alert.setButton(AlertDialog.BUTTON_POSITIVE, this.getString(R.string.close),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                });
        alert.show();
        return;
    }

    createUI();

    if (savedInstanceState != null) {
        mDocView.setDisplayedViewIndex(savedInstanceState.getInt(CURRENT_WINDOW, 0));
    }

    if (super.shouldShowInvoiceOptionsDialog(this)) {
        super.showInvoiceOptionsDialog(this);
    }
    super.showMetadata();
}

From source file:me.panpf.tool4a.app.MessageDialogFragment.java

/**
 * ?//  w  w w.  j  a va2  s . c  o  m
 *
 * @param messageDialog ?
 */
private void applyParams(AlertDialog messageDialog) {
    if (builder == null)
        throw new IllegalArgumentException("builder null ?setBuilder()Builder");
    if (builder.message == null)
        throw new IllegalArgumentException("Builder.setMessage()?");

    messageDialog.setTitle(builder.title);
    messageDialog.setMessage(builder.message);
    if (builder.confirmButtonName != null) {
        messageDialog.setButton(AlertDialog.BUTTON_POSITIVE, builder.confirmButtonName,
                builder.confirmButtonClickListener);
    }
    if (builder.cancelButtonName != null) {
        messageDialog.setButton(AlertDialog.BUTTON_NEGATIVE, builder.cancelButtonName,
                builder.cancelButtonClickListener);
    }
    if (builder.neutralButtonName != null) {
        messageDialog.setButton(AlertDialog.BUTTON_NEUTRAL, builder.neutralButtonName,
                builder.neutralButtonClickListener);
    }
    messageDialog.setOnKeyListener(builder.onKeyListener);
    messageDialog.setOnShowListener(builder.onShowListener);
    setCancelable(builder.cancelable);
}

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

/**
 * Writes an NFC Tag/*  w w  w  .  j a va  2  s .  c  om*/
 * 
 * @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;
}