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 android.app.Application;
|
|
|
|
|
2012-07-18 00:54:54 +00:00
|
|
|
public class GeckoApplication extends Application {
|
|
|
|
|
2012-09-27 14:52:59 +00:00
|
|
|
private boolean mInited;
|
2012-09-14 15:19:40 +00:00
|
|
|
private boolean mInBackground;
|
2013-01-29 21:59:42 +00:00
|
|
|
private boolean mPausedGecko;
|
2012-04-03 18:58:01 +00:00
|
|
|
|
2012-11-01 05:10:59 +00:00
|
|
|
private LightweightTheme mLightweightTheme;
|
|
|
|
|
2012-09-27 14:52:59 +00:00
|
|
|
protected void initialize() {
|
|
|
|
if (mInited)
|
|
|
|
return;
|
|
|
|
|
2012-07-07 05:38:05 +00:00
|
|
|
// workaround for http://code.google.com/p/android/issues/detail?id=20915
|
|
|
|
try {
|
|
|
|
Class.forName("android.os.AsyncTask");
|
|
|
|
} catch (ClassNotFoundException e) {}
|
|
|
|
|
2012-11-01 05:10:59 +00:00
|
|
|
mLightweightTheme = new LightweightTheme(this);
|
|
|
|
|
2012-09-14 15:19:40 +00:00
|
|
|
GeckoConnectivityReceiver.getInstance().init(getApplicationContext());
|
|
|
|
GeckoBatteryManager.getInstance().init(getApplicationContext());
|
|
|
|
GeckoBatteryManager.getInstance().start();
|
|
|
|
GeckoNetworkManager.getInstance().init(getApplicationContext());
|
2012-09-19 19:21:19 +00:00
|
|
|
MemoryMonitor.getInstance().init(getApplicationContext());
|
2012-09-27 14:52:59 +00:00
|
|
|
mInited = true;
|
2012-04-03 18:58:01 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 21:59:42 +00:00
|
|
|
protected void onActivityPause(GeckoActivityStatus activity) {
|
2012-05-08 23:40:12 +00:00
|
|
|
mInBackground = true;
|
|
|
|
|
2013-01-29 21:59:42 +00: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 15:19:40 +00:00
|
|
|
GeckoConnectivityReceiver.getInstance().stop();
|
|
|
|
GeckoNetworkManager.getInstance().stop();
|
2012-04-03 18:58:01 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 21:59:42 +00:00
|
|
|
protected void onActivityResume(GeckoActivityStatus activity) {
|
|
|
|
if (mPausedGecko) {
|
2012-09-14 15:19:40 +00:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createResumeEvent(true));
|
2013-01-29 21:59:42 +00:00
|
|
|
mPausedGecko = false;
|
|
|
|
}
|
2012-09-14 15:19:40 +00:00
|
|
|
GeckoConnectivityReceiver.getInstance().start();
|
|
|
|
GeckoNetworkManager.getInstance().start();
|
2012-05-08 23:40:12 +00:00
|
|
|
|
|
|
|
mInBackground = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isApplicationInBackground() {
|
|
|
|
return mInBackground;
|
2012-04-03 18:58:01 +00:00
|
|
|
}
|
2012-11-01 05:10:59 +00:00
|
|
|
|
|
|
|
public LightweightTheme getLightweightTheme() {
|
|
|
|
return mLightweightTheme;
|
|
|
|
}
|
2012-04-03 18:58:01 +00:00
|
|
|
}
|