Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/signin/ConfirmSyncDataStateMachineDelegate.java

Issue 2772203004: Add progress and timeout dialogs for getting account management policy (Closed)
Patch Set: Updated strings and addressed comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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.signin;
6
7 import android.app.Dialog;
8 import android.content.Context;
9 import android.content.DialogInterface;
10 import android.support.v7.app.AlertDialog;
11
12 import org.chromium.chrome.R;
13
14 /**
15 * Class to decouple ConfirmSyncDataStateMachine from UI code and dialog managem ent.
16 */
17 public class ConfirmSyncDataStateMachineDelegate {
18 /**
19 * Listener to receive events from progress dialog. If the dialog is not dis missed by showing
20 * other dialog or calling {@link ConfirmSyncDataStateMachineDelegate#dismis sAllDialogs},
21 * then {@link #onCancel} will be called once.
22 */
23 public interface ProgressDialogListener {
24 /**
25 * This method is called when user cancels the dialog in any way.
26 */
27 void onCancel();
28 }
29
30 /**
31 * Listener to receive events from timeout dialog. If the dialog is not dism issed by showing
32 * other dialog or calling {@link ConfirmSyncDataStateMachineDelegate#dismis sAllDialogs},
33 * then either {@link #onCancel} or {@link #onRetry} will be called once.
34 */
35 public interface TimeoutDialogListener {
36 /**
37 * This method is called when user cancels the dialog in any way.
38 */
39 void onCancel();
40
41 /**
42 * This method is called when user clicks retry button.
43 */
44 void onRetry();
45 }
46
47 private final Context mContext;
48
49 private Dialog mProgressDialog;
50 private AlertDialog mTimeoutAlertDialog;
51
52 public ConfirmSyncDataStateMachineDelegate(Context context) {
53 mContext = context;
54 }
55
56 /**
57 * Shows progress dialog. Will dismiss other dialogs shown, if any.
58 *
59 * @param listener The {@link ProgressDialogListener} that will be notified about user actions.
60 */
61 public void showFetchManagementPolicyProgressDialog(final ProgressDialogList ener listener) {
62 dismissAllDialogs();
63 mProgressDialog = new AlertDialog.Builder(mContext, R.style.AlertDialogT heme)
64 .setView(R.layout.signin_progress_bar_dialog)
65 .setNegativeButton(R.string.cancel,
66 new DialogInterface.OnClickListener() {
67 @Override
68 public void onClick(DialogInterfac e dialog, int i) {
69 dialog.cancel();
70 }
71 })
72 .setOnCancelListener(new DialogInterface.OnCan celListener() {
73 @Override
74 public void onCancel(DialogInterface dialo g) {
75 listener.onCancel();
76 }
77 })
78 .create();
79 mProgressDialog.show();
80 }
81
82 /**
83 * Shows timeout dialog. Will dismiss other dialogs shown, if any.
84 *
85 * @param listener The {@link TimeoutDialogListener} that will be notified a bout user actions.
86 */
87 public void showFetchManagementPolicyTimeoutDialog(final TimeoutDialogListen er listener) {
88 dismissAllDialogs();
89 mTimeoutAlertDialog =
90 new AlertDialog.Builder(mContext, R.style.AlertDialogTheme)
91 .setTitle(R.string.sign_in_timeout_title)
92 .setMessage(R.string.sign_in_timeout_message)
93 .setNegativeButton(R.string.cancel,
94 new DialogInterface.OnClickListener() {
95 @Override
96 public void onClick(DialogInterface dialog, int which) {
97 dialog.cancel();
98 }
99 })
100 .setPositiveButton(R.string.retry,
101 new DialogInterface.OnClickListener() {
102 @Override
103 public void onClick(DialogInterface dialog, int which) {
104 listener.onRetry();
105 }
106 })
107 .setOnCancelListener(new DialogInterface.OnCancelListene r() {
108 @Override
109 public void onCancel(DialogInterface dialog) {
110 listener.onCancel();
111 }
112 })
113 .create();
114 mTimeoutAlertDialog.show();
115 }
116
117 /**
118 * Dismisses all dialogs.
119 */
120 public void dismissAllDialogs() {
121 if (mProgressDialog != null) mProgressDialog.dismiss();
122 mProgressDialog = null;
123
124 if (mTimeoutAlertDialog != null) mTimeoutAlertDialog.dismiss();
125 mTimeoutAlertDialog = null;
126 }
127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698