michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko; michael@0: michael@0: import android.content.ComponentName; michael@0: import android.content.Intent; michael@0: import android.support.v4.app.FragmentActivity; michael@0: michael@0: public class GeckoActivity extends FragmentActivity implements GeckoActivityStatus { michael@0: // has this activity recently started another Gecko activity? michael@0: private boolean mGeckoActivityOpened = false; michael@0: michael@0: /** michael@0: * Display any resources that show strings or encompass locale-specific michael@0: * representations. michael@0: * michael@0: * onLocaleReady must always be called on the UI thread. michael@0: */ michael@0: public void onLocaleReady(final String locale) { michael@0: } michael@0: michael@0: @Override michael@0: public void onPause() { michael@0: super.onPause(); michael@0: michael@0: if (getApplication() instanceof GeckoApplication) { michael@0: ((GeckoApplication) getApplication()).onActivityPause(this); michael@0: } michael@0: } michael@0: michael@0: @Override michael@0: public void onResume() { michael@0: super.onResume(); michael@0: michael@0: if (getApplication() instanceof GeckoApplication) { michael@0: ((GeckoApplication) getApplication()).onActivityResume(this); michael@0: mGeckoActivityOpened = false; michael@0: } michael@0: } michael@0: michael@0: @Override michael@0: public void onCreate(android.os.Bundle savedInstanceState) { michael@0: super.onCreate(savedInstanceState); michael@0: if (AppConstants.MOZ_ANDROID_ANR_REPORTER) { michael@0: ANRReporter.register(getApplicationContext()); michael@0: } michael@0: } michael@0: michael@0: @Override michael@0: public void onDestroy() { michael@0: if (AppConstants.MOZ_ANDROID_ANR_REPORTER) { michael@0: ANRReporter.unregister(); michael@0: } michael@0: super.onDestroy(); michael@0: } michael@0: michael@0: @Override michael@0: public void startActivity(Intent intent) { michael@0: mGeckoActivityOpened = checkIfGeckoActivity(intent); michael@0: super.startActivity(intent); michael@0: } michael@0: michael@0: @Override michael@0: public void startActivityForResult(Intent intent, int request) { michael@0: mGeckoActivityOpened = checkIfGeckoActivity(intent); michael@0: super.startActivityForResult(intent, request); michael@0: } michael@0: michael@0: private static boolean checkIfGeckoActivity(Intent intent) { michael@0: // Whenever we call our own activity, the component and its package name is set. michael@0: // If we call an activity from another package, or an open intent (leaving android to resolve) michael@0: // component has a different package name or it is null. michael@0: ComponentName component = intent.getComponent(); michael@0: return (component != null && michael@0: AppConstants.ANDROID_PACKAGE_NAME.equals(component.getPackageName())); michael@0: } michael@0: michael@0: @Override michael@0: public boolean isGeckoActivityOpened() { michael@0: return mGeckoActivityOpened; michael@0: } michael@0: michael@0: public boolean isApplicationInBackground() { michael@0: return ((GeckoApplication) getApplication()).isApplicationInBackground(); michael@0: } michael@0: michael@0: @Override michael@0: public void onLowMemory() { michael@0: MemoryMonitor.getInstance().onLowMemory(); michael@0: super.onLowMemory(); michael@0: } michael@0: michael@0: @Override michael@0: public void onTrimMemory(int level) { michael@0: MemoryMonitor.getInstance().onTrimMemory(level); michael@0: super.onTrimMemory(level); michael@0: } michael@0: }