Bug 904172: Block content for thumbnails even before the cursor returns. [r=mfinkle]
authorSriram Ramasubramanian <sriram@mozilla.com>
Fri, 06 Sep 2013 16:36:46 -0700
changeset 146212 bbddba8cc6e61b6a7a2f04308697b4ce481ddf77
parent 146211 4d0f4b412d32131bddfb4c47fd158203d285c072
child 146213 5b664dac677c05dcd2a0ccb080c3792cfee3f4f6
push id25245
push userryanvm@gmail.com
push dateMon, 09 Sep 2013 20:57:55 +0000
treeherdermozilla-central@a468b2e34b04 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs904172
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 904172: Block content for thumbnails even before the cursor returns. [r=mfinkle]
mobile/android/base/home/TopBookmarksView.java
--- a/mobile/android/base/home/TopBookmarksView.java
+++ b/mobile/android/base/home/TopBookmarksView.java
@@ -13,18 +13,16 @@ import org.mozilla.gecko.home.HomePager.
 
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.database.Cursor;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.View;
-import android.view.animation.AnimationUtils;
-import android.view.animation.GridLayoutAnimationController;
 import android.widget.AbsListView;
 import android.widget.AdapterView;
 import android.widget.GridView;
 
 import java.util.EnumSet;
 
 /**
  * A grid view of top bookmarks and pinned tabs.
@@ -45,16 +43,22 @@ public class TopBookmarksView extends Gr
     private final int mNumColumns;
 
     // Horizontal spacing in between the rows.
     private final int mHorizontalSpacing;
 
     // Vertical spacing in between the rows.
     private final int mVerticalSpacing;
 
+    // Measured width of this view.
+    private int mMeasuredWidth;
+
+    // Measured height of this view.
+    private int mMeasuredHeight;
+
     // On URL open listener.
     private OnUrlOpenListener mUrlOpenListener;
 
     // Pin bookmark listener.
     private OnPinBookmarkListener mPinBookmarkListener;
 
     // Context menu info.
     private TopBookmarksContextMenuInfo mContextMenuInfo;
@@ -109,19 +113,16 @@ public class TopBookmarksView extends Gr
         setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
             @Override
             public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                 Cursor cursor = (Cursor) parent.getItemAtPosition(position);
                 mContextMenuInfo = new TopBookmarksContextMenuInfo(view, position, id, cursor);
                 return showContextMenuForChild(TopBookmarksView.this);
             }
         });
-
-        final GridLayoutAnimationController controller = new GridLayoutAnimationController(AnimationUtils.loadAnimation(getContext(), R.anim.grow_fade_in_center));
-        setLayoutAnimation(controller);
     }
 
     @Override
     public void onDetachedFromWindow() {
         super.onDetachedFromWindow();
 
         mUrlOpenListener = null;
         mPinBookmarkListener = null;
@@ -142,62 +143,55 @@ public class TopBookmarksView extends Gr
      * {@inheritDoc}
      */
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         // Sets the padding for this view.
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 
         final int measuredWidth = getMeasuredWidth();
+        if (measuredWidth == mMeasuredWidth) {
+            // Return the cached values as the width is the same.
+            setMeasuredDimension(mMeasuredWidth, mMeasuredHeight);
+            return;
+        }
+
         final int childWidth = getColumnWidth();
-        int childHeight = 0;
 
         // Set the column width as the thumbnail width.
         ThumbnailHelper.getInstance().setThumbnailWidth(childWidth);
 
-        // If there's an adapter, use it to calculate the height of this view.
-        final TopBookmarksAdapter adapter = (TopBookmarksAdapter) getAdapter();
-        final int count;
+        // Get the first child from the adapter.
+        final View child = new TopBookmarkItemView(getContext());
 
-        // There shouldn't be any inherent size (due to padding) if there are no child views.
-        if (adapter == null || (count = adapter.getCount()) == 0) {
-            setMeasuredDimension(0, 0);
-            return;
+        // Set a default LayoutParams on the child, if it doesn't have one on its own.
+        AbsListView.LayoutParams params = (AbsListView.LayoutParams) child.getLayoutParams();
+        if (params == null) {
+            params = new AbsListView.LayoutParams(AbsListView.LayoutParams.WRAP_CONTENT,
+                                                  AbsListView.LayoutParams.WRAP_CONTENT);
+            child.setLayoutParams(params);
         }
 
-        // Get the first child from the adapter.
-        final View child = adapter.getView(0, null, this);
-        if (child != null) {
-            // Set a default LayoutParams on the child, if it doesn't have one on its own.
-            AbsListView.LayoutParams params = (AbsListView.LayoutParams) child.getLayoutParams();
-            if (params == null) {
-                params = new AbsListView.LayoutParams(AbsListView.LayoutParams.WRAP_CONTENT,
-                                                      AbsListView.LayoutParams.WRAP_CONTENT);
-                child.setLayoutParams(params);
-            }
-
-            // Measure the exact width of the child, and the height based on the width.
-            // Note: the child (and BookmarkThumbnailView) takes care of calculating its height.
-            int childWidthSpec = MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY);
-            int childHeightSpec = MeasureSpec.makeMeasureSpec(0,  MeasureSpec.UNSPECIFIED);
-            child.measure(childWidthSpec, childHeightSpec);
-            childHeight = child.getMeasuredHeight();
-        }
-
-        // Find the minimum of bookmarks we need to show, and the one given by the cursor.
-        final int total = Math.min(count > 0 ? count : Integer.MAX_VALUE, mMaxBookmarks);
+        // Measure the exact width of the child, and the height based on the width.
+        // Note: the child (and BookmarkThumbnailView) takes care of calculating its height.
+        int childWidthSpec = MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY);
+        int childHeightSpec = MeasureSpec.makeMeasureSpec(0,  MeasureSpec.UNSPECIFIED);
+        child.measure(childWidthSpec, childHeightSpec);
+        final int childHeight = child.getMeasuredHeight();
 
         // Number of rows required to show these bookmarks.
-        final int rows = (int) Math.ceil((double) total / mNumColumns);
+        final int rows = (int) Math.ceil((double) mMaxBookmarks / mNumColumns);
         final int childrenHeight = childHeight * rows;
         final int totalVerticalSpacing = rows > 0 ? (rows - 1) * mVerticalSpacing : 0;
 
         // Total height of this view.
         final int measuredHeight = childrenHeight + getPaddingTop() + getPaddingBottom() + totalVerticalSpacing;
         setMeasuredDimension(measuredWidth, measuredHeight);
+        mMeasuredWidth = measuredWidth;
+        mMeasuredHeight = measuredHeight;
     }
 
     @Override
     public ContextMenuInfo getContextMenuInfo() {
         return mContextMenuInfo;
     }
 
     /**