1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.ui
.fragment
;
21 import android
.app
.AlertDialog
;
22 import android
.app
.Dialog
;
23 import android
.content
.DialogInterface
;
24 import android
.os
.Bundle
;
25 import android
.util
.Log
;
27 import com
.actionbarsherlock
.app
.SherlockDialogFragment
;
29 public class ConfirmationDialogFragment
extends SherlockDialogFragment
{
31 public final static String ARG_CONF_RESOURCE_ID
= "resource_id";
32 public final static String ARG_CONF_ARGUMENTS
= "string_array";
34 public final static String ARG_POSITIVE_BTN_RES
= "positive_btn_res";
35 public final static String ARG_NEUTRAL_BTN_RES
= "neutral_btn_res";
36 public final static String ARG_NEGATIVE_BTN_RES
= "negative_btn_res";
38 private ConfirmationDialogFragmentListener mListener
;
40 public static ConfirmationDialogFragment
newInstance(int string_id
, String
[] arguments
, int posBtn
, int neuBtn
, int negBtn
) {
41 ConfirmationDialogFragment frag
= new ConfirmationDialogFragment();
42 Bundle args
= new Bundle();
43 args
.putInt(ARG_CONF_RESOURCE_ID
, string_id
);
44 args
.putStringArray(ARG_CONF_ARGUMENTS
, arguments
);
45 args
.putInt(ARG_POSITIVE_BTN_RES
, posBtn
);
46 args
.putInt(ARG_NEUTRAL_BTN_RES
, neuBtn
);
47 args
.putInt(ARG_NEGATIVE_BTN_RES
, negBtn
);
48 frag
.setArguments(args
);
52 public void setOnConfirmationListener(ConfirmationDialogFragmentListener listener
) {
57 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
58 Object
[] confirmationTarget
= getArguments().getStringArray(ARG_CONF_ARGUMENTS
);
59 int resourceId
= getArguments().getInt(ARG_CONF_RESOURCE_ID
, -1);
60 int posBtn
= getArguments().getInt(ARG_POSITIVE_BTN_RES
, -1);
61 int neuBtn
= getArguments().getInt(ARG_NEUTRAL_BTN_RES
, -1);
62 int negBtn
= getArguments().getInt(ARG_NEGATIVE_BTN_RES
, -1);
64 if (confirmationTarget
== null
|| resourceId
== -1) {
65 Log
.wtf(getTag(), "Calling confirmation dialog without resource or arguments");
69 AlertDialog
.Builder builder
= new AlertDialog
.Builder(getActivity())
70 .setIcon(android
.R
.drawable
.ic_dialog_alert
)
71 .setMessage(String
.format(getString(resourceId
), confirmationTarget
))
72 .setTitle(android
.R
.string
.dialog_alert_title
);
73 if (android
.os
.Build
.VERSION
.SDK_INT
>= android
.os
.Build
.VERSION_CODES
.HONEYCOMB
) {
74 builder
.setIconAttribute(android
.R
.attr
.alertDialogIcon
);
78 builder
.setPositiveButton(posBtn
,
79 new DialogInterface
.OnClickListener() {
80 public void onClick(DialogInterface dialog
, int whichButton
) {
81 mListener
.onConfirmation(getTag());
85 builder
.setNeutralButton(neuBtn
,
86 new DialogInterface
.OnClickListener() {
87 public void onClick(DialogInterface dialog
, int whichButton
) {
88 mListener
.onNeutral(getTag());
92 builder
.setNegativeButton(negBtn
,
93 new DialogInterface
.OnClickListener() {
95 public void onClick(DialogInterface dialog
, int which
) {
96 mListener
.onCancel(getTag());
99 return builder
.create();
103 public interface ConfirmationDialogFragmentListener
{
104 public void onConfirmation(String callerTag
);
105 public void onNeutral(String callerTag
);
106 public void onCancel(String callerTag
);