Example usage for android.app AlertDialog show

List of usage examples for android.app AlertDialog show

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:cm.aptoide.pt.ManageRepo.java

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {

    LayoutInflater li = LayoutInflater.from(this);

    switch (item.getItemId()) {
    case ADD_REPO:
        View view = li.inflate(R.layout.addrepo, null);

        final TextView sec_msg = (TextView) view.findViewById(R.id.sec_msg);
        final TextView sec_msg2 = (TextView) view.findViewById(R.id.sec_msg2);

        final EditText sec_user = (EditText) view.findViewById(R.id.sec_user);
        final EditText sec_pwd = (EditText) view.findViewById(R.id.sec_pwd);

        final CheckBox sec = (CheckBox) view.findViewById(R.id.secure_chk);
        sec.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sec_user.setEnabled(true);
                    sec_pwd.setEnabled(true);
                } else {
                    sec_user.setEnabled(false);
                    sec_pwd.setEnabled(false);
                }/*from  www .  j av  a  2  s.  c o  m*/
            }
        });

        Builder p = new AlertDialog.Builder(this).setView(view);
        alrt = p.create();
        alrt.setIcon(android.R.drawable.ic_menu_add);
        alrt.setTitle("Add new repository");

        alrt.setButton("Add", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Message msg = new Message();
                EditText uri = (EditText) alrt.findViewById(R.id.edit_uri);
                String uri_str = uri.getText().toString();
                sec_msg.setVisibility(View.GONE);
                sec_msg2.setVisibility(View.GONE);
                if (sec.isChecked()) {
                    String user = sec_user.getText().toString();
                    String pwd = sec_pwd.getText().toString();
                    int result = checkServer(uri_str, user, pwd);
                    if (result == 200) {
                        msg.obj = 0;
                        db.addServer(uri_str);
                        db.addLogin(user, pwd, uri_str);
                        change = true;
                        redraw();
                    } else if (result == 401) {
                        sec_msg2.setText("Login is wrong");
                        sec_msg2.setVisibility(View.VISIBLE);
                        msg.obj = 1;
                    } else {
                        sec_msg.setText("Can't connect to server");
                        sec_msg.setVisibility(View.VISIBLE);
                        msg.obj = 1;
                    }
                } else {
                    int result = checkServer(uri_str, null, null);
                    if (result == 200) {
                        msg.obj = 0;
                        db.addServer(uri_str);
                        change = true;
                        redraw();
                    } else if (result == 401) {
                        sec_msg2.setText("Login required");
                        sec_msg2.setVisibility(View.VISIBLE);
                        msg.obj = 1;
                    } else {
                        sec_msg.setText("Can't connect to server");
                        sec_msg.setVisibility(View.VISIBLE);
                        msg.obj = 1;
                    }
                }
                new_repo.sendMessage(msg);
            }
        });

        alrt.setButton2("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                alrt.dismiss();
            }
        });
        alrt.show();
        break;

    case REM_REPO:
        final Vector<String> rem_lst = new Vector<String>();
        CharSequence[] b = new CharSequence[server_lst.size()];
        for (int i = 0; i < server_lst.size(); i++) {
            b[i] = server_lst.get(i).uri;
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Chose repository to remove");
        builder.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
        builder.setMultiChoiceItems(b, null, new DialogInterface.OnMultiChoiceClickListener() {
            public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
                if (isChecked) {
                    rem_lst.addElement(server_lst.get(whichButton).uri);
                } else {
                    rem_lst.removeElement(server_lst.get(whichButton).uri);
                }
            }
        });
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                db.removeServer(rem_lst);
                change = true;
                redraw();
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                return;
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
        break;

    case EDIT_REPO:
        CharSequence[] b2 = new CharSequence[server_lst.size()];
        for (int i = 0; i < server_lst.size(); i++) {
            b2[i] = server_lst.get(i).uri;
        }

        AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
        builder2.setTitle("Chose repository to edit");
        builder2.setIcon(android.R.drawable.ic_menu_edit);
        builder2.setSingleChoiceItems(b2, -1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                updt_repo = server_lst.get(which).uri;
            }
        });
        builder2.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                editRepo(updt_repo);
                return;
            }
        });
        builder2.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                return;
            }
        });
        alert2 = builder2.create();
        alert2.show();
        break;
    }
    return super.onMenuItemSelected(featureId, item);
}

From source file:com.mobicage.rogerthat.registration.ContentBrandingRegistrationActivity.java

private void registerWithQRUrl(final String qr_url) {
    if (!mService.getNetworkConnectivityManager().isConnected()) {
        UIUtils.showNoNetworkDialog(this);
        return;/*from  w  w  w . j  a va 2  s .  c  om*/
    }

    final String timestamp = "" + mWiz.getTimestamp();
    final String deviceId = mWiz.getDeviceId();
    final String registrationId = mWiz.getRegistrationId();
    final String installId = mWiz.getInstallationId();
    // Make call to Rogerthat webfarm

    mProgressContainer.setVisibility(View.VISIBLE);
    mButtonContainer.setVisibility(View.GONE);

    final SafeRunnable showErrorDialog = new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.UI();
            mProgressContainer.setVisibility(View.GONE);
            mButtonContainer.setVisibility(View.VISIBLE);
            AlertDialog.Builder builder = new AlertDialog.Builder(ContentBrandingRegistrationActivity.this);
            builder.setMessage(R.string.error_please_try_again);
            builder.setPositiveButton(R.string.rogerthat, null);
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    };

    mWorkerHandler.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.REGISTRATION();
            String version = "1";
            String signature = Security.sha256(version + " " + installId + " " + timestamp + " " + deviceId
                    + " " + registrationId + " " + qr_url + CloudConstants.REGISTRATION_MAIN_SIGNATURE);

            HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_QR_URL);
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(13);
                nameValuePairs.add(new BasicNameValuePair("version", version));
                nameValuePairs.add(new BasicNameValuePair("platform", "android"));
                nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp));
                nameValuePairs.add(new BasicNameValuePair("device_id", deviceId));
                nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId));
                nameValuePairs.add(new BasicNameValuePair("signature", signature));
                nameValuePairs.add(new BasicNameValuePair("install_id", installId));
                nameValuePairs.add(new BasicNameValuePair("qr_url", qr_url));
                nameValuePairs.add(new BasicNameValuePair("language", Locale.getDefault().getLanguage()));
                nameValuePairs.add(new BasicNameValuePair("country", Locale.getDefault().getCountry()));
                nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID));
                nameValuePairs.add(
                        new BasicNameValuePair("use_xmpp_kick", CloudConstants.USE_XMPP_KICK_CHANNEL + ""));
                nameValuePairs.add(new BasicNameValuePair("GCM_registration_id", mGCMRegistrationId));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = mHttpClient.execute(httppost);

                int statusCode = response.getStatusLine().getStatusCode();
                HttpEntity entity = response.getEntity();

                if (entity == null) {
                    mUIHandler.post(showErrorDialog);
                    return;
                }

                @SuppressWarnings("unchecked")
                final Map<String, Object> responseMap = (Map<String, Object>) JSONValue
                        .parse(new InputStreamReader(entity.getContent()));

                if (statusCode != 200 || responseMap == null) {
                    if (statusCode == 500 && responseMap != null) {
                        final String errorMessage = (String) responseMap.get("error");
                        if (errorMessage != null) {
                            mUIHandler.post(new SafeRunnable() {
                                @Override
                                protected void safeRun() throws Exception {
                                    T.UI();
                                    mProgressContainer.setVisibility(View.GONE);
                                    mButtonContainer.setVisibility(View.VISIBLE);
                                    AlertDialog.Builder builder = new AlertDialog.Builder(
                                            ContentBrandingRegistrationActivity.this);
                                    builder.setMessage(errorMessage);
                                    builder.setPositiveButton(R.string.rogerthat, null);
                                    AlertDialog dialog = builder.create();
                                    dialog.show();
                                }
                            });
                            return;
                        }
                    }
                    mUIHandler.post(showErrorDialog);
                    return;
                }
                JSONObject account = (JSONObject) responseMap.get("account");
                final String email = (String) responseMap.get("email");
                final RegistrationInfo info = new RegistrationInfo(email,
                        new Credentials((String) account.get("account"), (String) account.get("password")));
                mUIHandler.post(new SafeRunnable() {
                    @Override
                    protected void safeRun() throws Exception {
                        T.UI();
                        mWiz.setEmail(email);
                        mWiz.save();
                        tryConnect(1, getString(R.string.registration_establish_connection, email,
                                getString(R.string.app_name)) + " ", info);
                    }
                });

            } catch (Exception e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            }
        }
    });
}

From source file:com.otaupdater.utils.UserUtils.java

public static void showAccountDialog(final Context ctx, final DialogCallback dlgCallback) {
    final Config cfg = Config.getInstance(ctx);

    final AlertDialog dlg = new AlertDialog.Builder(ctx).setTitle("OTA Update Center Account")
            .setMessage("Logged in as: " + cfg.getUsername())
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override//from ww w.  j av  a  2  s  .c  o m
                public void onClick(DialogInterface dialogInterface, int i) {
                }
            }).setNegativeButton("Sign Out", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    APIUtils.userLogout(ctx, new APIUtils.APIAdapter() {
                        @Override
                        public void onSuccess(String message, JSONObject respObj) {
                            cfg.clearLogin();
                        }
                    });
                }
            }).create();

    dlg.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialogInterface) {
            if (dlgCallback != null)
                dlgCallback.onDialogShown(dlg);
        }
    });
    dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            if (dlgCallback != null)
                dlgCallback.onDialogClosed(dlg);
        }
    });
    dlg.show();
}

From source file:com.tarun.smartwomen.WebViewDemoActivity.java

@SuppressLint({ "JavascriptInterface", "SetJavaScriptEnabled" })
@Override/*  www  . j a  va 2s .  c o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.mainn);

    Intent intent = getIntent();
    reg = intent.getBooleanExtra("reg", false);

    i = (ImageView) findViewById(R.id.hj);

    try {

        big = new GifAnimationDrawable(getResources().openRawResource(R.raw.anim2));
        // big.setOneShot(true);
        android.util.Log.v("GifAnimationDrawable", "===>Four");
    } catch (IOException ioe) {

    }

    i.setImageDrawable(big);
    big.setVisible(true, true);

    sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
    // historyStack = new LinkedList<Link>();
    webview = (WebView) findViewById(R.id.webkit);

    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);

    webSettings.setDomStorageEnabled(true);
    // webview.addJavascriptInterface(new WebViewDemoActivity(), "Android");
    // webview.getSettings().setJavaScriptEnabled(true);

    webview.getSettings().setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        // webview.getSettings().setPluginState(PluginState.ON);
        // webview.getSettings().setJavaScriptEnabled(true);
    } else {
        // IMPORTANT!! this method is no longer available since Android 4.3
        // so the code doesn't compile anymore
        // webview.getSettings().setPluginsEnabled(true);
    }

    // Internet

    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    connected = false;
    if ((null != connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) && connectivityManager
            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED)
            || (null != connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI) && connectivityManager
                    .getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED)) {
        // we are connected to a network
        connected = true;
    }

    if (connected == false) {
        /*
         * Toast.makeText(Rss.this,
         * "Connect to internet and Restart Application",
         * Toast.LENGTH_SHORT).show();
         */
        webview.setVisibility(View.INVISIBLE);

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(WebViewDemoActivity.this);

        // alertDialogBuilder.setTitle("Please connect to Internet");
        alertDialogBuilder.setMessage(
                "In order to provide the freshest recipes and juicing information this app must be connected to the internet, please check your internet settings");
        // set positive button: Yes message

        alertDialogBuilder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // cancel the alert box and put a Toast to the user

                startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
            }
        });
        AlertDialog alertDialog = alertDialogBuilder.create();
        // show alert
        alertDialog.show();

    }

    // downloads
    // webview.setDownloadListener(new CustomDownloadListener());

    webview.setWebViewClient(new CustomWebViewClient());

    webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int progress) {

        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
        }

        @Override
        public void onReceivedIcon(WebView view, Bitmap icon) {

        }

    });

    // http://stackoverflow.com/questions/2083909/android-webview-refusing-user-input
    webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                    v.requestFocus();
                }
                break;
            }
            return false;
        }

    });

    if (reg == true) {
        if (Locale.getDefault().getLanguage().equals("es")) {

            webview.loadUrl("http://om-msmartwoman.com/member/register");
            // webview.loadUrl("http://live-juice-guru.gotpantheon.com/user/login");
        } else {
            webview.loadUrl("http://om-msmartwoman.com/member/register");
        }

        webview.requestFocus();
    } else {
        uhdj = sp.getString("your_int_key", "0");

        Log.e("Url is here ..............................", uhdj);
        // Welcome page loaded from assets directory
        if (Locale.getDefault().getLanguage().equals("es")) {

            webview.loadUrl(uhdj);
            // webview.loadUrl("http://live-juice-guru.gotpantheon.com/user/login");
        } else {
            webview.loadUrl(uhdj);
        }

        webview.requestFocus();
    }

}

From source file:com.alex.smartwomanmiddleeastfem.WebViewDemoActivity.java

@SuppressLint({ "JavascriptInterface", "SetJavaScriptEnabled" })
@Override/*from   w  ww  .j  av  a2s  .  c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.mainn);

    Intent intent = getIntent();
    reg = intent.getBooleanExtra("reg", false);

    i = (ImageView) findViewById(R.id.hj);

    try {

        big = new GifAnimationDrawable(getResources().openRawResource(R.raw.anim2));
        // big.setOneShot(true);
        android.util.Log.v("GifAnimationDrawable", "===>Four");
    } catch (IOException ioe) {

    }

    i.setImageDrawable(big);
    big.setVisible(true, true);

    sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
    // historyStack = new LinkedList<Link>();
    webview = (WebView) findViewById(R.id.webkit);

    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);

    webSettings.setDomStorageEnabled(true);
    // webview.addJavascriptInterface(new WebViewDemoActivity(), "Android");
    // webview.getSettings().setJavaScriptEnabled(true);

    webview.getSettings().setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        // webview.getSettings().setPluginState(PluginState.ON);
        // webview.getSettings().setJavaScriptEnabled(true);
    } else {
        // IMPORTANT!! this method is no longer available since Android 4.3
        // so the code doesn't compile anymore
        // webview.getSettings().setPluginsEnabled(true);
    }

    // Internet

    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    connected = false;
    if ((null != connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) && connectivityManager
            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED)
            || (null != connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI) && connectivityManager
                    .getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED)) {
        // we are connected to a network
        connected = true;
    }

    if (connected == false) {
        /*
         * Toast.makeText(Rss.this,
         * "Connect to internet and Restart Application",
         * Toast.LENGTH_SHORT).show();
         */
        webview.setVisibility(View.INVISIBLE);

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(WebViewDemoActivity.this);

        // alertDialogBuilder.setTitle("Please connect to Internet");
        alertDialogBuilder.setMessage(
                "Through our app offers some offline features, in order to stay actively connected to the SmartWoman community in realtime, you need an internet connection, tap here to check your settings or wait until you have connection.");
        // set positive button: Yes message

        alertDialogBuilder.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // cancel the alert box and put a Toast to the user

                startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
            }
        });
        AlertDialog alertDialog = alertDialogBuilder.create();
        // show alert
        alertDialog.show();

    }

    // downloads
    // webview.setDownloadListener(new CustomDownloadListener());

    webview.setWebViewClient(new CustomWebViewClient());

    webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int progress) {

        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
        }

        @Override
        public void onReceivedIcon(WebView view, Bitmap icon) {

        }

    });

    // http://stackoverflow.com/questions/2083909/android-webview-refusing-user-input
    webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                    v.requestFocus();
                }
                break;
            }
            return false;
        }

    });

    if (reg == true) {
        if (Locale.getDefault().getLanguage().equals("es")) {

            webview.loadUrl("http://www.qa-msmartwoman.com/member/register");
            // webview.loadUrl("http://live-juice-guru.gotpantheon.com/user/login");
        } else {
            webview.loadUrl("http://www.qa-msmartwoman.com/member/register");
        }

        webview.requestFocus();
    } else {
        uhdj = sp.getString("your_int_key", "0");

        //   Log.e("Url is here ..............................", uhdj);
        // Welcome page loaded from assets directory
        if (Locale.getDefault().getLanguage().equals("es")) {

            webview.loadUrl(uhdj);
            // webview.loadUrl("http://live-juice-guru.gotpantheon.com/user/login");
        } else {
            webview.loadUrl(uhdj);
        }

        webview.requestFocus();
    }

}

From source file:org.openremote.android.console.view.PanelSelectSpinnerView.java

@Override
public void urlConnectionDidReceiveResponse(HttpResponse httpResponse) {
    int statusCode = httpResponse.getStatusLine().getStatusCode();
    if (statusCode != Constants.HTTP_SUCCESS) {
        if (statusCode == ControllerException.UNAUTHORIZED) {
            LoginDialog loginDialog = new LoginDialog(getContext());
            loginDialog.setOnClickListener(loginDialog.new OnloginClickListener() {
                @Override/*from w  ww. j  av a 2s .  com*/
                public void onClick(View v) {
                    super.onClick(v);
                    requestPanelList(getContext(), PanelSelectSpinnerView.this);
                }

            });
        } else {
            // The following code customizes the dialog, because the finish method should do after dialog show and click ok.
            AlertDialog alertDialog = new AlertDialog.Builder(getContext()).create();
            alertDialog.setTitle("Panel List Not Found");
            alertDialog.setMessage(ControllerException.exceptionMessageOfCode(statusCode));
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    return;
                }
            });
            alertDialog.show();
            setDefaultAdapterContent();
        }
    }
}

From source file:com.jesjimher.bicipalma.MesProperesActivity.java

/**
 * //from ww w  .j a  va  2 s .  c o  m
 */
private void mostrarEstadisticas() {
    int bTot = 0;
    int bAver = 0;
    int aAver = 0;
    int bLib = 0;
    int aLib = 0;
    int noBicis = 0;

    for (Estacion e : estaciones) {
        bTot += e.getAnclajesAveriados() + e.getAnclajesLibres() + e.getAnclajesUsados();
        bAver += e.getBicisAveriadas();
        aAver += e.getAnclajesAveriados();
        bLib += e.getBicisLibres();
        aLib += e.getAnclajesLibres();
        if (e.getBicisLibres() == 0)
            noBicis++;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    // Si el n de bicis es negativo, es q an no se han descargado los datos
    if (bLib < 0) {
        builder.setMessage(R.string.sinDescargaTodavia).setCancelable(true).setPositiveButton(R.string.cerrar,
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    } else {
        String mensBicis = String.format(getString(R.string.estadisticasBicis), bLib, bAver);
        String mensAnclajes = String.format(getString(R.string.estadisticasAnclajes), bTot,
                bTot - (aLib + aAver), 100 * (1 - aLib / (0.0 + bTot - aAver)), aLib,
                100 * aLib / (0.0 + bTot - aAver), aAver, 100 * aAver / Double.valueOf(bTot));

        String mensVacias = String.format(getString(R.string.estadisticasVacias), noBicis, estaciones.size());

        builder.setMessage(mensBicis + mensAnclajes + mensVacias).setTitle(R.string.estadoservicio)
                .setCancelable(true).setPositiveButton(R.string.cerrar, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
}

From source file:cm.aptoide.pt.Aptoide.java

private void requestUpdateSelf() {
    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
    alertBuilder.setCancelable(false)//  w  w w .j  ava2s .c  om
            .setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    new DownloadSelfUpdate().execute();
                }
            }).setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    proceed();
                }
            }).setMessage(R.string.update_self_msg);

    AlertDialog alert = alertBuilder.create();

    alert.setTitle(R.string.update_self_title);
    alert.setIcon(R.drawable.icon);

    alert.show();
}

From source file:org.loon.framework.android.game.LGameActivity.java

/**
 * ??Select//  ww w  .j  ava 2s . co  m
 * 
 * @param title
 * @param text
 * @return
 */
public int showAndroidSelect(final String title, final String text[]) {
    Runnable showSelect = new Runnable() {
        public void run() {
            final AlertDialog.Builder builder = new AlertDialog.Builder(LGameActivity.this);
            builder.setTitle(title);
            builder.setItems(text, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    androidSelect = item;
                }
            });
            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    androidSelect = -1;
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        }
    };
    runOnUiThread(showSelect);
    return androidSelect;
}

From source file:com.mobicage.rogerthat.registration.YSAAARegistrationActivity.java

private void register() {
    mStatusLbl.setText(R.string.initializing);
    mProgressBar.setProgress(0);/*from ww  w  .  j a va  2  s . c om*/
    mProgressBar.setVisibility(View.VISIBLE);

    TimerTask timerTask = new TimerTask() {
        @Override
        public void run() {
            mUIHandler.post(new SafeRunnable() {
                @Override
                protected void safeRun() throws Exception {
                    T.UI();
                    mProgressBar.setProgress(mProgressBar.getProgress() + 1);
                }
            });
        }
    };
    mTimer.scheduleAtFixedRate(timerTask, 250, 250);

    mRetryBtn.setVisibility(View.GONE);
    if (!mService.getNetworkConnectivityManager().isConnected()) {
        mTimer.cancel();
        mProgressBar.setVisibility(View.GONE);
        mStatusLbl.setText(R.string.registration_screen_instructions_check_network_not_available);
        mRetryBtn.setVisibility(View.VISIBLE);
        UIUtils.showNoNetworkDialog(this);
        return;
    }

    final SafeRunnable showErrorDialog = new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.UI();
            AlertDialog.Builder builder = new AlertDialog.Builder(YSAAARegistrationActivity.this);
            builder.setMessage(R.string.error_please_try_again);
            builder.setPositiveButton(R.string.rogerthat, null);
            AlertDialog dialog = builder.create();
            dialog.show();

            mTimer.cancel();
            mProgressBar.setVisibility(View.GONE);
            mStatusLbl.setText(R.string.error_please_try_again);
            mRetryBtn.setVisibility(View.VISIBLE);
        }
    };

    final String timestamp = "" + mWiz.getTimestamp();
    final String deviceId = mWiz.getDeviceId();
    final String registrationId = mWiz.getRegistrationId();
    final String installId = mWiz.getInstallationId();

    mWorkerHandler.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.REGISTRATION();
            String version = "1";
            String signature = Security.sha256(
                    version + " " + installId + " " + timestamp + " " + deviceId + " " + registrationId + " "
                            + CloudConstants.APP_SERVICE_GUID + CloudConstants.REGISTRATION_MAIN_SIGNATURE);

            HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_YSAAA_URL);
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(13);
                nameValuePairs.add(new BasicNameValuePair("version", version));
                nameValuePairs.add(new BasicNameValuePair("platform", "android"));
                nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp));
                nameValuePairs.add(new BasicNameValuePair("device_id", deviceId));
                nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId));
                nameValuePairs.add(new BasicNameValuePair("signature", signature));
                nameValuePairs.add(new BasicNameValuePair("install_id", installId));
                nameValuePairs.add(new BasicNameValuePair("service", CloudConstants.APP_SERVICE_GUID));
                nameValuePairs.add(new BasicNameValuePair("language", Locale.getDefault().getLanguage()));
                nameValuePairs.add(new BasicNameValuePair("country", Locale.getDefault().getCountry()));
                nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID));
                nameValuePairs.add(
                        new BasicNameValuePair("use_xmpp_kick", CloudConstants.USE_XMPP_KICK_CHANNEL + ""));
                nameValuePairs.add(new BasicNameValuePair("GCM_registration_id", mGCMRegistrationId));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = mHttpClient.execute(httppost);

                int statusCode = response.getStatusLine().getStatusCode();
                HttpEntity entity = response.getEntity();

                if (entity == null) {
                    mUIHandler.post(showErrorDialog);
                    return;
                }

                @SuppressWarnings("unchecked")
                final Map<String, Object> responseMap = (Map<String, Object>) JSONValue
                        .parse(new InputStreamReader(entity.getContent()));

                if (statusCode != 200 || responseMap == null) {
                    if (statusCode == 500 && responseMap != null) {
                        final String errorMessage = (String) responseMap.get("error");
                        if (errorMessage != null) {
                            mUIHandler.post(new SafeRunnable() {
                                @Override
                                protected void safeRun() throws Exception {
                                    T.UI();
                                    AlertDialog.Builder builder = new AlertDialog.Builder(
                                            YSAAARegistrationActivity.this);
                                    builder.setMessage(errorMessage);
                                    builder.setPositiveButton(R.string.rogerthat, null);
                                    AlertDialog dialog = builder.create();
                                    dialog.show();

                                    mTimer.cancel();
                                    mProgressBar.setVisibility(View.GONE);
                                    mStatusLbl.setText(errorMessage);
                                    mRetryBtn.setVisibility(View.VISIBLE);
                                }
                            });
                            return;
                        }
                    }
                    mUIHandler.post(showErrorDialog);
                    return;
                }
                JSONObject account = (JSONObject) responseMap.get("account");
                final String email = (String) responseMap.get("email");
                final RegistrationInfo info = new RegistrationInfo(email,
                        new Credentials((String) account.get("account"), (String) account.get("password")));
                mUIHandler.post(new SafeRunnable() {
                    @Override
                    protected void safeRun() throws Exception {
                        T.UI();
                        mWiz.setEmail(email);
                        mWiz.save();
                        tryConnect(1, getString(R.string.registration_establish_connection, email,
                                getString(R.string.app_name)) + " ", info);
                    }
                });

            } catch (Exception e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            }
        }
    });
}