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.cpen321.fridgemanager.OcrReader.OcrCaptureActivity.java

private void showFirstTimeDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setCancelable(true);
    builder.setTitle("Scan Your Food");
    builder.setMessage(getString(R.string.ocr_explanation));

    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();//w  w  w.j  a  v  a  2  s  .c om
        }
    });

    AlertDialog alert = builder.create();
    alert.setCanceledOnTouchOutside(false);
    alert.show();
}

From source file:com.linkedin.android.eventsapp.EventFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final String eventNameArg = getArguments().getString(EXTRA_EVENT_NAME);
    final long eventDateArg = getArguments().getLong(EXTRA_EVENT_DATE);
    final String eventLocationArg = getArguments().getString(EXTRA_EVENT_LOCATION);
    int pictureIdArg = getArguments().getInt(EXTRA_PICTURE_ID);
    boolean isAttendingArg = getArguments().getBoolean(EXTRA_EVENT_ATTENDING);
    Person[] attendeesArg = (Person[]) getArguments().getParcelableArray(EXTRA_EVENT_ATTENDEES);

    SimpleDateFormat dateFormat = new SimpleDateFormat("E dd MMM yyyy 'at' hh:00 a");
    final String dateString = dateFormat.format(new Date(eventDateArg));

    View v = inflater.inflate(R.layout.layout_event_fragment, container, false);

    boolean accessTokenValid = LISessionManager.getInstance(getActivity()).getSession().isValid();
    if (!accessTokenValid) {
        ViewStub linkedinLogin = (ViewStub) v.findViewById(R.id.connectWithLinkedInStub);
        linkedinLogin.inflate();/*from   w w w . java 2s .  co m*/

        Button loginButton = (Button) v.findViewById(R.id.connectWithLinkedInButton);
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "clicked login button");
                LISessionManager.getInstance(getActivity()).init(getActivity(), Constants.scope,
                        new AuthListener() {
                            @Override
                            public void onAuthSuccess() {
                                Intent intent = new Intent(getActivity(), MainActivity.class);
                                startActivity(intent);
                                getActivity().finish();
                            }

                            @Override
                            public void onAuthError(LIAuthError error) {

                            }
                        }, false);
            }
        });
    }

    TextView eventNameView = (TextView) v.findViewById(R.id.eventName);
    eventNameView.setText(eventNameArg);

    TextView eventLocationAndDateView = (TextView) v.findViewById(R.id.eventLocationAndDate);
    eventLocationAndDateView.setText(eventLocationArg + "   " + dateString);

    TextView eventAttendeeCount = (TextView) v.findViewById(R.id.attendeeCount);
    eventAttendeeCount.setText("Other Attendees (" + attendeesArg.length + ")");

    ImageView eventImageView = (ImageView) v.findViewById(R.id.eventImage);
    eventImageView.setImageResource(pictureIdArg);

    final Button attendButton = (Button) v.findViewById(R.id.attendButton);
    final Button declineButton = (Button) v.findViewById(R.id.declineButton);

    if (isAttendingArg) {
        attendButton.setText("Attending");
        attendButton.setEnabled(false);

        declineButton.setText("Decline");
        declineButton.setEnabled(true);
    }

    attendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((Button) v).setText("Attending");
            v.setEnabled(false);
            declineButton.setText("Decline");
            declineButton.setEnabled(true);
            if (LISessionManager.getInstance(getActivity()).getSession().isValid()) {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
                alertDialogBuilder.setTitle("Share on LinkedIn?");
                alertDialogBuilder.setCancelable(true)
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                JSONObject shareObject = new JSONObject();
                                try {
                                    JSONObject visibilityCode = new JSONObject();
                                    visibilityCode.put("code", "anyone");
                                    shareObject.put("visibility", visibilityCode);
                                    shareObject.put("comment", "I am attending " + eventNameArg + " in "
                                            + eventLocationArg + " on " + dateString);
                                } catch (JSONException e) {

                                }
                                APIHelper.getInstance(getActivity()).postRequest(getActivity(),
                                        Constants.shareBaseUrl, shareObject, new ApiListener() {
                                            @Override
                                            public void onApiSuccess(ApiResponse apiResponse) {
                                                Toast.makeText(getActivity(), "Your share was successful!",
                                                        Toast.LENGTH_LONG);
                                            }

                                            @Override
                                            public void onApiError(LIApiError apiError) {
                                                Log.e(TAG, apiError.toString());
                                                Toast.makeText(getActivity(),
                                                        "Your share was unsuccessful. Try again later!",
                                                        Toast.LENGTH_LONG);
                                            }
                                        });
                            }
                        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            }
        }
    });

    declineButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((Button) v).setText("Declined");
            v.setEnabled(false);
            attendButton.setText("Attend");
            attendButton.setEnabled(true);
        }
    });

    ListView attendeesListView = (ListView) v.findViewById(R.id.attendeesList);
    AttendeeAdapter adapter = new AttendeeAdapter(getActivity(), R.layout.attendee_list_item, attendeesArg,
            accessTokenValid);
    attendeesListView.setAdapter(adapter);
    attendeesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ArrayAdapter adapter = (ArrayAdapter) parent.getAdapter();
            Person person = (Person) adapter.getItem(position);

            Intent intent = new Intent(getActivity(), ProfileActivity.class);
            Bundle extras = new Bundle();
            extras.putParcelable("person", person);
            intent.putExtras(extras);
            startActivity(intent);
        }
    });
    return v;
}

From source file:com.example.photoremark.MainActivity.java

private void showLicenseDialog(String content) {
    AlertDialog.Builder builder = new Builder(this);
    builder.setTitle("?");
    builder.setMessage(content);/*from w  w  w. j a  v  a2s. c o  m*/
    builder.setCancelable(false);
    builder.setPositiveButton("?", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            android.os.Process.killProcess(android.os.Process.myPid());
        }
    });

    AlertDialog alertDialog = builder.create();
    alertDialog.show();

}

From source file:com.daskiworks.ghwatch.WatchedRepositoriesActivity.java

private void showUnwatchConfirmDialog(final Repository repository) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.message_confirm_unwatch_repository_title);
    builder.setMessage(R.string.message_confirm_unwatch_repository);
    builder.setCancelable(true);
    builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
        @Override//ww  w .  ja  v  a2 s .c o m
        public void onClick(DialogInterface dialog, int id) {
            new UnwatchRepositoryTask().execute(repository.getId());
            repositoriesListAdapter.removeRepositoryById(repository.getId());
            ActivityTracker.sendEvent(WatchedRepositoriesActivity.this, ActivityTracker.CAT_UI,
                    "repository_unwatch", "", 0L);
            notifyDataSetChanged();
        }
    });
    builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
        }
    });
    builder.create().show();
}

From source file:com.meiste.greg.ptw.GameActivity.java

@SuppressLint("NewApi")
@Override/*from w  ww. j  a va 2 s . com*/
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.settings:
        startActivity(new Intent(this, EditPreferences.class));
        return true;

    case R.id.legal:
        trackEvent("onOptionsItemSelected", "legal");
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.legal);
        builder.setCancelable(true);
        builder.setPositiveButton(R.string.ok, null);
        builder.setMessage(R.string.legal_content);
        mDialog = builder.create();
        mDialog.show();
        return true;

    case R.string.google_plus:
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://plus.google.com/109696002032953241222/posts")));
        return true;

    case R.string.ads_remove:
        try {
            mHelper.launchPurchaseFlow(this, SKU_AD_FREE, IAB_REQUEST, mPurchaseFinishedListener);
            trackEvent("onOptionsItemSelected", "ads_remove");
        } catch (final IllegalStateException e) {
            // Can be caused by user double clicking option item
            Util.log("Unable to launch purchase flow: " + e);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:kn.uni.gis.foxhunt.GameActivity.java

@Override
public void onBackPressed() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCancelable(false);
    builder.setMessage(getString(R.string.GAME_BACK_DESC));
    builder.setTitle(getString(R.string.GAME_BACK_TITLE));
    builder.setNegativeButton(R.string.GAME_BACK_OK, new OnClickListener() {

        @Override//  ww w. j av a2 s.  co  m
        public void onClick(DialogInterface arg0, int arg1) {
            GameActivity.this.finish();
        }
    }).setPositiveButton(getString(R.string.GAME_BACK_CANCEL), new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // NOOP
        }
    }).create().show();
}

From source file:net.heroicefforts.viable.android.BugReporterActivity.java

/**
 * Issue already exists.  Now prompt the user whether they want to add an additional comment.
 *  //from w w w  . j ava 2s .c  o  m
 * @param issue the defect
 */
private void showSupplementDialog(Issue issue) {
    if (Config.LOGD)
        Log.d(TAG, "Prompting user to comment on existing issue '" + issue.getIssueId() + "'.");
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.bug_comment);
    builder.setCancelable(true);
    builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            comment = true;
        }
    });
    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
    });
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            finish();
        }
    });
    builder.setMessage(getString(R.string.bug_comment_prompt).replaceAll("\\{appName\\}", issue.getAppName()));
    builder.create().show();
}

From source file:at.jclehner.rxdroid.BackupFragment.java

private void showExceptionDialog(Exception e) {
    final AlertDialog.Builder ab = new AlertDialog.Builder(getActivity());
    ab.setTitle(R.string._title_error);//from   ww  w . ja  v  a 2  s  . co m
    ab.setIcon(android.R.drawable.ic_dialog_alert);
    ab.setPositiveButton(android.R.string.ok, null);
    ab.setCancelable(true);

    ab.setMessage(Html
            .fromHtml("<tt>" + e.getClass().getSimpleName() + "</tt><br/>" + Util.escapeHtml(e.getMessage())));

    //ab.show(getFragmentManager(), "create_error");
    ab.show();
}

From source file:com.google.android.demos.atom.app.FeedActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    if (id == DIALOG_ENTRY) {
        mEntryDialog = new EntryDialog(this);
        return mEntryDialog;
    } else if (id == DIALOG_INVALID_URL) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.atom_title);
        builder.setMessage(R.string.atom_error_invalid_url);
        builder.setPositiveButton(R.string.atom_button_ok, null);
        builder.setCancelable(true);
        return builder.create();
    } else {//from  www  .  j  a  v  a 2s .  c  o  m
        return super.onCreateDialog(id);
    }
}

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

private Dialog buildDialog1(Context context, String str) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);
    builder.setTitle("Confirm");
    builder.setMessage(str);//from w ww.  jav  a 2  s  . com
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            setHints();
        }
    });
    return builder.create();
}