From 0b39bc822c6e30380cb1ca1573bf95ae09f94ed8 Mon Sep 17 00:00:00 2001 From: razerdp Date: Mon, 13 Feb 2017 17:14:59 +0800 Subject: [PATCH] // drawable bounds --- .../github/com/widget/PhotoContents.java | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/razerdp/github/com/widget/PhotoContents.java b/lib/src/main/java/razerdp/github/com/widget/PhotoContents.java index 4447875..f67c75f 100644 --- a/lib/src/main/java/razerdp/github/com/widget/PhotoContents.java +++ b/lib/src/main/java/razerdp/github/com/widget/PhotoContents.java @@ -3,6 +3,7 @@ import android.content.Context; import android.graphics.Matrix; import android.graphics.Rect; +import android.graphics.drawable.Drawable; import android.support.annotation.NonNull; import android.util.AttributeSet; import android.util.SparseArray; @@ -491,20 +492,52 @@ public List getContentViewsGlobalVisibleRects() { return viewRects; } - public List getContentViewsDrawableMatrixList(){ + public List getContentViewsDrawableRects() { + final int childCount = getChildCount(); + if (childCount <= 0) return null; + List viewRects = new LinkedList<>(); + for (int i = 0; i < childCount; i++) { + View v = getChildAt(i); + if (v != null) { + Rect rect = getDrawableBounds((ImageView) v); + viewRects.add(rect); + } + } + return viewRects; + } + + public List getContentViewsDrawableMatrixList() { final int childCount = getChildCount(); if (childCount <= 0) return null; List viewMatrixs = new LinkedList<>(); for (int i = 0; i < childCount; i++) { View v = getChildAt(i); - if (v instanceof ImageView&&((ImageView) v).getDrawable()!=null) { - Matrix matrix=((ImageView) v).getImageMatrix(); + if (v instanceof ImageView && ((ImageView) v).getDrawable() != null) { + Matrix matrix = ((ImageView) v).getImageMatrix(); viewMatrixs.add(matrix); } } return viewMatrixs; } + private Rect getDrawableBounds(ImageView iv) { + if (iv == null || iv.getDrawable() == null) return null; + Drawable d = iv.getDrawable(); + Rect result = new Rect(); + Rect tDrawableRect = d.getBounds(); + Matrix drawableMatrix = iv.getImageMatrix(); + + float[] values = new float[9]; + drawableMatrix.getValues(values); + + result.left = (int) values[Matrix.MTRANS_X]; + result.top = (int) values[Matrix.MTRANS_Y]; + result.right = (int) (result.left + tDrawableRect.width() * values[Matrix.MSCALE_X]); + result.bottom = (int) (result.top + tDrawableRect.height() * values[Matrix.MSCALE_Y]); + + return result; + } + //------------------------------------------Interface----------------------------------------------- private OnSetUpChildLayoutParamsListener onSetUpChildLayoutParamsListener;