Bug 752709 - Extract a getDisplayMetrics function into GeckoApp. r=cpeterson a=johnath
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 23 May 2012 21:53:39 -0400
changeset 95892 de5e49beafa7e3d8c9480d03d622b035f38d266d
parent 95891 8b7b85eded3fd63e770292ef55d4fe43a49be1b3
child 95893 2bd4d69806b97f03f741a0df93702c860a02fb8e
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpeterson, johnath
bugs752709
milestone14.0a2
Bug 752709 - Extract a getDisplayMetrics function into GeckoApp. r=cpeterson a=johnath
mobile/android/base/AboutHomeContent.java
mobile/android/base/FormAssistPopup.java
mobile/android/base/GeckoApp.java
mobile/android/base/GeckoAppShell.java
mobile/android/base/GeckoEvent.java
mobile/android/base/Tab.java
mobile/android/base/gfx/GeckoLayerClient.java
mobile/android/base/gfx/ViewportMetrics.java
--- a/mobile/android/base/AboutHomeContent.java
+++ b/mobile/android/base/AboutHomeContent.java
@@ -72,17 +72,16 @@ import android.graphics.BitmapFactory;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.os.SystemClock;
 import android.text.SpannableString;
 import android.text.style.StyleSpan;
 import android.text.style.UnderlineSpan;
 import android.util.AttributeSet;
 import android.util.Log;
-import android.util.DisplayMetrics;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.ArrayAdapter;
 import android.widget.FrameLayout;
 import android.widget.GridView;
 import android.widget.ImageView;
 import android.widget.ListView;
@@ -676,19 +675,17 @@ public class AboutHomeContent extends Sc
          * ------
          * 109dip total height per top site grid item
          */
         private static final int kTopSiteItemHeight = 109;
         float mDisplayDensity ;
 
         public TopSitesGridView(Context context, AttributeSet attrs) {
             super(context, attrs);
-            DisplayMetrics dm = new DisplayMetrics();
-            GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(dm);
-            mDisplayDensity = dm.density;
+            mDisplayDensity = GeckoApp.mAppContext.getDisplayMetrics().density;
         }
 
         @Override
         protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
             int numRows;
 
             SimpleCursorAdapter adapter = (SimpleCursorAdapter) getAdapter();
             int nSites = Integer.MAX_VALUE;
--- a/mobile/android/base/FormAssistPopup.java
+++ b/mobile/android/base/FormAssistPopup.java
@@ -181,18 +181,17 @@ public class FormAssistPopup extends Rel
     private void showValidationMessage(String validationMessage, JSONArray rect, double zoom) {
         if (mValidationMessage == null) {
             LayoutInflater inflater = LayoutInflater.from(mContext);
             mValidationMessage = (RelativeLayout) inflater.inflate(R.layout.validation_message, null);
 
             addView(mValidationMessage);
             mValidationMessageText = (TextView) mValidationMessage.findViewById(R.id.validation_message_text);
 
-            DisplayMetrics metrics = new DisplayMetrics();
-            GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
+            DisplayMetrics metrics = GeckoApp.mAppContext.getDisplayMetrics();
             sValidationTextMarginTop = (int) (VALIDATION_MESSAGE_MARGIN_TOP_IN_DPI * metrics.density);
 
             sValidationTextLayoutNormal = new RelativeLayout.LayoutParams(mValidationMessageText.getLayoutParams());
             sValidationTextLayoutNormal.setMargins(0, sValidationTextMarginTop, 0, 0);
 
             sValidationTextLayoutInverted = new RelativeLayout.LayoutParams(sValidationTextLayoutNormal);
             sValidationTextLayoutInverted.setMargins(0, 0, 0, 0);
 
@@ -225,18 +224,17 @@ public class FormAssistPopup extends Rel
         if (mAutoCompleteList != null)
             mAutoCompleteList.setVisibility(isAutoComplete ? VISIBLE : GONE);
         if (mValidationMessage != null)
             mValidationMessage.setVisibility(isAutoComplete ? GONE : VISIBLE);
 
         // Initialize static variables based on DisplayMetrics. We delay this to
         // make sure DisplayMetrics isn't null to avoid an NPE.
         if (sAutoCompleteMinWidth == 0) {
-            DisplayMetrics metrics = new DisplayMetrics();
-            GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
+            DisplayMetrics metrics = GeckoApp.mAppContext.getDisplayMetrics();
             sAutoCompleteMinWidth = (int) (AUTOCOMPLETE_MIN_WIDTH_IN_DPI * metrics.density);
             sAutoCompleteRowHeight = (int) (AUTOCOMPLETE_ROW_HEIGHT_IN_DPI * metrics.density);
             sValidationMessageHeight = (int) (VALIDATION_MESSAGE_HEIGHT_IN_DPI * metrics.density);
         }
 
         // These values correspond to the input box for which we want to
         // display the FormAssistPopup.
         int left = 0;
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -539,16 +539,22 @@ abstract public class GeckoApp
         if (outState == null)
             outState = new Bundle();
 
         Tab tab = Tabs.getInstance().getSelectedTab();
         if (tab != null)
             outState.putString(SAVED_STATE_TITLE, tab.getDisplayTitle());
     }
 
+    public DisplayMetrics getDisplayMetrics() {
+        DisplayMetrics metrics = new DisplayMetrics();
+        getWindowManager().getDefaultDisplay().getMetrics(metrics);
+        return metrics;
+    }
+
     void getAndProcessThumbnailForTab(final Tab tab) {
         boolean isSelectedTab = Tabs.getInstance().isSelectedTab(tab);
         final Bitmap bitmap = isSelectedTab ? mLayerClient.getBitmap() : null;
         
         if ("about:home".equals(tab.getURL())) {
             tab.updateThumbnail(null);
             return;
         }
--- a/mobile/android/base/GeckoAppShell.java
+++ b/mobile/android/base/GeckoAppShell.java
@@ -480,18 +480,17 @@ public class GeckoAppShell
             combinedArgs += " " + args;
         if (url != null)
             combinedArgs += " -url " + url;
         if (type != null)
             combinedArgs += " " + type;
         if (restoreMode != RESTORE_NONE)
             combinedArgs += " -restoremode " + restoreMode;
 
-        DisplayMetrics metrics = new DisplayMetrics();
-        GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
+        DisplayMetrics metrics = GeckoApp.mAppContext.getDisplayMetrics();
         combinedArgs += " -width " + metrics.widthPixels + " -height " + metrics.heightPixels;
 
         GeckoApp.mAppContext.runOnUiThread(new Runnable() {
                 public void run() {
                     geckoLoaded();
                 }
             });
 
@@ -1187,19 +1186,17 @@ public class GeckoAppShell
 
         NotificationManager notificationManager = (NotificationManager)
             GeckoApp.mAppContext.getSystemService(Context.NOTIFICATION_SERVICE);
         notificationManager.cancel(notificationID);
     }
 
     public static int getDpi() {
         if (sDensityDpi == 0) {
-            DisplayMetrics metrics = new DisplayMetrics();
-            GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
-            sDensityDpi = metrics.densityDpi;
+            sDensityDpi = GeckoApp.mAppContext.getDisplayMetrics().densityDpi;
         }
 
         return sDensityDpi;
     }
 
     public static void setFullScreen(boolean fullscreen) {
         GeckoApp.mAppContext.setFullScreen(fullscreen);
     }
--- a/mobile/android/base/GeckoEvent.java
+++ b/mobile/android/base/GeckoEvent.java
@@ -279,18 +279,17 @@ public class GeckoEvent {
                     mPointRadii[index] = new Point((int)event.getToolMajor(eventIndex)/2,
                                                    (int)event.getToolMinor(eventIndex)/2);
                 } else {
                     mPointRadii[index] = new Point((int)event.getToolMinor(eventIndex)/2,
                                                    (int)event.getToolMajor(eventIndex)/2);
                 }
             } else {
                 float size = event.getSize(eventIndex);
-                DisplayMetrics displaymetrics = new DisplayMetrics();
-                GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
+                DisplayMetrics displaymetrics = GeckoApp.mAppContext.getDisplayMetrics();
                 size = size*Math.min(displaymetrics.heightPixels, displaymetrics.widthPixels);
                 mPointRadii[index] = new Point((int)size,(int)size);
                 mOrientations[index] = 0;
             }
             mPressures[index] = event.getPressure(eventIndex);
         } catch(Exception ex) {
             Log.e(LOGTAG, "Error creating motion point " + index, ex);
             mPointRadii[index] = new Point(0, 0);
--- a/mobile/android/base/Tab.java
+++ b/mobile/android/base/Tab.java
@@ -39,17 +39,16 @@ package org.mozilla.gecko;
 
 import android.content.ContentResolver;
 import android.database.ContentObserver;
 import android.graphics.Bitmap;
 import android.graphics.Color;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.os.AsyncTask;
-import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.Surface;
 import android.view.View;
 
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.gfx.Layer;
@@ -166,19 +165,17 @@ public final class Tab {
     }
 
     public Drawable getThumbnail() {
         return mThumbnail;
     }
 
     float getDensity() {
         if (sDensity == 0.0f) {
-            DisplayMetrics metrics = new DisplayMetrics();
-            GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
-            sDensity = metrics.density;
+            sDensity = GeckoApp.mAppContext.getDisplayMetrics().density;
         }
         return sDensity;
     }
 
     int getThumbnailWidth() {
         return (int)(kThumbnailWidth * getDensity());
     }
 
--- a/mobile/android/base/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/gfx/GeckoLayerClient.java
@@ -135,18 +135,17 @@ public class GeckoLayerClient implements
     }
 
     DisplayPortMetrics getDisplayPort() {
         return mDisplayPort;
     }
 
     /* Informs Gecko that the screen size has changed. */
     private void sendResizeEventIfNecessary(boolean force) {
-        DisplayMetrics metrics = new DisplayMetrics();
-        GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
+        DisplayMetrics metrics = GeckoApp.mAppContext.getDisplayMetrics();
         View view = mLayerController.getView();
 
         IntSize newScreenSize = new IntSize(metrics.widthPixels, metrics.heightPixels);
         IntSize newWindowSize = new IntSize(view.getWidth(), view.getHeight());
 
         boolean screenSizeChanged = !mScreenSize.equals(newScreenSize);
         boolean windowSizeChanged = !mWindowSize.equals(newWindowSize);
 
--- a/mobile/android/base/gfx/ViewportMetrics.java
+++ b/mobile/android/base/gfx/ViewportMetrics.java
@@ -61,18 +61,17 @@ public class ViewportMetrics {
     private static final String LOGTAG = "GeckoViewportMetrics";
 
     private FloatSize mPageSize;
     private FloatSize mCssPageSize;
     private RectF mViewportRect;
     private float mZoomFactor;
 
     public ViewportMetrics() {
-        DisplayMetrics metrics = new DisplayMetrics();
-        GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
+        DisplayMetrics metrics = GeckoApp.mAppContext.getDisplayMetrics();
 
         mPageSize = new FloatSize(metrics.widthPixels, metrics.heightPixels);
         mCssPageSize = new FloatSize(metrics.widthPixels, metrics.heightPixels);
         mViewportRect = new RectF(0, 0, metrics.widthPixels, metrics.heightPixels);
         mZoomFactor = 1.0f;
     }
 
     public ViewportMetrics(ViewportMetrics viewport) {