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.almunt.jgcaap.systemupdater.MainActivity.java

public void FlashFile(final String filename) {
    final boolean[] mayBeContinued = { true };
    AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this);
    builder1.setTitle("Flashing Confirmation");
    builder1.setMessage(//from  ww w  .ja  v  a 2s  . com
            "Are You sure you want to flash this file?\nIt will be added to the OpenRecoveryScript file and TWRP will automatically flash it without a warning!");
    builder1.setCancelable(true);
    builder1.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            try {
                Process su = Runtime.getRuntime().exec("su");
                DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
                outputStream.writeBytes("cd /cache/recovery/\n");
                outputStream.flush();
                outputStream.writeBytes("rm openrecoveryscript\n");
                outputStream.flush();
                outputStream.writeBytes("echo install " + Environment.getExternalStorageDirectory()
                        + "/JgcaapUpdates/" + filename + ">openrecoveryscript\n");
                outputStream.flush();
                outputStream.writeBytes("exit\n");
                outputStream.flush();
                su.waitFor();
            } catch (IOException e) {
                Toast.makeText(MainActivity.this, "Error No Root Access detected", Toast.LENGTH_LONG).show();
                mayBeContinued[0] = false;
            } catch (InterruptedException e) {
                Toast.makeText(MainActivity.this, "Error No Root Access detected", Toast.LENGTH_LONG).show();
                mayBeContinued[0] = false;
            }
            if (mayBeContinued[0]) {
                RebootRecovery(true);
            }
        }
    });
    builder1.setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });
    AlertDialog alert11 = builder1.create();
    alert11.show();
}

From source file:com.cypress.cysmart.RDKEmulatorView.MicrophoneEmulatorFragment.java

/**
 * Method to display a custom alert./*from  w w  w  .j av  a  2s. c  o m*/
 * Option for entering the google key in the method for voice to
 * text conversion
 */
private void showCustumAlert(String storedKey, boolean changeNeeded) {

    LayoutInflater li = LayoutInflater.from(getActivity());
    View promptsView = li.inflate(R.layout.api_key_dialog_alert, null);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());

    // set api_key_dialog_alert.xml to alertdialog builder
    alertDialogBuilder.setView(promptsView);

    //User input Edittext
    final EditText userInput = (EditText) promptsView.findViewById(R.id.custom_alert_user_input);
    if (changeNeeded) {
        userInput.setText(storedKey);
    }

    // set dialog message
    alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // get user input and set it to sharedpreferecne
            Logger.i("userInput.getText()--->" + userInput.getText());
            Utils.setStringSharedPreference(getActivity(), Constants.PREF_GOOGLE_API_KEY,
                    userInput.getText().toString());
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show();

}

From source file:tr.com.turkcellteknoloji.turkcellupdater.UpdaterDialogManager.java

@Override
public void onUpdateFailed(Exception exception) {
    Log.e("update check failed", exception);
    if (updateProgressDialog != null) {
        updateProgressDialog.dismiss();//from ww w  . j  ava 2  s  .  com
    }

    AlertDialog.Builder builder = new Builder(activity);
    builder.setIcon(android.R.drawable.ic_dialog_alert);
    builder.setTitle(R.string.error_occured);
    builder.setMessage(R.string.update_couldn_t_be_completed);
    builder.setCancelable(false);
    if (update == null || !update.forceUpdate) {
        builder.setNeutralButton(R.string.continue_, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                onCompleted();
            }
        });

    } else {
        builder.setNeutralButton(R.string.exit_application, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                onExit();
            }
        });

    }
    builder.create().show();

}

From source file:com.einzig.ipst2.activities.MainActivity.java

/**
 * Search through accounts on the user's device now that we have permission to do so.
 */// w  w w .j  a v a  2s  . c  om
public void gotAccountsPermission() {
    AccountManager manager = AccountManager.get(MainActivity.this);
    int numGoogAcct = 0;
    Account[] accountList = manager.getAccounts();
    for (Account a : accountList) {
        if (a.type.equals("com.google")) {
            numGoogAcct++;
        }
    }

    if (numGoogAcct == 0) {
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this,
                ThemeHelper.getDialogTheme(this));
        builder.setTitle(R.string.noaccountstitle);
        builder.setMessage(R.string.noaccountsmessage);//.  Would you like to log in manually?")
        builder.setCancelable(true);
        builder.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        builder.show();
    } else {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                findViewById(R.id.progress_view_mainactivity).setVisibility(View.VISIBLE);
                findViewById(R.id.gmail_login_button).setVisibility(View.INVISIBLE);
            }
        });
        Intent intent = AccountManager.newChooseAccountIntent(null, null, new String[] { "com.google" }, false,
                null, null, null, null);
        startActivityForResult(intent, LOGIN_ACTIVITY_CODE);
    }
}

From source file:com.gsma.rcs.ri.sharing.image.InitiateImageSharing.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (KeyEvent.KEYCODE_BACK == keyCode) {
        try {/*  ww  w.  ja  va 2 s.  c o  m*/
            if (mImageSharing == null || !RcsSessionUtil.isAllowedToAbortImageSharingSession(mImageSharing)) {
                finish();
                return true;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.label_confirm_close);
            builder.setPositiveButton(R.string.label_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    quitSession();
                }
            });
            builder.setNegativeButton(R.string.label_cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            builder.setCancelable(true);
            registerDialog(builder.show());
            return true;

        } catch (RcsServiceException e) {
            showException(e);
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.dsi.ant.antplus.pluginsampler.geocache.Activity_GeoScanList.java

/**
 * Resets the PCC connection to request access again and clears any existing display data.
 *//*  w  w  w  . j ava 2  s.co m*/
private void resetPcc() {
    //Release the old access if it exists
    if (releaseHandle != null) {
        releaseHandle.close();
    }

    //Reset the device list display
    bDevicesInList = false;
    deviceList_Display.clear();
    HashMap<String, String> listItem = new HashMap<String, String>();
    listItem.put("title", "No Devices Found");
    listItem.put("desc", "No results received from plugin yet...");
    deviceList_Display.add(listItem);
    adapter_deviceList_Display.notifyDataSetChanged();

    tv_status.setText("Connecting...");

    //Make the access request
    releaseHandle = AntPlusGeocachePcc.requestListAndRequestAccess(this,
            new IPluginAccessResultReceiver<AntPlusGeocachePcc>() {
                @Override
                public void onResultReceived(AntPlusGeocachePcc result, RequestAccessResult resultCode,
                        DeviceState initialDeviceState) {
                    switch (resultCode) {
                    case SUCCESS:
                        geoPcc = result;
                        tv_status.setText(result.getDeviceName() + ": " + initialDeviceState);
                        geoPcc.requestCurrentDeviceList();
                        //subscribeToEvents();
                        break;
                    case CHANNEL_NOT_AVAILABLE:
                        Toast.makeText(Activity_GeoScanList.this, "Channel Not Available", Toast.LENGTH_SHORT)
                                .show();
                        tv_status.setText("Error. Do Menu->Reset.");
                        break;
                    case ADAPTER_NOT_DETECTED:
                        Toast.makeText(Activity_GeoScanList.this,
                                "ANT Adapter Not Available. Built-in ANT hardware or external adapter required.",
                                Toast.LENGTH_SHORT).show();
                        tv_status.setText("Error. Do Menu->Reset.");
                        break;
                    case BAD_PARAMS:
                        //Note: Since we compose all the params ourself, we should never see this result
                        Toast.makeText(Activity_GeoScanList.this, "Bad request parameters.", Toast.LENGTH_SHORT)
                                .show();
                        tv_status.setText("Error. Do Menu->Reset.");
                        break;
                    case OTHER_FAILURE:
                        Toast.makeText(Activity_GeoScanList.this,
                                "RequestAccess failed. See logcat for details.", Toast.LENGTH_SHORT).show();
                        tv_status.setText("Error. Do Menu->Reset.");
                        break;
                    case DEPENDENCY_NOT_INSTALLED:
                        tv_status.setText("Error. Do Menu->Reset.");
                        AlertDialog.Builder adlgBldr = new AlertDialog.Builder(Activity_GeoScanList.this);
                        adlgBldr.setTitle("Missing Dependency");
                        adlgBldr.setMessage("The required service\n\""
                                + AntPlusGeocachePcc.getMissingDependencyName()
                                + "\"\n was not found. You need to install the ANT+ Plugins service or you may need to update your existing version if you already have it. Do you want to launch the Play Store to get it?");
                        adlgBldr.setCancelable(true);
                        adlgBldr.setPositiveButton("Go to Store", new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent startStore = null;
                                startStore = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="
                                        + AntPlusGeocachePcc.getMissingDependencyPackageName()));
                                startStore.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                                Activity_GeoScanList.this.startActivity(startStore);
                            }
                        });
                        adlgBldr.setNegativeButton("Cancel", new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });

                        final AlertDialog waitDialog = adlgBldr.create();
                        waitDialog.show();
                        break;
                    case USER_CANCELLED:
                        tv_status.setText("Cancelled. Do Menu->Reset.");
                        break;
                    case UNRECOGNIZED:
                        Toast.makeText(Activity_GeoScanList.this,
                                "Failed: UNRECOGNIZED. PluginLib Upgrade Required?", Toast.LENGTH_SHORT).show();
                        tv_status.setText("Error. Do Menu->Reset.");
                        break;
                    default:
                        Toast.makeText(Activity_GeoScanList.this, "Unrecognized result: " + resultCode,
                                Toast.LENGTH_SHORT).show();
                        tv_status.setText("Error. Do Menu->Reset.");
                        break;
                    }
                }
            },
            //Receives state changes and shows it on the status display line
            new IDeviceStateChangeReceiver() {
                @Override
                public void onDeviceStateChange(final DeviceState newDeviceState) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            tv_status.setText(geoPcc.getDeviceName() + ": " + newDeviceState);
                            if (newDeviceState == DeviceState.DEAD)
                                geoPcc = null;
                        }
                    });
                }
            },
            //Receives the device list updates and displays the current list
            new IAvailableDeviceListReceiver() {
                @Override
                public void onNewAvailableDeviceList(int[] deviceIDs, String[] deviceIdentifierStrings,
                        DeviceChangingCode changeCode, int changingDeviceID) {
                    deviceList_Display.clear();

                    if (deviceIDs.length != 0) {
                        bDevicesInList = true;
                        for (int i = 0; i < deviceIDs.length; ++i) {
                            if (deviceIdentifierStrings[i].trim().length() == 0)
                                deviceIdentifierStrings[i] = "<Unprogrammed Name>";
                            else if (deviceIdentifierStrings[i].contentEquals("_________"))
                                deviceIdentifierStrings[i] = "<Unprogrammed/Invalid Name>";

                            HashMap<String, String> listItem = new HashMap<String, String>();
                            listItem.put("title", deviceIdentifierStrings[i]);
                            listItem.put("desc", Integer.toString(deviceIDs[i]));

                            deviceList_Display.add(listItem);
                        }
                    } else {
                        bDevicesInList = false;
                        HashMap<String, String> listItem = new HashMap<String, String>();
                        listItem.put("title", "No Devices Found");
                        listItem.put("desc", "No geocaches sensors detected in range yet...");
                        deviceList_Display.add(listItem);
                    }

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            adapter_deviceList_Display.notifyDataSetChanged();
                        }
                    });
                }
            });
}

From source file:com.softminds.matrixcalculator.MainActivity.java

private void PopRateDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.WeLoveYou);
    builder.setMessage(R.string.RateRequest);
    builder.setCancelable(false);
    builder.setNegativeButton(R.string.WontRate, new DialogInterface.OnClickListener() {
        @Override//from ww  w  .  j a va2 s . c o m
        public void onClick(DialogInterface dialogInterface, int i) {
            Toast.makeText(getApplicationContext(), R.string.SadRequ, Toast.LENGTH_SHORT).show();
            SharedPreferences.Editor edit = PreferenceManager
                    .getDefaultSharedPreferences(getApplicationContext()).edit();
            edit.putString("RATED", "ignored");
            edit.apply();
            dialogInterface.dismiss();
            Log.d("Prefs Status : ", PreferenceManager.getDefaultSharedPreferences(getApplication())
                    .getString("RATED", "empty"));

        }
    });
    builder.setPositiveButton(R.string.RateNow, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
            try {
                Intent intent24 = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("market://details?id=" + getPackageName()));
                SharedPreferences.Editor edit = PreferenceManager
                        .getDefaultSharedPreferences(getApplicationContext()).edit();
                edit.putString("RATED", "yes");
                edit.apply();
                startActivity(intent24);
                Toast.makeText(getApplicationContext(), R.string.OpeningPlay, Toast.LENGTH_SHORT).show();
            } catch (ActivityNotFoundException e) { //if Play store is not installed
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName())));
            }
        }
    });
    builder.setNeutralButton(R.string.later, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
            SharedPreferences.Editor edit = PreferenceManager
                    .getDefaultSharedPreferences(getApplicationContext()).edit();
            edit.putString("RATED", "later");
            edit.apply();
            Log.d("Prefs Status : ", PreferenceManager.getDefaultSharedPreferences(getApplication())
                    .getString("RATED", "empty"));

        }
    });

    builder.show();
}

From source file:com.gmail.nagamatu.radiko.installer.RadikoInstallerActivity.java

private Dialog onCreateSelectAccountDialog() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.select_account);
    final CharSequence[] items = new CharSequence[mAccounts.length];
    int i = 0;/*from   w  ww .ja v  a2 s . c o  m*/
    for (Account a : mAccounts) {
        items[i++] = a.name;
    }
    builder.setItems(items, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            mAccount = mAccounts[which];
            showDialog(DIALOG_PASSWD);
        }
    });
    builder.setCancelable(false);
    return builder.create();
}

From source file:com.example.weather.SettingsActivity.java

/**
 * ???/*from www . j a  va  2 s  . co m*/
 *
 * @since 2.5.0
 */
private void showMissingPermissionDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.notifyTitle);
    builder.setMessage(R.string.notifyMsg);

    // ?, 
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
    });

    builder.setPositiveButton(R.string.setting, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            startAppSettings();
        }
    });

    builder.setCancelable(false);

    builder.show();
}

From source file:org.kde.necessitas.ministro.MinistroActivity.java

private boolean checkFreeSpace(final long size) throws InterruptedException {
    final StatFs stat = new StatFs(m_qtLibsRootPath);
    if (stat.getBlockSize() * stat.getAvailableBlocks() < size) {
        runOnUiThread(new Runnable() {
            public void run() {

                AlertDialog.Builder builder = new AlertDialog.Builder(MinistroActivity.this);
                builder.setMessage(getResources().getString(R.string.ministro_disk_space_msg,
                        (size - (stat.getBlockSize() * stat.getAvailableBlocks())) / 1024 + "Kb"));
                builder.setCancelable(true);
                builder.setNeutralButton(getResources().getString(R.string.settings_msg),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                try {
                                    startActivityForResult(
                                            new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS),
                                            freeSpaceCode);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    try {
                                        startActivityForResult(
                                                new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS),
                                                freeSpaceCode);
                                    } catch (Exception e1) {

                                        e1.printStackTrace();
                                    }/*from   ww w  .jav  a  2 s  .  com*/
                                }
                            }
                        });
                builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                        m_diskSpaceSemaphore.release();
                    }
                });
                builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                    public void onCancel(DialogInterface dialog) {
                        dialog.dismiss();
                        m_diskSpaceSemaphore.release();
                    }
                });
                m_distSpaceDialog = builder.create();
                m_distSpaceDialog.show();
            }
        });
        m_diskSpaceSemaphore.acquire();
    } else
        return true;

    return stat.getBlockSize() * stat.getAvailableBlocks() > size;
}