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.

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

mercurial