- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / android / java / src / org / chromium / chrome / browser / RepostFormWarningDialog.java
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
5 package org.chromium.chrome.browser;
6
7 import java.lang.Runnable;
8
9 import android.app.AlertDialog;
10 import android.app.Dialog;
11 import android.app.DialogFragment;
12 import android.content.DialogInterface;
13 import android.os.Bundle;
14
15 import org.chromium.chrome.R;
16
17 /**
18  * Form resubmission warning dialog. Presents the cancel/continue choice and fires one of two
19  * callbacks accordingly.
20  */
21 class RepostFormWarningDialog extends DialogFragment {
22     // Warning dialog currently being shown, stored for testing.
23     private static Dialog sCurrentDialog;
24
25     private final Runnable mCancelCallback;
26     private final Runnable mContinueCallback;
27
28     public RepostFormWarningDialog(Runnable cancelCallback, Runnable continueCallback) {
29         mCancelCallback = cancelCallback;
30         mContinueCallback = continueCallback;
31     }
32
33     @Override
34     public Dialog onCreateDialog(Bundle savedInstanceState) {
35         AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
36                 .setMessage(R.string.http_post_warning)
37                 .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
38                     public void onClick(DialogInterface dialog, int id) {
39                         mCancelCallback.run();
40                     }
41                 })
42                 .setPositiveButton(R.string.http_post_warning_resend,
43                         new DialogInterface.OnClickListener() {
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 }