Skip to content

Commit

Permalink
Merge pull request #272 from yanchenko/master
Browse files Browse the repository at this point in the history
NPE fix for ImageView without LayoutParams.
  • Loading branch information
nostra13 committed May 16, 2013
2 parents 8f36a41 + 6f39b40 commit e582e41
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public static ImageSize defineTargetSizeForView(ImageView imageView, int maxImag
final DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics();

final LayoutParams params = imageView.getLayoutParams();
int width = params.width == LayoutParams.WRAP_CONTENT ? 0 : imageView.getWidth(); // Get actual image width
if (width <= 0) width = params.width; // Get layout width parameter
int width = (params != null && params.width == LayoutParams.WRAP_CONTENT) ? 0 : imageView.getWidth(); // Get actual image width
if (width <= 0) width = (params != null) ? params.width : width; // Get layout width parameter
if (width <= 0) width = getImageViewFieldValue(imageView, "mMaxWidth"); // Check maxWidth parameter
if (width <= 0) width = maxImageWidth;
if (width <= 0) width = displayMetrics.widthPixels;

int height = params.height == LayoutParams.WRAP_CONTENT ? 0 : imageView.getHeight(); // Get actual image height
if (height <= 0) height = params.height; // Get layout height parameter
int height = (params != null && params.height == LayoutParams.WRAP_CONTENT) ? 0 : imageView.getHeight(); // Get actual image height
if (height <= 0) height = (params != null) ? params.height : height; // Get layout height parameter
if (height <= 0) height = getImageViewFieldValue(imageView, "mMaxHeight"); // Check maxHeight parameter
if (height <= 0) height = maxImageHeight;
if (height <= 0) height = displayMetrics.heightPixels;
Expand Down

0 comments on commit e582e41

Please sign in to comment.