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.github.kanata3249.ffxieq.android.AugmentEditActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;/* ww  w .j a  va  2 s  .  co  m*/
    AlertDialog.Builder builder;

    switch (id) {
    case R.string.QueryDiscardChanges:
        builder = new AlertDialog.Builder(this);
        builder.setCancelable(true);
        builder.setMessage(getString(R.string.QueryDiscardChanges));
        builder.setTitle(getString(R.string.QueryDiscardChangesTitle));
        builder.setPositiveButton(R.string.DiscardOK, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dismissDialog(R.string.QueryDiscardChanges);

                Intent result = new Intent();

                result.putExtra("From", "AugmentEditActivity");
                setResult(RESULT_CANCELED, result);
                finish();
            }
        });
        builder.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dismissDialog(R.string.QueryDiscardChanges);
            }
        });
        dialog = builder.create();
        return dialog;
    case R.string.BaseEquipmentNotFound:
        builder = new AlertDialog.Builder(this);
        builder.setCancelable(true);
        builder.setMessage(getString(R.string.BaseEquipmentNotFound));
        builder.setTitle(getString(R.string.app_name));
        builder.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dismissDialog(R.string.BaseEquipmentNotFound);

                EquipmentSelectorActivity.startActivity(AugmentEditActivity.this, 0, getFFXICharacter(), mPart,
                        -1, -1);
            }
        });
        builder.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dismissDialog(R.string.BaseEquipmentNotFound);

                Intent result = new Intent();

                result.putExtra("From", "AugmentEditActivity");
                setResult(RESULT_CANCELED, result);
                finish();
            }
        });
        dialog = builder.create();
        return dialog;
    }
    return super.onCreateDialog(id);
}

From source file:com.death.yttorrents.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    haveStoragePermission();/*  w ww.j a v  a2s .c  o  m*/
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitleTextColor(Color.WHITE);
    toolbar.setTitle(R.string.app_name);

    final SharedPreferences preferences = getSharedPreferences(Constants.PREFERENCE_NAME, MODE_APPEND);
    Boolean isFirstRun = preferences.getBoolean(Constants.PREFERENCE_KEY_FOR_FIRSTRUN, true);

    if (isFirstRun) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, R.style.MyDialogTheme);
        alertDialogBuilder.setTitle(Html.fromHtml("<font color='#ffffff'>Disclaimer/License</font>"));
        alertDialogBuilder.setCancelable(true);
        alertDialogBuilder.setMessage(
                Html.fromHtml("<font color='#ffffff'>" + getResources().getString(R.string.terms) + "</font>"));
        alertDialogBuilder.setIcon(R.drawable.ic_icon);
        alertDialogBuilder.setCancelable(false)
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                        MainActivity.this.finish();
                        finishActivity(0);
                    }
                }).setPositiveButton("Accept", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        SharedPreferences.Editor editor = preferences.edit();
                        editor.putBoolean(Constants.PREFERENCE_KEY_FOR_FIRSTRUN, false);
                        editor.apply();
                        editor.commit();
                    }
                });
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.setCancelable(true);
        alertDialog.show();
    }

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    pDialog = new ProgressDialog(this);
    movies = new ArrayList<>();
    mAdapter = new GalleryAdapter(getApplicationContext(), movies);

    mLayoutManager = new GridLayoutManager(getApplicationContext(), 2);
    recyclerView.addItemDecoration(new GridItemDecoration(2, UrlUtils.dpToPx(this, 5), true));
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(mAdapter);

    /**
     * Click event handler on recycler view.
     */
    recyclerView.addOnItemTouchListener(new GalleryAdapter.RecyclerTouchListener(getApplicationContext(),
            recyclerView, new GalleryAdapter.ClickListener() {
                @Override
                public void onClick(View view, int position) {
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("movies", movies);
                    bundle.putInt("position", position);
                    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                    SlideshowDialogFragment newFragment = SlideshowDialogFragment.newInstance();
                    newFragment.setArguments(bundle);
                    newFragment.show(ft, "slideshow");
                }

                @Override
                public void onLongClick(View view, int position) {

                }
            }));
    fetchMovies(endpoint);
}

From source file:com.otaupdater.TabDisplay.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Context context = getApplicationContext();
    cfg = Config.getInstance(context);//from  w  w w. j a v  a 2 s  .  com

    if (!Utils.haveProKey(context)) {
        cfg.setKeyExpiry(0);
    } else if (!cfg.hasValidProKey()) {
        if (cfg.isProKeyTemporary()) {
            if (cfg.getKeyExpires() < System.currentTimeMillis()) {
                Utils.verifyProKey(context);
            }
        } else {
            Utils.verifyProKey(context);
        }
    }

    if (!Utils.isRomOtaEnabled() && !Utils.isKernelOtaEnabled()) {
        if (!cfg.getIgnoredUnsupportedWarn()) {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setTitle(R.string.alert_unsupported_title);
            alert.setMessage(R.string.alert_unsupported_message);
            alert.setCancelable(false);
            alert.setNegativeButton(R.string.alert_exit, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    finish();
                }
            });
            alert.setPositiveButton(R.string.alert_ignore, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    cfg.setIgnoredUnsupportedWarn(true);
                    dialog.dismiss();
                }
            });
            alert.create().show();
        }

        if (Utils.marketAvailable(this)) {
            GCMRegistrar.checkDevice(context);
            GCMRegistrar.checkManifest(context);
            final String regId = GCMRegistrar.getRegistrationId(context);
            if (regId.length() != 0) {
                GCMRegistrar.unregister(context);
            }
        }

    } else {
        if (Utils.marketAvailable(this)) {
            GCMRegistrar.checkDevice(context);
            GCMRegistrar.checkManifest(context);
            final String regId = GCMRegistrar.getRegistrationId(context);
            if (regId.length() != 0) {
                if (cfg.upToDate()) {
                    Log.v(Config.LOG_TAG + "GCMRegister", "Already registered");
                } else {
                    Log.v(Config.LOG_TAG + "GCMRegister", "Already registered, out-of-date");
                    cfg.setValuesToCurrent();
                    new AsyncTask<Void, Void, Void>() {
                        @Override
                        protected Void doInBackground(Void... params) {
                            Utils.updateGCMRegistration(context, regId);
                            return null;
                        }
                    }.execute();
                }
            } else {
                GCMRegistrar.register(context, Config.GCM_SENDER_ID);
                Log.v(Config.LOG_TAG + "GCMRegister", "GCM registered");
            }
        } else {
            UpdateCheckReceiver.setAlarm(context);
        }
    }

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);
    setContentView(mViewPager);

    final ActionBar bar = getActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
    bar.setTitle(R.string.app_name);

    mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.main_about), AboutTab.class, null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.main_rom), ROMTab.class, null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.main_kernel), KernelTab.class, null);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.main_walls), WallsTab.class, null);

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }
}

From source file:edu.missouri.bas.activities.AdminManageActivity.java

private Dialog buildDialog2(Context context, String str) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);
    builder.setTitle("Confirm");
    builder.setMessage(str);//from  w  w  w .j  a  v  a2s  .  c  o  m
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            editor.putString(ASID, asID.getText().toString());
            Log.d("here!!!", "id is " + asID.getText().toString());
            //format check

            editor.putString(ASPWD, "");
            editor.commit();
            setHints();
            setResult(8);
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

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

From source file:com.getkickbak.plugin.NotificationPlugin.java

/**
 * Builds and shows a native Android alert with given Strings
 * //from ww w.  jav  a2s .c  o m
 * @param message
 *           The message the alert should display
 * @param title
 *           The title of the alert
 * @param buttonLabel
 *           The label of the button
 * @param callbackContext
 *           The callback context
 */
public synchronized void alert(final String message, final String title, final String buttonLabel,
        final CallbackContext callbackContext) {

    final CordovaInterface cordova = this.cordova;

    Runnable runnable = new Runnable() {
        public void run() {

            AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity());
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(true);
            dlg.setPositiveButton(buttonLabel, new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                }
            });
            dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                }
            });

            dlg.create();
            dlg.show();
        };
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.juick.android.UserCenterActivity.java

private void enableJAM(final Runnable then) {
    if (!MainActivity.isJAMServiceRunning(UserCenterActivity.this)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(true);
        builder.setMessage(R.string.JAMNotEnabledEnable);
        builder.setTitle(getString(R.string.JuickAdvancedFunctionality));
        builder.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
            @Override//from  w w w .  j a  v  a 2s . c  o m
            public void onClick(DialogInterface dialog, int which) {
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(UserCenterActivity.this);
                sp.edit().putBoolean("enableJAMessaging", true).commit();
                MainActivity.toggleJAMessaging(UserCenterActivity.this, true);
                final ProgressDialog pd = new ProgressDialog(UserCenterActivity.this);
                dialog.cancel();
                pd.setIndeterminate(true);
                pd.setMessage(getString(R.string.WaitingForService));
                final Thread thread = new Thread() {
                    @Override
                    public void run() {
                        while (true) {
                            try {
                                JAMService instance = JAMService.instance;
                                if (instance != null) {
                                    JAXMPPClient client = instance.client;
                                    if (client != null && client.loggedIn) {
                                        runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                pd.cancel();
                                                then.run();
                                            }
                                        });
                                    }
                                }
                                Thread.sleep(500);
                            } catch (InterruptedException e) {
                                break;
                            }
                        }
                        super.run(); //To change body of overridden methods use File | Settings | File Templates.
                    }
                };
                thread.start();
                pd.setCancelable(true);
                pd.setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        thread.interrupt();
                    }
                });
                pd.show();
            }
        });
        builder.setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.show();
    } else {
        then.run();
    }
    return;
}

From source file:com.peppermint.peppermint.ui.AnswerFragment.java

/**
 * Shows the custom message entry dialog.
 *//*from  w w w . ja v  a2s  . c  om*/
public void showCustomMessageDialog() {
    // Create an alert dialog containing an EditText
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    final EditText et = new EditText(builder.getContext());
    builder.setCancelable(true).setView(et)
            .setPositiveButton(R.string.custom_message_send, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // The order is arranged in a way that the popup will be destroyed when the
                    // InCallActivity is about to finish.
                    final String textMessage = et.getText().toString().trim();
                    dismissCustomMessagePopup();
                    //                        getPresenter().rejectCallWithMessage(textMessage);
                    Log.d(this, "Call rejected with message");
                    LOGD(TAG, "Call rejected with mesage" + textMessage);
                    MainActivity.hangupCall();
                    callActivity.finish();

                }
            }).setNegativeButton(R.string.custom_message_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismissCustomMessagePopup();
                    Log.d(this, "Dismiss with custom message");

                    //        getPresenter().onDismissDialog();
                }
            }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    dismissCustomMessagePopup();
                    Log.d(this, "Dismiss with custom message");
                    //                        getPresenter().onDismissDialog();
                }
            }).setTitle(R.string.respond_via_sms_custom_message);
    mCustomMessagePopup = builder.create();

    // Enable/disable the send button based on whether there is a message in the EditText
    et.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            final Button sendButton = mCustomMessagePopup.getButton(DialogInterface.BUTTON_POSITIVE);
            sendButton.setEnabled(s != null && s.toString().trim().length() != 0);
        }
    });

    // Keyboard up, show the dialog
    mCustomMessagePopup.getWindow()
            .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    mCustomMessagePopup.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    mCustomMessagePopup.show();

    // Send button starts out disabled
    final Button sendButton = mCustomMessagePopup.getButton(DialogInterface.BUTTON_POSITIVE);
    sendButton.setEnabled(false);
}

From source file:com.semaphore.sm.MainActivity.java

private void changeTheme() {
    AlertDialog.Builder ad = new AlertDialog.Builder(this);
    ad.setMessage("Toggle dark/light theme.\nDo you want to continue?");
    ad.setCancelable(false);
    ad.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
            boolean darktheme = prefs.getBoolean("darktheme", false);
            Editor edit = prefs.edit();/*from   w  w w .java 2  s.c o  m*/
            edit.putBoolean("darktheme", !darktheme);
            edit.commit();
            MainActivity.this.recreate();
        }
    });
    ad.setNegativeButton("Cancel", null);
    ad.show();
}

From source file:com.agustinprats.myhrv.MainActivity.java

/** Shows BLE is not supported and exit app. */
public void showBleRequireDialog() {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCancelable(false);
    builder.setMessage(R.string.ble_required)
            .setNeutralButton(R.string.exit, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                    finish();/*from w  w w  . j  a v  a2  s .c  o  m*/
                }
            }).create().show();
}

From source file:com.google.zxing.client.android.history.HistoryActivity.java

public void limpaHistorico() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this, 3);
    builder.setMessage(R.string.msg_sure);
    builder.setCancelable(true);
    builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
        @Override/*from   w w w  .j  a v  a 2 s. c o m*/
        public void onClick(DialogInterface dialog, int i2) {
            historyManager.clearHistory();
            dialog.dismiss();
            finish();
        }
    });
    builder.setNegativeButton(R.string.button_cancel, null);
    builder.show();
}