Example usage for android.app AlertDialog.Builder AlertDialog.Builder

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

Introduction

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

Prototype

public Builder(Context context) 

Source Link

Document

Creates a builder for an alert dialog that uses the default alert dialog theme.

Usage

From source file:org.steveleach.scoresheet.ui.ScoresheetActivity.java

private void questionDialog(String prompt, String yesButton, String noButton, final Runnable action) {
    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @Override//w  w  w .  j  ava2  s. c  o  m
        public void onClick(DialogInterface dialog, int button) {
            switch (button) {
            case DialogInterface.BUTTON_POSITIVE:
                action.run();
                break;
            case DialogInterface.BUTTON_NEGATIVE:
                break;
            }
        }
    };

    ContextThemeWrapper wrapper = new ContextThemeWrapper(this, R.style.AppDialog);
    AlertDialog.Builder builder = new AlertDialog.Builder(wrapper);
    AlertDialog dialog = builder.setTitle(getString(R.string.confirmAlertTitle)).setMessage(prompt)
            .setPositiveButton(yesButton, listener).setNegativeButton(noButton, listener).create();

    dialog.show();

    int color = getResources().getColor(R.color.appdark);

    TextView tv = (TextView) getDialogView(dialog, "android:id/alertTitle");
    tv.setTextColor(color);

    View divider = getDialogView(dialog, "android:id/titleDivider");
    divider.setBackgroundColor(color);
}

From source file:in.shick.diode.common.Common.java

/**
 * Helper function to display a list of URLs.
 * @param theContext The current application context.
 * @param settings The settings to use regarding the browser component.
 * @param theItem The ThingInfo item to get URLs from.
 *//* w ww  .j  a  v  a  2 s .c  om*/
public static void showLinksDialog(final Context theContext, final RedditSettings settings,
        final ThingInfo theItem) {
    assert (theContext != null);
    assert (theItem != null);
    assert (settings != null);
    final ArrayList<String> urls = new ArrayList<String>();
    final ArrayList<MarkdownURL> vtUrls = theItem.getUrls();
    for (MarkdownURL vtUrl : vtUrls) {
        urls.add(vtUrl.url);
    }
    ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(theContext,
            android.R.layout.select_dialog_item, vtUrls) {
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView tv;
            if (convertView == null) {
                tv = (TextView) ((LayoutInflater) theContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                        .inflate(android.R.layout.select_dialog_item, null);
            } else {
                tv = (TextView) convertView;
            }

            String url = getItem(position).url;
            String anchorText = getItem(position).anchorText;
            //                        if (Constants.LOGGING) Log.d(TAG, "links url="+url + " anchorText="+anchorText);

            Drawable d = null;
            try {
                d = theContext.getPackageManager()
                        .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            } catch (PackageManager.NameNotFoundException ignore) {
            }
            if (d != null) {
                d.setBounds(0, 0, d.getIntrinsicHeight(), d.getIntrinsicHeight());
                tv.setCompoundDrawablePadding(10);
                tv.setCompoundDrawables(d, null, null, null);
            }

            final String telPrefix = "tel:";
            if (url.startsWith(telPrefix)) {
                url = PhoneNumberUtils.formatNumber(url.substring(telPrefix.length()));
            }

            if (anchorText != null)
                tv.setText(Html.fromHtml("<span>" + anchorText + "</span><br /><small>" + url + "</small>"));
            else
                tv.setText(Html.fromHtml(url));

            return tv;
        }
    };

    AlertDialog.Builder b = new AlertDialog.Builder(
            new ContextThemeWrapper(theContext, settings.getDialogTheme()));

    DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() {
        public final void onClick(DialogInterface dialog, int which) {
            if (which >= 0) {
                Common.launchBrowser(settings, theContext, urls.get(which),
                        Util.createThreadUri(theItem).toString(), false, false, settings.isUseExternalBrowser(),
                        settings.isSaveHistory());
            }
        }
    };

    b.setTitle(R.string.select_link_title);
    b.setCancelable(true);
    b.setAdapter(adapter, click);

    b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public final void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    b.show();
}

From source file:org.guohai.android.cta.CoordinateTalk.java

/** ? */
private void inita() {

    locationInfo = new LocationInfo();
    GSMManager gsm = new GSMManager(getApplicationContext(), locationInfo);
    GPSManager gps = new GPSManager(getApplicationContext(), locationInfo);
    LocationManagers = new ArrayList<ILocationManager>();
    LocationManagers.add(gsm);//from  ww w  . ja v a2 s .  c o  m
    LocationManagers.add(gps);

    //??    
    mMainHandler = new Handler();

    openHandler();
    textCoordinate.setText("" + locationInfo.Latitude + "\n?" + locationInfo.Longitude
            + "\n" + locationInfo.Altitude);

    if (!gps.IsOpen()) {
        new AlertDialog.Builder(CoordinateTalk.this).setTitle(R.string.setting_gps_title)
                .setMessage(R.string.setting_gps_info)
                .setPositiveButton(R.string.gps_setting, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
                        startActivityForResult(intent, 0);

                    }
                }).setNegativeButton(R.string.jump_gps_setting, null).show();

        textCoordinate.setText("?GPS????");
    }
}

From source file:com.vuze.android.remote.AndroidUtils.java

public static void showFeatureRequiresVuze(final Activity activity, final String feature) {
    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (activity.isFinishing()) {
                if (DEBUG) {
                    System.out.println("can't display -- finishing");
                }//from ww w .j a  v a2 s. c o  m
                return;
            }
            String msg = activity.getResources().getString(R.string.vuze_required, feature);
            Builder builder = new AlertDialog.Builder(activity).setMessage(msg).setCancelable(true)
                    .setPositiveButton(android.R.string.ok, new OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });
            builder.show();
        }
    });

}

From source file:com.denel.facepatrol.MainActivity.java

public void ContactEdit(View view) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Contact Information Feedback")
            .setMessage("You're about to edit and send personal information. "
                    + "Please note that the current database will only reflect your modification"
                    + " once the IT department verifies the change and the updated database"
                    + " is synced to your device. \n \n Do you want to continue?")
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
                    emailIntent.setData(Uri.parse("mailto:"));
                    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "pkantue@gmail.com" }); // this email address will change
                    emailIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, feedback_subject);
                    emailIntent.putExtra(Intent.EXTRA_TEXT, feedback_body);
                    startActivity(Intent.createChooser(emailIntent, "Send Email..."));
                }/*from   ww w .ja v a2 s.  c o  m*/
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // User cancelled the dialog 
                }
            });
    builder.show();
    // exit the application
    //finish();      
}

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

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

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

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

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

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

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

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

From source file:mx.klozz.xperience.tweaker.fragments.VoltageControlSettings.java

private void showDialog(final int min, final int step, final int total) {
    final LayoutInflater factory = LayoutInflater.from(context);
    final View voltageDialog = factory.inflate(R.layout.voltage_dialog, null);

    final SeekBar voltageSeek = (SeekBar) voltageDialog.findViewById(R.id.voltageSeek);
    final TextView voltageMeter = (TextView) voltageDialog.findViewById(R.id.voltageMeter);

    final String savedMv = mVoltage.getSavedMV();
    final int savedVolt = Integer.parseInt(savedMv);

    voltageMeter.setText(savedMv + um);/*from  w  w  w.  jav a  2 s.  com*/
    voltageSeek.setMax(total);
    voltageSeek.setProgress(getNearestStepIndex(savedVolt, vmin, vstep, nvsteps));
    voltageSeek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar sb, int progress, boolean fromUser) {
            if (fromUser) {
                final String volt = Integer.toString(progress * step + min);
                voltageMeter.setText(volt + um);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    new AlertDialog.Builder(context).setTitle(mVoltage.getFreq() + " kHz").setView(voltageDialog)
            .setPositiveButton(getResources().getString(R.string.ps_volt_save),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                            final String value = Integer.toString(voltageSeek.getProgress() * step + min);
                            SharedPreferences.Editor editor = mPreferences.edit();
                            editor.putString(mVoltage.getFreq(), value).commit();
                            mVoltage.setSavedMV(value);
                            mAdapter.notifyDataSetChanged();
                        }
                    })
            .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            }).create().show();
}

From source file:com.kylemsguy.fishyfishes.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);/*w  ww.  j  a v  a2 s  .  co m*/
        return true;
    } else if (id == R.id.action_about) {
        Uri url = Uri.parse("https://github.com/kylemsguy/fishy-fishes");
        Intent browser = new Intent(Intent.ACTION_VIEW, url);
        startActivity(browser);
        return true;
    } else if (id == R.id.action_focus) {
        LatLng currentLocation = new LatLng(me.getPosition().latitude, me.getPosition().longitude);
        theMap.animateCamera(CameraUpdateFactory.newLatLng(currentLocation));
        theMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLocation, 15));
        // Zoom in, animating the camera.
        theMap.animateCamera(CameraUpdateFactory.zoomIn());
        // Zoom out to zoom level 10, animating with a duration of 2 seconds.
        theMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
        return true;
    } else if (id == R.id.action_licenses) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this))
                .setTitle(R.string.licenses_title);
        builder.setPositiveButton(R.string.ok, null);
        builder.show();
    }

    return super.onOptionsItemSelected(item);
}

From source file:no.digipost.android.gui.MainContentActivity.java

private void openMailboxSelection() {
    mailboxDialog = null;//from w w  w.  j av a2  s  . c  o  m

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.generic_dialog_layout, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(this).setNegativeButton(getString(R.string.abort),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

    builder.setView(view);
    ListView mailboxListView = (ListView) view.findViewById(R.id.generic_dialog_listview);

    mailboxAdapter = new MailboxArrayAdapter(this, R.layout.generic_dialog_list_item, mailboxes);
    mailboxListView.setAdapter(mailboxAdapter);
    mailboxListView.setOnItemClickListener(new ChangeMailboxListOnItemClickListener());

    builder.setTitle(getResources().getString(R.string.drawer_change_account));
    mailboxDialog = builder.create();
    mailboxDialog.show();

}

From source file:de.NeonSoft.neopowermenu.Preferences.PreferencesPartFragment.java

public void showPermissionDialog(int permission) {
    switch (permission) {
    case MY_PERMISSIONS_REQUEST:
        adb = new AlertDialog.Builder(getActivity());
        adb.setTitle(R.string.permissionRequestTitle);
        adb.setMessage(R.string.permissionRequestMsg);
        adb.setPositiveButton(R.string.Dialog_Ok, new DialogInterface.OnClickListener() {

            @Override/*w w  w  . ja v  a 2 s.co  m*/
            public void onClick(DialogInterface p1, int p2) {
                // TODO: Implement this method
                adb = null;
                requestPermissions(
                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA },
                        MY_PERMISSIONS_REQUEST);
            }
        });
        adb.setNegativeButton(R.string.Dialog_Cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface p1, int p2) {
                // TODO: Implement this method
                getActivity().finish();
            }
        });
        adb.show();
        break;
    }
}