1 /* 2 * Copyright (C) 2014 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 android.app.AlertDialog; 20 import android.app.Dialog; 21 import android.app.DialogFragment; 22 import android.content.Context; 23 import android.content.DialogInterface; 24 import android.os.Bundle; 25 26 import com.android.email.R; 27 28 public class AccountSetupNoteDialogFragment extends DialogFragment { 29 public static final String TAG = "NoteDialogFragment"; 30 31 // Argument bundle keys 32 private static final String BUNDLE_KEY_NOTE = "NoteDialogFragment.Note"; 33 34 public static interface Callback { 35 void onNoteDialogComplete(); 36 void onNoteDialogCancel(); 37 } 38 39 // Public no-args constructor needed for fragment re-instantiation 40 public AccountSetupNoteDialogFragment() {} 41 42 /** 43 * Create the dialog with parameters 44 */ 45 public static AccountSetupNoteDialogFragment newInstance(String note) { 46 final AccountSetupNoteDialogFragment f = new AccountSetupNoteDialogFragment(); 47 final Bundle b = new Bundle(1); 48 b.putString(BUNDLE_KEY_NOTE, note); 49 f.setArguments(b); 50 return f; 51 } 52 53 @Override 54 public Dialog onCreateDialog(Bundle savedInstanceState) { 55 final Context context = getActivity(); 56 final String note = getArguments().getString(BUNDLE_KEY_NOTE); 57 58 setCancelable(true); 59 60 return new AlertDialog.Builder(context) 61 .setIconAttribute(android.R.attr.alertDialogIcon) 62 .setTitle(android.R.string.dialog_alert_title) 63 .setMessage(note) 64 .setPositiveButton( 65 android.R.string.ok, 66 new DialogInterface.OnClickListener() { 67 @Override 68 public void onClick(DialogInterface dialog, int which) { 69 final Callback a = (Callback) getActivity(); 70 a.onNoteDialogComplete(); 71 dismiss(); 72 } 73 }) 74 .setNegativeButton( 75 context.getString(android.R.string.cancel), 76 new DialogInterface.OnClickListener() { 77 @Override 78 public void onClick(DialogInterface dialog, int which) { 79 dialog.cancel(); 80 } 81 }) 82 .create(); 83 } 84 85 @Override 86 public void onCancel(DialogInterface dialog) { 87 super.onCancel(dialog); 88 final Callback a = (Callback) getActivity(); 89 a.onNoteDialogCancel(); 90 } 91 } 92