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/. */
|
|
|
|
|
2013-01-29 21:59:42 +00:00
|
|
|
#filter substitution
|
|
|
|
|
2012-04-03 18:58:01 +00:00
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2013-01-29 21:59:42 +00:00
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
|
|
interface GeckoActivityStatus {
|
|
|
|
public boolean isGeckoActivityOpened();
|
|
|
|
public boolean isFinishing(); // typically from android.app.Activity
|
|
|
|
};
|
|
|
|
|
|
|
|
public class GeckoActivity extends Activity implements GeckoActivityStatus {
|
|
|
|
// has this activity recently started another Gecko activity?
|
|
|
|
private boolean mGeckoActivityOpened = false;
|
2012-04-03 18:58:01 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
|
2012-09-14 15:19:40 +00:00
|
|
|
if (getApplication() instanceof GeckoApplication) {
|
2012-04-03 18:58:01 +00:00
|
|
|
((GeckoApplication) getApplication()).onActivityPause(this);
|
2012-09-14 15:19:40 +00:00
|
|
|
}
|
2012-04-03 18:58:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
2012-09-14 15:19:40 +00:00
|
|
|
if (getApplication() instanceof GeckoApplication) {
|
2012-04-03 18:58:01 +00:00
|
|
|
((GeckoApplication) getApplication()).onActivityResume(this);
|
2013-01-29 21:59:42 +00:00
|
|
|
mGeckoActivityOpened = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 23:17:41 +00:00
|
|
|
#ifdef MOZ_ANDROID_ANR_REPORTER
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
ANRReporter.register(getApplicationContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
ANRReporter.unregister();
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-29 21:59:42 +00:00
|
|
|
@Override
|
|
|
|
public void startActivity(Intent intent) {
|
|
|
|
checkIfGeckoActivity(intent);
|
|
|
|
super.startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startActivityForResult(Intent intent, int request) {
|
|
|
|
checkIfGeckoActivity(intent);
|
|
|
|
super.startActivityForResult(intent, request);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkIfGeckoActivity(Intent intent) {
|
|
|
|
// Whenever we call our own activity, the component and it's package name is set.
|
|
|
|
// If we call an activity from another package, or an open intent (leaving android to resolve)
|
|
|
|
// component has a different package name or it is null.
|
|
|
|
ComponentName component = intent.getComponent();
|
|
|
|
mGeckoActivityOpened = false;
|
|
|
|
if (component != null &&
|
|
|
|
component.getPackageName() != null &&
|
|
|
|
component.getPackageName().equals("@ANDROID_PACKAGE_NAME@")) {
|
|
|
|
mGeckoActivityOpened = true;
|
2012-04-03 18:58:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2013-01-29 21:59:42 +00:00
|
|
|
public boolean isGeckoActivityOpened() {
|
|
|
|
return mGeckoActivityOpened;
|
|
|
|
}
|
|
|
|
|
2012-04-03 18:58:01 +00:00
|
|
|
public boolean isApplicationInBackground() {
|
2012-05-08 23:40:12 +00:00
|
|
|
return ((GeckoApplication) getApplication()).isApplicationInBackground();
|
2012-09-19 19:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLowMemory() {
|
|
|
|
MemoryMonitor.getInstance().onLowMemory();
|
|
|
|
super.onLowMemory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTrimMemory(int level) {
|
|
|
|
MemoryMonitor.getInstance().onTrimMemory(level);
|
|
|
|
super.onTrimMemory(level);
|
|
|
|
}
|
2012-11-01 05:10:59 +00:00
|
|
|
|
|
|
|
public LightweightTheme getLightweightTheme() {
|
|
|
|
return ((GeckoApplication) getApplication()).getLightweightTheme();
|
|
|
|
}
|
2012-04-03 18:58:01 +00:00
|
|
|
}
|