Example usage for android.app AlertDialog.Builder setView

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

Introduction

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

Prototype

public void setView(View view) 

Source Link

Document

Set the view to display in that dialog.

Usage

From source file:co.taqat.call.AccountPreferencesFragment.java

private void initAccountPreferencesFields(PreferenceScreen parent) {
    boolean isDefaultAccount = mPrefs.getDefaultAccountIndex() == n;

    accountCreator = LinphoneCoreFactory.instance().createAccountCreator(LinphoneManager.getLc(),
            LinphonePreferences.instance().getXmlrpcUrl());
    accountCreator.setListener(this);

    PreferenceCategory account = (PreferenceCategory) getPreferenceScreen()
            .findPreference(getString(R.string.pref_sipaccount_key));
    EditTextPreference username = (EditTextPreference) account.getPreference(0);
    username.setOnPreferenceChangeListener(usernameChangedListener);
    if (!isNewAccount) {
        username.setText(mPrefs.getAccountUsername(n));
        username.setSummary(username.getText());
    }//from   w ww  . j ava 2  s  .  c  om

    EditTextPreference userid = (EditTextPreference) account.getPreference(1);
    userid.setOnPreferenceChangeListener(useridChangedListener);
    if (!isNewAccount) {
        userid.setText(mPrefs.getAccountUserId(n));
        userid.setSummary(userid.getText());
    }

    EditTextPreference password = (EditTextPreference) account.getPreference(2);
    password.setOnPreferenceChangeListener(passwordChangedListener);
    if (!isNewAccount) {
        password.setText(mPrefs.getAccountPassword(n));
    }

    EditTextPreference domain = (EditTextPreference) account.getPreference(3);
    domain.setOnPreferenceChangeListener(domainChangedListener);
    if (!isNewAccount) {
        domain.setText(mPrefs.getAccountDomain(n));
        domain.setSummary(domain.getText());
    }

    EditTextPreference displayName = (EditTextPreference) account.getPreference(4);
    displayName.setOnPreferenceChangeListener(displayNameChangedListener);
    if (!isNewAccount) {
        displayName.setText(mPrefs.getAccountDisplayName(n));
        displayName.setSummary(displayName.getText());
    }

    PreferenceCategory advanced = (PreferenceCategory) getPreferenceScreen()
            .findPreference(getString(R.string.pref_advanced_key));
    mTransportPreference = (ListPreference) advanced.getPreference(0);
    initializeTransportPreference(mTransportPreference);
    mTransportPreference.setOnPreferenceChangeListener(transportChangedListener);
    if (!isNewAccount) {
        mTransportPreference.setSummary(mPrefs.getAccountTransportString(n));
    }

    mProxyPreference = (EditTextPreference) advanced.getPreference(1);
    mProxyPreference.setOnPreferenceChangeListener(proxyChangedListener);
    if (!isNewAccount) {
        mProxyPreference.setText(mPrefs.getAccountProxy(n));
        mProxyPreference
                .setSummary("".equals(mProxyPreference.getText()) || (mProxyPreference.getText() == null)
                        ? getString(R.string.pref_help_proxy)
                        : mProxyPreference.getText());
    }

    CheckBoxPreference outboundProxy = (CheckBoxPreference) advanced.getPreference(2);
    outboundProxy.setOnPreferenceChangeListener(outboundProxyChangedListener);
    if (!isNewAccount) {
        outboundProxy.setChecked(mPrefs.isAccountOutboundProxySet(n));
    }

    EditTextPreference expires = (EditTextPreference) advanced.getPreference(3);
    expires.setOnPreferenceChangeListener(expiresChangedListener);
    if (!isNewAccount) {
        expires.setText(mPrefs.getExpires(n));
        expires.setSummary(mPrefs.getExpires(n));
    }

    EditTextPreference prefix = (EditTextPreference) advanced.getPreference(4);
    prefix.setOnPreferenceChangeListener(prefixChangedListener);
    if (!isNewAccount) {
        String prefixValue = mPrefs.getPrefix(n);
        prefix.setText(prefixValue);
        prefix.setSummary(prefixValue);
    }

    CheckBoxPreference avpf = (CheckBoxPreference) advanced.getPreference(5);
    avpf.setOnPreferenceChangeListener(avpfChangedListener);
    if (!isNewAccount) {
        avpf.setChecked(mPrefs.avpfEnabled(n));
    }

    EditTextPreference avpfRRInterval = (EditTextPreference) advanced.getPreference(6);
    avpfRRInterval.setOnPreferenceChangeListener(avpfRRIntervalChangedListener);
    if (!isNewAccount) {
        avpfRRInterval.setText(mPrefs.getAvpfRRInterval(n));
        avpfRRInterval.setSummary(mPrefs.getAvpfRRInterval(n));
    }

    CheckBoxPreference escape = (CheckBoxPreference) advanced.getPreference(7);
    escape.setOnPreferenceChangeListener(escapeChangedListener);
    if (!isNewAccount) {
        escape.setChecked(mPrefs.getReplacePlusByZeroZero(n));
    }

    CheckBoxPreference friendlistSubscribe = (CheckBoxPreference) advanced.getPreference(8);
    friendlistSubscribe.setOnPreferenceChangeListener(friendlistSubscribeListener);
    if (!isNewAccount) {
        friendlistSubscribe.setChecked(mPrefs.isFriendlistsubscriptionEnabled());
    }

    Preference linkAccount = advanced.getPreference(9);
    linkAccount.setOnPreferenceClickListener(linkAccountListener);

    PreferenceCategory manage = (PreferenceCategory) getPreferenceScreen()
            .findPreference(getString(R.string.pref_manage_key));
    final CheckBoxPreference disable = (CheckBoxPreference) manage.getPreference(0);
    disable.setEnabled(true);
    disable.setOnPreferenceChangeListener(disableChangedListener);
    if (!isNewAccount) {
        disable.setChecked(!mPrefs.isAccountEnabled(n));
    }

    CheckBoxPreference mainAccount = (CheckBoxPreference) manage.getPreference(1);
    mainAccount.setChecked(isDefaultAccount);
    mainAccount.setEnabled(!mainAccount.isChecked());
    mainAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            mPrefs.setDefaultAccount(n);
            disable.setEnabled(false);
            disable.setChecked(false);
            preference.setEnabled(false);
            return true;
        }
    });
    if (!isNewAccount) {
        mainAccount.setEnabled(!mainAccount.isChecked());
    }

    final Preference changePassword = manage.getPreference(2);
    if (mPrefs.getAccountDomain(n).compareTo(getString(R.string.default_domain)) == 0) {
        changePassword.setEnabled(!isNewAccount);
        changePassword.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                final AlertDialog.Builder alert = new AlertDialog.Builder(LinphoneActivity.instance());
                LayoutInflater inflater = LinphoneActivity.instance().getLayoutInflater();
                View layout = inflater.inflate(R.layout.new_password, null);
                final EditText pass1 = (EditText) layout.findViewById(R.id.password1);
                final EditText pass2 = (EditText) layout.findViewById(R.id.password2);
                alert.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        LinphoneAccountCreator.Status status = accountCreator
                                .setPassword(pass1.getText().toString());
                        if (status.equals(LinphoneAccountCreator.Status.Ok)) {
                            if (pass1.getText().toString().compareTo(pass2.getText().toString()) == 0) {
                                accountCreator.setUsername(mPrefs.getAccountUsername(n));
                                accountCreator.setHa1(mPrefs.getAccountHa1(n));
                                status = accountCreator.updatePassword(pass1.getText().toString());
                                if (!status.equals(LinphoneAccountCreator.Status.Ok)) {
                                    LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status),
                                            LinphoneActivity.instance());
                                } else {
                                    progress = ProgressDialog.show(LinphoneActivity.instance(), null, null);
                                    Drawable d = new ColorDrawable(ContextCompat
                                            .getColor(LinphoneActivity.instance(), R.color.colorE));
                                    d.setAlpha(200);
                                    progress.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                                            WindowManager.LayoutParams.MATCH_PARENT);
                                    progress.getWindow().setBackgroundDrawable(d);
                                    progress.setContentView(R.layout.progress_dialog);
                                    progress.show();
                                }
                            } else {
                                LinphoneUtils.displayErrorAlert(getString(R.string.wizard_passwords_unmatched),
                                        LinphoneActivity.instance());
                            }
                            return;
                        }
                        LinphoneUtils.displayErrorAlert(LinphoneUtils.errorForStatus(status),
                                LinphoneActivity.instance());
                    }
                });

                alert.setView(layout);
                alert.show();
                return true;
            }
        });
    } else {
        changePassword.setEnabled(false);
    }

    final Preference delete = manage.getPreference(3);
    delete.setEnabled(!isNewAccount);
    delete.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            mPrefs.deleteAccount(n);
            LinphoneActivity.instance().refreshAccounts();
            LinphoneActivity.instance().displaySettings();
            return true;
        }
    });
}

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog receive_Cha() {
    View content = View.inflate(this, R.layout.receive_cha, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);
    builder.setTitle(R.string.received_Cha);

    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // startNewGame(2);
            //                                System.out.print("runnable" + fen)
            if (chafen != null) {
                try {
                    ctrl.setFENOrPGN(chafen);
                } catch (ChessParseError e) {

                }/* w w  w  . ja va  2s  . c o m*/
            }

        }
    });
    builder.setNegativeButton(R.string.cancel, null);

    final AlertDialog dialog = builder.create();

    return dialog;
}

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog selectPgnSaveNewFileDialog() {
    View content = View.inflate(this, R.layout.create_pgn_file, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);
    builder.setTitle(R.string.select_pgn_file_save);
    final EditText fileNameView = (EditText) content.findViewById(R.id.create_pgn_filename);
    fileNameView.setText("");
    final Runnable savePGN = new Runnable() {
        public void run() {
            String pgnFile = fileNameView.getText().toString();
            if ((pgnFile.length() > 0) && !pgnFile.contains("."))
                pgnFile += ".pgn";
            String sep = File.separator;
            String pathName = Environment.getExternalStorageDirectory() + sep + pgnDir + sep + pgnFile;
            savePGNToFile(pathName, false);
        }/*from  ww  w  .  java 2 s  .  com*/
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            savePGN.run();
        }
    });
    builder.setNegativeButton(R.string.cancel, null);

    final Dialog dialog = builder.create();
    fileNameView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                savePGN.run();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog selectMoveDialog() {
    View content = View.inflate(this, R.layout.select_move_number, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);
    builder.setTitle(R.string.goto_move);
    final EditText moveNrView = (EditText) content.findViewById(R.id.selmove_number);
    moveNrView.setText("1");
    final Runnable gotoMove = new Runnable() {
        public void run() {
            try {
                int moveNr = Integer.parseInt(moveNrView.getText().toString());
                ctrl.gotoMove(moveNr);/*from  www  .j a v a  2  s.co  m*/
            } catch (NumberFormatException nfe) {
                Toast.makeText(getApplicationContext(), R.string.invalid_number_format, Toast.LENGTH_SHORT)
                        .show();
            }
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            gotoMove.run();
        }
    });
    builder.setNegativeButton(R.string.cancel, null);

    final AlertDialog dialog = builder.create();

    moveNrView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                gotoMove.run();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java

public static AlertDialog getaddtextdialog(String title, final int itemnumber, Context ctx) {

    AlertDialog.Builder getaddtext = new AlertDialog.Builder(ctx);

    final LinearLayout linearlayout = new LinearLayout(ctx);
    linearlayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    linearlayout.setOrientation(LinearLayout.VERTICAL);

    final EditText nameet = new EditText(ctx);
    nameet.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    final TextView fontname = new TextView(ctx);
    fontname.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    final TextView colorname = new TextView(ctx);
    colorname.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    final Spinner fontsizespinner = new Spinner(ctx);
    fontsizespinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    final Spinner colorspinner = new Spinner(ctx);
    fontsizespinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    List<String> fontsizelist = new ArrayList<String>();
    for (int t = 1; t < 200; t++) {
        fontsizelist.add(u.s(t));//from  ww  w  . j av a 2  s.  c  om
    }
    ArrayAdapter<String> fontsizearrayadapter = new ArrayAdapter<String>(ctx, R.layout.spinnertextview,
            fontsizelist);
    fontsizearrayadapter.setDropDownViewResource(R.layout.spinnertextview);

    List<String> colorlist = new ArrayList<String>();
    {
        colorlist.add("RED");
        colorlist.add("BLACK");
        colorlist.add("BLUE");
        colorlist.add("GREEN");
        colorlist.add("WHITE");
        colorlist.add("GRAY");
    }
    ArrayAdapter<String> colorlistarrayadapter = new ArrayAdapter<String>(ctx, R.layout.spinnertextview,
            colorlist);
    fontsizearrayadapter.setDropDownViewResource(R.layout.spinnertextview);
    colorspinner.setAdapter(colorlistarrayadapter);
    fontsizespinner.setAdapter(fontsizearrayadapter);
    fontsizespinner.setSelection(getIndexofSpinner(fontsizespinner, "25"));

    fontname.setText("Select Font Size");
    fontname.setTextSize(20f);
    colorname.setText("Select Color");
    colorname.setTextSize(20f);

    linearlayout.addView(nameet);
    linearlayout.addView(fontname);
    linearlayout.addView(fontsizespinner);
    linearlayout.addView(colorname);
    linearlayout.addView(colorspinner);

    if (!(itemnumber == view.i)) {
        nameet.setText(view.ITEMstring[itemnumber]);
        fontsizespinner.setSelection(getIndexofSpinner(fontsizespinner, u.s(view.ITEMfontsize[itemnumber])));
        colorspinner.setSelection(getIndexofSpinner(colorspinner, u.s(view.ITEMfontcolor[itemnumber])));
    }

    getaddtext.setView(linearlayout);
    getaddtext.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });
    getaddtext.setTitle(title);
    getaddtext.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override

        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            String string = nameet.getText().toString();

            float fontsize = fontsizespinner.getSelectedItemPosition() + 1;
            //ITEMelcnumber[itemselectednumber]=u.i(string);
            int colpos = colorspinner.getSelectedItemPosition();
            int[] col = new int[] { Color.RED, Color.BLACK, Color.BLUE, Color.GREEN, Color.WHITE, Color.GRAY };
            int color = col[colpos];

            Log.d("addtext", u.s((int) fontsize) + colpos + color);

            view.ITEMstring[itemnumber] = string;
            view.ITEMfontsize[itemnumber] = (int) fontsize;
            view.ITEMfontcolor[itemnumber] = color;

            view.itemname = string;
            view.fontsize = (int) fontsize;
            view.color = color;
            view.invalidate();
            dialog.dismiss();
            FloorPlanActivity.writeonedbitem(itemnumber);
        }

    });

    return getaddtext.create();
}

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog newNetworkEngineDialog() {
    View content = View.inflate(this, R.layout.create_network_engine, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);
    builder.setTitle(R.string.create_network_engine);
    final EditText engineNameView = (EditText) content.findViewById(R.id.create_network_engine);
    engineNameView.setText("");
    final Runnable createEngine = new Runnable() {
        public void run() {
            String engineName = engineNameView.getText().toString();
            String sep = File.separator;
            String pathName = Environment.getExternalStorageDirectory() + sep + engineDir + sep + engineName;
            File file = new File(pathName);
            boolean nameOk = true;
            int errMsg = -1;
            if (engineName.contains("/")) {
                nameOk = false;/* w  w  w.java  2s  .c om*/
                errMsg = R.string.slash_not_allowed;
            } else if (internalEngine(engineName) || file.exists()) {
                nameOk = false;
                errMsg = R.string.engine_name_in_use;
            }
            if (!nameOk) {
                Toast.makeText(getApplicationContext(), errMsg, Toast.LENGTH_LONG).show();
                removeDialog(NETWORK_ENGINE_DIALOG);
                showDialog(NETWORK_ENGINE_DIALOG);
                return;
            }
            networkEngineToConfig = pathName;
            removeDialog(NETWORK_ENGINE_CONFIG_DIALOG);
            showDialog(NETWORK_ENGINE_CONFIG_DIALOG);
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            createEngine.run();
        }
    });
    builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });

    final Dialog dialog = builder.create();
    engineNameView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                createEngine.run();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog networkEngineConfigDialog() {
    View content = View.inflate(this, R.layout.network_engine_config, null);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(content);
    builder.setTitle(R.string.configure_network_engine);
    final EditText hostNameView = (EditText) content.findViewById(R.id.network_engine_host);
    final EditText portView = (EditText) content.findViewById(R.id.network_engine_port);
    String hostName = "";
    String port = "0";
    try {// w  ww . j  a  v  a  2 s.c o m
        String[] lines = Util.readFile(networkEngineToConfig);
        if ((lines.length >= 1) && lines[0].equals("NETE")) {
            if (lines.length > 1)
                hostName = lines[1];
            if (lines.length > 2)
                port = lines[2];
        }
    } catch (IOException e1) {
    }
    hostNameView.setText(hostName);
    portView.setText(port);
    final Runnable writeConfig = new Runnable() {
        public void run() {
            String hostName = hostNameView.getText().toString();
            String port = portView.getText().toString();
            try {
                FileWriter fw = new FileWriter(new File(networkEngineToConfig), false);
                fw.write("NETE\n");
                fw.write(hostName);
                fw.write("\n");
                fw.write(port);
                fw.write("\n");
                fw.close();
                setEngineOptions(true);
            } catch (IOException e) {
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    };
    builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            writeConfig.run();
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            removeDialog(NETWORK_ENGINE_DIALOG);
            showDialog(NETWORK_ENGINE_DIALOG);
        }
    });
    builder.setNeutralButton(R.string.delete, new Dialog.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(DELETE_NETWORK_ENGINE_DIALOG);
            showDialog(DELETE_NETWORK_ENGINE_DIALOG);
        }
    });

    final Dialog dialog = builder.create();
    portView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                writeConfig.run();
                dialog.cancel();
                removeDialog(NETWORK_ENGINE_DIALOG);
                showDialog(NETWORK_ENGINE_DIALOG);
                return true;
            }
            return false;
        }
    });
    return dialog;
}

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog aboutDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    String title = getString(R.string.app_name);
    WebView wv = new WebView(this);
    builder.setView(wv);
    InputStream is = getResources().openRawResource(R.raw.about);
    String data = Util.readFromStream(is);
    if (data == null)
        data = "";
    try {/*from  ww w .ja v  a2s.  com*/
        is.close();
    } catch (IOException e1) {
    }
    wv.loadDataWithBaseURL(null, data, "text/html", "utf-8", null);
    try {
        PackageInfo pi = getPackageManager().getPackageInfo("edu.mit.viral.shen", 0);
        title += " " + pi.versionName;
    } catch (NameNotFoundException e) {
    }
    builder.setTitle(title);
    AlertDialog alert = builder.create();
    return alert;
}

From source file:app.clirnet.com.clirnetapp.activity.LoginActivity.java

private void showDialog12() {

    final View checkBoxView = View.inflate(this, R.layout.alert_checkbox, null);
    final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkBox);
    final WebView wv = (WebView) checkBoxView.findViewById(R.id.webview);

    //  checkBox.setText("Yes, I accept the terms and condition");
    final AlertDialog.Builder ad = new AlertDialog.Builder(this)
            // .setMessage(termsnconditiomessage)
            .setView(checkBoxView).setIcon(R.drawable.info).setTitle("Terms of Service");

    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override/*from  www.  j av  a2 s  . c  o  m*/
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (isChecked) {
                //Method will send radio button checked status to yes button for further process of redirection
                checkedStatus(true);

            } else {

                checkedStatus(false);
                Toast.makeText(getApplicationContext(), "Please accept the terms and condition to proceed ",
                        Toast.LENGTH_LONG).show();
            }

        }

    });

    wv.setVisibility(View.VISIBLE);
    wv.loadUrl("http://doctor.clirnet.com/doctor/patientcentral/termsandcondition");
    wv.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);

            return true;
        }
    });

    ad.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            //Toast.makeText(mContext.getApplicationContext(), "You have accepted the TOS. Welcom to the site", Toast.LENGTH_SHORT).show();
            if (responceCheck) {
                rememberTermsCondition("Yes");
                Intent intent = new Intent(getApplicationContext(), SplashActivity.class);
                startActivity(intent);
                new AppController().showToastMsg(getApplicationContext(), "Login Successful");
                startService();

            } else {
                new AppController().showToastMsg(getApplicationContext(),
                        "Please accept the terms and condition to proceed");
                // Toast.makeText(mContext.getApplicationContext(), "Please accept the terms and condition to proceed", Toast.LENGTH_SHORT).show();

            }

        }
    });
    ad.setNegativeButton("No", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(getApplicationContext(), "You have denied the TOS. You may not access the site",
                    Toast.LENGTH_SHORT).show();
            rememberTermsCondition("No");
        }
    });

    ad.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(getApplicationContext(), "Please select yes or no", Toast.LENGTH_SHORT).show();
            rememberTermsCondition("No");
        }
    });

    ad.setCancelable(false);
    ad.setView(checkBoxView);
    ad.show();

}

From source file:cl.gisred.android.InspActivity.java

public void dialogBusqueda() {

    AlertDialog.Builder dialogBusqueda = new AlertDialog.Builder(this);
    dialogBusqueda.setTitle("Busqueda");
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View v = inflater.inflate(R.layout.dialog_busqueda, null);
    dialogBusqueda.setView(v);

    Spinner spinner = (Spinner) v.findViewById(R.id.spinnerBusqueda);
    final LinearLayout llBuscar = (LinearLayout) v.findViewById(R.id.llBuscar);
    final LinearLayout llDireccion = (LinearLayout) v.findViewById(R.id.llBuscarDir);

    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            R.layout.support_simple_spinner_dropdown_item, searchArray);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);/*  w  w w  .  ja  v a2s. c om*/
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            SpiBusqueda = position;

            if (position != 4) {
                if (llDireccion != null)
                    llDireccion.setVisibility(View.GONE);
                if (llBuscar != null)
                    llBuscar.setVisibility(View.VISIBLE);
            } else {
                if (llDireccion != null)
                    llDireccion.setVisibility(View.VISIBLE);
                if (llBuscar != null)
                    llBuscar.setVisibility(View.GONE);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            Toast.makeText(getApplicationContext(), "Nada seleccionado", Toast.LENGTH_SHORT).show();
        }
    });

    final EditText eSearch = (EditText) v.findViewById(R.id.txtBuscar);
    final EditText eStreet = (EditText) v.findViewById(R.id.txtCalle);
    final EditText eNumber = (EditText) v.findViewById(R.id.txtNum);

    dialogBusqueda.setPositiveButton("Buscar", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            if (SpiBusqueda == 4) {
                txtBusqueda = new String();
                if (!eStreet.getText().toString().isEmpty())
                    txtBusqueda = (eNumber.getText().toString().trim().isEmpty()) ? "0 "
                            : eNumber.getText().toString().trim() + " ";
                txtBusqueda = txtBusqueda + eStreet.getText().toString();
            } else {
                if (SpiBusqueda > 1)
                    txtBusqueda = eSearch.getText().toString();
                else
                    txtBusqueda = Util.extraerNum(eSearch.getText().toString());
            }

            if (txtBusqueda.trim().isEmpty()) {
                Toast.makeText(myMapView.getContext(), "Debe ingresar un valor", Toast.LENGTH_SHORT).show();
            } else {
                // Escala de calle para busquedas por default
                // TODO Asignar a res values o strings
                iBusqScale = 4000;
                switch (SpiBusqueda) {
                case 0:
                    callQuery(txtBusqueda, getValueByEmp("CLIENTES_XY_006.nis"),
                            LyCLIENTES.getUrl().concat("/0"));
                    if (LyCLIENTES.getLayers() != null && LyCLIENTES.getLayers().length > 0)
                        iBusqScale = LyCLIENTES.getLayers()[0].getLayerServiceInfo().getMinScale();
                    break;
                case 1:
                    callQuery(txtBusqueda, "codigo", LySED.getUrl().concat("/1"));
                    if (LySED.getLayers() != null && LySED.getLayers().length > 1)
                        iBusqScale = LySED.getLayers()[1].getLayerServiceInfo().getMinScale();
                    break;
                case 2:
                    callQuery(txtBusqueda, "rotulo", LyPOSTES.getUrl().concat("/0"));
                    if (LyPOSTES.getLayers() != null && LyPOSTES.getLayers().length > 0)
                        iBusqScale = LyPOSTES.getLayers()[0].getLayerServiceInfo().getMinScale();
                    break;
                case 3:
                    callQuery(txtBusqueda, "serie_medidor", LyMEDIDORES.getUrl().concat("/1"));
                    if (LyMEDIDORES.getLayers() != null && LyMEDIDORES.getLayers().length > 1)
                        iBusqScale = LyMEDIDORES.getLayers()[1].getLayerServiceInfo().getMinScale();
                    break;
                case 4:
                    iBusqScale = 5000;
                    String[] sBuscar = { eStreet.getText().toString(), eNumber.getText().toString() };
                    String[] sFields = { "nombre_calle", "numero" };
                    callQuery(sBuscar, sFields, LyDIRECCIONES.getUrl().concat("/0"));
                    break;
                case 5:
                    callQuery(txtBusqueda, new String[] { "id_equipo", "nombre" },
                            LyEQUIPOSLINEA.getUrl().concat("/0"));
                    if (LyEQUIPOSLINEA.getLayers() != null && LyEQUIPOSLINEA.getLayers().length > 0)
                        iBusqScale = LyEQUIPOSLINEA.getLayers()[0].getLayerServiceInfo().getMinScale();
                    break;
                }
            }
        }
    });

    dialogBusqueda.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });

    dialogBusqueda.show();
}