1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/GeckoActivity.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko; 1.9 + 1.10 +import android.content.ComponentName; 1.11 +import android.content.Intent; 1.12 +import android.support.v4.app.FragmentActivity; 1.13 + 1.14 +public class GeckoActivity extends FragmentActivity implements GeckoActivityStatus { 1.15 + // has this activity recently started another Gecko activity? 1.16 + private boolean mGeckoActivityOpened = false; 1.17 + 1.18 + /** 1.19 + * Display any resources that show strings or encompass locale-specific 1.20 + * representations. 1.21 + * 1.22 + * onLocaleReady must always be called on the UI thread. 1.23 + */ 1.24 + public void onLocaleReady(final String locale) { 1.25 + } 1.26 + 1.27 + @Override 1.28 + public void onPause() { 1.29 + super.onPause(); 1.30 + 1.31 + if (getApplication() instanceof GeckoApplication) { 1.32 + ((GeckoApplication) getApplication()).onActivityPause(this); 1.33 + } 1.34 + } 1.35 + 1.36 + @Override 1.37 + public void onResume() { 1.38 + super.onResume(); 1.39 + 1.40 + if (getApplication() instanceof GeckoApplication) { 1.41 + ((GeckoApplication) getApplication()).onActivityResume(this); 1.42 + mGeckoActivityOpened = false; 1.43 + } 1.44 + } 1.45 + 1.46 + @Override 1.47 + public void onCreate(android.os.Bundle savedInstanceState) { 1.48 + super.onCreate(savedInstanceState); 1.49 + if (AppConstants.MOZ_ANDROID_ANR_REPORTER) { 1.50 + ANRReporter.register(getApplicationContext()); 1.51 + } 1.52 + } 1.53 + 1.54 + @Override 1.55 + public void onDestroy() { 1.56 + if (AppConstants.MOZ_ANDROID_ANR_REPORTER) { 1.57 + ANRReporter.unregister(); 1.58 + } 1.59 + super.onDestroy(); 1.60 + } 1.61 + 1.62 + @Override 1.63 + public void startActivity(Intent intent) { 1.64 + mGeckoActivityOpened = checkIfGeckoActivity(intent); 1.65 + super.startActivity(intent); 1.66 + } 1.67 + 1.68 + @Override 1.69 + public void startActivityForResult(Intent intent, int request) { 1.70 + mGeckoActivityOpened = checkIfGeckoActivity(intent); 1.71 + super.startActivityForResult(intent, request); 1.72 + } 1.73 + 1.74 + private static boolean checkIfGeckoActivity(Intent intent) { 1.75 + // Whenever we call our own activity, the component and its package name is set. 1.76 + // If we call an activity from another package, or an open intent (leaving android to resolve) 1.77 + // component has a different package name or it is null. 1.78 + ComponentName component = intent.getComponent(); 1.79 + return (component != null && 1.80 + AppConstants.ANDROID_PACKAGE_NAME.equals(component.getPackageName())); 1.81 + } 1.82 + 1.83 + @Override 1.84 + public boolean isGeckoActivityOpened() { 1.85 + return mGeckoActivityOpened; 1.86 + } 1.87 + 1.88 + public boolean isApplicationInBackground() { 1.89 + return ((GeckoApplication) getApplication()).isApplicationInBackground(); 1.90 + } 1.91 + 1.92 + @Override 1.93 + public void onLowMemory() { 1.94 + MemoryMonitor.getInstance().onLowMemory(); 1.95 + super.onLowMemory(); 1.96 + } 1.97 + 1.98 + @Override 1.99 + public void onTrimMemory(int level) { 1.100 + MemoryMonitor.getInstance().onTrimMemory(level); 1.101 + super.onTrimMemory(level); 1.102 + } 1.103 +}