Skip to content

Commit ba5070b

Browse files
committed
Merge pull request etsy#88 from jstralko/master
Properly detech the orientation of the device.
2 parents 8fe5f82 + 73f6e1b commit ba5070b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

library/src/main/java/com/etsy/android/grid/StaggeredGridView.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.etsy.android.grid;
1818

1919
import android.content.Context;
20+
import android.content.res.Configuration;
2021
import android.content.res.TypedArray;
2122
import android.os.Parcel;
2223
import android.os.Parcelable;
@@ -241,13 +242,16 @@ public void setColumnCount(int columnCount) {
241242
// //////////////////////////////////////////////////////////////////////////////////////////
242243
// MEASUREMENT
243244
//
245+
private boolean isLandscape() {
246+
return getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? true : false;
247+
}
244248

245249
@Override
246250
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
247251
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
248252

249253
if (mColumnCount <= 0) {
250-
boolean isLandscape = getMeasuredWidth() > getMeasuredHeight();
254+
boolean isLandscape = isLandscape();
251255
mColumnCount = isLandscape ? mColumnCountLandscape : mColumnCountPortrait;
252256
}
253257

@@ -860,7 +864,7 @@ protected void onSizeChanged(final int w, final int h, final int oldw, final int
860864
@Override
861865
protected void onSizeChanged(int w, int h) {
862866
super.onSizeChanged(w, h);
863-
boolean isLandscape = w > h;
867+
boolean isLandscape = isLandscape();
864868
int newColumnCount = isLandscape ? mColumnCountLandscape : mColumnCountPortrait;
865869
if (mColumnCount != newColumnCount) {
866870
mColumnCount = newColumnCount;

0 commit comments

Comments
 (0)