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
.support
.v7
.app
.AlertDialog
; 
  24 import android
.app
.Dialog
; 
  25 import android
.content
.DialogInterface
; 
  26 import android
.os
.Bundle
; 
  27 import android
.support
.v4
.app
.DialogFragment
; 
  29 import com
.owncloud
.android
.R
; 
  30 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
; 
  33 public class ConfirmationDialogFragment 
extends DialogFragment 
{ 
  35     public final static String ARG_CONF_RESOURCE_ID 
= "resource_id"; 
  36     public final static String ARG_CONF_ARGUMENTS 
= "string_array"; 
  38     public final static String ARG_POSITIVE_BTN_RES 
= "positive_btn_res"; 
  39     public final static String ARG_NEUTRAL_BTN_RES 
= "neutral_btn_res"; 
  40     public final static String ARG_NEGATIVE_BTN_RES 
= "negative_btn_res"; 
  42     public static final String FTAG_CONFIRMATION 
= "CONFIRMATION_FRAGMENT"; 
  44     private ConfirmationDialogFragmentListener mListener
; 
  47      * Public factory method to create new ConfirmationDialogFragment instances. 
  49      * @param string_id         Resource id for a message to show in the dialog. 
  50      * @param arguments         Arguments to complete the message, if it's a format string. 
  51      * @param posBtn            Resource id for the text of the positive button. 
  52      * @param neuBtn            Resource id for the text of the neutral button. 
  53      * @param negBtn            Resource id for the text of the negative button. 
  54      * @return                  Dialog ready to show. 
  56     public static ConfirmationDialogFragment 
newInstance(int string_id
, String
[] arguments
, int posBtn
, int neuBtn
, int negBtn
) { 
  57         ConfirmationDialogFragment frag 
= new ConfirmationDialogFragment(); 
  58         Bundle args 
= new Bundle(); 
  59         args
.putInt(ARG_CONF_RESOURCE_ID
, string_id
); 
  60         args
.putStringArray(ARG_CONF_ARGUMENTS
, arguments
); 
  61         args
.putInt(ARG_POSITIVE_BTN_RES
, posBtn
); 
  62         args
.putInt(ARG_NEUTRAL_BTN_RES
, neuBtn
); 
  63         args
.putInt(ARG_NEGATIVE_BTN_RES
, negBtn
); 
  64         frag
.setArguments(args
); 
  68     public void setOnConfirmationListener(ConfirmationDialogFragmentListener listener
) { 
  73     public Dialog 
onCreateDialog(Bundle savedInstanceState
) { 
  74         Object
[] confirmationTarget 
= getArguments().getStringArray(ARG_CONF_ARGUMENTS
); 
  75         int resourceId 
= getArguments().getInt(ARG_CONF_RESOURCE_ID
, -1); 
  76         int posBtn 
= getArguments().getInt(ARG_POSITIVE_BTN_RES
, -1); 
  77         int neuBtn 
= getArguments().getInt(ARG_NEUTRAL_BTN_RES
, -1); 
  78         int negBtn 
= getArguments().getInt(ARG_NEGATIVE_BTN_RES
, -1); 
  80         if (confirmationTarget 
== null 
|| resourceId 
== -1) { 
  81             Log_OC
.wtf(getTag(), "Calling confirmation dialog without resource or arguments"); 
  85         AlertDialog
.Builder builder 
= new AlertDialog
.Builder(getActivity(), R
.style
.Theme_ownCloud_Dialog
) 
  86             .setIcon(R
.drawable
.ic_warning
) 
  87             .setMessage(String
.format(getString(resourceId
), confirmationTarget
)) 
  88             .setTitle(android
.R
.string
.dialog_alert_title
); 
  89         if (android
.os
.Build
.VERSION
.SDK_INT 
>= android
.os
.Build
.VERSION_CODES
.HONEYCOMB
) { 
  90             builder
.setIconAttribute(android
.R
.attr
.alertDialogIcon
); 
  94             builder
.setPositiveButton(posBtn
, 
  95                     new DialogInterface
.OnClickListener() { 
  96                         public void onClick(DialogInterface dialog
, int whichButton
) { 
  97                             if (mListener 
!= null
) { 
  98                                 mListener
.onConfirmation(getTag()); 
 104             builder
.setNeutralButton(neuBtn
, 
 105                     new DialogInterface
.OnClickListener() { 
 106                         public void onClick(DialogInterface dialog
, int whichButton
) { 
 107                             if (mListener 
!= null
) { 
 108                                 mListener
.onNeutral(getTag()); 
 114             builder
.setNegativeButton(negBtn
, 
 115                     new DialogInterface
.OnClickListener() { 
 117                         public void onClick(DialogInterface dialog
, int which
) { 
 118                             if (mListener 
!= null
) { 
 119                                 mListener
.onCancel(getTag()); 
 124       return builder
.create(); 
 128     public interface ConfirmationDialogFragmentListener 
{ 
 129         public void onConfirmation(String callerTag
); 
 130         public void onNeutral(String callerTag
); 
 131         public void onCancel(String callerTag
);