ScaleImageView.java 6.71 KB
package com.instabug.library.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

public class ScaleImageView
  extends ImageView
  implements View.OnTouchListener
{
  String a = "ScaleImageView";
  private Context b;
  private float c = 5.0F;
  private Matrix d;
  private final float[] e = new float[9];
  private int f;
  private int g;
  private int h;
  private int i;
  private float j;
  private float k;
  private float l;
  private boolean m;
  private int n;
  private int o;
  private GestureDetector p;
  
  public ScaleImageView(Context paramContext)
  {
    super(paramContext);
    this.b = paramContext;
    b();
  }
  
  public ScaleImageView(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    this.b = paramContext;
    b();
  }
  
  private static float a(float paramFloat1, float paramFloat2, float paramFloat3, float paramFloat4)
  {
    paramFloat1 -= paramFloat2;
    paramFloat2 = paramFloat3 - paramFloat4;
    return (float)Math.sqrt(paramFloat1 * paramFloat1 + paramFloat2 * paramFloat2);
  }
  
  private void b()
  {
    setScaleType(ImageView.ScaleType.MATRIX);
    this.d = new Matrix();
    Drawable localDrawable = getDrawable();
    if (localDrawable != null)
    {
      this.h = localDrawable.getIntrinsicWidth();
      this.i = localDrawable.getIntrinsicHeight();
      setOnTouchListener(this);
    }
    this.p = new GestureDetector(this.b, new GestureDetector.SimpleOnGestureListener()
    {
      public final boolean onDoubleTap(MotionEvent paramAnonymousMotionEvent)
      {
        ScaleImageView.this.a((int)paramAnonymousMotionEvent.getX(), (int)paramAnonymousMotionEvent.getY());
        ScaleImageView.this.a();
        return super.onDoubleTap(paramAnonymousMotionEvent);
      }
    });
  }
  
  protected float a(Matrix paramMatrix, int paramInt)
  {
    paramMatrix.getValues(this.e);
    return this.e[paramInt];
  }
  
  public void a()
  {
    int i1 = (int)(this.h * getScale());
    int i2 = (int)(this.i * getScale());
    if (getTranslateX() < -(i1 - this.f)) {
      this.d.postTranslate(-(getTranslateX() + i1 - this.f), 0.0F);
    }
    if (getTranslateX() > 0.0F) {
      this.d.postTranslate(-getTranslateX(), 0.0F);
    }
    if (getTranslateY() < -(i2 - this.g)) {
      this.d.postTranslate(0.0F, -(getTranslateY() + i2 - this.g));
    }
    if (getTranslateY() > 0.0F) {
      this.d.postTranslate(0.0F, -getTranslateY());
    }
    if (i1 < this.f) {
      this.d.postTranslate((this.f - i1) / 2, 0.0F);
    }
    if (i2 < this.g) {
      this.d.postTranslate(0.0F, (this.g - i2) / 2);
    }
    setImageMatrix(this.d);
  }
  
  public void a(float paramFloat, int paramInt1, int paramInt2)
  {
    if (getScale() * paramFloat < this.k) {}
    while ((paramFloat >= 1.0F) && (getScale() * paramFloat > this.c)) {
      return;
    }
    this.d.postScale(paramFloat, paramFloat);
    this.d.postTranslate(-(this.f * paramFloat - this.f) / 2.0F, -(this.g * paramFloat - this.g) / 2.0F);
    this.d.postTranslate(-(paramInt1 - this.f / 2) * paramFloat, 0.0F);
    this.d.postTranslate(0.0F, -(paramInt2 - this.g / 2) * paramFloat);
    setImageMatrix(this.d);
  }
  
  protected void a(int paramInt1, int paramInt2)
  {
    if ((this.k != getScale()) && (getScale() - this.k > 0.1F))
    {
      a(this.k / getScale(), paramInt1, paramInt2);
      return;
    }
    a(this.c / getScale(), paramInt1, paramInt2);
  }
  
  protected float getScale()
  {
    return a(this.d, 0);
  }
  
  public float getTranslateX()
  {
    return a(this.d, 2);
  }
  
  protected float getTranslateY()
  {
    return a(this.d, 5);
  }
  
  public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
  {
    return super.onTouchEvent(paramMotionEvent);
  }
  
  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    if (this.p.onTouchEvent(paramMotionEvent)) {}
    do
    {
      do
      {
        return true;
        i1 = paramMotionEvent.getPointerCount();
        switch (paramMotionEvent.getAction())
        {
        default: 
          return true;
        case 0: 
        case 5: 
        case 261: 
          if (i1 >= 2)
          {
            this.l = a(paramMotionEvent.getX(0), paramMotionEvent.getX(1), paramMotionEvent.getY(0), paramMotionEvent.getY(1));
            this.m = true;
          }
        case 2: 
          while ((i1 >= 2) && (this.m))
          {
            float f1 = a(paramMotionEvent.getX(0), paramMotionEvent.getX(1), paramMotionEvent.getY(0), paramMotionEvent.getY(1));
            float f2 = (f1 - this.l) / (float)Math.sqrt(this.f * this.f + this.g * this.g);
            this.l = f1;
            f1 = 1.0F + f2;
            a(f1 * f1, this.f / 2, this.g / 2);
            a();
            return true;
            this.n = ((int)paramMotionEvent.getX());
            this.o = ((int)paramMotionEvent.getY());
          }
        }
      } while (this.m);
      int i1 = this.n;
      int i2 = (int)paramMotionEvent.getX();
      int i3 = this.o;
      int i4 = (int)paramMotionEvent.getY();
      this.n = ((int)paramMotionEvent.getX());
      this.o = ((int)paramMotionEvent.getY());
      this.d.postTranslate(-(i1 - i2), -(i3 - i4));
      a();
      return true;
    } while (paramMotionEvent.getPointerCount() > 1);
    this.m = false;
    return true;
  }
  
  protected boolean setFrame(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    int i2 = 0;
    this.f = (paramInt3 - paramInt1);
    this.g = (paramInt4 - paramInt2);
    this.d.reset();
    this.j = ((paramInt3 - paramInt1) / this.h);
    if (this.j * this.i > this.g)
    {
      this.j = (this.g / this.i);
      this.d.postScale(this.j, this.j);
    }
    for (int i1 = (paramInt3 - this.f) / 2;; i1 = 0)
    {
      this.d.postTranslate(i1, i2);
      setImageMatrix(this.d);
      this.k = this.j;
      a(this.j, this.f / 2, this.g / 2);
      a();
      return super.setFrame(paramInt1, paramInt2, paramInt3, paramInt4);
      this.d.postScale(this.j, this.j);
      i2 = (paramInt4 - this.g) / 2;
    }
  }
  
  public void setImageBitmap(Bitmap paramBitmap)
  {
    super.setImageBitmap(paramBitmap);
    b();
  }
  
  public void setImageResource(int paramInt)
  {
    super.setImageResource(paramInt);
    b();
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/instabug/library/view/ScaleImageView.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */