AccountSetupNoteDialogFragment.java revision d2ffe23fca3eed8c63d3e798551bba85442c2aa9
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 17package com.android.email.activity.setup; 18 19import android.app.AlertDialog; 20import android.app.Dialog; 21import android.app.DialogFragment; 22import android.content.Context; 23import android.content.DialogInterface; 24import android.os.Bundle; 25 26import com.android.email.R; 27 28public 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 return new AlertDialog.Builder(context) 59 .setIconAttribute(android.R.attr.alertDialogIcon) 60 .setTitle(android.R.string.dialog_alert_title) 61 .setMessage(note) 62 .setPositiveButton( 63 R.string.okay_action, 64 new DialogInterface.OnClickListener() { 65 @Override 66 public void onClick(DialogInterface dialog, int which) { 67 final Callback a = (Callback) getActivity(); 68 a.onNoteDialogComplete(); 69 dismiss(); 70 } 71 }) 72 .setNegativeButton( 73 context.getString(R.string.cancel_action), 74 new DialogInterface.OnClickListener() { 75 @Override 76 public void onClick(DialogInterface dialog, int which) { 77 final Callback a = (Callback) getActivity(); 78 a.onNoteDialogCancel(); 79 dismiss(); 80 } 81 }) 82 .create(); 83 } 84} 85