Example usage for android.app AlertDialog.Builder setCancelable

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

Introduction

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

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:com.example.android.lightcontrol.MainActivity.java

public void openOptionsDialog() {

    final AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
    dialog.setCancelable(false);
    dialog.setTitle(R.string.about_title);

    if (String.valueOf(mChatService.getState()).equals("0")) {
        String state_bt = "Bluetooth State : " + "Not Connected";
        dialog.setMessage(state_bt);/*ww  w . j ava2s . c  o  m*/
        dialog.setNegativeButton(R.string.ok_label, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialoginterface, int i) {
                if (mChatService.getState() != BluetoothChatService.STATE_CONNECTED) {
                    Intent serverIntent = new Intent(MainActivity.this, DeviceListActivity.class);
                    startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
                }
            }
        });
        dialog.setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialoginterface, int i) {
                finish();
            }

        });
        dialog.show();
    }

    if (String.valueOf(mChatService.getState()).equals("2")) {
        String state_bt = "Bluetooth State : " + "Connecting...";
        dialog.setMessage(state_bt);
        dialog.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialoginterface, int i) {
                new wait_and_connect().execute();

            }
        });
        dialog.show();
    }

}

From source file:com.smc.tw.waltz.MainActivity.java

private void showNewAccessCodeDialog(WaltzDevice device) {
    if (DEBUG)//www. j a v  a  2 s. c o m
        Log.d(TAG, "showNewAccessCodeDialog d:" + device);

    if (mNewAccessCodeDialog != null) {
        mNewAccessCodeDialog.dismiss();
    }

    LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
    View dialogView = inflater.inflate(R.layout.dialog_access_code_new, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.WaltzDialog);

    final TextView firstTextView = (TextView) dialogView.findViewById(R.id.new_first_access_code_text);
    final TextView secondTextView = (TextView) dialogView.findViewById(R.id.new_second_access_code_text);
    final PinEditText firstView = (PinEditText) dialogView.findViewById(R.id.new_first_access_code_view);
    final PinEditText secondView = (PinEditText) dialogView.findViewById(R.id.new_second_access_code_view);

    firstView.requestFocus();

    String name = device.getName();

    firstTextView.setText(getString(R.string.dialog_access_code_new) + " " + name);
    secondTextView.setText(getString(R.string.dialog_access_code_again));

    builder.setIcon(R.drawable.ic_launcher);
    builder.setTitle(R.string.dialog_access_code);
    builder.setView(dialogView);
    builder.setCancelable(false);

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int id) {
            String firstText = firstView.getText().toString();
            String secondText = secondView.getText().toString();

            if (firstText == null || secondText == null || !firstText.equals(secondText)) {
                showAccessCodeNotMatchDialog();
                return;
            }

            device.changeAccessCode(firstText);
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int id) {
        }
    });

    mNewAccessCodeDialog = builder.create();

    firstView.setOnPinListener(new PinEditText.OnPinListener() {
        @Override
        public void onPincodeDone() {
            if (DEBUG)
                Log.d(TAG, "showNewAccessCodeDialog ft:" + firstView.getText().toString());

            secondView.requestFocus();
        }
    });

    secondView.setOnPinListener(new PinEditText.OnPinListener() {
        @Override
        public void onPincodeDone() {
            if (DEBUG)
                Log.d(TAG, "showNewAccessCodeDialog st:" + secondView.getText().toString());
        }
    });

    mNewAccessCodeDialog.show();
}

From source file:com.eugene.fithealthmaingit.UI.ManualEntrySaveMealFragment.java

private void updateItems() {
    mToolbar.setNavigationIcon(R.mipmap.ic_arrow_back);
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override// ww w.  j ava2  s .co  m
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), ChooseAddMealActivity.class);
            intent.putExtra(Globals.MEAL_TYPE, mealType);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
    });
    mToolbar.inflateMenu(R.menu.menu_user_info);
    mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            if (menuItem.getItemId() == R.id.action_save)
                saveMeal();
            return false;
        }
    });
    mServingSizeUpdated.setText("1");

    LinearLayout changeServing = (LinearLayout) v.findViewById(R.id.changeServing);
    changeServing.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());

            alert.setTitle("Update Serving Size: ");
            alert.setMessage("Servings Consumed");

            final EditText input = new EditText(getActivity());
            input.setText(mServingg.getText().toString());
            input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            input.selectAll();
            input.setGravity(Gravity.CENTER_HORIZONTAL);
            alert.setView(input, 64, 0, 64, 0);
            alert.setPositiveButton("Update", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    double values = Double.valueOf(input.getText().toString());
                    mServingg.setText(df.format(values));
                    mServingSizeUpdated.setText(df.format(values));
                    mCalUpdate.setText(dfW.format(Double.valueOf(mCalories) * values));
                    mCalorieProgress = Double.valueOf(mCalories) * values;
                    mFattieUpdate.setText(df.format(Double.valueOf(mFat) * values));
                    mFatProgress = Double.valueOf(mFat) * values;
                    mSaturatedFatUpdate.setText(df.format(Double.valueOf(mSaturatedFat) * values));
                    mCholesterolUpdate.setText(df.format(Double.valueOf(mCholesterol) * values));
                    mSodiumUpdate.setText(df.format(Double.valueOf(mSodium) * values));
                    mCarbUpdate.setText(df.format(Double.valueOf(mCarbohydrates) * values));
                    mCarbProgress = Double.valueOf(mCarbohydrates) * values;
                    mFiberUpdate.setText(df.format(Double.valueOf(mFiber) * values));
                    mSugarUpdate.setText(df.format(Double.valueOf(mSugar) * values));
                    mProUpdate.setText(df.format(Double.valueOf(mProtein) * values));
                    mProteinProgress = Double.valueOf(mProtein) * values;
                    mVitAUpdate.setText(df.format(Double.valueOf(mVitA) * values));
                    mVitCUpdate.setText(df.format(Double.valueOf(mVitC) * values));
                    mCalciumUpdate.setText(df.format(Double.valueOf(mCalcium) * values));
                    mIronUpdate.setText(df.format(Double.valueOf(mIron) * values));
                    progressBars();
                    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(input.getWindowToken(), 0);
                }
            });

            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(input.getWindowToken(), 0);
                }
            });
            alert.setCancelable(false);
            alert.show();
            ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                    .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS);
        }
    });

}

From source file:com.example.android.lightcontrol.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.scan:
        // Launch the DeviceListActivity to see devices and do scan
        if (mChatService.getState() != BluetoothChatService.STATE_CONNECTED) {
            Intent serverIntent = new Intent(this, DeviceListActivity.class);
            startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
            return true;
        } else {/*from w  ww .j  a  va2s.c  o  m*/
            Toast.makeText(MainActivity.this, "You have connected to a device", Toast.LENGTH_SHORT).show();
            return true;

        }
    case R.id.about:
        LayoutInflater inflater = LayoutInflater.from(this);
        final View v = inflater.inflate(R.layout.hello, null);
        final AlertDialog.Builder dialog = new AlertDialog.Builder(this);

        dialog.setCancelable(false);
        dialog.setTitle(R.string.about_title);
        dialog.setView(v);
        dialog.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialoginterface, int i) {

            }
        });
        dialog.show();
        return true;
    case R.id.action_settings:
        if (!B) {
            // Launch the DeviceListActivity to see devices and do scan
            LayoutInflater inflater1 = LayoutInflater.from(this);
            final View v1 = inflater1.inflate(R.layout.login, null);
            final AlertDialog.Builder dialog1 = new AlertDialog.Builder(this);
            final EditText password = (EditText) v1.findViewById(R.id.editText2);

            dialog1.setCancelable(false);
            dialog1.setTitle("Enter the password");
            dialog1.setView(v1);
            dialog1.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialoginterface, int i) {

                    if (password.getText().toString().equals(GlobalVariable.VAT_number)) {
                        fadetime();
                    } else {
                        Toast.makeText(MainActivity.this, "Error,wrong password!!", Toast.LENGTH_SHORT).show();
                    }

                }
            });
            dialog1.show();
            return true;
        } else {
            Toast.makeText(MainActivity.this, "Cannel round theme before set fadetime", Toast.LENGTH_SHORT)
                    .show();
        }
    case R.id.action_theme:
        LayoutInflater inflater1 = LayoutInflater.from(this);
        final View v2 = inflater1.inflate(R.layout.login, null);
        final AlertDialog.Builder dialog1 = new AlertDialog.Builder(this);
        final EditText password1 = (EditText) v2.findViewById(R.id.editText2);

        dialog1.setCancelable(false);
        dialog1.setTitle("Enter the password");
        dialog1.setView(v2);
        dialog1.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialoginterface, int i) {

                if (password1.getText().toString().equals(GlobalVariable.VAT_number)) {
                    theme_to_who();
                } else {
                    Toast.makeText(MainActivity.this, "Error,wrong password!!", Toast.LENGTH_SHORT).show();
                }

            }
        });
        dialog1.show();
        return true;
    case R.id.action_light:
        LayoutInflater inflater2 = LayoutInflater.from(this);
        final View v3 = inflater2.inflate(R.layout.login, null);
        final AlertDialog.Builder dialog2 = new AlertDialog.Builder(this);
        final EditText password2 = (EditText) v3.findViewById(R.id.editText2);

        dialog2.setCancelable(false);
        dialog2.setTitle("Enter the password");
        dialog2.setView(v3);
        dialog2.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialoginterface, int i) {

                if (password2.getText().toString().equals(GlobalVariable.VAT_number)) {
                    light_configure();
                } else {
                    Toast.makeText(MainActivity.this, "Error,wrong password!!", Toast.LENGTH_SHORT).show();
                }

            }
        });
        dialog2.show();
        return true;
    }
    return false;
}

From source file:com.morlunk.mumbleclient.app.PlumbleActivity.java

/**
 * Updates the activity to represent the connection state of the given service.
 * Will show reconnecting dialog if reconnecting, dismiss otherwise, etc.
 * Basically, this service will do catch-up if the activity wasn't bound to receive
 * connection state updates./*from   w  w w.  j  a va 2s .  c om*/
 * @param service A bound IJumbleService.
 */
private void updateConnectionState(IJumbleService service) {
    if (mConnectingDialog != null)
        mConnectingDialog.dismiss();
    if (mErrorDialog != null)
        mErrorDialog.dismiss();

    switch (mService.getConnectionState()) {
    case CONNECTING:
        Server server = service.getConnectedServer();
        mConnectingDialog = new ProgressDialog(this);
        mConnectingDialog.setIndeterminate(true);
        mConnectingDialog.setCancelable(true);
        mConnectingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                mService.disconnect();
                Toast.makeText(PlumbleActivity.this, R.string.cancelled, Toast.LENGTH_SHORT).show();
            }
        });
        mConnectingDialog
                .setMessage(getString(R.string.connecting_to_server, server.getHost(), server.getPort()));
        mConnectingDialog.show();
        break;
    case CONNECTION_LOST:
        // Only bother the user if the error hasn't already been shown.
        if (!getService().isErrorShown()) {
            JumbleException error = getService().getConnectionError();
            AlertDialog.Builder ab = new AlertDialog.Builder(PlumbleActivity.this);
            ab.setTitle(R.string.connectionRefused);
            if (mService.isReconnecting()) {
                ab.setMessage(getString(R.string.attempting_reconnect, error.getMessage()));
                ab.setPositiveButton(R.string.cancel_reconnect, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (getService() != null) {
                            getService().cancelReconnect();
                            getService().markErrorShown();
                        }
                    }
                });
            } else if (error.getReason() == JumbleException.JumbleDisconnectReason.REJECT
                    && (error.getReject().getType() == Mumble.Reject.RejectType.WrongUserPW
                            || error.getReject().getType() == Mumble.Reject.RejectType.WrongServerPW)) {
                // FIXME(acomminos): Long conditional.
                final EditText passwordField = new EditText(this);
                passwordField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                passwordField.setHint(R.string.password);
                ab.setTitle(R.string.invalid_password);
                ab.setMessage(error.getMessage());
                ab.setView(passwordField);
                ab.setPositiveButton(R.string.reconnect, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Server server = getService().getConnectedServer();
                        if (server == null)
                            return;
                        String password = passwordField.getText().toString();
                        server.setPassword(password);
                        if (server.isSaved())
                            mDatabase.updateServer(server);
                        connectToServer(server);
                    }
                });
                ab.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (getService() != null)
                            getService().markErrorShown();
                    }
                });
            } else {
                ab.setMessage(error.getMessage());
                ab.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (getService() != null)
                            getService().markErrorShown();
                    }
                });
            }
            ab.setCancelable(false);
            mErrorDialog = ab.show();
        }
        break;

    }
}

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

private Dialog crearDialogoImg(final ImageView img) {
    AlertDialog.Builder builder = new AlertDialog.Builder(InspActivity.this);
    builder.setCancelable(false);
    builder.setMessage("Desea eliminar el contenido?");
    builder.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {

        @Override//  w  w w. j a va2 s . c  o  m
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            eliminarImg(img);

        }
    });

    builder.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {

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

    return builder.create();
}

From source file:com.smc.tw.waltz.MainActivity.java

private void showConnectionFailDialog(final WaltzDevice device, int error) {
    if (DEBUG)/*  w ww. jav  a2s .  c o m*/
        Log.d(TAG, "showConnectionFailDialog d:" + device);

    String name = device.getName();

    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.WaltzDialog);

    builder.setIcon(R.drawable.ic_launcher);
    builder.setTitle(R.string.dialog_connection_fail);
    //builder.setMessage(getString(R.string.dialog_fail_to_connect) + " " + name);
    switch (error) {
    case WaltzDevice.ACCESS_CODE_AUTHORITY_ERROR:
        builder.setMessage(getString(R.string.dialog_fail_to_connect) + " " + name);
        break;
    case WaltzDevice.REQUEST_TIMEOUT:
        builder.setMessage(getString(R.string.dialog_fail_to_connect) + " " + name);
        break;
    case WaltzDevice.AM_SERVER_CONNECTION_ERROR:
        builder.setMessage(name + " " + getString(R.string.cannot_connect) + " " + "AM Server");
        break;
    case WaltzDevice.AM_SERVER_PERMISSION_ERROR:
        builder.setMessage(getString(R.string.dialog_fail_to_connect) + " " + name + "(Permission)");
        break;
    case WaltzDevice.PORT_BLOCKING_ERROR:
        builder.setMessage(name + " " + getString(R.string.cannot_reach_am));
        break;
    case WaltzDevice.DNS_RESOLVING_ERROR:
        builder.setMessage(getString(R.string.cannot_resolve_dns));
        break;
    default:
        builder.setMessage(getString(R.string.dialog_fail_to_connect) + " " + name);
        break;
    }
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int id) {
            showDeviceList();
        }
    });

    builder.create().show();
}

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  w  w w. j a va2s .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:com.digitalarx.android.ui.activity.FileDisplayActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog = null;/*from w w  w  . jav  a2s. c om*/
    AlertDialog.Builder builder;
    switch (id) {
    case DIALOG_SHORT_WAIT: {
        ProgressDialog working_dialog = new ProgressDialog(this);
        working_dialog.setMessage(getResources().getString(R.string.wait_a_moment));
        working_dialog.setIndeterminate(true);
        working_dialog.setCancelable(false);
        dialog = working_dialog;
        break;
    }
    case DIALOG_CHOOSE_UPLOAD_SOURCE: {

        String[] items = null;

        String[] allTheItems = { getString(R.string.actionbar_upload_files),
                getString(R.string.actionbar_upload_from_apps),
                getString(R.string.actionbar_failed_instant_upload) };

        String[] commonItems = { getString(R.string.actionbar_upload_files),
                getString(R.string.actionbar_upload_from_apps) };

        if (InstantUploadActivity.IS_ENABLED)
            items = allTheItems;
        else
            items = commonItems;

        builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.actionbar_upload);
        builder.setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                if (item == 0) {
                    // if (!mDualPane) {
                    Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class);
                    action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, FileDisplayActivity.this.getAccount());
                    startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
                    // } else {
                    // TODO create and handle new fragment
                    // LocalFileListFragment
                    // }
                } else if (item == 1) {
                    Intent action = new Intent(Intent.ACTION_GET_CONTENT);
                    action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
                    startActivityForResult(
                            Intent.createChooser(action, getString(R.string.upload_chooser_title)),
                            ACTION_SELECT_CONTENT_FROM_APPS);
                } else if (item == 2 && InstantUploadActivity.IS_ENABLED) {
                    Intent action = new Intent(FileDisplayActivity.this, InstantUploadActivity.class);
                    action.putExtra(FileUploader.KEY_ACCOUNT, FileDisplayActivity.this.getAccount());
                    startActivity(action);
                }
            }
        });
        dialog = builder.create();
        break;
    }
    case DIALOG_CERT_NOT_SAVED: {
        builder = new AlertDialog.Builder(this);
        builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            };
        });
        dialog = builder.create();
        break;
    }
    default:
        dialog = null;
    }

    return dialog;
}

From source file:org.xbmc.android.remote.presentation.controller.AbstractController.java

public void onWrongConnectionState(int state, final INotifiableManager manager, final Command<?> source) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
    switch (state) {
    case WifiHelper.WIFI_STATE_DISABLED:
        builder.setTitle("Wifi disabled");
        builder.setMessage("This host is Wifi only. Should I activate Wifi?");
        builder.setNeutralButton("Activate Wifi", new OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                final ProgressDialog pd = new ProgressDialog(mActivity);
                pd.setCancelable(true);//from w  w  w.j a v a 2s  .c om
                pd.setTitle("Activating Wifi");
                pd.setMessage("Please wait while Wifi is activated.");
                pd.show();
                (new Thread() {
                    public void run() {
                        final WifiHelper helper = WifiHelper.getInstance(mActivity);
                        helper.enableWifi(true);
                        int wait = 0;
                        while (wait <= MAX_WAIT_FOR_WIFI * 1000
                                && helper.getWifiState() != WifiHelper.WIFI_STATE_ENABLED) {
                            try {
                                sleep(500);
                                wait += 500;
                            } catch (InterruptedException e) {
                            }
                        }
                        manager.retryAll();
                        pd.cancel();
                        mDialogShowing = false;

                    }
                }).start();
            }
        });
        showDialog(builder);
        break;
    case WifiHelper.WIFI_STATE_ENABLED:
        final Host host = HostFactory.host;
        final WifiHelper helper = WifiHelper.getInstance(mActivity);
        final String msg;
        if (host != null && host.access_point != null && !host.access_point.equals("")) {
            helper.connect(host);
            msg = "Connecting to " + host.access_point + ". Please wait";
        } else {
            msg = "Waiting for Wifi to connect to your LAN.";
        }
        final ProgressDialog pd = new ProgressDialog(mActivity);
        pd.setCancelable(true);
        pd.setTitle("Connecting");
        pd.setMessage(msg);
        mWaitForWifi = new Thread() {
            public void run() {
                mDialogShowing = true;
                pd.show();
                (new Thread() {
                    public void run() {
                        int wait = 0;
                        while (wait <= MAX_WAIT_FOR_WIFI * 1000
                                && helper.getWifiState() != WifiHelper.WIFI_STATE_CONNECTED) {
                            try {
                                sleep(500);
                                wait += 500;
                            } catch (InterruptedException e) {
                            }
                        }
                        pd.cancel();
                        mDialogShowing = false;
                    }
                }).start();
                pd.setOnDismissListener(new OnDismissListener() {
                    public void onDismiss(DialogInterface dialog) {
                        if (helper.getWifiState() != WifiHelper.WIFI_STATE_CONNECTED) {
                            builder.setTitle("Wifi doesn't seem to connect");
                            builder.setMessage(
                                    "You can open the Wifi settings or wait " + MAX_WAIT_FOR_WIFI + " seconds");
                            builder.setNeutralButton("Wifi Settings", new OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    mDialogShowing = false;
                                    mActivity.startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));
                                }
                            });
                            builder.setCancelable(true);
                            builder.setNegativeButton("Wait", new OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    mDialogShowing = false;
                                    mActivity.runOnUiThread(mWaitForWifi); //had to make the Thread a field because of this line
                                }
                            });

                            mActivity.runOnUiThread(new Runnable() {
                                public void run() {
                                    final AlertDialog alert = builder.create();
                                    try {
                                        if (!mDialogShowing) {
                                            alert.show();
                                            mDialogShowing = true;
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            });
                        }
                    }

                });
            }
        };
        mActivity.runOnUiThread(mWaitForWifi);
    }

}