Example usage for android.app DialogFragment DialogFragment

List of usage examples for android.app DialogFragment DialogFragment

Introduction

In this page you can find the example usage for android.app DialogFragment DialogFragment.

Prototype

public DialogFragment() 

Source Link

Usage

From source file:cf.obsessiveorange.rhcareerfairlayout.ui.activities.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle option item selections.
    int id = item.getItemId();
    DialogFragment df;/*from w  w  w  . j a  v a  2 s  .c  o m*/

    switch (id) {
    case R.id.refresh_data:
        df = new DialogFragment() {
            @Override
            public Dialog onCreateDialog(Bundle savedInstanceState) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle("Reload Data?");
                builder.setMessage("This will clear all your current results. Continue?");
                builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        dismiss();

                        reloadData();

                    }
                });
                builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dismiss();
                    }
                });
                return builder.create();
            }
        };
        df.show(getFragmentManager(), null);
        break;
    case R.id.about:
        df = new DialogFragment() {
            @Override
            public Dialog onCreateDialog(Bundle savedInstanceState) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

                builder.setTitle(getString(R.string.about));
                builder.setMessage(getString(R.string.about_description));
                builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dismiss();
                    }
                });
                return builder.create();
            }
        };
        df.show(getFragmentManager(), "");
        break;
    case R.id.action_search:
        openSearch();
        break;
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:com.amgems.uwschedule.ui.HomeActivity.java

@Override
public void onLoadFinished(Loader<GetSlnLoader.Slns> loader, final GetSlnLoader.Slns data) {
    Toast.makeText(this, "Done loading!", Toast.LENGTH_SHORT).show();
    mPublisher.publish(data.getSlns().toString());
    WebService.putCourses(mUsername, QUARTER, data.getSlns().toString(), new Callback<List<Course>>() {
        @Override//www. j  a  va2s  .  c  o m
        public void success(List<Course> courses, Response response) {
            mAsyncDataHandler.insertUserCourses(mUsername, courses, null);
        }

        @Override
        public void failure(RetrofitError error) {
            Log.e(getClass().getSimpleName(), "Failed to putCourses:" + data.getSlns());
            Response response = error.getResponse();
            String errorMsg = "";
            if (error.isNetworkError()) {
                errorMsg = "Network Error, please check your network connection.";
                Log.e(TAG, errorMsg);
            }
            if (response != null) {
                errorMsg = "Status: " + response.getStatus() + " " + response.getReason() + " URL:"
                        + response.getUrl();
                Log.e(TAG, errorMsg + "\nCause " + error.getCause() + "\nBody: " + response.getBody());
            } else {
                errorMsg = "Response is NULL. URL: " + error.getUrl() + "\nCause: " + error.getCause();
                Log.e(TAG, errorMsg + "\nBody: " + error.getBody());
            }
            final String errorMessage = errorMsg;
            new DialogFragment() {
                @Override
                public Dialog onCreateDialog(Bundle savedInstanceState) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setMessage(errorMessage).setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {

                                }
                            });
                    return builder.create();
                }
            }.show(getFragmentManager(), "dialog");
        }
    });
}

From source file:com.marcopolci.paperwalletvalidator.MainActivity.java

private static DialogFragment createCameraProblemdDialog() {
    return new DialogFragment() {
        @Override//from w  w  w  . j  av  a 2 s.  c o m
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            final AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
            dialog.setIcon(R.drawable.ic_menu_warning);
            dialog.setTitle(R.string.scan_camera_problem_dialog_title);
            dialog.setMessage(R.string.scan_camera_problem_dialog_message);
            dialog.setNeutralButton(R.string.button_dismiss, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    dialog.dismiss();
                }
            });
            dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(final DialogInterface dialog) {
                    dialog.dismiss();
                }
            });
            return dialog.create();
        }
    };
}

From source file:com.marcopolci.paperwalletvalidator.MainActivity.java

private static DialogFragment createPassphraseDialog(final PassphraseListener passphraseListener,
        final DialogInterface.OnCancelListener cancelListener) {
    return new DialogFragment() {
        @Override//from www .  j a  v  a  2s  .  c  o  m
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            LayoutInflater inflater = getActivity().getLayoutInflater();
            builder.setView(inflater.inflate(R.layout.dialog_passphrase, null))
                    .setPositiveButton(R.string.decode, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            EditText edit = (EditText) ((Dialog) dialog).findViewById(R.id.passphrase);
                            String p = edit.getText().toString();
                            dialog.dismiss();
                            passphraseListener.onPassphrase(p);
                        }
                    });
            return builder.create();
        }

        @Override
        public void onCancel(DialogInterface dialog) {
            cancelListener.onCancel(dialog);
        }
    };
}

From source file:cf.obsessiveorange.rhcareerfairlayout.ui.activities.MainActivity.java

/**
 * Private helper method to reload data, presenting dialog on failure.
 *//*w  w  w  .j a va  2  s .com*/
private void reloadData() {

    final ProgressDialog progressDialog = ProgressDialog.show(MainActivity.this, "", "Loading...");

    // If successful, notify all that that refreshed.
    Runnable successHandler = new Runnable() {
        @Override
        public void run() {
            synchronized (RHCareerFairLayout.refreshCompaniesNotifier) {
                RHCareerFairLayout.refreshCompaniesNotifier.notifyChanged();
            }
            synchronized (RHCareerFairLayout.refreshMapNotifier) {
                RHCareerFairLayout.refreshMapNotifier.notifyChanged();
            }

            progressDialog.dismiss();
        }
    };

    // If exception or failure, show error message, and ask if they want to retry.
    Runnable exceptionHandler = new Runnable() {
        @Override
        public void run() {

            progressDialog.dismiss();

            runOnUiThread(new Runnable() {
                @Override
                public void run() {

                    DialogFragment df = new DialogFragment() {
                        @Override
                        public Dialog onCreateDialog(Bundle savedInstanceState) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                            builder.setTitle("Error");
                            builder.setMessage(
                                    getResources().getString(R.string.loadingStatus_errorDownloadingData));
                            builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                    dismiss();

                                    reloadData();

                                }
                            });
                            builder.setNegativeButton(android.R.string.cancel,
                                    new DialogInterface.OnClickListener() {

                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            dismiss();
                                        }
                                    });
                            return builder.create();
                        }
                    };
                    df.show(getFragmentManager(), null);
                }
            });
        }
    };

    Runnable failHandler = new Runnable() {
        @Override
        public void run() {

            progressDialog.dismiss();

            runOnUiThread(new Runnable() {
                @Override
                public void run() {

                    DialogFragment df = new DialogFragment() {
                        @Override
                        public Dialog onCreateDialog(Bundle savedInstanceState) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                            builder.setTitle("Error");
                            builder.setMessage(
                                    getResources().getString(R.string.loadingStatus_errorParsingData));
                            builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                    dismiss();

                                    reloadData();

                                }
                            });
                            builder.setNegativeButton(android.R.string.cancel,
                                    new DialogInterface.OnClickListener() {

                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            dismiss();
                                        }
                                    });
                            return builder.create();
                        }
                    };
                    df.show(getFragmentManager(), null);
                }
            });
        }
    };

    GetAllDataRequest req = new GetAllDataRequest(successHandler, exceptionHandler, failHandler);

    Log.d(RHCareerFairLayout.RH_CFL, "Data not saved or outdated. Downloading.");
    ConnectionManager.enqueueRequest(req);
}