OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.externalauth; | 5 package org.chromium.chrome.browser.externalauth; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.app.Dialog; | 8 import android.app.Dialog; |
9 import android.content.Context; | 9 import android.content.Context; |
10 | 10 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 * The modal dialog that is shown to the user. | 131 * The modal dialog that is shown to the user. |
132 */ | 132 */ |
133 private Dialog mDialog; | 133 private Dialog mDialog; |
134 | 134 |
135 /** | 135 /** |
136 * Whether the dialog can be canceled by the user. | 136 * Whether the dialog can be canceled by the user. |
137 */ | 137 */ |
138 private final boolean mCancelable; | 138 private final boolean mCancelable; |
139 | 139 |
140 /** | 140 /** |
141 * Error code from Google Play Services. | |
Bernhard Bauer
2017/01/12 10:14:33
Nit: "Last error code [...]"?
estevenson
2017/01/12 19:52:33
Done.
| |
142 */ | |
143 private int mErrorCode; | |
144 | |
145 /** | |
141 * Create a new Modal Dialog handler for the specified activity and erro r code. The | 146 * Create a new Modal Dialog handler for the specified activity and erro r code. The |
142 * specified activity may be used to launch the dialog via | 147 * specified activity may be used to launch the dialog via |
143 * {@link Activity#startActivityForResult(android.content.Intent, int)} and also to receive | 148 * {@link Activity#startActivityForResult(android.content.Intent, int)} and also to receive |
144 * the result via Activity's protected onActivityResult method. | 149 * the result via Activity's protected onActivityResult method. |
145 * | 150 * |
146 * @param activity the activity to use | 151 * @param activity the activity to use |
147 * @param cancelable whether the dialog can be canceled by the user | 152 * @param cancelable whether the dialog can be canceled by the user |
148 */ | 153 */ |
149 public ModalDialog(Activity activity, boolean cancelable) { | 154 public ModalDialog(Activity activity, boolean cancelable) { |
150 mActivity = activity; | 155 mActivity = activity; |
151 mCancelable = cancelable; | 156 mCancelable = cancelable; |
152 } | 157 } |
153 | 158 |
154 /** | 159 /** |
155 * Displays the dialog in a modal manner using | 160 * Displays the dialog in a modal manner using |
156 * {@link GoogleApiAvailability#getErrorDialog(Activity, int, int)}. | 161 * {@link GoogleApiAvailability#getErrorDialog(Activity, int, int)}. |
157 * @param context the context in which the error was encountered | 162 * @param context the context in which the error was encountered |
158 * @param errorCode the error code from Google Play Services | 163 * @param errorCode the error code from Google Play Services |
159 */ | 164 */ |
160 @Override | 165 @Override |
161 protected final void handle(final Context context, final int errorCode) { | 166 protected final void handle(final Context context, final int errorCode) { |
162 mDialog = GoogleApiAvailability.getInstance().getErrorDialog( | 167 // Assume old dialogs generated by the same error handler are obsole te when an error |
163 mActivity, errorCode, NO_RESPONSE_REQUIRED); | 168 // with a different error code is encountered. |
169 if (mErrorCode != errorCode) { | |
170 cancelDialog(); | |
171 } | |
172 if (mDialog == null) { | |
173 mDialog = GoogleApiAvailability.getInstance().getErrorDialog( | |
174 mActivity, errorCode, NO_RESPONSE_REQUIRED); | |
175 mErrorCode = errorCode; | |
176 } | |
164 // This can happen if |errorCode| is ConnectionResult.SERVICE_INVALI D. | 177 // This can happen if |errorCode| is ConnectionResult.SERVICE_INVALI D. |
165 if (mDialog != null) { | 178 if (mDialog != null) { |
166 mDialog.setCancelable(mCancelable); | 179 mDialog.setCancelable(mCancelable); |
167 mDialog.show(); | 180 mDialog.show(); |
168 } | 181 } |
169 sErrorHandlerActionHistogramSample.record(ERROR_HANDLER_ACTION_MODAL _DIALOG); | 182 sErrorHandlerActionHistogramSample.record(ERROR_HANDLER_ACTION_MODAL _DIALOG); |
170 } | 183 } |
171 | 184 |
172 /** | 185 /** |
173 * Cancels the dialog. | 186 * Cancels the dialog. |
174 */ | 187 */ |
175 public void cancelDialog() { | 188 public void cancelDialog() { |
176 if (mDialog != null) { | 189 if (mDialog != null) { |
177 mDialog.cancel(); | 190 mDialog.cancel(); |
191 mDialog = null; | |
178 } | 192 } |
179 } | 193 } |
180 } | 194 } |
181 } | 195 } |
OLD | NEW |