private int calculateNewZoom(int flag) { mNewZoom = mZoom; if (mZoom < mStdMinZoom) { mNewZoom = mStdMinZoom; flag |= AnimationFlag.ZOOM; } else if (mZoom > mStdMaxZoom) { mNewZoom = mStdMaxZoom; flag |= AnimationFlag.ZOOM; } mDeltaZoom = (mNewZoom - mZoom) / 3; logd("mZoom = " + mZoom); logd("mStdMinZoom,mStdMaxZoom =" + mStdMinZoom + "," + mStdMaxZoom); return flag; }
// --参数计算--------------------------------------------------------------- public void resetZoomState(ImageZoomView view, Bitmap bitmap) { mView = view; mBitmap = bitmap; mAspectQuotient = -1; do { if (null == mView || null == mBitmap) { break; } if (mView.getHeight() <= 0 || mView.getWidth() <= 0 || mBitmap.getHeight() <= 0 || mBitmap.getWidth() <= 0) { break; } mAspectQuotient = (((float) mBitmap.getWidth()) / mBitmap.getHeight()) / (((float) mView.getWidth()) / mView.getHeight()); logd("mAspectQuotient = " + mAspectQuotient); calculateMinMaxZoom(); calculateMinMaxPanX(); calculateMinMaxPanY(); // 初始化OK,通知外部,显示小图标 setZoomChanged(); notifyObservers(); } while (false); }
public void setPanY(float panY) { panY = adjustPanY(panY); if (!floatEquel(panY, mPanY)) { mPanY = panY; logd("----> mPanY = " + mPanY); setZoomChanged(); } }
public void setPanX(float panX) { panX = adjustPanX(panX); if (!floatEquel(panX, mPanX)) { mPanX = panX; logd("----> mPanX = " + mPanX); setZoomChanged(); } }
public void setZoom(float zoom) { zoom = adjustZoom(zoom); if (!floatEquel(zoom, mZoom)) { mZoom = zoom; logd("----> mZoom = " + mZoom); calculateMinMaxPanX(); calculateMinMaxPanY(); setZoomChanged(); } }
private void calculateMinMaxPanY() { if (mAspectQuotient > 0) { float bmpH = mBitmap.getHeight(); float viewH = mView.getHeight(); float zoomY = getZoomY(); mStdMinPanY = viewH / (zoomY * 2 * bmpH); mStdMaxPanY = 1 - mStdMinPanY; if (mAspectQuotient > 1) { if (mZoom <= mMidZoom) { // 上下两边出现空隙时,居中显示 mStdMinPanY = mStdMaxPanY = 0.5f; } } else { if (mZoom <= mStdMinZoom) { mStdMinPanY = mStdMaxPanY = 0.5f; } } mMinPanY = (viewH / 2 + 10) / (zoomY * 2 * bmpH); mMaxPanY = 1 - mMinPanY; logd("mStdMinPanY,mStdMaxPanY =" + mStdMinPanY + "," + mStdMaxPanY); logd("mMinPanY,mMaxPanY =" + mMinPanY + "," + mMaxPanY); } }
private void calculateMinMaxZoom() { if (mAspectQuotient > 0) { float bmpW = mBitmap.getWidth(); float viewW = mView.getWidth(); float bmpH = mBitmap.getHeight(); float viewH = mView.getHeight(); if (mAspectQuotient > 1) { mStdMinZoom = 1; mMidZoom = mAspectQuotient; mStdMaxZoom = bmpW / viewW; } else { mStdMinZoom = 1; mMidZoom = 1 / mAspectQuotient; mStdMaxZoom = bmpH / viewH; } mZoom = mStdMinZoom; mMinZoom = mStdMinZoom * (1 - 0.35f); mMaxZoom = mStdMaxZoom * (1 + 0.2f); logd("mStdMinZoom,mStdMaxZoom =" + mStdMinZoom + "," + mStdMaxZoom); logd("mMinZoom,mMidZoom,mMaxZoom =" + mMinZoom + "," + mMidZoom + "," + mMaxZoom); } }