summaryrefslogtreecommitdiffstats
path: root/src/com
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
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')
-rw-r--r--src/com/android/browser/BrowserBookmarksAdapter.java6
-rw-r--r--src/com/android/browser/BrowserBookmarksPage.java6
-rw-r--r--src/com/android/browser/view/BookmarkExpandableGridView.java33
3 files changed, 26 insertions, 19 deletions
diff --git a/src/com/android/browser/BrowserBookmarksAdapter.java b/src/com/android/browser/BrowserBookmarksAdapter.java
index 7543528..16bcda5 100644
--- a/src/com/android/browser/BrowserBookmarksAdapter.java
+++ b/src/com/android/browser/BrowserBookmarksAdapter.java
@@ -52,6 +52,12 @@ public class BrowserBookmarksAdapter extends CursorAdapter {
}
void bindGridView(View view, Context context, Cursor cursor) {
+ // We need to set this to handle rotation and other configuration change
+ // events. If the padding didn't change, this is a no op.
+ int padding = context.getResources()
+ .getDimensionPixelSize(R.dimen.combo_horizontalSpacing);
+ view.setPadding(padding, view.getPaddingTop(),
+ padding, view.getPaddingBottom());
ImageView thumb = (ImageView) view.findViewById(R.id.thumb);
TextView tv = (TextView) view.findViewById(R.id.label);
diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java
index f92272f..d871f22 100644
--- a/src/com/android/browser/BrowserBookmarksPage.java
+++ b/src/com/android/browser/BrowserBookmarksPage.java
@@ -556,13 +556,9 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Resources res = getActivity().getResources();
- int horizontalSpacing = (int) res.getDimension(R.dimen.combo_horizontalSpacing);
- mGrid.setHorizontalSpacing(horizontalSpacing);
mGrid.setColumnWidthFromLayout(R.layout.bookmark_thumbnail);
- int paddingLeftRight = (int) res.getDimension(R.dimen.combo_paddingLeftRight);
int paddingTop = (int) res.getDimension(R.dimen.combo_paddingTop);
- mRoot.setPadding(paddingLeftRight, paddingTop,
- paddingLeftRight, 0);
+ mRoot.setPadding(0, paddingTop, 0, 0);
getActivity().invalidateOptionsMenu();
}
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;