2 * ownCloud Android client application
4 * Copyright (C) 2012 Bartek Przybylski
5 * Copyright (C) 2015 ownCloud Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 package com
.owncloud
.android
.ui
.dialog
;
23 import android
.app
.AlertDialog
;
24 import android
.app
.Dialog
;
25 import android
.content
.DialogInterface
;
26 import android
.os
.Bundle
;
28 import com
.actionbarsherlock
.app
.SherlockDialogFragment
;
29 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
32 public class ConfirmationDialogFragment
extends SherlockDialogFragment
{
34 public final static String ARG_CONF_RESOURCE_ID
= "resource_id";
35 public final static String ARG_CONF_ARGUMENTS
= "string_array";
37 public final static String ARG_POSITIVE_BTN_RES
= "positive_btn_res";
38 public final static String ARG_NEUTRAL_BTN_RES
= "neutral_btn_res";
39 public final static String ARG_NEGATIVE_BTN_RES
= "negative_btn_res";
41 public static final String FTAG_CONFIRMATION
= "CONFIRMATION_FRAGMENT";
43 private ConfirmationDialogFragmentListener mListener
;
46 * Public factory method to create new ConfirmationDialogFragment instances.
48 * @param string_id Resource id for a message to show in the dialog.
49 * @param arguments Arguments to complete the message, if it's a format string.
50 * @param posBtn Resource id for the text of the positive button.
51 * @param neuBtn Resource id for the text of the neutral button.
52 * @param negBtn Resource id for the text of the negative button.
53 * @return Dialog ready to show.
55 public static ConfirmationDialogFragment
newInstance(int string_id
, String
[] arguments
, int posBtn
, int neuBtn
, int negBtn
) {
56 ConfirmationDialogFragment frag
= new ConfirmationDialogFragment();
57 Bundle args
= new Bundle();
58 args
.putInt(ARG_CONF_RESOURCE_ID
, string_id
);
59 args
.putStringArray(ARG_CONF_ARGUMENTS
, arguments
);
60 args
.putInt(ARG_POSITIVE_BTN_RES
, posBtn
);
61 args
.putInt(ARG_NEUTRAL_BTN_RES
, neuBtn
);
62 args
.putInt(ARG_NEGATIVE_BTN_RES
, negBtn
);
63 frag
.setArguments(args
);
67 public void setOnConfirmationListener(ConfirmationDialogFragmentListener listener
) {
72 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
73 Object
[] confirmationTarget
= getArguments().getStringArray(ARG_CONF_ARGUMENTS
);
74 int resourceId
= getArguments().getInt(ARG_CONF_RESOURCE_ID
, -1);
75 int posBtn
= getArguments().getInt(ARG_POSITIVE_BTN_RES
, -1);
76 int neuBtn
= getArguments().getInt(ARG_NEUTRAL_BTN_RES
, -1);
77 int negBtn
= getArguments().getInt(ARG_NEGATIVE_BTN_RES
, -1);
79 if (confirmationTarget
== null
|| resourceId
== -1) {
80 Log_OC
.wtf(getTag(), "Calling confirmation dialog without resource or arguments");
84 AlertDialog
.Builder builder
= new AlertDialog
.Builder(getActivity())
85 .setIcon(android
.R
.drawable
.ic_dialog_alert
)
86 .setMessage(String
.format(getString(resourceId
), confirmationTarget
))
87 .setTitle(android
.R
.string
.dialog_alert_title
);
88 if (android
.os
.Build
.VERSION
.SDK_INT
>= android
.os
.Build
.VERSION_CODES
.HONEYCOMB
) {
89 builder
.setIconAttribute(android
.R
.attr
.alertDialogIcon
);
93 builder
.setPositiveButton(posBtn
,
94 new DialogInterface
.OnClickListener() {
95 public void onClick(DialogInterface dialog
, int whichButton
) {
96 if (mListener
!= null
) {
97 mListener
.onConfirmation(getTag());
103 builder
.setNeutralButton(neuBtn
,
104 new DialogInterface
.OnClickListener() {
105 public void onClick(DialogInterface dialog
, int whichButton
) {
106 if (mListener
!= null
) {
107 mListener
.onNeutral(getTag());
113 builder
.setNegativeButton(negBtn
,
114 new DialogInterface
.OnClickListener() {
116 public void onClick(DialogInterface dialog
, int which
) {
117 if (mListener
!= null
) {
118 mListener
.onCancel(getTag());
123 return builder
.create();
127 public interface ConfirmationDialogFragmentListener
{
128 public void onConfirmation(String callerTag
);
129 public void onNeutral(String callerTag
);
130 public void onCancel(String callerTag
);