Skip to content

Commit

Permalink
// drawable bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
razerdp committed Feb 13, 2017
1 parent 70119ad commit 0b39bc8
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions lib/src/main/java/razerdp/github/com/widget/PhotoContents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -491,20 +492,52 @@ public List<Rect> getContentViewsGlobalVisibleRects() {
return viewRects;
}

public List<Matrix> getContentViewsDrawableMatrixList(){
public List<Rect> getContentViewsDrawableRects() {
final int childCount = getChildCount();
if (childCount <= 0) return null;
List<Rect> 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<Matrix> getContentViewsDrawableMatrixList() {
final int childCount = getChildCount();
if (childCount <= 0) return null;
List<Matrix> 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;

Expand Down

0 comments on commit 0b39bc8

Please sign in to comment.