Merge "add accessibility descriptions/events"
diff --git a/res/layout/snapshot_item.xml b/res/layout/snapshot_item.xml
index 128dedf..7c7ba3b 100644
--- a/res/layout/snapshot_item.xml
+++ b/res/layout/snapshot_item.xml
@@ -28,7 +28,7 @@
         android:cropToPadding="true"
         android:background="@drawable/border_thumb_bookmarks_widget_holo" />
     <TextView
-        android:id="@+id/title"
+        android:id="@+id/date"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignBottom="@id/thumb"
@@ -37,30 +37,32 @@
         android:background="@drawable/overlay_url_bookmark_widget_holo"
         android:singleLine="true"
         android:ellipsize="end"
-        android:textSize="12sp"
+        android:textSize="14sp"
         android:typeface="sans"
-        android:textColor="@android:color/white"
+        android:textColor="#AAAAAA"
         android:paddingLeft="6dip"
         android:paddingRight="2dip"
         android:gravity="center_vertical" />
+    <TextView android:id="@+id/title"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_below="@+id/thumb"
+        android:layout_alignLeft="@+id/thumb"
+        android:layout_alignRight="@+id/thumb"
+        android:layout_marginTop="6dip"
+        android:paddingLeft="8dip"
+        android:gravity="center_vertical"
+        android:typeface="sans"
+        android:textSize="12sp"
+        android:textColor="#AAAAAA"
+        android:lines="2" />
     <ImageView
         android:id="@+id/divider"
         android:src="?android:attr/dividerVertical"
         android:layout_width="wrap_content"
-        android:layout_height="24dip"
-        android:layout_below="@+id/thumb"
-        android:layout_alignLeft="@+id/thumb"
-        android:scaleType="fitXY"
-        android:layout_marginTop="12dip" />
-    <TextView android:id="@+id/date"
-        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_toRightOf="@id/divider"
-        android:layout_alignTop="@id/divider"
-        android:layout_alignBottom="@id/divider"
-        android:paddingLeft="8dip"
-        android:gravity="center_vertical"
-        android:typeface="sans"
-        android:textSize="14sp"
-        android:textColor="#AAAAAA" />
+        android:layout_alignLeft="@+id/title"
+        android:layout_alignTop="@+id/title"
+        android:layout_alignBottom="@+id/title"
+        android:scaleType="fitXY" />
 </RelativeLayout>
diff --git a/res/layout/snapshots.xml b/res/layout/snapshots.xml
index 54d4e01..a02fbb9 100644
--- a/res/layout/snapshots.xml
+++ b/res/layout/snapshots.xml
@@ -20,7 +20,7 @@
     android:layout_height="match_parent"
     android:paddingTop="@dimen/combo_paddingTop">
 
-    <GridView
+    <com.android.browser.view.SnapshotGridView
         android:id="@+id/grid"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
diff --git a/src/com/android/browser/provider/BrowserProvider2.java b/src/com/android/browser/provider/BrowserProvider2.java
index 1821b50..0c1fd42 100644
--- a/src/com/android/browser/provider/BrowserProvider2.java
+++ b/src/com/android/browser/provider/BrowserProvider2.java
@@ -355,6 +355,7 @@
     SyncStateContentProviderHelper mSyncHelper = new SyncStateContentProviderHelper();
     // This is so provider tests can intercept widget updating
     ContentObserver mWidgetObserver = null;
+    boolean mUpdateWidgets = false;
 
     final class DatabaseHelper extends SQLiteOpenHelper {
         static final String DATABASE_NAME = "browser2.db";
@@ -766,10 +767,19 @@
     }
 
     void refreshWidgets() {
-        if (mWidgetObserver == null) {
-            BookmarkThumbnailWidgetProvider.refreshWidgets(getContext());
-        } else {
-            mWidgetObserver.dispatchChange(false);
+        mUpdateWidgets = true;
+    }
+
+    @Override
+    protected void onEndTransaction(boolean callerIsSyncAdapter) {
+        super.onEndTransaction(callerIsSyncAdapter);
+        if (mUpdateWidgets) {
+            if (mWidgetObserver == null) {
+                BookmarkThumbnailWidgetProvider.refreshWidgets(getContext());
+            } else {
+                mWidgetObserver.dispatchChange(false);
+            }
+            mUpdateWidgets = false;
         }
     }
 
diff --git a/src/com/android/browser/view/SnapshotGridView.java b/src/com/android/browser/view/SnapshotGridView.java
new file mode 100644
index 0000000..ab12060
--- /dev/null
+++ b/src/com/android/browser/view/SnapshotGridView.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.browser.view;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.GridView;
+
+public class SnapshotGridView extends GridView {
+
+    private static final int MAX_COLUMNS = 5;
+
+    private int mColWidth;
+
+    public SnapshotGridView(Context context) {
+        super(context);
+    }
+
+    public SnapshotGridView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public SnapshotGridView(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
+        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
+        if (widthSize > 0 && mColWidth > 0) {
+            int numCols = widthSize / mColWidth;
+            widthSize = Math.min(
+                    Math.min(numCols, MAX_COLUMNS) * mColWidth,
+                    widthSize);
+            widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
+        }
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+    }
+
+    @Override
+    public void setColumnWidth(int columnWidth) {
+        mColWidth = columnWidth;
+        super.setColumnWidth(columnWidth);
+    }
+}