Java Code Examples for android.widget.ImageView.ScaleType#FIT_CENTER

The following examples show how to use android.widget.ImageView.ScaleType#FIT_CENTER . 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 check out the related API usage on the sidebar.
Example 1
Source File: WXImage.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
private ScaleType getResizeMode(String resizeMode) {
  ScaleType scaleType = ScaleType.FIT_XY;
  if (TextUtils.isEmpty(resizeMode)) {
    return scaleType;
  }

  switch (resizeMode) {
    case "cover":
      scaleType = ScaleType.CENTER_CROP;
      break;
    case "contain":
      scaleType = ScaleType.FIT_CENTER;
      break;
    case "stretch":
      scaleType = ScaleType.FIT_XY;
      break;
  }
  return scaleType;
}
 
Example 2
Source File: WXImage.java    From weex with Apache License 2.0 6 votes vote down vote up
private ScaleType getResizeMode(String resizeMode) {
    ScaleType scaleType = ScaleType.FIT_XY;
    if (TextUtils.isEmpty(resizeMode)) {
        return scaleType;
    }

    if (resizeMode.equals("cover")) {
        scaleType = ScaleType.CENTER_CROP;
    } else if (resizeMode.equals("contain")) {
        scaleType = ScaleType.FIT_CENTER;
    } else if (resizeMode.equals("stretch")) {
        scaleType = ScaleType.FIT_XY;
    } else if (resizeMode.equals("center")) {
        scaleType = ScaleType.CENTER;
    } else if (resizeMode.equals("start")) {
        scaleType = ScaleType.MATRIX;
    } else if (resizeMode.equals("end")) {
        scaleType = ScaleType.FIT_END;
    }
    return scaleType;
}
 
Example 3
Source File: WXImage.java    From weex-uikit with MIT License 6 votes vote down vote up
private ScaleType getResizeMode(String resizeMode) {
  ScaleType scaleType = ScaleType.FIT_XY;
  if (TextUtils.isEmpty(resizeMode)) {
    return scaleType;
  }

  switch (resizeMode) {
    case "cover":
      scaleType = ScaleType.CENTER_CROP;
      break;
    case "contain":
      scaleType = ScaleType.FIT_CENTER;
      break;
    case "stretch":
      scaleType = ScaleType.FIT_XY;
      break;
  }
  return scaleType;
}
 
Example 4
Source File: RoundedDrawable.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
public RoundedDrawable setScaleType(ScaleType scaleType) {
  if (scaleType == null) {
    scaleType = ScaleType.FIT_CENTER;
  }
  if (mScaleType != scaleType) {
    mScaleType = scaleType;
    updateShaderMatrix();
  }
  return this;
}
 
Example 5
Source File: RoundedDrawable.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
public RoundedDrawable setScaleType(ScaleType scaleType) {
    if (scaleType == null) {
        scaleType = ScaleType.FIT_CENTER;
    }
    if (mScaleType != scaleType) {
        mScaleType = scaleType;
        updateShaderMatrix();
    }
    return this;
}
 
Example 6
Source File: RoundedDrawable.java    From QuickReturn with Apache License 2.0 5 votes vote down vote up
public RoundedDrawable setScaleType(ScaleType scaleType) {
    if (scaleType == null) {
        scaleType = ScaleType.FIT_CENTER;
    }
    if (mScaleType != scaleType) {
        mScaleType = scaleType;
        updateShaderMatrix();
    }
    return this;
}
 
Example 7
Source File: RoundedDrawable.java    From ClipCircleHeadLikeQQ with Apache License 2.0 5 votes vote down vote up
public RoundedDrawable setScaleType(ScaleType scaleType) {
  if (scaleType == null) {
    scaleType = ScaleType.FIT_CENTER;
  }
  if (mScaleType != scaleType) {
    mScaleType = scaleType;
    updateShaderMatrix();
  }
  return this;
}
 
Example 8
Source File: RoundedDrawable.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
public RoundedDrawable setScaleType(ScaleType scaleType) {
	if (scaleType == null) {
		scaleType = ScaleType.FIT_CENTER;
	}
	if (mScaleType != scaleType) {
		mScaleType = scaleType;
		updateShaderMatrix();
	}
	return this;
}
 
Example 9
Source File: RoundedDrawable.java    From MyBlogDemo with Apache License 2.0 5 votes vote down vote up
public RoundedDrawable setScaleType(ScaleType scaleType) {
    if (scaleType == null) {
        scaleType = ScaleType.FIT_CENTER;
    }
    if (mScaleType != scaleType) {
        mScaleType = scaleType;
        updateShaderMatrix();
    }
    return this;
}
 
Example 10
Source File: RoundedDrawable.java    From MousePaint with MIT License 5 votes vote down vote up
public RoundedDrawable setScaleType(ScaleType scaleType) {
  if (scaleType == null) {
    scaleType = ScaleType.FIT_CENTER;
  }
  if (mScaleType != scaleType) {
    mScaleType = scaleType;
    updateShaderMatrix();
  }
  return this;
}
 
Example 11
Source File: RoundedDrawable.java    From Loop with Apache License 2.0 5 votes vote down vote up
public RoundedDrawable setScaleType(ScaleType scaleType) {
    if (scaleType == null) {
        scaleType = ScaleType.FIT_CENTER;
    }
    if (mScaleType != scaleType) {
        mScaleType = scaleType;
        updateShaderMatrix();
    }
    return this;
}
 
Example 12
Source File: RoundedPagerDrawable.java    From letv with Apache License 2.0 5 votes vote down vote up
public RoundedPagerDrawable setScaleType(ScaleType scaleType) {
    if (scaleType == null) {
        scaleType = ScaleType.FIT_CENTER;
    }
    if (this.mScaleType != scaleType) {
        this.mScaleType = scaleType;
        updateShaderMatrix();
    }
    return this;
}
 
Example 13
Source File: RoundedDrawable.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
public RoundedDrawable setScaleType(ScaleType scaleType) {
  if (scaleType == null) {
    scaleType = ScaleType.FIT_CENTER;
  }
  if (mScaleType != scaleType) {
    mScaleType = scaleType;
    updateShaderMatrix();
  }
  return this;
}
 
Example 14
Source File: RoundedDrawable.java    From Android with MIT License 5 votes vote down vote up
public RoundedDrawable setScaleType(ScaleType scaleType) {
  if (scaleType == null) {
    scaleType = ScaleType.FIT_CENTER;
  }
  if (mScaleType != scaleType) {
    mScaleType = scaleType;
    updateShaderMatrix();
  }
  return this;
}
 
Example 15
Source File: ModNavigationBar.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private static ScaleType getIconScaleType(int index, int keyId) {
    if (mUseLargerIcons) {
        return ScaleType.FIT_CENTER;
    } else {
        ScaleType origScaleType = mNavbarViewInfo[index] == null ? ScaleType.CENTER :
                mNavbarViewInfo[index].originalScaleType.get(keyId, ScaleType.CENTER);
        if (index == 0) {
            return (mNavbarHeight < 75 ? ScaleType.CENTER_INSIDE : origScaleType);
        } else {
            boolean hasVerticalNavbar = mGbContext.getResources().getBoolean(R.bool.hasVerticalNavbar);
            return (mNavbarWidth < 75 && hasVerticalNavbar ? ScaleType.CENTER_INSIDE :
                    origScaleType);
        }
    }
}
 
Example 16
Source File: RoundedDrawable.java    From DMusic with Apache License 2.0 5 votes vote down vote up
public RoundedDrawable setScaleType(ScaleType scaleType) {
    if (scaleType == null) {
        scaleType = ScaleType.FIT_CENTER;
    }
    if (mScaleType != scaleType) {
        mScaleType = scaleType;
        updateShaderMatrix();
    }
    return this;
}
 
Example 17
Source File: RoundedImageView.java    From letv with Apache License 2.0 5 votes vote down vote up
public RoundedImageView(Context context) {
    super(context);
    this.mCornerRadii = new float[]{0.0f, 0.0f, 0.0f, 0.0f};
    this.mBorderColor = ColorStateList.valueOf(-16777216);
    this.mBorderWidth = 0.0f;
    this.mColorFilter = null;
    this.mColorMod = false;
    this.mHasColorFilter = false;
    this.mIsOval = false;
    this.mMutateBackground = false;
    this.mScaleType = ScaleType.FIT_CENTER;
    this.mTileModeX = DEFAULT_TILE_MODE;
    this.mTileModeY = DEFAULT_TILE_MODE;
}
 
Example 18
Source File: ScaleDragHelper.java    From sketch with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("ConstantConditions")
private void resetBaseMatrix() {
    baseMatrix.reset();

    Size viewSize = imageZoomer.getViewSize();
    Size imageSize = imageZoomer.getImageSize();
    Size drawableSize = imageZoomer.getDrawableSize();
    boolean readMode = imageZoomer.isReadMode();
    ScaleType scaleType = imageZoomer.getScaleType();

    final int drawableWidth = imageZoomer.getRotateDegrees() % 180 == 0 ? drawableSize.getWidth() : drawableSize.getHeight();
    final int drawableHeight = imageZoomer.getRotateDegrees() % 180 == 0 ? drawableSize.getHeight() : drawableSize.getWidth();
    final int imageWidth = imageZoomer.getRotateDegrees() % 180 == 0 ? imageSize.getWidth() : imageSize.getHeight();
    final int imageHeight = imageZoomer.getRotateDegrees() % 180 == 0 ? imageSize.getHeight() : imageSize.getWidth();
    boolean imageThanViewLarge = drawableWidth > viewSize.getWidth() || drawableHeight > viewSize.getHeight();

    final ScaleType finalScaleType;
    if (scaleType == ScaleType.MATRIX) {
        finalScaleType = ScaleType.FIT_CENTER;
    } else if (scaleType == ScaleType.CENTER_INSIDE) {
        finalScaleType = imageThanViewLarge ? ScaleType.FIT_CENTER : ScaleType.CENTER;
    } else {
        finalScaleType = scaleType;
    }

    float initScale = imageZoomer.getZoomScales().getInitZoomScale();

    ImageSizeCalculator sizeCalculator = Sketch.with(imageZoomer.getImageView().getContext()).getConfiguration().getSizeCalculator();
    if (readMode && sizeCalculator.canUseReadModeByHeight(imageWidth, imageHeight)) {
        baseMatrix.postScale(initScale, initScale);
    } else if (readMode && sizeCalculator.canUseReadModeByWidth(imageWidth, imageHeight)) {
        baseMatrix.postScale(initScale, initScale);
    } else if (finalScaleType == ScaleType.CENTER) {
        baseMatrix.postScale(initScale, initScale);
        baseMatrix.postTranslate((viewSize.getWidth() - drawableWidth) / 2F, (viewSize.getHeight() - drawableHeight) / 2F);
    } else if (finalScaleType == ScaleType.CENTER_CROP) {
        baseMatrix.postScale(initScale, initScale);
        baseMatrix.postTranslate((viewSize.getWidth() - drawableWidth * initScale) / 2F, (viewSize.getHeight() - drawableHeight * initScale) / 2F);
    } else if (finalScaleType == ScaleType.FIT_START) {
        baseMatrix.postScale(initScale, initScale);
        baseMatrix.postTranslate(0, 0);
    } else if (finalScaleType == ScaleType.FIT_END) {
        baseMatrix.postScale(initScale, initScale);
        baseMatrix.postTranslate(0, (viewSize.getHeight() - drawableHeight * initScale));
    } else if (finalScaleType == ScaleType.FIT_CENTER) {
        baseMatrix.postScale(initScale, initScale);
        baseMatrix.postTranslate(0, (viewSize.getHeight() - drawableHeight * initScale) / 2F);
    } else if (finalScaleType == ScaleType.FIT_XY) {
        RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
        RectF mTempDst = new RectF(0, 0, viewSize.getWidth(), viewSize.getHeight());
        baseMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.FILL);
    }
}
 
Example 19
Source File: AdaptiveTwoLevelScales.java    From sketch with Apache License 2.0 4 votes vote down vote up
private float getInitScale(@NonNull final Context context, @NonNull final Sizes sizes, @NonNull final ScaleType scaleType, final float rotateDegrees, final boolean readMode) {
    final int drawableWidth = rotateDegrees % 180 == 0 ? sizes.drawableSize.getWidth() : sizes.drawableSize.getHeight();
    final int drawableHeight = rotateDegrees % 180 == 0 ? sizes.drawableSize.getHeight() : sizes.drawableSize.getWidth();
    final int imageWidth = rotateDegrees % 180 == 0 ? sizes.imageSize.getWidth() : sizes.imageSize.getHeight();
    final int imageHeight = rotateDegrees % 180 == 0 ? sizes.imageSize.getHeight() : sizes.imageSize.getWidth();

    final float widthScale = (float) sizes.viewSize.getWidth() / drawableWidth;
    final float heightScale = (float) sizes.viewSize.getHeight() / drawableHeight;
    boolean imageThanViewLarge = drawableWidth > sizes.viewSize.getWidth() || drawableHeight > sizes.viewSize.getHeight();

    ImageSizeCalculator sizeCalculator = Sketch.with(context).getConfiguration().getSizeCalculator();

    final ScaleType finalScaleType;
    if (scaleType == ScaleType.MATRIX) {
        finalScaleType = ScaleType.FIT_CENTER;
    } else if (scaleType == ScaleType.CENTER_INSIDE) {
        finalScaleType = imageThanViewLarge ? ScaleType.FIT_CENTER : ScaleType.CENTER;
    } else {
        finalScaleType = scaleType;
    }

    if (readMode && sizeCalculator.canUseReadModeByHeight(imageWidth, imageHeight)) {
        return widthScale;
    } else if (readMode && sizeCalculator.canUseReadModeByWidth(imageWidth, imageHeight)) {
        return heightScale;
    } else if (finalScaleType == ScaleType.CENTER) {
        return 1.0f;
    } else if (finalScaleType == ScaleType.CENTER_CROP) {
        return Math.max(widthScale, heightScale);
    } else if (finalScaleType == ScaleType.FIT_START) {
        return Math.min(widthScale, heightScale);
    } else if (finalScaleType == ScaleType.FIT_END) {
        return Math.min(widthScale, heightScale);
    } else if (finalScaleType == ScaleType.FIT_CENTER) {
        return Math.min(widthScale, heightScale);
    } else if (finalScaleType == ScaleType.FIT_XY) {
        return 1.0f;
    } else {
        return 1.0f;
    }
}
 
Example 20
Source File: RoundedImageView.java    From letv with Apache License 2.0 4 votes vote down vote up
public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
    int i;
    super(context, attrs, defStyle);
    this.mCornerRadii = new float[]{0.0f, 0.0f, 0.0f, 0.0f};
    this.mBorderColor = ColorStateList.valueOf(-16777216);
    this.mBorderWidth = 0.0f;
    this.mColorFilter = null;
    this.mColorMod = false;
    this.mHasColorFilter = false;
    this.mIsOval = false;
    this.mMutateBackground = false;
    this.mScaleType = ScaleType.FIT_CENTER;
    this.mTileModeX = DEFAULT_TILE_MODE;
    this.mTileModeY = DEFAULT_TILE_MODE;
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundedImageView, defStyle, 0);
    int index = a.getInt(R.styleable.RoundedImageView_android_scaleType, -1);
    if (index >= 0) {
        setScaleType(SCALE_TYPES[index]);
    } else {
        setScaleType(ScaleType.FIT_CENTER);
    }
    float cornerRadiusOverride = (float) a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius, -1);
    this.mCornerRadii[0] = (float) a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_left, -1);
    this.mCornerRadii[1] = (float) a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_right, -1);
    this.mCornerRadii[2] = (float) a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_right, -1);
    this.mCornerRadii[3] = (float) a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_left, -1);
    boolean any = false;
    int len = this.mCornerRadii.length;
    for (i = 0; i < len; i++) {
        if (this.mCornerRadii[i] < 0.0f) {
            this.mCornerRadii[i] = 0.0f;
        } else {
            any = true;
        }
    }
    if (!any) {
        if (cornerRadiusOverride < 0.0f) {
            cornerRadiusOverride = 0.0f;
        }
        len = this.mCornerRadii.length;
        for (i = 0; i < len; i++) {
            this.mCornerRadii[i] = cornerRadiusOverride;
        }
    }
    this.mBorderWidth = (float) a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_border_width, -1);
    if (this.mBorderWidth < 0.0f) {
        this.mBorderWidth = 0.0f;
    }
    this.mBorderColor = a.getColorStateList(R.styleable.RoundedImageView_riv_border_color);
    if (this.mBorderColor == null) {
        this.mBorderColor = ColorStateList.valueOf(-16777216);
    }
    this.mMutateBackground = a.getBoolean(R.styleable.RoundedImageView_riv_mutate_background, false);
    this.mIsOval = a.getBoolean(R.styleable.RoundedImageView_riv_oval, false);
    int tileMode = a.getInt(R.styleable.RoundedImageView_riv_tile_mode, -2);
    if (tileMode != -2) {
        setTileModeX(parseTileMode(tileMode));
        setTileModeY(parseTileMode(tileMode));
    }
    int tileModeX = a.getInt(R.styleable.RoundedImageView_riv_tile_mode_x, -2);
    if (tileModeX != -2) {
        setTileModeX(parseTileMode(tileModeX));
    }
    int tileModeY = a.getInt(R.styleable.RoundedImageView_riv_tile_mode_y, -2);
    if (tileModeY != -2) {
        setTileModeY(parseTileMode(tileModeY));
    }
    updateDrawableAttrs();
    updateBackgroundDrawableAttrs(true);
    a.recycle();
}