From 5bc1a73c63589ce384b754925b44dd4a7357153d Mon Sep 17 00:00:00 2001 From: Sriram Ramasubramanian Date: Fri, 27 Jul 2012 23:31:54 -0700 Subject: [PATCH] Bug 778247: mAppContext cleanup: Tabs can avoid it. [r=mbrubeck] --HG-- extra : rebase_source : 1a5ed5ec5dbfdd72c81877196e3a3f10764e3d07 --- mobile/android/base/GeckoApp.java | 22 +++++++++++++--- mobile/android/base/Tabs.java | 36 +++++++++++--------------- mobile/android/base/gfx/LayerView.java | 4 +-- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index e70fae72cf0..fbb80e6ea06 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -98,9 +98,9 @@ abstract public class GeckoApp private Favicons mFavicons; private TextSelection mTextSelection; - public DoorHangerPopup mDoorHangerPopup; - public FormAssistPopup mFormAssistPopup; - public TabsPanel mTabsPanel; + protected DoorHangerPopup mDoorHangerPopup; + protected FormAssistPopup mFormAssistPopup; + protected TabsPanel mTabsPanel; private LayerController mLayerController; private GeckoLayerClient mLayerClient; @@ -561,7 +561,7 @@ abstract public class GeckoApp return metrics; } - void getAndProcessThumbnailForTab(final Tab tab) { + public void getAndProcessThumbnailForTab(final Tab tab) { boolean isSelectedTab = Tabs.getInstance().isSelectedTab(tab); final Bitmap bitmap = isSelectedTab ? mLayerClient.getBitmap() : null; @@ -618,6 +618,11 @@ abstract public class GeckoApp return (Tabs.getInstance().isSelectedTab(tab) || areTabsShown()); } + public void hideFormAssistPopup() { + if (mFormAssistPopup != null) + mFormAssistPopup.hide(); + } + void updatePopups(final Tab tab) { mDoorHangerPopup.updatePopup(); } @@ -1253,6 +1258,14 @@ abstract public class GeckoApp }, 500); } + public void showToast(final int resId, final int duration) { + mMainHandler.post(new Runnable() { + public void run() { + Toast.makeText(mAppContext, resId, duration); + } + }); + } + void handleShowToast(final String message, final String duration) { mMainHandler.post(new Runnable() { public void run() { @@ -1503,6 +1516,7 @@ abstract public class GeckoApp GeckoAppShell.registerGlobalExceptionHandler(); mAppContext = this; + Tabs.getInstance().attachToActivity(this); // Check to see if the activity is restarted after configuration change. if (getLastNonConfigurationInstance() != null) { diff --git a/mobile/android/base/Tabs.java b/mobile/android/base/Tabs.java index c1d86c3c27b..5a949c4b1f6 100644 --- a/mobile/android/base/Tabs.java +++ b/mobile/android/base/Tabs.java @@ -29,6 +29,8 @@ public class Tabs implements GeckoEventListener { private ContentResolver mResolver; private boolean mRestoringSession; + private GeckoApp mActivity; + private Tabs() { mTabs = new HashMap(); mOrder = new ArrayList(); @@ -46,6 +48,10 @@ public class Tabs implements GeckoEventListener { GeckoAppShell.registerGeckoEventListener("Reader:Share", this); } + public void attachToActivity(GeckoApp activity) { + mActivity = activity; + } + public int getCount() { return mTabs.size(); } @@ -66,7 +72,7 @@ public class Tabs implements GeckoEventListener { mOrder.add(tab); if (!mRestoringSession) { - GeckoApp.mAppContext.mMainHandler.post(new Runnable() { + mActivity.runOnUiThread(new Runnable() { public void run() { notifyListeners(tab, TabEvents.ADDED); } @@ -99,10 +105,9 @@ public class Tabs implements GeckoEventListener { return null; mSelectedTab = tab; - GeckoApp.mAppContext.mMainHandler.post(new Runnable() { + mActivity.runOnUiThread(new Runnable() { public void run() { - if (GeckoApp.mAppContext.mFormAssistPopup != null) - GeckoApp.mAppContext.mFormAssistPopup.hide(); + mActivity.hideFormAssistPopup(); if (isSelectedTab(tab)) { String url = tab.getURL(); notifyListeners(tab, TabEvents.SELECTED); @@ -165,7 +170,7 @@ public class Tabs implements GeckoEventListener { int tabId = tab.getId(); removeTab(tabId); - GeckoApp.mAppContext.mMainHandler.post(new Runnable() { + mActivity.runOnUiThread(new Runnable() { public void run() { notifyListeners(tab, TabEvents.CLOSED); tab.onDestroy(); @@ -258,7 +263,7 @@ public class Tabs implements GeckoEventListener { mRestoringSession = true; } else if (event.equals("Session:RestoreEnd")) { mRestoringSession = false; - GeckoApp.mAppContext.mMainHandler.post(new Runnable() { + mActivity.runOnUiThread(new Runnable() { public void run() { notifyListeners(null, TabEvents.RESTORED); } @@ -282,25 +287,14 @@ public class Tabs implements GeckoEventListener { void handleReaderAdded(boolean success, final String title, final String url) { if (!success) { - GeckoApp.mAppContext.mMainHandler.post(new Runnable() { - public void run() { - Toast.makeText(GeckoApp.mAppContext, - R.string.reading_list_failed, Toast.LENGTH_SHORT).show(); - } - }); + mActivity.showToast(R.string.reading_list_failed, Toast.LENGTH_SHORT); return; } GeckoAppShell.getHandler().post(new Runnable() { public void run() { - BrowserDB.addReadingListItem(GeckoApp.mAppContext.getContentResolver(), title, url); - - GeckoApp.mAppContext.mMainHandler.post(new Runnable() { - public void run() { - Toast.makeText(GeckoApp.mAppContext, - R.string.reading_list_added, Toast.LENGTH_SHORT).show(); - } - }); + BrowserDB.addReadingListItem(mActivity.getContentResolver(), title, url); + mActivity.showToast(R.string.reading_list_added, Toast.LENGTH_SHORT); } }); } @@ -311,7 +305,7 @@ public class Tabs implements GeckoEventListener { final Tab tab = iterator.next(); GeckoAppShell.getHandler().post(new Runnable() { public void run() { - GeckoApp.mAppContext.getAndProcessThumbnailForTab(tab); + mActivity.getAndProcessThumbnailForTab(tab); } }); } diff --git a/mobile/android/base/gfx/LayerView.java b/mobile/android/base/gfx/LayerView.java index 503eb9ae367..aadbb574769 100644 --- a/mobile/android/base/gfx/LayerView.java +++ b/mobile/android/base/gfx/LayerView.java @@ -73,8 +73,8 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback { requestFocus(); /** We need to manually hide FormAssistPopup because it is not a regular PopupWindow. */ - if (GeckoApp.mAppContext != null && GeckoApp.mAppContext.mFormAssistPopup != null) - GeckoApp.mAppContext.mFormAssistPopup.hide(); + if (GeckoApp.mAppContext != null) + GeckoApp.mAppContext.hideFormAssistPopup(); return mTouchEventHandler.handleEvent(event); }