|
79 | 79 |
|
80 | 80 | public class Engine extends View implements EngineApi |
81 | 81 | { |
| 82 | + public interface LifecycleListener |
| 83 | + { |
| 84 | + public abstract void OnResume(); |
| 85 | + public abstract void OnPause(); |
| 86 | + } |
| 87 | + |
82 | 88 | public static final String TAG = "revandroid.Engine"; |
83 | 89 |
|
84 | 90 | // This is true if the engine is not suspended. |
@@ -143,6 +149,8 @@ public class Engine extends View implements EngineApi |
143 | 149 |
|
144 | 150 | private int m_night_mode; |
145 | 151 |
|
| 152 | + private List<LifecycleListener> m_lifecycle_listeners; |
| 153 | + |
146 | 154 | //////////////////////////////////////////////////////////////////////////////// |
147 | 155 |
|
148 | 156 | public Engine(Context p_context) |
@@ -248,6 +256,8 @@ public void onScreenOrientationChanged(int orientation) |
248 | 256 | m_night_mode = |
249 | 257 | p_context.getResources().getConfiguration().uiMode & |
250 | 258 | Configuration.UI_MODE_NIGHT_MASK; |
| 259 | + |
| 260 | + m_lifecycle_listeners = new ArrayList<LifecycleListener>(); |
251 | 261 | } |
252 | 262 |
|
253 | 263 | //////////////////////////////////////////////////////////////////////////////// |
@@ -3368,6 +3378,14 @@ public void onAppLaunched() |
3368 | 3378 |
|
3369 | 3379 | public void onPause() |
3370 | 3380 | { |
| 3381 | + /* Pause registered listeners in reverse order of registration as |
| 3382 | + * then components will be paused before any components they |
| 3383 | + * depend on. */ |
| 3384 | + for (int i = m_lifecycle_listeners.size() - 1; i >= 0; i--) |
| 3385 | + { |
| 3386 | + m_lifecycle_listeners.get(i).OnPause(); |
| 3387 | + } |
| 3388 | + |
3371 | 3389 | if (m_text_editor_visible) |
3372 | 3390 | hideKeyboard(); |
3373 | 3391 |
|
@@ -3440,7 +3458,15 @@ public void onResume() |
3440 | 3458 |
|
3441 | 3459 | // IM-2013-08-16: [[ Bugfix 11103 ]] dispatch any remote notifications received while paused |
3442 | 3460 | dispatchNotifications(); |
3443 | | - |
| 3461 | + |
| 3462 | + /* Resume registered listeners in order of registration as then |
| 3463 | + * components will be resumed before any components which depend |
| 3464 | + * on them. */ |
| 3465 | + for (int i = 0; i < m_lifecycle_listeners.size(); i++) |
| 3466 | + { |
| 3467 | + m_lifecycle_listeners.get(i).OnResume(); |
| 3468 | + } |
| 3469 | + |
3444 | 3470 | if (m_wake_on_event) |
3445 | 3471 | doProcess(false); |
3446 | 3472 | } |
@@ -3994,7 +4020,31 @@ public int getSystemAppearance() |
3994 | 4020 | return 0; |
3995 | 4021 | } |
3996 | 4022 | } |
3997 | | - |
| 4023 | + |
| 4024 | + //////////////////////////////////////////////////////////////////////////////// |
| 4025 | + |
| 4026 | + public boolean registerLifecycleListener(LifecycleListener p_listener) |
| 4027 | + { |
| 4028 | + return m_lifecycle_listeners.add(p_listener); |
| 4029 | + } |
| 4030 | + |
| 4031 | + public boolean unregisterLifecycleListener(LifecycleListener p_listener) |
| 4032 | + { |
| 4033 | + /* We can't remove the listener directly since LifecycleListener does |
| 4034 | + * not implement equals. Instead, search backwards through the array |
| 4035 | + * until we find the passed listener. */ |
| 4036 | + for (int i = m_lifecycle_listeners.size() - 1; i >= 0; i--) |
| 4037 | + { |
| 4038 | + if (m_lifecycle_listeners.get(i) == p_listener) |
| 4039 | + { |
| 4040 | + m_lifecycle_listeners.remove(i); |
| 4041 | + return true; |
| 4042 | + } |
| 4043 | + } |
| 4044 | + |
| 4045 | + return false; |
| 4046 | + } |
| 4047 | + |
3998 | 4048 | //////////////////////////////////////////////////////////////////////////////// |
3999 | 4049 |
|
4000 | 4050 | // url launch callback |
|
0 commit comments