1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 package com
.owncloud
.android
.ui
.fragment
;
22 import android
.app
.AlertDialog
;
23 import android
.app
.Dialog
;
24 import android
.content
.DialogInterface
;
25 import android
.os
.Bundle
;
26 import android
.util
.Log
;
28 import com
.actionbarsherlock
.app
.SherlockDialogFragment
;
29 import com
.owncloud
.android
.Log_OC
;
31 public class ConfirmationDialogFragment
extends SherlockDialogFragment
{
33 public final static String ARG_CONF_RESOURCE_ID
= "resource_id";
34 public final static String ARG_CONF_ARGUMENTS
= "string_array";
36 public final static String ARG_POSITIVE_BTN_RES
= "positive_btn_res";
37 public final static String ARG_NEUTRAL_BTN_RES
= "neutral_btn_res";
38 public final static String ARG_NEGATIVE_BTN_RES
= "negative_btn_res";
40 public static final String FTAG_CONFIRMATION
= "CONFIRMATION_FRAGMENT";
42 private ConfirmationDialogFragmentListener mListener
;
45 * Public factory method to create new ConfirmationDialogFragment instances.
47 * @param string_id Resource id for a message to show in the dialog.
48 * @param arguments Arguments to complete the message, if it's a format string.
49 * @param posBtn Resource id for the text of the positive button.
50 * @param neuBtn Resource id for the text of the neutral button.
51 * @param negBtn Resource id for the text of the negative button.
52 * @return Dialog ready to show.
54 public static ConfirmationDialogFragment
newInstance(int string_id
, String
[] arguments
, int posBtn
, int neuBtn
, int negBtn
) {
55 ConfirmationDialogFragment frag
= new ConfirmationDialogFragment();
56 Bundle args
= new Bundle();
57 args
.putInt(ARG_CONF_RESOURCE_ID
, string_id
);
58 args
.putStringArray(ARG_CONF_ARGUMENTS
, arguments
);
59 args
.putInt(ARG_POSITIVE_BTN_RES
, posBtn
);
60 args
.putInt(ARG_NEUTRAL_BTN_RES
, neuBtn
);
61 args
.putInt(ARG_NEGATIVE_BTN_RES
, negBtn
);
62 frag
.setArguments(args
);
66 public void setOnConfirmationListener(ConfirmationDialogFragmentListener listener
) {
71 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
72 Object
[] confirmationTarget
= getArguments().getStringArray(ARG_CONF_ARGUMENTS
);
73 int resourceId
= getArguments().getInt(ARG_CONF_RESOURCE_ID
, -1);
74 int posBtn
= getArguments().getInt(ARG_POSITIVE_BTN_RES
, -1);
75 int neuBtn
= getArguments().getInt(ARG_NEUTRAL_BTN_RES
, -1);
76 int negBtn
= getArguments().getInt(ARG_NEGATIVE_BTN_RES
, -1);
78 if (confirmationTarget
== null
|| resourceId
== -1) {
79 Log_OC
.wtf(getTag(), "Calling confirmation dialog without resource or arguments");
83 AlertDialog
.Builder builder
= new AlertDialog
.Builder(getActivity())
84 .setIcon(android
.R
.drawable
.ic_dialog_alert
)
85 .setMessage(String
.format(getString(resourceId
), confirmationTarget
))
86 .setTitle(android
.R
.string
.dialog_alert_title
);
87 if (android
.os
.Build
.VERSION
.SDK_INT
>= android
.os
.Build
.VERSION_CODES
.HONEYCOMB
) {
88 builder
.setIconAttribute(android
.R
.attr
.alertDialogIcon
);
92 builder
.setPositiveButton(posBtn
,
93 new DialogInterface
.OnClickListener() {
94 public void onClick(DialogInterface dialog
, int whichButton
) {
95 mListener
.onConfirmation(getTag());
100 builder
.setNeutralButton(neuBtn
,
101 new DialogInterface
.OnClickListener() {
102 public void onClick(DialogInterface dialog
, int whichButton
) {
103 mListener
.onNeutral(getTag());
108 builder
.setNegativeButton(negBtn
,
109 new DialogInterface
.OnClickListener() {
111 public void onClick(DialogInterface dialog
, int which
) {
112 mListener
.onCancel(getTag());
116 return builder
.create();
120 public interface ConfirmationDialogFragmentListener
{
121 public void onConfirmation(String callerTag
);
122 public void onNeutral(String callerTag
);
123 public void onCancel(String callerTag
);