summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ben Kwa <kenobi@google.com> 2016-03-16 13:01:20 -0700
committer Ben Kwa <kenobi@google.com> 2016-03-16 15:50:58 -0700
commit1a63c613ead0abcbecc208a88a88513628835d5f (patch)
treeb41c25794de2969eb9484b720044ad5972661f4b
parentec09996b595a2092c92ac3bf4572d64ca698bbab (diff)
DocsUI: Don't crash on invalid window sizes.
Our layout code asserts when passed an (invalid) width of 0. The assert is unnecessary as we already handle this situation by always laying out the content pane with a column count of at least 1. Also, per Steve, bump the minimum column count in grid mode to 2. BUG=27150284 Change-Id: I8aa87beaaf4907ef5248999d0c590deef732589f
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java7
1 files changed, 3 insertions, 4 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java
index bfc8d71c3fdf..438edc972795 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java
@@ -98,7 +98,6 @@ import com.android.documentsui.model.RootInfo;
import com.android.documentsui.services.FileOperationService;
import com.android.documentsui.services.FileOperationService.OpType;
import com.android.documentsui.services.FileOperations;
-
import com.google.common.collect.Lists;
import java.lang.annotation.Retention;
@@ -406,9 +405,9 @@ public class DirectoryFragment extends Fragment
int cellMargin = 2 * getResources().getDimensionPixelSize(R.dimen.grid_item_margin);
int viewPadding = mRecView.getPaddingLeft() + mRecView.getPaddingRight();
- assert(mRecView.getWidth() > 0);
-
- int columnCount = Math.max(1,
+ // RecyclerView sometimes gets a width of 0 (see b/27150284). Clamp so that we always lay
+ // out the grid with at least 2 columns.
+ int columnCount = Math.max(2,
(mRecView.getWidth() - viewPadding) / (cellWidth + cellMargin));
return columnCount;