金坛河长通 v1.1.6版本的 MD5 值为:20e883288031684b3415ea19cd21af4d
以下内容为反编译后的 GestureImageView.java 源代码,内容仅作参考
package com.polites.android;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import java.io.InputStream;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
public class GestureImageView extends ImageView {
private static int[] $SWITCH_TABLE$android$widget$ImageView$ScaleType = null;
public static final String GLOBAL_NS = "http://schemas.android.com/apk/res/android";
public static final String LOCAL_NS = "http://schemas.polites.com/android";
private int alpha;
private Animator animator;
private float centerX;
private float centerY;
private ColorFilter colorFilter;
private View.OnTouchListener customOnTouchListener;
private int deviceOrientation;
private int displayHeight;
private int displayWidth;
private final Semaphore drawLock;
private Drawable drawable;
private float fitScaleHorizontal;
private float fitScaleVertical;
private GestureImageViewListener gestureImageViewListener;
private GestureImageViewTouchListener gestureImageViewTouchListener;
private int hHeight;
private int hWidth;
private int imageOrientation;
private boolean layout;
private float maxScale;
private float minScale;
private View.OnClickListener onClickListener;
private boolean recycle;
private int resId;
private float rotation;
private float scale;
private float scaleAdjust;
private Float startX;
private Float startY;
private float startingScale;
private boolean strict;
private float x;
private float y;
static int[] $SWITCH_TABLE$android$widget$ImageView$ScaleType() {
int[] iArr = $SWITCH_TABLE$android$widget$ImageView$ScaleType;
if (iArr == null) {
iArr = new int[ImageView.ScaleType.values().length];
try {
iArr[ImageView.ScaleType.CENTER.ordinal()] = 1;
} catch (NoSuchFieldError e) {
}
try {
iArr[ImageView.ScaleType.CENTER_CROP.ordinal()] = 2;
} catch (NoSuchFieldError e2) {
}
try {
iArr[ImageView.ScaleType.CENTER_INSIDE.ordinal()] = 3;
} catch (NoSuchFieldError e3) {
}
try {
iArr[ImageView.ScaleType.FIT_CENTER.ordinal()] = 4;
} catch (NoSuchFieldError e4) {
}
try {
iArr[ImageView.ScaleType.FIT_END.ordinal()] = 5;
} catch (NoSuchFieldError e5) {
}
try {
iArr[ImageView.ScaleType.FIT_START.ordinal()] = 6;
} catch (NoSuchFieldError e6) {
}
try {
iArr[ImageView.ScaleType.FIT_XY.ordinal()] = 7;
} catch (NoSuchFieldError e7) {
}
try {
iArr[ImageView.ScaleType.MATRIX.ordinal()] = 8;
} catch (NoSuchFieldError e8) {
}
$SWITCH_TABLE$android$widget$ImageView$ScaleType = iArr;
}
return iArr;
}
public GestureImageView(Context context, AttributeSet attrs, int defStyle) {
this(context, attrs);
}
public GestureImageView(Context context, AttributeSet attrs) {
super(context, attrs);
this.drawLock = new Semaphore(0);
this.x = 0.0f;
this.y = 0.0f;
this.layout = false;
this.scaleAdjust = 1.0f;
this.startingScale = -1.0f;
this.scale = 1.0f;
this.maxScale = 5.0f;
this.minScale = 0.75f;
this.fitScaleHorizontal = 1.0f;
this.fitScaleVertical = 1.0f;
this.rotation = 0.0f;
this.resId = -1;
this.recycle = false;
this.strict = false;
this.alpha = 255;
this.deviceOrientation = -1;
String scaleType = attrs.getAttributeValue(GLOBAL_NS, "scaleType");
if (scaleType == null || scaleType.trim().length() == 0) {
setScaleType(ImageView.ScaleType.CENTER_INSIDE);
}
String strStartX = attrs.getAttributeValue(LOCAL_NS, "start-x");
String strStartY = attrs.getAttributeValue(LOCAL_NS, "start-y");
if (strStartX != null && strStartX.trim().length() > 0) {
this.startX = Float.valueOf(Float.parseFloat(strStartX));
}
if (strStartY != null && strStartY.trim().length() > 0) {
this.startY = Float.valueOf(Float.parseFloat(strStartY));
}
setStartingScale(attrs.getAttributeFloatValue(LOCAL_NS, "start-scale", this.startingScale));
setMinScale(attrs.getAttributeFloatValue(LOCAL_NS, "min-scale", this.minScale));
setMaxScale(attrs.getAttributeFloatValue(LOCAL_NS, "max-scale", this.maxScale));
setStrict(attrs.getAttributeBooleanValue(LOCAL_NS, "strict", this.strict));
setRecycle(attrs.getAttributeBooleanValue(LOCAL_NS, "recycle", this.recycle));
initImage();
}
public GestureImageView(Context context) {
super(context);
this.drawLock = new Semaphore(0);
this.x = 0.0f;
this.y = 0.0f;
this.layout = false;
this.scaleAdjust = 1.0f;
this.startingScale = -1.0f;
this.scale = 1.0f;
this.maxScale = 5.0f;
this.minScale = 0.75f;
this.fitScaleHorizontal = 1.0f;
this.fitScaleVertical = 1.0f;
this.rotation = 0.0f;
this.resId = -1;
this.recycle = false;
this.strict = false;
this.alpha = 255;
this.deviceOrientation = -1;
setScaleType(ImageView.ScaleType.CENTER_INSIDE);
initImage();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (this.drawable != null) {
int orientation = getResources().getConfiguration().orientation;
if (orientation == 2) {
this.displayHeight = View.MeasureSpec.getSize(heightMeasureSpec);
if (getLayoutParams().width == -2) {
float ratio = getImageWidth() / getImageHeight();
this.displayWidth = Math.round(this.displayHeight * ratio);
} else {
this.displayWidth = View.MeasureSpec.getSize(widthMeasureSpec);
}
} else {
this.displayWidth = View.MeasureSpec.getSize(widthMeasureSpec);
if (getLayoutParams().height == -2) {
float ratio2 = getImageHeight() / getImageWidth();
this.displayHeight = Math.round(this.displayWidth * ratio2);
} else {
this.displayHeight = View.MeasureSpec.getSize(heightMeasureSpec);
}
}
} else {
this.displayHeight = View.MeasureSpec.getSize(heightMeasureSpec);
this.displayWidth = View.MeasureSpec.getSize(widthMeasureSpec);
}
setMeasuredDimension(this.displayWidth, this.displayHeight);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (changed || !this.layout) {
setupCanvas(this.displayWidth, this.displayHeight, getResources().getConfiguration().orientation);
}
}
protected void setupCanvas(int measuredWidth, int measuredHeight, int orientation) {
if (this.deviceOrientation != orientation) {
this.layout = false;
this.deviceOrientation = orientation;
}
if (this.drawable != null && !this.layout) {
int imageWidth = getImageWidth();
int imageHeight = getImageHeight();
this.hWidth = Math.round(imageWidth / 2.0f);
this.hHeight = Math.round(imageHeight / 2.0f);
int measuredWidth2 = measuredWidth - (getPaddingLeft() + getPaddingRight());
int measuredHeight2 = measuredHeight - (getPaddingTop() + getPaddingBottom());
computeCropScale(imageWidth, imageHeight, measuredWidth2, measuredHeight2);
if (this.startingScale <= 0.0f) {
computeStartingScale(imageWidth, imageHeight, measuredWidth2, measuredHeight2);
}
this.scaleAdjust = this.startingScale;
this.centerX = measuredWidth2 / 2.0f;
this.centerY = measuredHeight2 / 2.0f;
if (this.startX == null) {
this.x = this.centerX;
} else {
this.x = this.startX.floatValue();
}
if (this.startY == null) {
this.y = this.centerY;
} else {
this.y = this.startY.floatValue();
}
this.gestureImageViewTouchListener = new GestureImageViewTouchListener(this, measuredWidth2, measuredHeight2);
if (isLandscape()) {
this.gestureImageViewTouchListener.setMinScale(this.minScale * this.fitScaleHorizontal);
} else {
this.gestureImageViewTouchListener.setMinScale(this.minScale * this.fitScaleVertical);
}
this.gestureImageViewTouchListener.setMaxScale(this.maxScale * this.startingScale);
this.gestureImageViewTouchListener.setFitScaleHorizontal(this.fitScaleHorizontal);
this.gestureImageViewTouchListener.setFitScaleVertical(this.fitScaleVertical);
this.gestureImageViewTouchListener.setCanvasWidth(measuredWidth2);
this.gestureImageViewTouchListener.setCanvasHeight(measuredHeight2);
this.gestureImageViewTouchListener.setOnClickListener(this.onClickListener);
this.drawable.setBounds(-this.hWidth, -this.hHeight, this.hWidth, this.hHeight);
super.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (GestureImageView.this.customOnTouchListener != null) {
GestureImageView.this.customOnTouchListener.onTouch(v, event);
}
return GestureImageView.this.gestureImageViewTouchListener.onTouch(v, event);
}
});
this.layout = true;
}
}
protected void computeCropScale(int imageWidth, int imageHeight, int measuredWidth, int measuredHeight) {
this.fitScaleHorizontal = measuredWidth / imageWidth;
this.fitScaleVertical = measuredHeight / imageHeight;
}
protected void computeStartingScale(int imageWidth, int imageHeight, int measuredWidth, int measuredHeight) {
switch ($SWITCH_TABLE$android$widget$ImageView$ScaleType()[getScaleType().ordinal()]) {
case 1:
this.startingScale = 1.0f;
return;
case 2:
this.startingScale = Math.max(measuredHeight / imageHeight, measuredWidth / imageWidth);
return;
case 3:
float wRatio = imageWidth / measuredWidth;
float hRatio = imageHeight / measuredHeight;
if (wRatio > hRatio) {
this.startingScale = this.fitScaleHorizontal;
return;
} else {
this.startingScale = this.fitScaleVertical;
return;
}
default:
return;
}
}
protected boolean isRecycled() {
Bitmap bitmap;
if (this.drawable == null || !(this.drawable instanceof BitmapDrawable) || (bitmap = ((BitmapDrawable) this.drawable).getBitmap()) == null) {
return false;
}
return bitmap.isRecycled();
}
protected void recycle() {
Bitmap bitmap;
if (this.recycle && this.drawable != null && (this.drawable instanceof BitmapDrawable) && (bitmap = ((BitmapDrawable) this.drawable).getBitmap()) != null) {
bitmap.recycle();
}
}
@Override
protected void onDraw(Canvas canvas) {
if (this.layout) {
if (this.drawable != null && !isRecycled()) {
canvas.save();
float adjustedScale = this.scale * this.scaleAdjust;
canvas.translate(this.x, this.y);
if (this.rotation != 0.0f) {
canvas.rotate(this.rotation);
}
if (adjustedScale != 1.0f) {
canvas.scale(adjustedScale, adjustedScale);
}
this.drawable.draw(canvas);
canvas.restore();
}
if (this.drawLock.availablePermits() <= 0) {
this.drawLock.release();
}
}
}
public boolean waitForDraw(long timeout) throws InterruptedException {
return this.drawLock.tryAcquire(timeout, TimeUnit.MILLISECONDS);
}
@Override
protected void onAttachedToWindow() {
this.animator = new Animator(this, "GestureImageViewAnimator");
this.animator.start();
if (this.resId >= 0 && this.drawable == null) {
setImageResource(this.resId);
}
super.onAttachedToWindow();
}
public void animationStart(Animation animation) {
if (this.animator != null) {
this.animator.play(animation);
}
}
public void animationStop() {
if (this.animator != null) {
this.animator.cancel();
}
}
@Override
protected void onDetachedFromWindow() {
if (this.animator != null) {
this.animator.finish();
}
if (this.recycle && this.drawable != null && !isRecycled()) {
recycle();
this.drawable = null;
}
super.onDetachedFromWindow();
}
protected void initImage() {
if (this.drawable != null) {
this.drawable.setAlpha(this.alpha);
this.drawable.setFilterBitmap(true);
if (this.colorFilter != null) {
this.drawable.setColorFilter(this.colorFilter);
}
}
if (!this.layout) {
requestLayout();
redraw();
}
}
@Override
public void setImageBitmap(Bitmap image) {
this.drawable = new BitmapDrawable(getResources(), image);
initImage();
}
@Override
public void setImageDrawable(Drawable drawable) {
this.drawable = drawable;
initImage();
}
@Override
public void setImageResource(int id) {
if (this.drawable != null) {
recycle();
}
if (id >= 0) {
this.resId = id;
setImageDrawable(getContext().getResources().getDrawable(id));
}
}
public int getScaledWidth() {
return Math.round(getImageWidth() * getScale());
}
public int getScaledHeight() {
return Math.round(getImageHeight() * getScale());
}
public int getImageWidth() {
if (this.drawable != null) {
return this.drawable.getIntrinsicWidth();
}
return 0;
}
public int getImageHeight() {
if (this.drawable != null) {
return this.drawable.getIntrinsicHeight();
}
return 0;
}
public void moveBy(float x, float y) {
this.x += x;
this.y += y;
}
public void setPosition(float x, float y) {
this.x = x;
this.y = y;
}
public void redraw() {
postInvalidate();
}
public void setMinScale(float min) {
this.minScale = min;
if (this.gestureImageViewTouchListener != null) {
this.gestureImageViewTouchListener.setMinScale(this.fitScaleHorizontal * min);
}
}
public void setMaxScale(float max) {
this.maxScale = max;
if (this.gestureImageViewTouchListener != null) {
this.gestureImageViewTouchListener.setMaxScale(this.startingScale * max);
}
}
public void setScale(float scale) {
this.scaleAdjust = scale;
}
public float getScale() {
return this.scaleAdjust;
}
public float getImageX() {
return this.x;
}
public float getImageY() {
return this.y;
}
public boolean isStrict() {
return this.strict;
}
public void setStrict(boolean strict) {
this.strict = strict;
}
public boolean isRecycle() {
return this.recycle;
}
public void setRecycle(boolean recycle) {
this.recycle = recycle;
}
public void reset() {
this.x = this.centerX;
this.y = this.centerY;
this.scaleAdjust = this.startingScale;
if (this.gestureImageViewTouchListener != null) {
this.gestureImageViewTouchListener.reset();
}
redraw();
}
@Override
public void setRotation(float rotation) {
this.rotation = rotation;
}
public void setGestureImageViewListener(GestureImageViewListener pinchImageViewListener) {
this.gestureImageViewListener = pinchImageViewListener;
}
public GestureImageViewListener getGestureImageViewListener() {
return this.gestureImageViewListener;
}
@Override
public Drawable getDrawable() {
return this.drawable;
}
@Override
public void setAlpha(int alpha) {
this.alpha = alpha;
if (this.drawable != null) {
this.drawable.setAlpha(alpha);
}
}
@Override
public void setColorFilter(ColorFilter cf) {
this.colorFilter = cf;
if (this.drawable != null) {
this.drawable.setColorFilter(cf);
}
}
@Override
public void setImageURI(Uri mUri) {
if ("content".equals(mUri.getScheme())) {
try {
String[] orientationColumn = {"orientation"};
Cursor cur = getContext().getContentResolver().query(mUri, orientationColumn, null, null, null);
if (cur != null && cur.moveToFirst()) {
this.imageOrientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
}
InputStream in = null;
try {
in = getContext().getContentResolver().openInputStream(mUri);
Bitmap bmp = BitmapFactory.decodeStream(in);
if (this.imageOrientation != 0) {
Matrix m = new Matrix();
m.postRotate(this.imageOrientation);
Bitmap rotated = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), m, true);
bmp.recycle();
setImageDrawable(new BitmapDrawable(getResources(), rotated));
} else {
setImageDrawable(new BitmapDrawable(getResources(), bmp));
}
} finally {
if (in != null) {
in.close();
}
if (cur != null) {
cur.close();
}
}
} catch (Exception e) {
Log.w("GestureImageView", "Unable to open content: " + mUri, e);
}
} else {
setImageDrawable(Drawable.createFromPath(mUri.toString()));
}
if (this.drawable == null) {
Log.e("GestureImageView", "resolveUri failed on bad bitmap uri: " + mUri);
}
}
@Override
public Matrix getImageMatrix() {
if (this.strict) {
throw new UnsupportedOperationException("Not supported");
}
return super.getImageMatrix();
}
@Override
public void setScaleType(ImageView.ScaleType scaleType) {
if (scaleType == ImageView.ScaleType.CENTER || scaleType == ImageView.ScaleType.CENTER_CROP || scaleType == ImageView.ScaleType.CENTER_INSIDE) {
super.setScaleType(scaleType);
} else if (this.strict) {
throw new UnsupportedOperationException("Not supported");
}
}
@Override
public void invalidateDrawable(Drawable dr) {
if (this.strict) {
throw new UnsupportedOperationException("Not supported");
}
super.invalidateDrawable(dr);
}
@Override
public int[] onCreateDrawableState(int extraSpace) {
if (this.strict) {
throw new UnsupportedOperationException("Not supported");
}
return super.onCreateDrawableState(extraSpace);
}
@Override
public void setAdjustViewBounds(boolean adjustViewBounds) {
if (this.strict) {
throw new UnsupportedOperationException("Not supported");
}
super.setAdjustViewBounds(adjustViewBounds);
}
@Override
public void setImageLevel(int level) {
if (this.strict) {
throw new UnsupportedOperationException("Not supported");
}
super.setImageLevel(level);
}
@Override
public void setImageMatrix(Matrix matrix) {
if (this.strict) {
throw new UnsupportedOperationException("Not supported");
}
}
@Override
public void setImageState(int[] state, boolean merge) {
if (this.strict) {
throw new UnsupportedOperationException("Not supported");
}
}
@Override
public void setSelected(boolean selected) {
if (this.strict) {
throw new UnsupportedOperationException("Not supported");
}
super.setSelected(selected);
}
@Override
public void setOnTouchListener(View.OnTouchListener l) {
this.customOnTouchListener = l;
}
public float getCenterX() {
return this.centerX;
}
public float getCenterY() {
return this.centerY;
}
public boolean isLandscape() {
return getImageWidth() >= getImageHeight();
}
public boolean isPortrait() {
return getImageWidth() <= getImageHeight();
}
public void setStartingScale(float startingScale) {
this.startingScale = startingScale;
}
public void setStartingPosition(float x, float y) {
this.startX = Float.valueOf(x);
this.startY = Float.valueOf(y);
}
@Override
public void setOnClickListener(View.OnClickListener l) {
this.onClickListener = l;
if (this.gestureImageViewTouchListener != null) {
this.gestureImageViewTouchListener.setOnClickListener(l);
}
}
public boolean isOrientationAligned() {
if (this.deviceOrientation == 2) {
return isLandscape();
}
if (this.deviceOrientation == 1) {
return isPortrait();
}
return true;
}
public int getDeviceOrientation() {
return this.deviceOrientation;
}
}