Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4193)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java

Issue 2896313004: Photo Picker dialog: Handle device orientation changes. (Closed)
Patch Set: Address feedback from Theresa Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java
index 18b21dc42e07bf2b1f21a715fdb49477c02aecd9..eae61d5713970d228569b6a18f3db7141fddf5ad 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/photo_picker/PickerCategoryView.java
@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.photo_picker;
import android.app.Activity;
import android.content.Context;
+import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.support.v7.widget.GridLayoutManager;
@@ -60,6 +61,12 @@ public class PickerCategoryView extends RelativeLayout
// The {@link PickerAdapter} for the RecyclerView.
private PickerAdapter mPickerAdapter;
+ // The layout manager for the RecyclerView.
+ private GridLayoutManager mLayoutManager;
+
+ // The decoration to use for the RecyclerView.
+ private GridSpacingItemDecoration mSpacingDecoration;
+
// The {@link SelectionDelegate} keeping track of which images are selected.
private SelectionDelegate<PickerBitmap> mSelectionDelegate;
@@ -124,14 +131,13 @@ public class PickerCategoryView extends RelativeLayout
Button doneButton = (Button) toolbar.findViewById(R.id.done);
doneButton.setOnClickListener(this);
- Rect appRect = new Rect();
- ((Activity) context).getWindow().getDecorView().getWindowVisibleDisplayFrame(appRect);
- calculateGridMetrics(appRect.width());
+ calculateGridMetrics();
- RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(mContext, mColumns);
+ mLayoutManager = new GridLayoutManager(mContext, mColumns);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(mLayoutManager);
- mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(mColumns, mPadding));
+ mSpacingDecoration = new GridSpacingItemDecoration(mColumns, mPadding);
+ mRecyclerView.addItemDecoration(mSpacingDecoration);
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / KILOBYTE);
final int cacheSizeLarge = maxMemory / 2; // 1/2 of the available memory.
@@ -140,6 +146,17 @@ public class PickerCategoryView extends RelativeLayout
mHighResBitmaps = new LruCache<String, Bitmap>(cacheSizeLarge);
}
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+
+ calculateGridMetrics();
+ mLayoutManager.setSpanCount(mColumns);
+ mRecyclerView.removeItemDecoration(mSpacingDecoration);
+ mSpacingDecoration = new GridSpacingItemDecoration(mColumns, mPadding);
+ mRecyclerView.addItemDecoration(mSpacingDecoration);
+ }
+
/**
* Severs the connection to the decoding utility process and cancels any outstanding requests.
*/
@@ -266,9 +283,12 @@ public class PickerCategoryView extends RelativeLayout
/**
* Calculates image size and how many columns can fit on-screen.
- * @param width The total width of the boundary to show the images in.
*/
- private void calculateGridMetrics(int width) {
+ private void calculateGridMetrics() {
+ Rect appRect = new Rect();
+ ((Activity) mContext).getWindow().getDecorView().getWindowVisibleDisplayFrame(appRect);
+
+ int width = appRect.width();
int minSize =
mContext.getResources().getDimensionPixelSize(R.dimen.photo_picker_tile_min_size);
mPadding = mContext.getResources().getDimensionPixelSize(R.dimen.photo_picker_tile_gap);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698