1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.android.launcher3.util;
17 
18 import android.app.Activity;
19 import android.app.Application.*;
20 import android.os.Bundle;
21 
22 import java.util.ArrayList;
23 
24 /**
25  * Simple monitor to keep a list of active activities.
26  */
27 public class SimpleActivityMonitor implements ActivityLifecycleCallbacks {
28 
29     public final ArrayList<Activity> created = new ArrayList<>();
30     public final ArrayList<Activity> started = new ArrayList<>();
31     public final ArrayList<Activity> resumed = new ArrayList<>();
32 
33     @Override
onActivityCreated(Activity activity, Bundle bundle)34     public void onActivityCreated(Activity activity, Bundle bundle) {
35         created.add(activity);
36     }
37 
38     @Override
onActivityStarted(Activity activity)39     public void onActivityStarted(Activity activity) {
40         started.add(activity);
41     }
42 
43     @Override
onActivityResumed(Activity activity)44     public void onActivityResumed(Activity activity) {
45         resumed.add(activity);
46     }
47 
48     @Override
onActivityPaused(Activity activity)49     public void onActivityPaused(Activity activity) {
50         resumed.remove(activity);
51     }
52 
53     @Override
onActivityStopped(Activity activity)54     public void onActivityStopped(Activity activity) {
55         started.remove(activity);
56     }
57 
58     @Override
onActivitySaveInstanceState(Activity activity, Bundle bundle)59     public void onActivitySaveInstanceState(Activity activity, Bundle bundle) { }
60 
61     @Override
onActivityDestroyed(Activity activity)62     public void onActivityDestroyed(Activity activity) {
63         created.remove(activity);
64     }
65 }
66