mobile/android/base/GeckoActivity.java

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:0d81e6aa1038
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/. */
4
5 package org.mozilla.gecko;
6
7 import android.content.ComponentName;
8 import android.content.Intent;
9 import android.support.v4.app.FragmentActivity;
10
11 public class GeckoActivity extends FragmentActivity implements GeckoActivityStatus {
12 // has this activity recently started another Gecko activity?
13 private boolean mGeckoActivityOpened = false;
14
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 }
23
24 @Override
25 public void onPause() {
26 super.onPause();
27
28 if (getApplication() instanceof GeckoApplication) {
29 ((GeckoApplication) getApplication()).onActivityPause(this);
30 }
31 }
32
33 @Override
34 public void onResume() {
35 super.onResume();
36
37 if (getApplication() instanceof GeckoApplication) {
38 ((GeckoApplication) getApplication()).onActivityResume(this);
39 mGeckoActivityOpened = false;
40 }
41 }
42
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 }
50
51 @Override
52 public void onDestroy() {
53 if (AppConstants.MOZ_ANDROID_ANR_REPORTER) {
54 ANRReporter.unregister();
55 }
56 super.onDestroy();
57 }
58
59 @Override
60 public void startActivity(Intent intent) {
61 mGeckoActivityOpened = checkIfGeckoActivity(intent);
62 super.startActivity(intent);
63 }
64
65 @Override
66 public void startActivityForResult(Intent intent, int request) {
67 mGeckoActivityOpened = checkIfGeckoActivity(intent);
68 super.startActivityForResult(intent, request);
69 }
70
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 }
79
80 @Override
81 public boolean isGeckoActivityOpened() {
82 return mGeckoActivityOpened;
83 }
84
85 public boolean isApplicationInBackground() {
86 return ((GeckoApplication) getApplication()).isApplicationInBackground();
87 }
88
89 @Override
90 public void onLowMemory() {
91 MemoryMonitor.getInstance().onLowMemory();
92 super.onLowMemory();
93 }
94
95 @Override
96 public void onTrimMemory(int level) {
97 MemoryMonitor.getInstance().onTrimMemory(level);
98 super.onTrimMemory(level);
99 }
100 }

mercurial