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;
|
|
|
|
|
2013-01-29 13:59:42 -08:00
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Intent;
|
2013-04-16 14:34:46 -07:00
|
|
|
import android.support.v4.app.FragmentActivity;
|
2013-01-29 13:59:42 -08:00
|
|
|
|
2013-04-16 14:34:46 -07:00
|
|
|
public class GeckoActivity extends FragmentActivity implements GeckoActivityStatus {
|
2013-01-29 13:59:42 -08:00
|
|
|
// has this activity recently started another Gecko activity?
|
|
|
|
private boolean mGeckoActivityOpened = false;
|
2012-04-03 11:58:01 -07:00
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
/**
|
|
|
|
* Display any resources that show strings or encompass locale-specific
|
|
|
|
* representations.
|
|
|
|
*
|
|
|
|
* onLocaleReady must always be called on the UI thread.
|
|
|
|
*/
|
|
|
|
public void onLocaleReady(final String locale) {
|
|
|
|
}
|
|
|
|
|
2012-04-03 11:58:01 -07:00
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
|
2012-09-14 08:19:40 -07:00
|
|
|
if (getApplication() instanceof GeckoApplication) {
|
2012-04-03 11:58:01 -07:00
|
|
|
((GeckoApplication) getApplication()).onActivityPause(this);
|
2012-09-14 08:19:40 -07:00
|
|
|
}
|
2012-04-03 11:58:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
2012-09-14 08:19:40 -07:00
|
|
|
if (getApplication() instanceof GeckoApplication) {
|
2012-04-03 11:58:01 -07:00
|
|
|
((GeckoApplication) getApplication()).onActivityResume(this);
|
2013-01-29 13:59:42 -08:00
|
|
|
mGeckoActivityOpened = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 15:17:41 -08:00
|
|
|
@Override
|
2013-03-18 07:28:48 -07:00
|
|
|
public void onCreate(android.os.Bundle savedInstanceState) {
|
2013-02-08 15:17:41 -08:00
|
|
|
super.onCreate(savedInstanceState);
|
2013-04-09 17:10:47 -07:00
|
|
|
if (AppConstants.MOZ_ANDROID_ANR_REPORTER) {
|
|
|
|
ANRReporter.register(getApplicationContext());
|
|
|
|
}
|
2013-02-08 15:17:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2013-04-09 17:10:47 -07:00
|
|
|
if (AppConstants.MOZ_ANDROID_ANR_REPORTER) {
|
|
|
|
ANRReporter.unregister();
|
|
|
|
}
|
2013-02-08 15:17:41 -08:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
2013-01-29 13:59:42 -08:00
|
|
|
@Override
|
|
|
|
public void startActivity(Intent intent) {
|
2013-03-26 11:04:20 -07:00
|
|
|
mGeckoActivityOpened = checkIfGeckoActivity(intent);
|
2013-01-29 13:59:42 -08:00
|
|
|
super.startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startActivityForResult(Intent intent, int request) {
|
2013-03-26 11:04:20 -07:00
|
|
|
mGeckoActivityOpened = checkIfGeckoActivity(intent);
|
2013-01-29 13:59:42 -08:00
|
|
|
super.startActivityForResult(intent, request);
|
|
|
|
}
|
|
|
|
|
2013-03-26 11:04:20 -07:00
|
|
|
private static boolean checkIfGeckoActivity(Intent intent) {
|
|
|
|
// Whenever we call our own activity, the component and its package name is set.
|
2013-01-29 13:59:42 -08: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-09 17:10:47 -07:00
|
|
|
return (component != null &&
|
|
|
|
AppConstants.ANDROID_PACKAGE_NAME.equals(component.getPackageName()));
|
2012-04-03 11:58:01 -07:00
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2013-01-29 13:59:42 -08:00
|
|
|
public boolean isGeckoActivityOpened() {
|
|
|
|
return mGeckoActivityOpened;
|
|
|
|
}
|
|
|
|
|
2012-04-03 11:58:01 -07:00
|
|
|
public boolean isApplicationInBackground() {
|
2012-05-08 16:40:12 -07:00
|
|
|
return ((GeckoApplication) getApplication()).isApplicationInBackground();
|
2012-09-19 12:21:19 -07: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 11:58:01 -07:00
|
|
|
}
|