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:Main.java

public static void alert(final Activity activity, final String msg, final String ok, final boolean exit) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setMessage(msg).setCancelable(false).setPositiveButton(ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();//from w  w  w  . java  2  s .com
            if (exit) {
                activity.setResult(activity.RESULT_CANCELED);
                activity.finish();
            }
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:app.screen.PopupInfoDialogFragment.java

/** pull in the fragment layout {@link R.id#ttf_dialog_info} and create the dialog */
@Override/*w ww .  j a v a  2  s  .  c om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    View rootView = getActivity().getLayoutInflater().inflate(R.layout.dialog_fragment, null);

    // set the info text field value
    TextView ttf_info = (TextView) rootView.findViewById(R.id.ttf_dialog_info);
    ttf_info.setText(item);

    builder.setView(rootView).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            getDialog().cancel();
        }
    });
    builder.setCancelable(false);
    return builder.create();
}

From source file:com.midisheetmusic.ChooseSongActivity.java

/** Show an error dialog with the given message */
public static void showErrorDialog(String message, Activity activity) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setMessage(message);//from   w  w w .j a  va2s  .c  om
    builder.setCancelable(false);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.altcanvas.twitspeak.TwitSpeakActivity.java

private void promptTTSInstall() {
    AlertDialog ttsInstallDlg = new AlertDialog.Builder(this).create();
    ttsInstallDlg.setMessage(getString(R.string.tts_install_msg));
    ttsInstallDlg.setTitle(getString(R.string.tts_install_title));

    ttsInstallDlg.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.proceed_str),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();/*from  w w w. j a v a 2s  . co  m*/
                    Intent installIntent = new Intent();
                    installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                    startActivity(installIntent);
                }
            });

    ttsInstallDlg.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel_str),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                    finish();
                }
            });
}

From source file:it.scoppelletti.mobilepower.app.AbstractDialogFragment.java

/**
 * Istanzia un costruttore di dialoghi.//from ww w.  j  a v a 2  s. com
 * 
 * @return Oggetto.
 */
@SuppressWarnings("unchecked")
protected final AlertDialog.Builder newAlertDialogBuilder() {
    Constructor<AlertDialog.Builder> ctor;

    if (Build.VERSION.SDK_INT < BuildCompat.VERSION_CODES.HONEYCOMB) {
        return new AlertDialog.Builder(getActivity());
    }

    try {
        ctor = (Constructor<AlertDialog.Builder>) MemberCache.getInstance().getMember(AlertDialog.Builder.class,
                AbstractDialogFragment.CTOR_ALERTDIALOGBUILDER, this);
        return ctor.newInstance(getActivity(), AppUtils.getDialogTheme());
    } catch (Exception ex) {
        myLogger.error("Failed to instantiate AlertDialog.Builder.", ex);
        return new AlertDialog.Builder(getActivity());
    }
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.voltage_settings, root, false);

    final ListView listView = (ListView) view.findViewById(R.id.ListView);
    final Switch setOnBoot = (Switch) view.findViewById(R.id.applyAtBoot);

    if (mVoltages.isEmpty()) {
        (view.findViewById(R.id.emptyList)).setVisibility(View.VISIBLE);
        (view.findViewById(R.id.BottomBar)).setVisibility(View.GONE);
    }//  w w w  . j  a  v  a 2  s  .c  o  m

    setOnBoot.setChecked(mPreferences.getBoolean(VOLTAGE_SOB, false));
    setOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mPreferences.edit().putBoolean(VOLTAGE_SOB, isChecked).apply();
            if (isChecked) {
                String warningMessage = getString(R.string.volt_info);

                new AlertDialog.Builder(context).setMessage(warningMessage)
                        .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                setOnBoot.setChecked(false);
                            }
                        }).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        }).create().show();
            }

        }
    });

    (view.findViewById(R.id.applyBtn)).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            final StringBuilder sb = new StringBuilder();
            final String vdd = Helpers.getVoltagePath();
            if (vdd.equals(VDD_PATH)) {
                for (final Voltage volt : mVoltages) {
                    if (!volt.getSavedMV().equals(volt.getCurrentMv())) {
                        for (int i = 0; i < Helpers.getNumOfCPUS(); i++) {
                            sb.append("busybox echo \"").append(volt.getFreq()).append(" ")
                                    .append(volt.getSavedMV()).append("\" > ")
                                    .append(vdd.replace("cpu0", "cpu" + i)).append(";\n");
                        }
                    }
                }
            } else if (vdd.equals(VDD_TABLE)) {
                for (final Voltage volt : mVoltages) {
                    if (!volt.getSavedMV().equals(volt.getCurrentMv())) {
                        sb.append("busybox echo \"").append(volt.getFreq()).append(" ")
                                .append(volt.getSavedMV()).append("\" > ").append(vdd).append(";\n");
                    }
                }
            } else {
                final StringBuilder b = new StringBuilder();
                for (final Voltage volt : mVoltages) {
                    b.append(volt.getSavedMV()).append(" ");
                }
                if (vdd.equals(COMMON_VDD_PATH)) {
                    sb.append("busybox echo \"").append(b.toString()).append("\" > ").append(vdd).append(";\n");
                } else {
                    for (int i = 0; i < Helpers.getNumOfCPUS(); i++) {
                        sb.append("busybox echo \"").append(b.toString()).append("\" > ")
                                .append(vdd.replace("cpu0", "cpu" + i)).append(";\n");
                    }
                }
            }
            Helpers.shExec(sb, context, true);

            final List<Voltage> volts = getVolts(mPreferences);
            mVoltages.clear();
            mVoltages.addAll(volts);
            mAdapter.notifyDataSetChanged();
        }
    });

    mAdapter.setListItems(mVoltages);
    listView.setAdapter(mAdapter);
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mVoltage = mVoltages.get(position);
            showDialog(vmin, vstep, nvsteps);
        }
    });

    return view;
}

From source file:com.hartcode.hartweather.list.WeatherItemViewHolder.java

@Override
public boolean onLongClick(View v) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this.view.getContext());
    builder.setTitle(resources.getString(R.string.dialog_delete_title));
    builder.setIcon(android.R.drawable.ic_menu_delete);
    builder.setMessage(resources.getString(R.string.dialog_delete_question))
            .setPositiveButton(resources.getString(R.string.dialog_delete_positive), this)
            .setNegativeButton(resources.getString(R.string.dialog_delete_negative), this).show();
    return false;
}

From source file:ua.naiksoftware.chars.Sender.java

@Override
protected void onPreExecute() {
    Log.d(tag, "onPreExecute begin");

    ProgressBar progressBar = new ProgressBar(EngineActivity.CONTEXT);
    progressBar.setIndeterminate(true);/*from ww w .  j av a  2s.  c o  m*/

    AlertDialog.Builder builder = new AlertDialog.Builder(EngineActivity.CONTEXT);
    builder.setCustomTitle(progressBar);
    builder.setIcon(android.R.drawable.ic_menu_upload);
    builder.setMessage(R.string.send_record);
    builder.setCancelable(false);
    dialog = builder.create();
    dialog.show();
    Log.d(tag, "onPreExecute end");
}

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

/**
 * Creates an AlertDialog.Builder that has the proper theme for Gingerbread
 *//*from   ww  w . ja v a2  s  .co m*/
public static AndroidUtils.AlertDialogBuilder createAlertDialogBuilder(Activity activity, int resource) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);

    // Not sure if we need this anymore, but once upon a time, pre-honeycomb
    // (2.x) had dialog color issues
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
        builder.setInverseBackgroundForced(true);
    }

    View view = View.inflate(activity, resource, null);
    builder.setView(view);

    return new AndroidUtils.AlertDialogBuilder(view, builder);
}

From source file:com.zprogrammer.tool.ui.MainActivity.java

private void showDialog(String T, String M, String ok, String qx, final int i) {
    final AlertDialog dialog = new AlertDialog.Builder(this).setTitle(T).setMessage(M)
            .setPositiveButton(ok, new DialogInterface.OnClickListener() {
                @Override//from   www.  j  a  v a2s .  com
                public void onClick(DialogInterface arg0, int arg1) {
                    finish();
                }
            }).setNegativeButton(qx, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                    //dialog.dismiss();
                }
            }).create();
    dialog.show();
}