'无法解析为变量'错误:ImageDisplayView

时间:2013-12-31 04:13:10

标签: java android

public class ImageDisplayView1
  extends View
  implements View.OnTouchListener
{
  public static float MAX_SCALE_RATIO = 5.0F;
  public static float MIN_SCALE_RATIO = 0.1F;
  float bitmapCenterX;
  float bitmapCenterY;
  int displayCenterX = 0;
  int displayCenterY = 0;
  float displayHeight = 0.0F;
  float displayWidth = 0.0F;
  float distanceThreshold = 3.0F;
  boolean isScrolling = false;
  int lastX;
  int lastY;
  Bitmap mBitmap;
  Canvas mCanvas;
  Context mContext;
  Matrix mMatrix;
  Paint mPaint;
  float oldDistance = 0.0F;
  int oldPointerCount = 0;
  float scaleRatio;
  Bitmap sourceBitmap;
  float sourceHeight = 0.0F;
  float sourceWidth = 0.0F;
  public float startX;
  public float startY;
  float totalScaleRatio;

  public ImageDisplayView1(Context paramContext)
  {
    super(paramContext);
    this.mContext = paramContext;
    init();
  }

  public ImageDisplayView1(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    this.mContext = paramContext;
    init();
  }

  private void init()
  {
    this.mPaint = new Paint();
    this.mMatrix = new Matrix();
    this.lastX = -1;
    this.lastY = -1;
    setOnTouchListener(this);
  }

  private void moveImage(float paramFloat1, float paramFloat2)
  {
    Log.d("test", "moveImage() called : " + paramFloat1 + ", " + paramFloat2);
    this.mMatrix.postTranslate(paramFloat1, paramFloat2);
    redraw();
  }

  private void scaleImage(float paramFloat)
  {
    Log.d("test", "scaleImage() called : " + paramFloat);
    this.mMatrix.postScale(paramFloat, paramFloat, this.bitmapCenterX, this.bitmapCenterY);
    this.mMatrix.postRotate(0.0F);
    this.totalScaleRatio = (paramFloat * this.totalScaleRatio);
    redraw();
  }

  public void drawBackground(Canvas paramCanvas)
  {
    if (paramCanvas != null) {
      paramCanvas.drawColor(-16777216);
    }
  }

  public void newImage(int paramInt1, int paramInt2)
  {
    Bitmap localBitmap = Bitmap.createBitmap(paramInt1, paramInt2, Bitmap.Config.ARGB_8888);
    Canvas localCanvas = new Canvas();
    localCanvas.setBitmap(localBitmap);
    this.mBitmap = localBitmap;
    this.mCanvas = localCanvas;
    this.displayWidth = paramInt1;
    this.displayHeight = paramInt2;
    this.displayCenterX = (paramInt1 / 2);
    this.displayCenterY = (paramInt2 / 2);
  }

  protected void onDraw(Canvas paramCanvas)
  {
    if (this.mBitmap != null) {
      paramCanvas.drawBitmap(this.mBitmap, 0.0F, 0.0F, null);
    }
  }

  protected void onSizeChanged(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    if ((paramInt1 > 0) && (paramInt2 > 0))
    {
      newImage(paramInt1, paramInt2);
      redraw();
    }
  }

  public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
  {
    int i = paramMotionEvent.getAction();
    int j = paramMotionEvent.getPointerCount();
    switch (i)
    {
    default: 
    case 0: 
    case 2: 
      float f9;
      for (;;)
      {
        return true;
        if (j == 1)
        {
          float f15 = paramMotionEvent.getX();
          float f16 = paramMotionEvent.getY();
          this.startX = f15;
          this.startY = f16;
        }
        for (;;)
        {
          return true;
          if (j == 2)
          {
            this.oldDistance = 0.0F;
            this.isScrolling = true;
          }
        }
        if (j == 1)
        {
          if (this.isScrolling) {
            return true;
          }
          f11 = paramMotionEvent.getX();
          f12 = paramMotionEvent.getY();
          if (this.startX == 0.0F)
          {
            this.startX = f11;
            this.startY = f12;
            return true;
          }
          f13 = this.startX - f11;
          f14 = this.startY - f12;
          if (this.oldPointerCount != 2)
          {
            if (this.totalScaleRatio > 1.0F) {
              moveImage(-f13, -f14);
            }
            this.startX = f11;
            this.startY = f12;
          }
        }
        while (j != 2)
        {
          float f11;
          float f12;
          float f13;
          float f14;
          this.oldPointerCount = j;
          break;
        }
        float f3 = paramMotionEvent.getX(0);
        float f4 = paramMotionEvent.getY(0);
        float f5 = paramMotionEvent.getX(1);
        float f6 = paramMotionEvent.getY(1);
        float f7 = f3 - f5;
        float f8 = f4 - f6;
        f9 = FloatMath.sqrt(f7 * f7 + f8 * f8);
        if (this.oldDistance != 0.0F) {
          break;
        }
        this.oldDistance = f9;
      }
      float f10;
      if (f9 > this.oldDistance)
      {
        if (f9 - this.oldDistance < this.distanceThreshold) {
          return true;
        }
        f10 = this.scaleRatio + 0.05F * (this.oldDistance / f9);
        label335:
        if ((f10 >= MIN_SCALE_RATIO) && (f10 <= MAX_SCALE_RATIO)) {
          break label439;
        }
        Log.d("test", "Invalid scaleRatio : " + f10);
      }
      for (;;)
      {
        this.oldDistance = f9;
        break;
        boolean bool = f9 < this.oldDistance;
        f10 = 0.0F;
        if (!bool) {
          break label335;
        }
        if (this.oldDistance - f9 < this.distanceThreshold) {
          return true;
        }
        f10 = this.scaleRatio - 0.05F * (f9 / this.oldDistance);
        break label335;
        label439:
        Log.d("test", "Distance : " + f9 + ", ScaleRatio : " + f10);
        scaleImage(f10);
      }
    }
    if (j == 1)
    {
      float f1 = paramMotionEvent.getX();
      float f2 = paramMotionEvent.getY();
      (this.startX - f1);
      (this.startY - f2);
    }
    for (;;)
    {
      return true;
      this.isScrolling = false;
    }
  }

  public void recycle()
  {
    if (this.sourceBitmap != null) {
      this.sourceBitmap.recycle();
    }
  }

  public void redraw()
  {
    if (this.sourceBitmap == null) {
      return;
    }
    drawBackground(this.mCanvas);
    float f1 = (this.displayWidth - this.sourceBitmap.getWidth()) / 2.0F;
    float f2 = (this.displayHeight - this.sourceBitmap.getHeight()) / 2.0F;
    this.mCanvas.translate(f1, f2);
    this.mCanvas.drawBitmap(this.sourceBitmap, this.mMatrix, this.mPaint);
    this.mCanvas.translate(-f1, -f2);
    invalidate();
  }

  public void setImageData(Bitmap paramBitmap)
  {
    recycle();
    this.sourceBitmap = paramBitmap;
    this.sourceWidth = this.sourceBitmap.getWidth();
    this.sourceHeight = this.sourceBitmap.getHeight();
    this.bitmapCenterX = (this.sourceBitmap.getWidth() / 2);
    this.bitmapCenterY = (this.sourceBitmap.getHeight() / 2);
    this.scaleRatio = 1.0F;
    this.totalScaleRatio = 1.0F;
  }
}

我在使用f11f12f13f14时遇到错误,无法将其解析为变量。有人可以帮忙吗?此外,还有语法错误吗?

2 个答案:

答案 0 :(得分:1)

  f11 = paramMotionEvent.getX();
  f12 = paramMotionEvent.getY();

你在哪里声明了这些f11和f12 ..

记住声明

while (j != 2)
        {
          float f11;
          float f12;
          float f13;
          float f14;
          this.oldPointerCount = j;
          break;
        }

将使f11和f12可用&#34;仅在循环内#34; ..也就是说,你在声明它们之前使用你的变量..

答案 1 :(得分:0)

以下是您问题的代码段

        this.startX = f11;
        this.startY = f12;
      }
    }
    while (j != 2)
    {
      float f11;
      float f12;

正如您所看到的,您在声明它们之前使用它们。此外,您在while循环中声明它们将使其在其他地方无法使用。实际上,它们的声明方式使它们在整个程序中完全无法使用,并且完全没有没有

在您的计划的最开始

float bitmapCenterX;
float bitmapCenterY;

和其他声明,添加行

float f11;
float f12;
float f13;
float f14;