2012-04-03 18:58:01 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
|
2012-07-18 00:54:54 +00:00
|
|
|
public class GeckoApplication extends Application {
|
|
|
|
|
2012-05-08 23:40:12 +00:00
|
|
|
private boolean mInBackground = false;
|
2012-04-03 18:58:01 +00:00
|
|
|
private ArrayList<ApplicationLifecycleCallbacks> mListeners;
|
|
|
|
|
2012-07-07 05:38:05 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
// workaround for http://code.google.com/p/android/issues/detail?id=20915
|
|
|
|
try {
|
|
|
|
Class.forName("android.os.AsyncTask");
|
|
|
|
} catch (ClassNotFoundException e) {}
|
|
|
|
|
|
|
|
super.onCreate();
|
|
|
|
}
|
|
|
|
|
2012-04-03 18:58:01 +00:00
|
|
|
public interface ApplicationLifecycleCallbacks {
|
|
|
|
public void onApplicationPause();
|
|
|
|
public void onApplicationResume();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addApplicationLifecycleCallbacks(ApplicationLifecycleCallbacks callback) {
|
|
|
|
if (mListeners == null)
|
|
|
|
mListeners = new ArrayList<ApplicationLifecycleCallbacks>();
|
|
|
|
|
|
|
|
mListeners.add(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeApplicationLifecycleCallbacks(ApplicationLifecycleCallbacks callback) {
|
|
|
|
if (mListeners == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mListeners.remove(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onActivityPause(GeckoActivity activity) {
|
2012-05-08 23:40:12 +00:00
|
|
|
if (activity.isGeckoActivityOpened())
|
2012-04-03 18:58:01 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (mListeners == null)
|
|
|
|
return;
|
|
|
|
|
2012-05-08 23:40:12 +00:00
|
|
|
mInBackground = true;
|
|
|
|
|
2012-04-03 18:58:01 +00:00
|
|
|
for (ApplicationLifecycleCallbacks listener: mListeners)
|
|
|
|
listener.onApplicationPause();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onActivityResume(GeckoActivity activity) {
|
2012-05-08 23:40:12 +00:00
|
|
|
// This is a misnomer. Should have been "wasGeckoActivityOpened".
|
|
|
|
if (activity.isGeckoActivityOpened())
|
2012-04-03 18:58:01 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (mListeners == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (ApplicationLifecycleCallbacks listener: mListeners)
|
|
|
|
listener.onApplicationResume();
|
2012-05-08 23:40:12 +00:00
|
|
|
|
|
|
|
mInBackground = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isApplicationInBackground() {
|
|
|
|
return mInBackground;
|
2012-04-03 18:58:01 +00:00
|
|
|
}
|
|
|
|
}
|