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.salmannazir.filemanager.businesslogic.EventHandler.java

@Override
public void onClick(View v) {

    switch (v.getId()) {

    case R.id.back_button:
        handleBackButton();/* w w  w .  ja v  a  2 s.  c o m*/
        break;

    case R.id.home_button:
        handleHomeButton();
        break;

    case R.id.hidden_move:
    case R.id.hidden_copy:
        /* check if user selected objects before going further */
        if (mMultiSelectedData == null || mMultiSelectedData.isEmpty()) {
            mListAdapter.removeMultiSelect(true);
            break;
        }

        if (v.getId() == R.id.hidden_move)
            delete_after_copy = true;

        mInformationLabel.setText("Holding " + mMultiSelectedData.size() + " file(s)");

        mListAdapter.removeMultiSelect(false);
        break;

    case R.id.hidden_delete:
        /* check if user selected objects before going further */
        if (mMultiSelectedData == null || mMultiSelectedData.isEmpty()) {
            mListAdapter.removeMultiSelect(true);
            break;
        }

        final String[] data = new String[mMultiSelectedData.size()];
        int at = 0;

        for (String string : mMultiSelectedData)
            data[at++] = string;

        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage("Are you sure you want to delete " + data.length + " files? This cannot be "
                + "undone after that.");
        builder.setCancelable(false);
        builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                new BackgroundWork(Constants.DELETE_TYPE).execute(data);
                mListAdapter.removeMultiSelect(true);
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mListAdapter.removeMultiSelect(true);
                dialog.cancel();
            }
        });

        builder.create().show();
        break;
    }
}

From source file:com.soma.second.matnam.ui.advrecyclerview.fragment.ExpandableItemPinnedMessageDialogFragment.java

@NonNull
@Override// w  ww.  j a  v  a  2  s . co m
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    final int groupPosition = getArguments().getInt(KEY_GROUP_ITEM_POSITION, Integer.MIN_VALUE);
    final int childPosition = getArguments().getInt(KEY_CHILD_ITEM_POSITION, Integer.MIN_VALUE);

    // for expandable list
    if (childPosition == RecyclerView.NO_POSITION) {
        builder.setMessage(getString(R.string.app_name, groupPosition));
    } else {
        builder.setMessage(getString(R.string.app_name, groupPosition, childPosition));
    }
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            notifyItemPinnedDialogDismissed(true);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    builder.setCancelable(true);
    return builder.create();
}

From source file:com.example.drugsformarinemammals.ViewPager_Pinnipeds.java

private void displayMessage(String messageTitle, String message) {
    AlertDialog.Builder myalert = new AlertDialog.Builder(this);

    TextView title = new TextView(this);
    title.setTypeface(Typeface.SANS_SERIF);
    title.setTextSize(20);//from  w  w w . j av a 2 s .  c  o  m
    title.setTextColor(getResources().getColor(R.color.blue));
    title.setPadding(8, 8, 8, 8);
    title.setText("");
    title.setGravity(Gravity.CENTER_VERTICAL);

    LinearLayout layout = new LinearLayout(this);
    TextView text = new TextView(this);
    text.setTypeface(Typeface.SANS_SERIF);
    text.setTextSize(20);
    text.setPadding(10, 10, 10, 10);
    text.setText(message);
    layout.addView(text);

    myalert.setView(layout);
    myalert.setCustomTitle(title);
    myalert.setCancelable(true);
    myalert.show();

}

From source file:com.andybotting.tubechaser.activity.Home.java

/**
 * Show about dialog window/*from   w  ww  .  j a  v a2 s .com*/
 */
public void showAbout() {
    // Get the package name
    String heading = getResources().getText(R.string.app_name) + "\n";

    try {
        PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
        heading += "v" + pi.versionName + "\n\n";
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    // Build alert dialog
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setTitle(heading);
    View aboutView = getLayoutInflater().inflate(R.layout.dialog_about, null);
    dialogBuilder.setView(aboutView);
    dialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Set first launch flag in DB
            mPreferenceHelper.setFirstLaunchThisVersion();
        }
    });
    dialogBuilder.setCancelable(false);
    dialogBuilder.setIcon(R.drawable.appicon);
    dialogBuilder.show();
}

From source file:edu.pitt.gis.uniapp.UniApp.java

/**
 * Display an error dialog and optionally exit application.
 *
 * @param title/*from w  ww  .j ava 2 s  . co m*/
 * @param message
 * @param button
 * @param exit
 */
public void displayError(final String title, final String message, final String button, final boolean exit) {
    final UniApp me = this;
    me.runOnUiThread(new Runnable() {
        public void run() {
            try {
                AlertDialog.Builder dlg = new AlertDialog.Builder(me);
                dlg.setMessage(message);
                dlg.setTitle(title);
                dlg.setCancelable(false);
                dlg.setPositiveButton(button, new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        if (exit) {
                            me.endActivity();
                        }
                    }
                });
                dlg.create();
                dlg.show();
            } catch (Exception e) {
                finish();
            }
        }
    });
}

From source file:com.dvn.vindecoder.ui.seller.GetAllVehicalSellerDetails.java

public void openDialog() {

    // get prompts.xml view
    LayoutInflater li = LayoutInflater.from(GetAllVehicalSellerDetails.this);
    View promptsView = li.inflate(R.layout.prompt, null);

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

    // set prompts.xml to alertdialog builder
    alertDialogBuilder.setView(promptsView);
    alertDialogBuilder.setTitle("Why you want to stop this");
    final EditText userInput = (EditText) promptsView.findViewById(R.id.editTextDialogUserInput);

    // 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 result
            // edit text
            //result.setText(userInput.getText());
            if (!userInput.getText().toString().trim().isEmpty()) {
                reason = userInput.getText().toString().trim();
                getUserData(reason);//from   www  .  j  a v a 2 s. co m
            } else {
                Toast.makeText(GetAllVehicalSellerDetails.this, "Please fill your reason", Toast.LENGTH_LONG)
                        .show();
            }
        }
    }).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:com.dwdesign.tweetings.fragment.StatusFragment.java

protected void translate(final ParcelableStatus status) {
    ThreadPolicy tp = ThreadPolicy.LAX;
    StrictMode.setThreadPolicy(tp);//from   ww  w . ja  v a  2 s .com

    String language = Locale.getDefault().getLanguage();
    String url = "http://api.microsofttranslator.com/v2/Http.svc/Translate?contentType="
            + URLEncoder.encode("text/plain") + "&appId=" + BING_TRANSLATE_API_KEY + "&from=&to=" + language
            + "&text=";
    url = url + URLEncoder.encode(status.text_plain);
    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = httpClient.execute(new HttpGet(url));

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        String sResponse;
        StringBuilder s = new StringBuilder();

        while ((sResponse = reader.readLine()) != null) {
            s = s.append(sResponse);
        }
        String finalString = s.toString();
        finalString = finalString
                .replace("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">", "");
        finalString = finalString.replace("</string>", "");

        AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
        builder.setTitle(getString(R.string.translate));
        builder.setMessage(finalString);
        builder.setCancelable(true);
        builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });

        AlertDialog alert = builder.create();
        alert.show();
        //Toast.makeText(getActivity(), finalString, Toast.LENGTH_LONG).show();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:jp.ne.sakura.kkkon.android.exceptionhandler.DefaultUploaderWeb.java

public static AlertDialog.Builder setupAlertDialog(final Context context) {
    final AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
    final Locale defaultLocale = Locale.getDefault();

    String title = "";
    String message = "";
    String positive = "";
    String negative = "";

    boolean needDefaultLang = true;
    if (null != defaultLocale) {
        if (defaultLocale.equals(Locale.JAPANESE) || defaultLocale.equals(Locale.JAPAN)) {
            title = "";
            message = "???????";
            positive = "?";
            negative = "";
            needDefaultLang = false;//from   www .ja v  a 2 s .c o m
        }
    }
    if (needDefaultLang) {
        title = "INFO";
        message = "Now uploading error information. Cancel upload?";
        positive = "Wait";
        negative = "Cancel";
    }
    alertDialog.setTitle(title);
    alertDialog.setMessage(message);
    alertDialog.setPositiveButton(positive, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface di, int i) {
            if (null != thread) {
                if (thread.isAlive()) {
                    alertDialog.show();
                } else {
                    terminate();
                }
            }
        }
    });

    alertDialog.setNegativeButton(negative, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface di, int i) {
            if (null != thread) {
                if (thread.isAlive()) {
                    Log.d(TAG, "request interrupt");
                    terminate();
                } else {
                    // nothing
                    terminate();
                }
            }
        }
    });

    alertDialog.setCancelable(false);

    return alertDialog;
}

From source file:com.gsma.rcs.ri.messaging.GroupTalkView.java

private void addQuickText() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.label_select_quicktext);
    builder.setCancelable(true);
    builder.setItems(R.array.select_quicktext, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String[] items = getResources().getStringArray(R.array.select_quicktext);
            mComposeText.append(items[which]);
        }/*from  w  ww  . j a va  2 s .  c  o  m*/
    });
    registerDialog(builder.show());
}

From source file:com.h6ah4i.android.example.advrecyclerview.common.fragment.ExpandableItemPinnedMessageDialogFragment.java

@NonNull
@Override//from ww  w.  j  av a  2 s  .co m
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    final int groupPosition = getArguments().getInt(KEY_GROUP_ITEM_POSITION, Integer.MIN_VALUE);
    final int childPosition = getArguments().getInt(KEY_CHILD_ITEM_POSITION, Integer.MIN_VALUE);

    // for expandable list
    if (childPosition == RecyclerView.NO_POSITION) {
        builder.setMessage(getString(R.string.dialog_message_group_item_pinned, groupPosition));
    } else {
        builder.setMessage(getString(R.string.dialog_message_child_item_pinned, groupPosition, childPosition));
    }
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            notifyItemPinnedDialogDismissed(true);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    builder.setCancelable(true);
    return builder.create();
}