ConfirmationDialogFragment.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package eu.alefzero.owncloud.ui.fragment;
  2. import android.app.AlertDialog;
  3. import android.app.Dialog;
  4. import android.content.DialogInterface;
  5. import android.os.Bundle;
  6. import com.actionbarsherlock.app.SherlockDialogFragment;
  7. import eu.alefzero.owncloud.R;
  8. public class ConfirmationDialogFragment extends SherlockDialogFragment {
  9. public final static String ARG_CONF_TARGET = "target";
  10. ConfirmationDialogFragmentListener mListener;
  11. public static ConfirmationDialogFragment newInstance(String confirmationTarget) {
  12. ConfirmationDialogFragment frag = new ConfirmationDialogFragment();
  13. Bundle args = new Bundle();
  14. args.putString(ARG_CONF_TARGET, confirmationTarget);
  15. frag.setArguments(args);
  16. return frag;
  17. }
  18. public void setOnConfirmationListener(ConfirmationDialogFragmentListener listener) {
  19. mListener = listener;
  20. }
  21. @Override
  22. public Dialog onCreateDialog(Bundle savedInstanceState) {
  23. String confirmationTarget = getArguments().getString(ARG_CONF_TARGET);
  24. if (confirmationTarget == null)
  25. confirmationTarget = "";
  26. return new AlertDialog.Builder(getActivity())
  27. .setIcon(android.R.drawable.ic_dialog_alert)
  28. .setMessage(String.format(getString(R.string.confirmation_alert_prefix), confirmationTarget))
  29. .setPositiveButton(R.string.common_ok,
  30. new DialogInterface.OnClickListener() {
  31. public void onClick(DialogInterface dialog, int whichButton) {
  32. mListener.onConfirmation(true, getTag());
  33. }
  34. }
  35. )
  36. .setNegativeButton(R.string.common_cancel,
  37. new DialogInterface.OnClickListener() {
  38. public void onClick(DialogInterface dialog, int whichButton) {
  39. mListener.onConfirmation(false, getTag());
  40. }
  41. }
  42. )
  43. .create();
  44. }
  45. public interface ConfirmationDialogFragmentListener {
  46. public void onConfirmation(boolean confirmation, String callerTag);
  47. }
  48. }