From d5d8dbb0b39238c4c50ad5255592a2ad30c0f996 Mon Sep 17 00:00:00 2001 From: Margaret Leibovic Date: Mon, 7 May 2012 16:17:08 -0700 Subject: [PATCH] Bug 752172 - Turn SiteIdentityPopup into a singleton. r=mbrubeck --- mobile/android/base/BrowserToolbar.java | 2 +- mobile/android/base/GeckoApp.java | 13 +++++------ mobile/android/base/SiteIdentityPopup.java | 25 ++++++++++++++++------ 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/mobile/android/base/BrowserToolbar.java b/mobile/android/base/BrowserToolbar.java index bb93e5ff205..7219bc3b62a 100644 --- a/mobile/android/base/BrowserToolbar.java +++ b/mobile/android/base/BrowserToolbar.java @@ -181,7 +181,7 @@ public class BrowserToolbar { // Calculate the left margin for the arrow based on the position of the lock icon. int leftMargin = lockLocation[0] - lockLayoutParams.rightMargin; - GeckoApp.mSiteIdentityPopup.show(leftMargin); + SiteIdentityPopup.getInstance().show(leftMargin); } }); diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index 0daf14d6a0e..8974f4b9993 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -138,7 +138,6 @@ abstract public class GeckoApp public static BrowserToolbar mBrowserToolbar; public static DoorHangerPopup mDoorHangerPopup; - public static SiteIdentityPopup mSiteIdentityPopup; public static FormAssistPopup mFormAssistPopup; public Favicons mFavicons; @@ -1658,7 +1657,6 @@ abstract public class GeckoApp mPluginContainer = (AbsoluteLayout) findViewById(R.id.plugin_container); mDoorHangerPopup = new DoorHangerPopup(this); - mSiteIdentityPopup = new SiteIdentityPopup(this); mFormAssistPopup = (FormAssistPopup) findViewById(R.id.form_assist_popup); Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - UI almost up"); @@ -1949,8 +1947,7 @@ abstract public class GeckoApp // Undo whatever we did in onPause. super.onResume(); - if (mSiteIdentityPopup != null) - mSiteIdentityPopup.dismiss(); + SiteIdentityPopup.getInstance().dismiss(); int newOrientation = getResources().getConfiguration().orientation; @@ -2079,8 +2076,7 @@ abstract public class GeckoApp mOrientation = newConfig.orientation; if (mFormAssistPopup != null) mFormAssistPopup.hide(); - if (mSiteIdentityPopup != null) - mSiteIdentityPopup.dismiss(); + SiteIdentityPopup.getInstance().dismiss(); refreshActionBar(); } } @@ -2524,8 +2520,9 @@ abstract public class GeckoApp return; } - if (mSiteIdentityPopup.isShowing()) { - mSiteIdentityPopup.dismiss(); + SiteIdentityPopup identityPopup = SiteIdentityPopup.getInstance(); + if (identityPopup.isShowing()) { + identityPopup.dismiss(); return; } diff --git a/mobile/android/base/SiteIdentityPopup.java b/mobile/android/base/SiteIdentityPopup.java index 5255f263977..0f3ca5d6831 100644 --- a/mobile/android/base/SiteIdentityPopup.java +++ b/mobile/android/base/SiteIdentityPopup.java @@ -20,6 +20,10 @@ import android.widget.TextView; import org.json.JSONObject; import org.json.JSONException; +/** + * SiteIdentityPopup is a singleton class that displays site identity data in + * an arrow panel popup hanging from the lock icon in the browser toolbar. + */ public class SiteIdentityPopup extends PopupWindow { private static final String LOGTAG = "GeckoSiteIdentityPopup"; @@ -27,7 +31,6 @@ public class SiteIdentityPopup extends PopupWindow { public static final String VERIFIED = "verified"; public static final String IDENTIFIED = "identified"; - private Context mContext; private Resources mResources; private boolean mInflated; @@ -40,19 +43,27 @@ public class SiteIdentityPopup extends PopupWindow { private ImageView mLarry; private ImageView mArrow; - public SiteIdentityPopup(Context aContext) { - super(aContext); - mContext = aContext; - mResources = aContext.getResources(); + private SiteIdentityPopup() { + super(GeckoApp.mAppContext); + + mResources = GeckoApp.mAppContext.getResources(); mInflated = false; - } + } + + private static class InstanceHolder { + private static final SiteIdentityPopup INSTANCE = new SiteIdentityPopup(); + } + + public static SiteIdentityPopup getInstance() { + return SiteIdentityPopup.InstanceHolder.INSTANCE; + } private void init() { setBackgroundDrawable(new BitmapDrawable()); setOutsideTouchable(true); setWindowLayoutMode(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); - LayoutInflater inflater = LayoutInflater.from(mContext); + LayoutInflater inflater = LayoutInflater.from(GeckoApp.mAppContext); RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.site_identity_popup, null); setContentView(layout);