android.widget.ImageView#getScaleType ( )源码实例Demo

下面列出了android.widget.ImageView#getScaleType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: giffun   文件: GenericRequestBuilder.java
/**
 * Sets the {@link ImageView} the resource will be loaded into, cancels any existing loads into the view, and frees
 * any resources Glide may have previously loaded into the view so they may be reused.
 *
 * @see Glide#clear(android.view.View)
 *
 * @param view The view to cancel previous loads for and load the new resource into.
 * @return The {@link Target} used to wrap the given {@link ImageView}.
 */
public Target<TranscodeType> into(ImageView view) {
    Util.assertMainThread();
    if (view == null) {
        throw new IllegalArgumentException("You must pass in a non null View");
    }

    if (!isTransformationSet && view.getScaleType() != null) {
        switch (view.getScaleType()) {
            case CENTER_CROP:
                applyCenterCrop();
                break;
            case FIT_CENTER:
            case FIT_START:
            case FIT_END:
                applyFitCenter();
                break;
            //$CASES-OMITTED$
            default:
                // Do nothing.
        }
    }

    return into(glide.buildImageViewTarget(view, transcodeClass));
}
 
private void captureBoundsAndInfo(TransitionValues transitionValues) {
    View view = transitionValues.view;
    if (!(view instanceof ImageView) || view.getVisibility() != View.VISIBLE || isFrescoView(view)) {
        return;
    }
    ImageView imageView = (ImageView) view;
    Drawable drawable = imageView.getDrawable();
    if (drawable == null) {
        return;
    }
    Map<String, Object> values = transitionValues.values;
    int left = view.getLeft();
    int top = view.getTop();
    int right = view.getRight();
    int bottom = view.getBottom();

    Rect bounds = new Rect(left, top, right, bottom);
    values.put(PROPNAME_BOUNDS, bounds);
    values.put(PROPNAME_SCALE_TYPE, imageView.getScaleType());
    if (imageView.getScaleType() == ImageView.ScaleType.MATRIX) {
        values.put(PROPNAME_MATRIX, imageView.getImageMatrix());
    }
}
 
源代码3 项目: SprintNBA   文件: PhotoView.java
public static Info getImageViewInfo(ImageView imgView) {
    int[] p = new int[2];
    getLocation(imgView, p);

    Drawable drawable = imgView.getDrawable();

    Matrix matrix = imgView.getImageMatrix();

    int width = getDrawableWidth(drawable);
    int height = getDrawableHeight(drawable);

    RectF imgRect = new RectF(0, 0, width, height);
    matrix.mapRect(imgRect);

    RectF rect = new RectF(p[0] + imgRect.left, p[1] + imgRect.top, p[0] + imgRect.right, p[1] + imgRect.bottom);
    RectF widgetRect = new RectF(0, 0, imgView.getWidth(), imgView.getHeight());
    RectF baseRect = new RectF(widgetRect);
    PointF screenCenter = new PointF(widgetRect.width() / 2, widgetRect.height() / 2);

    return new Info(rect, imgRect, widgetRect, baseRect, screenCenter, 1, 0, imgView.getScaleType());
}
 
源代码4 项目: school_shop   文件: PhotoViewAttacher.java
private void checkImageViewScaleType() {
	ImageView imageView = getImageView();

	/**
	 * PhotoView's getScaleType() will just divert to this.getScaleType() so
	 * only call if we're not attached to a PhotoView.
	 */
	if (null != imageView && !(imageView instanceof PhotoView)) {
		if (imageView.getScaleType() != ScaleType.MATRIX) {
			throw new IllegalStateException(
					"The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
		}
	}
}
 
源代码5 项目: WifiChat   文件: PhotoViewAttacher.java
private void checkImageViewScaleType() {
    ImageView imageView = getImageView();

    /**
     * PhotoView's getScaleType() will just divert to this.getScaleType() so
     * only call if we're not attached to a PhotoView.
     */
    if (null != imageView && !(imageView instanceof PhotoView)) {
        if (imageView.getScaleType() != ScaleType.MATRIX) {
            throw new IllegalStateException(
                    "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
        }
    }
}
 
/**
 * Captures placement information for Views with a shared element name for
 * Activity Transitions.
 *
 * @param view           The View to capture the placement information for.
 * @param name           The shared element name in the target Activity to apply the placement
 *                       information for.
 * @param transitionArgs Bundle to store shared element placement information.
 * @param tempBounds     A temporary Rect for capturing the current location of views.
 */
protected void captureSharedElementState(View view, String name, Bundle transitionArgs,
        Matrix tempMatrix, RectF tempBounds) {
    Bundle sharedElementBundle = new Bundle();
    tempMatrix.reset();
    view.transformMatrixToGlobal(tempMatrix);
    tempBounds.set(0, 0, view.getWidth(), view.getHeight());
    tempMatrix.mapRect(tempBounds);

    sharedElementBundle.putFloat(KEY_SCREEN_LEFT, tempBounds.left);
    sharedElementBundle.putFloat(KEY_SCREEN_RIGHT, tempBounds.right);
    sharedElementBundle.putFloat(KEY_SCREEN_TOP, tempBounds.top);
    sharedElementBundle.putFloat(KEY_SCREEN_BOTTOM, tempBounds.bottom);
    sharedElementBundle.putFloat(KEY_TRANSLATION_Z, view.getTranslationZ());
    sharedElementBundle.putFloat(KEY_ELEVATION, view.getElevation());

    Parcelable bitmap = null;
    if (mListener != null) {
        bitmap = mListener.onCaptureSharedElementSnapshot(view, tempMatrix, tempBounds);
    }

    if (bitmap != null) {
        sharedElementBundle.putParcelable(KEY_SNAPSHOT, bitmap);
    }

    if (view instanceof ImageView) {
        ImageView imageView = (ImageView) view;
        int scaleTypeInt = scaleTypeToInt(imageView.getScaleType());
        sharedElementBundle.putInt(KEY_SCALE_TYPE, scaleTypeInt);
        if (imageView.getScaleType() == ImageView.ScaleType.MATRIX) {
            float[] matrix = new float[9];
            imageView.getImageMatrix().getValues(matrix);
            sharedElementBundle.putFloatArray(KEY_IMAGE_MATRIX, matrix);
        }
    }

    transitionArgs.putBundle(name, sharedElementBundle);
}
 
源代码7 项目: o2oa   文件: PhotoViewAttacher.java
private void checkImageViewScaleType() {
	ImageView imageView = getImageView();

	/**
	 * PhotoView's getScaleType() will just divert to this.getScaleType() so
	 * only call if we're not attached to a PhotoView.
	 */
	if (null != imageView && !(imageView instanceof PhotoView)) {
		if (imageView.getScaleType() != ScaleType.MATRIX) {
			throw new IllegalStateException(
					"The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
		}
	}
}
 
源代码8 项目: android-discourse   文件: PhotoViewAttacher.java
private void checkImageViewScaleType() {
    ImageView imageView = getImageView();

    /**
     * PhotoView's getScaleType() will just divert to this.getScaleType() so
     * only call if we're not attached to a PhotoView.
     */
    if (null != imageView && !(imageView instanceof IPhotoView)) {
        if (imageView.getScaleType() != ScaleType.MATRIX) {
            throw new IllegalStateException("The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
        }
    }
}
 
源代码9 项目: Oblique   文件: ObliqueView.java
private Matrix setUpScaleType(Bitmap bitmap, ImageView iv, float width, float height) {
    float scaleX = 1, scaleY = 1, dx = 0, dy = 0;
    Matrix shaderMatrix = new Matrix();
    if (bitmap == null) {
        return null;
    }
    shaderMatrix.set(null);
    if (iv.getScaleType() == ImageView.ScaleType.CENTER_CROP) {
        if (width != bitmap.getWidth()) {
            scaleX = width / bitmap.getWidth();
        }
        if (scaleX * bitmap.getHeight() < height) {
            scaleX = height / bitmap.getHeight();
        }
        dy = (height - bitmap.getHeight() * scaleX) * 0.5f;
        dx = (width - bitmap.getWidth() * scaleX) * 0.5f;
        shaderMatrix.setScale(scaleX, scaleX);
    } else {
        scaleX = width / bitmap.getWidth();
        scaleY = height / bitmap.getHeight();
        dy = (height - bitmap.getHeight() * scaleY) * 0.5f;
        dx = (width - bitmap.getWidth() * scaleX) * 0.5f;
        shaderMatrix.setScale(scaleX, scaleY);
    }
    shaderMatrix.postTranslate(dx + 0.5f, dy + 0.5f);
    //Log.e("logs","setUpScaleType");
    return shaderMatrix;
}
 
源代码10 项目: Social   文件: PhotoViewAttacher.java
private void checkImageViewScaleType() {
	ImageView imageView = getImageView();

	/**
	 * PhotoView's getScaleType() will just divert to this.getScaleType() so
	 * only call if we're not attached to a PhotoView.
	 */
	if (null != imageView && !(imageView instanceof EasePhotoView)) {
		if (imageView.getScaleType() != ScaleType.MATRIX) {
			throw new IllegalStateException(
					"The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
		}
	}
}
 
@Override
public Parcelable onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix,
    RectF screenBounds) {
  // This is a replacement for the platform's overzealous onCaptureSharedElementSnapshot.
  // If you look at what it's doing, it's creating an ARGB_8888 copy of every single shared
  // element.
  // This was causing us to allocate 7+mb of bitmaps on every P3 load even though we didn't
  // need any of them...
  // They're slow to garbage collect and lead to OOMs too....
  // This just pulls the bitmap from the ImageView that we're already using and shoves it into
  // the a bundle formatted all nice
  // and pretty like the platform wants it to be and never has to know the difference.
  if (sharedElement instanceof ImageView) {
    ImageView imageView = (ImageView) sharedElement;
    Drawable drawable = ((ImageView) sharedElement).getDrawable();
    if (drawable != null && drawable instanceof BitmapDrawable) {
      Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
      Bundle bundle = new Bundle();
      bundle.putParcelable(BUNDLE_SNAPSHOT_BITMAP, bitmap);
      bundle.putString(BUNDLE_SNAPSHOT_IMAGE_SCALETYPE, imageView.getScaleType().toString());
      if (imageView.getScaleType() == ImageView.ScaleType.MATRIX) {
        Matrix matrix = imageView.getImageMatrix();
        float[] values = new float[9];
        matrix.getValues(values);
        bundle.putFloatArray(BUNDLE_SNAPSHOT_IMAGE_MATRIX, values);
      }
      return bundle;
    }
  }
  return null;
}
 
源代码12 项目: monolog-android   文件: PhotoViewAttacher.java
private void checkImageViewScaleType() {
	ImageView imageView = getImageView();

	/**
	 * PhotoView's getScaleType() will just divert to this.getScaleType() so
	 * only call if we're not attached to a PhotoView.
	 */
	if (null != imageView && !(imageView instanceof EasePhotoView)) {
		if (imageView.getScaleType() != ScaleType.MATRIX) {
			throw new IllegalStateException(
					"The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
		}
	}
}
 
源代码13 项目: LLApp   文件: PhotoViewAttacher.java
private void checkImageViewScaleType() {
	ImageView imageView = getImageView();

	/**
	 * PhotoView's getScaleType() will just divert to this.getScaleType() so
	 * only call if we're not attached to a PhotoView.
	 */
	if (null != imageView && !(imageView instanceof PhotoView)) {
		if (imageView.getScaleType() != ScaleType.MATRIX) {
			throw new IllegalStateException(
					"The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
		}
	}
}
 
源代码14 项目: iBeebo   文件: PhotoViewAttacher.java
private void checkImageViewScaleType() {
    ImageView imageView = getImageView();

    /**
     * PhotoView's getScaleType() will just divert to this.getScaleType() so only call if we're
     * not attached to a PhotoView.
     */
    if (null != imageView && !(imageView instanceof WeiboGalleryPhotoView)) {
        if (imageView.getScaleType() != ScaleType.MATRIX) {
            throw new IllegalStateException(
                    "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
        }
    }
}
 
源代码15 项目: Study_Android_Demo   文件: PhotoViewAttacher.java
private void checkImageViewScaleType() {
	ImageView imageView = getImageView();

	/**
	 * PhotoView's getScaleType() will just divert to this.getScaleType() so
	 * only call if we're not attached to a PhotoView.
	 */
	if (null != imageView && !(imageView instanceof EasePhotoView)) {
		if (imageView.getScaleType() != ScaleType.MATRIX) {
			throw new IllegalStateException(
					"The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
		}
	}
}
 
源代码16 项目: aurora-imui   文件: PhotoViewAttacher.java
private void checkImageViewScaleType() {
	ImageView imageView = getImageView();

	/**
	 * PhotoView's getScaleType() will just divert to this.getScaleType() so
	 * only call if we're not attached to a PhotoView.
	 */
	if (null != imageView && !(imageView instanceof PhotoView)) {
		if (imageView.getScaleType() != ScaleType.MATRIX) {
			throw new IllegalStateException(
					"The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
		}
	}
}
 
源代码17 项目: FanXin-based-HuanXin   文件: PhotoViewAttacher.java
private void checkImageViewScaleType() {
	ImageView imageView = getImageView();

	/**
	 * PhotoView's getScaleType() will just divert to this.getScaleType() so
	 * only call if we're not attached to a PhotoView.
	 */
	if (null != imageView && !(imageView instanceof PhotoView)) {
		if (imageView.getScaleType() != ScaleType.MATRIX) {
			throw new IllegalStateException(
					"The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
		}
	}
}
 
源代码18 项目: jmessage-android-uikit   文件: PhotoViewAttacher.java
private void checkImageViewScaleType() {
	ImageView imageView = getImageView();

	/**
	 * PhotoView's getScaleType() will just divert to this.getScaleType() so
	 * only call if we're not attached to a PhotoView.
	 */
	if (null != imageView && !(imageView instanceof PhotoView)) {
		if (imageView.getScaleType() != ScaleType.MATRIX) {
			throw new IllegalStateException(
					"The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
		}
	}
}
 
源代码19 项目: letv   文件: SharedElementCallback.java
public Parcelable onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix, RectF screenBounds) {
    Bitmap bitmap;
    if (sharedElement instanceof ImageView) {
        ImageView imageView = (ImageView) sharedElement;
        Drawable d = imageView.getDrawable();
        Drawable bg = imageView.getBackground();
        if (d != null && bg == null) {
            bitmap = createDrawableBitmap(d);
            if (bitmap != null) {
                Bundle bundle = new Bundle();
                bundle.putParcelable(BUNDLE_SNAPSHOT_BITMAP, bitmap);
                bundle.putString(BUNDLE_SNAPSHOT_IMAGE_SCALETYPE, imageView.getScaleType().toString());
                if (imageView.getScaleType() != ScaleType.MATRIX) {
                    return bundle;
                }
                float[] values = new float[9];
                imageView.getImageMatrix().getValues(values);
                bundle.putFloatArray(BUNDLE_SNAPSHOT_IMAGE_MATRIX, values);
                return bundle;
            }
        }
    }
    int bitmapWidth = Math.round(screenBounds.width());
    int bitmapHeight = Math.round(screenBounds.height());
    bitmap = null;
    if (bitmapWidth > 0 && bitmapHeight > 0) {
        float scale = Math.min(1.0f, ((float) MAX_IMAGE_SIZE) / ((float) (bitmapWidth * bitmapHeight)));
        bitmapWidth = (int) (((float) bitmapWidth) * scale);
        bitmapHeight = (int) (((float) bitmapHeight) * scale);
        if (this.mTempMatrix == null) {
            this.mTempMatrix = new Matrix();
        }
        this.mTempMatrix.set(viewToGlobalMatrix);
        this.mTempMatrix.postTranslate(-screenBounds.left, -screenBounds.top);
        this.mTempMatrix.postScale(scale, scale);
        bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.concat(this.mTempMatrix);
        sharedElement.draw(canvas);
    }
    return bitmap;
}
 
源代码20 项目: base-imageloader   文件: ImageUtils.java
/**
 * 计算合适的inSampleSize
 */
public static int computeImageSampleSize(ImageSize srcSize, ImageSize targetSize, ImageView imageView)
{
    final int srcWidth = srcSize.width;
    final int srcHeight = srcSize.height;
    final int targetWidth = targetSize.width;
    final int targetHeight = targetSize.height;

    int scale = 1;

    if (imageView == null)
    {
        scale = Math.max(srcWidth / targetWidth, srcHeight / targetHeight); // max
    } else
    {
        switch (imageView.getScaleType())
        {
            case FIT_CENTER:
            case FIT_XY:
            case FIT_START:
            case FIT_END:
            case CENTER_INSIDE:
                scale = Math.max(srcWidth / targetWidth, srcHeight / targetHeight); // max
                break;
            case CENTER:
            case CENTER_CROP:
            case MATRIX:
                scale = Math.max(srcWidth / targetWidth, srcHeight / targetHeight); // min
                break;
            default:
                scale = Math.max(srcWidth / targetWidth, srcHeight / targetHeight); // max
                break;
        }
    }

    if (scale < 1)
    {
        scale = 1;
    }

    return scale;
}