1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.email.activity.setup; 18 19 import com.android.email.R; 20 import com.android.mail.utils.LogUtils; 21 22 import android.app.AlertDialog; 23 import android.app.Dialog; 24 import android.app.DialogFragment; 25 import android.content.Context; 26 import android.content.DialogInterface; 27 import android.os.Bundle; 28 29 /** 30 * Dialog fragment to show "duplicate account" dialog 31 */ 32 public class DuplicateAccountDialogFragment extends DialogFragment { 33 public final static String TAG = "DuplicateAccountDialogFragment"; 34 35 // Argument bundle keys 36 private final static String BUNDLE_KEY_ACCOUNT_NAME = "NoteDialogFragment.AccountName"; 37 38 public interface Callback { 39 void onDuplicateAccountDialogDismiss(); 40 } 41 42 // Public no-args constructor needed for fragment re-instantiation 43 public DuplicateAccountDialogFragment() {} 44 45 /** 46 * Create the dialog with parameters 47 */ 48 public static DuplicateAccountDialogFragment newInstance(String note) { 49 DuplicateAccountDialogFragment f = new DuplicateAccountDialogFragment(); 50 Bundle b = new Bundle(); 51 b.putString(BUNDLE_KEY_ACCOUNT_NAME, note); 52 f.setArguments(b); 53 return f; 54 } 55 56 @Override 57 public Dialog onCreateDialog(Bundle savedInstanceState) { 58 Context context = getActivity(); 59 String accountName = getArguments().getString(BUNDLE_KEY_ACCOUNT_NAME); 60 61 setCancelable(true); 62 63 return new AlertDialog.Builder(context) 64 .setIconAttribute(android.R.attr.alertDialogIcon) 65 .setTitle(R.string.account_duplicate_dlg_title) 66 .setMessage(context.getString( 67 R.string.account_duplicate_dlg_message_fmt, accountName)) 68 .setPositiveButton(android.R.string.ok, null) 69 .create(); 70 } 71 72 @Override 73 public void onDismiss(DialogInterface dialog) { 74 super.onDismiss(dialog); 75 final Callback callback = (Callback) getActivity(); 76 if (callback != null) { 77 callback.onDuplicateAccountDialogDismiss(); 78 } else { 79 LogUtils.d(LogUtils.TAG, "Null callback in DuplicateAccount dialog onDismiss"); 80 } 81 } 82 } 83