summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/view/BookmarkExpandableGridView.java
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2011-06-14 17:21:55 -0700
committerJohn Reck <jreck@google.com>2011-06-15 11:27:24 -0700
commitf3828cd09f12cbf2980af72187628a608db8e938 (patch)
tree1f40bddbea3b53a58a82199da0815fdd0544a3fc /src/com/android/browser/view/BookmarkExpandableGridView.java
parentd8c7452a7d8975a2d60414c5a33842b4a743e631 (diff)
downloadpackages_apps_browser-f3828cd09f12cbf2980af72187628a608db8e938.zip
packages_apps_browser-f3828cd09f12cbf2980af72187628a608db8e938.tar.gz
packages_apps_browser-f3828cd09f12cbf2980af72187628a608db8e938.tar.bz2
Remove magic paddings from bookmark view
Use calculated sizes to correctly center without the need for "magic" padding values. Change-Id: Ida64a80243df9bf05355dd1db1047fc16c10b726
Diffstat (limited to 'src/com/android/browser/view/BookmarkExpandableGridView.java')
-rw-r--r--src/com/android/browser/view/BookmarkExpandableGridView.java33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/com/android/browser/view/BookmarkExpandableGridView.java b/src/com/android/browser/view/BookmarkExpandableGridView.java
index f6b9f19..c8811d1 100644
--- a/src/com/android/browser/view/BookmarkExpandableGridView.java
+++ b/src/com/android/browser/view/BookmarkExpandableGridView.java
@@ -57,6 +57,7 @@ public class BookmarkExpandableGridView extends ExpandableListView
private boolean mLongClickable;
private BreadCrumbView.Controller mBreadcrumbController;
private BookmarkDragHandler mDragHandler;
+ private int mMaxColumnCount;
public BookmarkExpandableGridView(Context context) {
super(context);
@@ -78,14 +79,27 @@ public class BookmarkExpandableGridView extends ExpandableListView
mContext = context;
setItemsCanFocus(true);
setLongClickable(false);
+ mMaxColumnCount = mContext.getResources()
+ .getInteger(R.integer.max_bookmark_columns);
mAdapter = new BookmarkAccountAdapter(mContext);
super.setAdapter(mAdapter);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ int width = MeasureSpec.getSize(widthMeasureSpec);
+ int widthMode = MeasureSpec.getMode(widthMeasureSpec);
+ if (width > 0) {
+ mAdapter.measureChildren(width);
+ if (mAdapter.mRowPadding > 0) {
+ width -= mAdapter.mRowPadding * 2;
+ }
+ widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, widthMode);
+ }
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- mAdapter.measureChildren();
+ if (width != getMeasuredWidth()) {
+ mAdapter.measureChildren(getMeasuredWidth());
+ }
}
@Override
@@ -100,10 +114,6 @@ public class BookmarkExpandableGridView extends ExpandableListView
mColumnWidth = v.getMeasuredWidth();
}
- public void setHorizontalSpacing(int horizontalSpacing) {
- // TODO Auto-generated method stub
- }
-
public void clearAccounts() {
mAdapter.clear();
}
@@ -330,11 +340,6 @@ public class BookmarkExpandableGridView extends ExpandableListView
convertView = mInflater.inflate(R.layout.bookmark_grid_row, parent, false);
}
LinearLayout row = (LinearLayout) convertView;
- row.setPadding(
- mRowPadding,
- row.getPaddingTop(),
- mRowPadding,
- row.getPaddingBottom());
if (row.getChildCount() > mRowCount) {
row.removeViews(mRowCount, row.getChildCount() - mRowCount);
}
@@ -387,13 +392,13 @@ public class BookmarkExpandableGridView extends ExpandableListView
return mGroups.size();
}
- public void measureChildren() {
- int viewWidth = getMeasuredWidth();
+ public void measureChildren(int viewWidth) {
if (mLastViewWidth == viewWidth) return;
- ViewGroup parent = (ViewGroup) mInflater.inflate(R.layout.bookmark_grid_row, null);
- viewWidth -= parent.getPaddingLeft() + parent.getPaddingRight();
int rowCount = viewWidth / mColumnWidth;
+ if (mMaxColumnCount > 0) {
+ rowCount = Math.min(rowCount, mMaxColumnCount);
+ }
int rowPadding = (viewWidth - (rowCount * mColumnWidth)) / 2;
boolean notify = rowCount != mRowCount || rowPadding != mRowPadding;
mRowCount = rowCount;