1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5package org.chromium.chrome.browser; 6 7import android.app.AlertDialog; 8import android.app.Dialog; 9import android.app.DialogFragment; 10import android.content.DialogInterface; 11import android.os.Bundle; 12 13import org.chromium.chrome.R; 14 15/** 16 * Form resubmission warning dialog. Presents the cancel/continue choice and fires one of two 17 * callbacks accordingly. 18 */ 19class RepostFormWarningDialog extends DialogFragment { 20 // Warning dialog currently being shown, stored for testing. 21 private static Dialog sCurrentDialog; 22 23 private final Runnable mCancelCallback; 24 private final Runnable mContinueCallback; 25 26 public RepostFormWarningDialog(Runnable cancelCallback, Runnable continueCallback) { 27 mCancelCallback = cancelCallback; 28 mContinueCallback = continueCallback; 29 } 30 31 @Override 32 public Dialog onCreateDialog(Bundle savedInstanceState) { 33 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) 34 .setMessage(R.string.http_post_warning) 35 .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 36 @Override 37 public void onClick(DialogInterface dialog, int id) { 38 mCancelCallback.run(); 39 } 40 }) 41 .setPositiveButton(R.string.http_post_warning_resend, 42 new DialogInterface.OnClickListener() { 43 @Override 44 public void onClick(DialogInterface dialog, int id) { 45 mContinueCallback.run(); 46 } 47 }); 48 49 assert getCurrentDialog() == null; 50 Dialog dialog = builder.create(); 51 setCurrentDialog(dialog); 52 53 return dialog; 54 } 55 56 @Override 57 public void onDismiss(DialogInterface dialog) { 58 super.onDismiss(dialog); 59 setCurrentDialog(null); 60 } 61 62 /** 63 * Sets the currently displayed dialog in sCurrentDialog. This is required by findbugs, which 64 * allows static fields only to be set from static methods. 65 */ 66 private static void setCurrentDialog(Dialog dialog) { 67 sCurrentDialog = dialog; 68 } 69 70 /** 71 * @return dialog currently being displayed. 72 */ 73 public static Dialog getCurrentDialog() { 74 return sCurrentDialog; 75 } 76} 77