| 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.widget; | 5 package org.chromium.chrome.browser.widget; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.app.Dialog; | 8 import android.app.Dialog; |
| 9 | 9 |
| 10 import org.chromium.base.ActivityState; | 10 import org.chromium.base.ActivityState; |
| 11 import org.chromium.base.ApplicationStatus; | 11 import org.chromium.base.ApplicationStatus; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Dialog subclass that ensures that dismiss() is called, even if the dialog is
implicitly dismissed | 14 * Dialog subclass that ensures that dismiss() is called, even if the dialog is
implicitly dismissed |
| 15 * due to its activity being destroyed. This is important if the dialog's dismis
s() method releases | 15 * due to its activity being destroyed. This is important if the dialog's dismis
s() method releases |
| 16 * references to memory or performs other crucial cleanup. See http://crbug.com/
507748. | 16 * references to memory or performs other crucial cleanup. See http://crbug.com/
507748. |
| 17 * DialogFragments ensure that dismiss() is called as well. | 17 * DialogFragments ensure that dismiss() is called as well. |
| 18 */ | 18 */ |
| 19 public class AlwaysDismissedDialog | 19 public class AlwaysDismissedDialog |
| 20 extends Dialog implements ApplicationStatus.ActivityStateListener { | 20 extends Dialog implements ApplicationStatus.ActivityStateListener { |
| 21 public AlwaysDismissedDialog(Activity ownerActivity, int theme) { | 21 public AlwaysDismissedDialog(Activity ownerActivity, int theme) { |
| 22 super(ownerActivity, theme); | 22 super(ownerActivity, theme); |
| 23 ApplicationStatus.registerStateListenerForActivity(this, ownerActivity); | 23 ApplicationStatus.registerStateListenerForActivity(this, ownerActivity); |
| 24 |
| 25 setOwnerActivity(ownerActivity); |
| 24 } | 26 } |
| 25 | 27 |
| 26 @Override | 28 @Override |
| 27 public void dismiss() { | 29 public void dismiss() { |
| 28 super.dismiss(); | 30 super.dismiss(); |
| 29 ApplicationStatus.unregisterActivityStateListener(this); | 31 ApplicationStatus.unregisterActivityStateListener(this); |
| 30 } | 32 } |
| 31 | 33 |
| 32 @Override | 34 @Override |
| 33 public void onActivityStateChange(Activity activity, int newState) { | 35 public void onActivityStateChange(Activity activity, int newState) { |
| 34 if (newState == ActivityState.DESTROYED) dismiss(); | 36 if (newState == ActivityState.DESTROYED) dismiss(); |
| 35 } | 37 } |
| 36 } | 38 } |
| OLD | NEW |