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 android.app.Application;
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
public class GeckoApplication extends Application {
|
|
|
|
|
2012-09-27 07:52:59 -07:00
|
|
|
private boolean mInited;
|
2012-09-14 08:19:40 -07:00
|
|
|
private boolean mInBackground;
|
2013-01-29 13:59:42 -08:00
|
|
|
private boolean mPausedGecko;
|
2012-04-03 11:58:01 -07:00
|
|
|
|
2012-10-31 22:10:59 -07:00
|
|
|
private LightweightTheme mLightweightTheme;
|
|
|
|
|
2012-09-27 07:52:59 -07:00
|
|
|
protected void initialize() {
|
|
|
|
if (mInited)
|
|
|
|
return;
|
|
|
|
|
2012-07-06 22:38:05 -07:00
|
|
|
// workaround for http://code.google.com/p/android/issues/detail?id=20915
|
|
|
|
try {
|
|
|
|
Class.forName("android.os.AsyncTask");
|
|
|
|
} catch (ClassNotFoundException e) {}
|
|
|
|
|
2012-10-31 22:10:59 -07:00
|
|
|
mLightweightTheme = new LightweightTheme(this);
|
|
|
|
|
2012-09-14 08:19:40 -07:00
|
|
|
GeckoConnectivityReceiver.getInstance().init(getApplicationContext());
|
|
|
|
GeckoBatteryManager.getInstance().init(getApplicationContext());
|
|
|
|
GeckoBatteryManager.getInstance().start();
|
|
|
|
GeckoNetworkManager.getInstance().init(getApplicationContext());
|
2012-09-19 12:21:19 -07:00
|
|
|
MemoryMonitor.getInstance().init(getApplicationContext());
|
2012-09-27 07:52:59 -07:00
|
|
|
mInited = true;
|
2012-04-03 11:58:01 -07:00
|
|
|
}
|
|
|
|
|
2013-01-29 13:59:42 -08:00
|
|
|
protected void onActivityPause(GeckoActivityStatus activity) {
|
2012-05-08 16:40:12 -07:00
|
|
|
mInBackground = true;
|
|
|
|
|
2013-01-29 13:59:42 -08:00
|
|
|
if ((activity.isFinishing() == false) &&
|
|
|
|
(activity.isGeckoActivityOpened() == false)) {
|
|
|
|
// Notify Gecko that we are pausing; the cache service will be
|
|
|
|
// shutdown, closing the disk cache cleanly. If the android
|
|
|
|
// low memory killer subsequently kills us, the disk cache will
|
|
|
|
// be left in a consistent state, avoiding costly cleanup and
|
|
|
|
// re-creation.
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createPauseEvent(true));
|
|
|
|
mPausedGecko = true;
|
|
|
|
}
|
2012-09-14 08:19:40 -07:00
|
|
|
GeckoConnectivityReceiver.getInstance().stop();
|
|
|
|
GeckoNetworkManager.getInstance().stop();
|
2012-04-03 11:58:01 -07:00
|
|
|
}
|
|
|
|
|
2013-01-29 13:59:42 -08:00
|
|
|
protected void onActivityResume(GeckoActivityStatus activity) {
|
|
|
|
if (mPausedGecko) {
|
2012-09-14 08:19:40 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createResumeEvent(true));
|
2013-01-29 13:59:42 -08:00
|
|
|
mPausedGecko = false;
|
|
|
|
}
|
2012-09-14 08:19:40 -07:00
|
|
|
GeckoConnectivityReceiver.getInstance().start();
|
|
|
|
GeckoNetworkManager.getInstance().start();
|
2012-05-08 16:40:12 -07:00
|
|
|
|
|
|
|
mInBackground = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isApplicationInBackground() {
|
|
|
|
return mInBackground;
|
2012-04-03 11:58:01 -07:00
|
|
|
}
|
2012-10-31 22:10:59 -07:00
|
|
|
|
|
|
|
public LightweightTheme getLightweightTheme() {
|
|
|
|
return mLightweightTheme;
|
|
|
|
}
|
2012-04-03 11:58:01 -07:00
|
|
|
}
|