Java Code Examples for android.widget.ImageView#getScaleType()

The following examples show how to use android.widget.ImageView#getScaleType() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: giffun   File: GenericRequestBuilder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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));
}
 
Example 2
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());
    }
}
 
Example 3
Source Project: SprintNBA   File: PhotoView.java    License: Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 4
Source Project: school_shop   File: PhotoViewAttacher.java    License: MIT License 5 votes vote down vote up
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");
		}
	}
}
 
Example 5
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");
        }
    }
}
 
Example 6
/**
 * 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);
}
 
Example 7
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");
		}
	}
}
 
Example 8
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");
        }
    }
}
 
Example 9
Source Project: Oblique   File: ObliqueView.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 10
Source Project: Social   File: PhotoViewAttacher.java    License: Apache License 2.0 5 votes vote down vote up
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");
		}
	}
}
 
Example 11
@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;
}
 
Example 12
Source Project: monolog-android   File: PhotoViewAttacher.java    License: MIT License 5 votes vote down vote up
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");
		}
	}
}
 
Example 13
Source Project: LLApp   File: PhotoViewAttacher.java    License: Apache License 2.0 5 votes vote down vote up
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");
		}
	}
}
 
Example 14
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");
        }
    }
}
 
Example 15
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");
		}
	}
}
 
Example 16
Source Project: aurora-imui   File: PhotoViewAttacher.java    License: MIT License 5 votes vote down vote up
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");
		}
	}
}
 
Example 17
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");
		}
	}
}
 
Example 18
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");
		}
	}
}
 
Example 19
Source Project: letv   File: SharedElementCallback.java    License: Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 20
Source Project: base-imageloader   File: ImageUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 计算合适的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;
}