2012-04-03 11:58:01 -07: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.Activity;
|
|
|
|
import android.app.Application;
|
|
|
|
|
|
|
|
public class GeckoApplication extends Application {
|
|
|
|
|
2012-05-08 16:40:12 -07:00
|
|
|
private boolean mInBackground = false;
|
2012-04-03 11:58:01 -07:00
|
|
|
private ArrayList<ApplicationLifecycleCallbacks> mListeners;
|
|
|
|
|
2012-07-06 22:38:05 -07: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 11:58:01 -07: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 16:40:12 -07:00
|
|
|
if (activity.isGeckoActivityOpened())
|
2012-04-03 11:58:01 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (mListeners == null)
|
|
|
|
return;
|
|
|
|
|
2012-05-08 16:40:12 -07:00
|
|
|
mInBackground = true;
|
|
|
|
|
2012-04-03 11:58:01 -07:00
|
|
|
for (ApplicationLifecycleCallbacks listener: mListeners)
|
|
|
|
listener.onApplicationPause();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onActivityResume(GeckoActivity activity) {
|
2012-05-08 16:40:12 -07:00
|
|
|
// This is a misnomer. Should have been "wasGeckoActivityOpened".
|
|
|
|
if (activity.isGeckoActivityOpened())
|
2012-04-03 11:58:01 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (mListeners == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (ApplicationLifecycleCallbacks listener: mListeners)
|
|
|
|
listener.onApplicationResume();
|
2012-05-08 16:40:12 -07:00
|
|
|
|
|
|
|
mInBackground = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isApplicationInBackground() {
|
|
|
|
return mInBackground;
|
2012-04-03 11:58:01 -07:00
|
|
|
}
|
|
|
|
}
|