mobile/android/base/GeckoActivity.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 package org.mozilla.gecko;
michael@0 6
michael@0 7 import android.content.ComponentName;
michael@0 8 import android.content.Intent;
michael@0 9 import android.support.v4.app.FragmentActivity;
michael@0 10
michael@0 11 public class GeckoActivity extends FragmentActivity implements GeckoActivityStatus {
michael@0 12 // has this activity recently started another Gecko activity?
michael@0 13 private boolean mGeckoActivityOpened = false;
michael@0 14
michael@0 15 /**
michael@0 16 * Display any resources that show strings or encompass locale-specific
michael@0 17 * representations.
michael@0 18 *
michael@0 19 * onLocaleReady must always be called on the UI thread.
michael@0 20 */
michael@0 21 public void onLocaleReady(final String locale) {
michael@0 22 }
michael@0 23
michael@0 24 @Override
michael@0 25 public void onPause() {
michael@0 26 super.onPause();
michael@0 27
michael@0 28 if (getApplication() instanceof GeckoApplication) {
michael@0 29 ((GeckoApplication) getApplication()).onActivityPause(this);
michael@0 30 }
michael@0 31 }
michael@0 32
michael@0 33 @Override
michael@0 34 public void onResume() {
michael@0 35 super.onResume();
michael@0 36
michael@0 37 if (getApplication() instanceof GeckoApplication) {
michael@0 38 ((GeckoApplication) getApplication()).onActivityResume(this);
michael@0 39 mGeckoActivityOpened = false;
michael@0 40 }
michael@0 41 }
michael@0 42
michael@0 43 @Override
michael@0 44 public void onCreate(android.os.Bundle savedInstanceState) {
michael@0 45 super.onCreate(savedInstanceState);
michael@0 46 if (AppConstants.MOZ_ANDROID_ANR_REPORTER) {
michael@0 47 ANRReporter.register(getApplicationContext());
michael@0 48 }
michael@0 49 }
michael@0 50
michael@0 51 @Override
michael@0 52 public void onDestroy() {
michael@0 53 if (AppConstants.MOZ_ANDROID_ANR_REPORTER) {
michael@0 54 ANRReporter.unregister();
michael@0 55 }
michael@0 56 super.onDestroy();
michael@0 57 }
michael@0 58
michael@0 59 @Override
michael@0 60 public void startActivity(Intent intent) {
michael@0 61 mGeckoActivityOpened = checkIfGeckoActivity(intent);
michael@0 62 super.startActivity(intent);
michael@0 63 }
michael@0 64
michael@0 65 @Override
michael@0 66 public void startActivityForResult(Intent intent, int request) {
michael@0 67 mGeckoActivityOpened = checkIfGeckoActivity(intent);
michael@0 68 super.startActivityForResult(intent, request);
michael@0 69 }
michael@0 70
michael@0 71 private static boolean checkIfGeckoActivity(Intent intent) {
michael@0 72 // Whenever we call our own activity, the component and its package name is set.
michael@0 73 // If we call an activity from another package, or an open intent (leaving android to resolve)
michael@0 74 // component has a different package name or it is null.
michael@0 75 ComponentName component = intent.getComponent();
michael@0 76 return (component != null &&
michael@0 77 AppConstants.ANDROID_PACKAGE_NAME.equals(component.getPackageName()));
michael@0 78 }
michael@0 79
michael@0 80 @Override
michael@0 81 public boolean isGeckoActivityOpened() {
michael@0 82 return mGeckoActivityOpened;
michael@0 83 }
michael@0 84
michael@0 85 public boolean isApplicationInBackground() {
michael@0 86 return ((GeckoApplication) getApplication()).isApplicationInBackground();
michael@0 87 }
michael@0 88
michael@0 89 @Override
michael@0 90 public void onLowMemory() {
michael@0 91 MemoryMonitor.getInstance().onLowMemory();
michael@0 92 super.onLowMemory();
michael@0 93 }
michael@0 94
michael@0 95 @Override
michael@0 96 public void onTrimMemory(int level) {
michael@0 97 MemoryMonitor.getInstance().onTrimMemory(level);
michael@0 98 super.onTrimMemory(level);
michael@0 99 }
michael@0 100 }

mercurial