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;
|
|
|
|
|
2013-01-29 21:59:42 +00:00
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Intent;
|
2013-04-16 21:34:46 +00:00
|
|
|
import android.support.v4.app.FragmentActivity;
|
2013-01-29 21:59:42 +00:00
|
|
|
|
2013-04-16 21:34:46 +00:00
|
|
|
public class GeckoActivity extends FragmentActivity implements GeckoActivityStatus {
|
2013-01-29 21:59:42 +00:00
|
|
|
// 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
|
|
|
@Override
|
2013-03-18 14:28:48 +00:00
|
|
|
public void onCreate(android.os.Bundle savedInstanceState) {
|
2013-02-08 23:17:41 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
2013-04-10 00:10:47 +00:00
|
|
|
if (AppConstants.MOZ_ANDROID_ANR_REPORTER) {
|
|
|
|
ANRReporter.register(getApplicationContext());
|
|
|
|
}
|
2013-02-08 23:17:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2013-04-10 00:10:47 +00:00
|
|
|
if (AppConstants.MOZ_ANDROID_ANR_REPORTER) {
|
|
|
|
ANRReporter.unregister();
|
|
|
|
}
|
2013-02-08 23:17:41 +00:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
2013-01-29 21:59:42 +00:00
|
|
|
@Override
|
|
|
|
public void startActivity(Intent intent) {
|
2013-03-26 18:04:20 +00:00
|
|
|
mGeckoActivityOpened = checkIfGeckoActivity(intent);
|
2013-01-29 21:59:42 +00:00
|
|
|
super.startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startActivityForResult(Intent intent, int request) {
|
2013-03-26 18:04:20 +00:00
|
|
|
mGeckoActivityOpened = checkIfGeckoActivity(intent);
|
2013-01-29 21:59:42 +00:00
|
|
|
super.startActivityForResult(intent, request);
|
|
|
|
}
|
|
|
|
|
2013-03-26 18:04:20 +00:00
|
|
|
private static boolean checkIfGeckoActivity(Intent intent) {
|
|
|
|
// Whenever we call our own activity, the component and its package name is set.
|
2013-01-29 21:59:42 +00:00
|
|
|
// 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();
|
2013-04-10 00:10:47 +00:00
|
|
|
return (component != null &&
|
|
|
|
AppConstants.ANDROID_PACKAGE_NAME.equals(component.getPackageName()));
|
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-04-03 18:58:01 +00:00
|
|
|
}
|