1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of 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,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.camera;
18
19import android.app.Activity;
20import android.os.Bundle;
21
22import java.util.ArrayList;
23
24public class MonitoredActivity extends NoSearchActivity {
25
26    private final ArrayList<LifeCycleListener> mListeners =
27            new ArrayList<LifeCycleListener>();
28
29    public static interface LifeCycleListener {
30        public void onActivityCreated(MonitoredActivity activity);
31        public void onActivityDestroyed(MonitoredActivity activity);
32        public void onActivityStarted(MonitoredActivity activity);
33        public void onActivityStopped(MonitoredActivity activity);
34    }
35
36    public static class LifeCycleAdapter implements LifeCycleListener {
37        public void onActivityCreated(MonitoredActivity activity) {
38        }
39
40        public void onActivityDestroyed(MonitoredActivity activity) {
41        }
42
43        public void onActivityStarted(MonitoredActivity activity) {
44        }
45
46        public void onActivityStopped(MonitoredActivity activity) {
47        }
48    }
49
50    public void addLifeCycleListener(LifeCycleListener listener) {
51        if (mListeners.contains(listener)) return;
52        mListeners.add(listener);
53    }
54
55    public void removeLifeCycleListener(LifeCycleListener listener) {
56        mListeners.remove(listener);
57    }
58
59    @Override
60    protected void onCreate(Bundle savedInstanceState) {
61        super.onCreate(savedInstanceState);
62        for (LifeCycleListener listener : mListeners) {
63            listener.onActivityCreated(this);
64        }
65    }
66
67    @Override
68    protected void onDestroy() {
69        super.onDestroy();
70        for (LifeCycleListener listener : mListeners) {
71            listener.onActivityDestroyed(this);
72        }
73    }
74
75    @Override
76    protected void onStart() {
77        super.onStart();
78        for (LifeCycleListener listener : mListeners) {
79            listener.onActivityStarted(this);
80        }
81    }
82
83    @Override
84    protected void onStop() {
85        super.onStop();
86        for (LifeCycleListener listener : mListeners) {
87            listener.onActivityStopped(this);
88        }
89    }
90}
91