Java Code Examples for android.widget.ImageView.ScaleType

The following examples show how to use android.widget.ImageView.ScaleType. 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 check out the related API usage on the sidebar.
Example 1
Source Project: ALLGO   Source File: WelcomeACTIVITY.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 初始化数据
 */
private void initData(){
	//定义一个布局并设置参数
	LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
               														  LinearLayout.LayoutParams.MATCH_PARENT);

       //初始化引导图片列表
		ImageView iv0 = new ImageView(this);
		iv0.setScaleType(ScaleType.FIT_CENTER);
		iv0.setLayoutParams(mParams);
           iv0.setImageResource(pics[0]);
           views.add(iv0);
           ImageView iv1 = new ImageView(this);
           iv1.setScaleType(ScaleType.FIT_CENTER);
           iv1.setLayoutParams(mParams);
           iv1.setImageResource(pics[1]); 
           views.add(iv1);
       
       //设置数据
       viewPager.setAdapter(vpAdapter);
       //设置监听
       viewPager.setOnPageChangeListener(this);
       
       //初始化底部小点
       initPoint();
}
 
Example 2
@Override
protected void onLoadingDrawableSet(Drawable imageDrawable) {
	if (null != imageDrawable) {
		final int dHeight = imageDrawable.getIntrinsicHeight();
		final int dWidth = imageDrawable.getIntrinsicWidth();

		/**
		 * We need to set the width/height of the ImageView so that it is
		 * square with each side the size of the largest drawable dimension.
		 * This is so that it doesn't clip when rotated.
		 */
		ViewGroup.LayoutParams lp = mHeaderImage.getLayoutParams();
		lp.width = lp.height = Math.max(dHeight, dWidth);
		mHeaderImage.requestLayout();

		/**
		 * We now rotate the Drawable so that is at the correct rotation,
		 * and is centered.
		 */
		mHeaderImage.setScaleType(ScaleType.MATRIX);
		Matrix matrix = new Matrix();
		matrix.postTranslate((lp.width - dWidth) / 2f, (lp.height - dHeight) / 2f);
		matrix.postRotate(getDrawableRotationAngle(), lp.width / 2f, lp.height / 2f);
		mHeaderImage.setImageMatrix(matrix);
	}
}
 
Example 3
public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
	super(context, mode, scrollDirection, attrs);

	mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true);

	mHeaderImage.setScaleType(ScaleType.MATRIX);
	mHeaderImageMatrix = new Matrix();
	mHeaderImage.setImageMatrix(mHeaderImageMatrix);

	mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
			0.5f);
	mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
	mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION);
	mRotateAnimation.setRepeatCount(Animation.INFINITE);
	mRotateAnimation.setRepeatMode(Animation.RESTART);
}
 
Example 4
Source Project: volley   Source File: ImageRequest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new image request, decoding to a maximum specified width and height. If both width
 * and height are zero, the image will be decoded to its natural size. If one of the two is
 * nonzero, that dimension will be clamped and the other one will be set to preserve the image's
 * aspect ratio. If both width and height are nonzero, the image will be decoded to be fit in
 * the rectangle of dimensions width x height while keeping its aspect ratio.
 *
 * @param url URL of the image
 * @param listener Listener to receive the decoded bitmap
 * @param maxWidth Maximum width to decode this bitmap to, or zero for none
 * @param maxHeight Maximum height to decode this bitmap to, or zero for none
 * @param scaleType The ImageViews ScaleType used to calculate the needed image size.
 * @param decodeConfig Format to decode the bitmap to
 * @param errorListener Error listener, or null to ignore errors
 */
public ImageRequest(
        String url,
        Response.Listener<Bitmap> listener,
        int maxWidth,
        int maxHeight,
        ScaleType scaleType,
        Config decodeConfig,
        @Nullable Response.ErrorListener errorListener) {
    super(Method.GET, url, errorListener);
    setRetryPolicy(
            new DefaultRetryPolicy(
                    DEFAULT_IMAGE_TIMEOUT_MS,
                    DEFAULT_IMAGE_MAX_RETRIES,
                    DEFAULT_IMAGE_BACKOFF_MULT));
    mListener = listener;
    mDecodeConfig = decodeConfig;
    mMaxWidth = maxWidth;
    mMaxHeight = maxHeight;
    mScaleType = scaleType;
}
 
Example 5
Source Project: volley   Source File: ImageRequestTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void publicMethods() throws Exception {
    // Catch-all test to find API-breaking changes.
    assertNotNull(
            ImageRequest.class.getConstructor(
                    String.class,
                    Response.Listener.class,
                    int.class,
                    int.class,
                    Bitmap.Config.class,
                    Response.ErrorListener.class));
    assertNotNull(
            ImageRequest.class.getConstructor(
                    String.class,
                    Response.Listener.class,
                    int.class,
                    int.class,
                    ImageView.ScaleType.class,
                    Bitmap.Config.class,
                    Response.ErrorListener.class));
    assertEquals(ImageRequest.DEFAULT_IMAGE_TIMEOUT_MS, 1000);
    assertEquals(ImageRequest.DEFAULT_IMAGE_MAX_RETRIES, 2);
    assertEquals(ImageRequest.DEFAULT_IMAGE_BACKOFF_MULT, 2f, 0);
}
 
Example 6
Source Project: MoeGallery   Source File: ButtonFloat.java    License: GNU General Public License v3.0 6 votes vote down vote up
public ButtonFloat(Context context, AttributeSet attrs) {
    super(context, attrs);
    setBackgroundResource(R.drawable.background_button_float);
    setBackgroundColor(backgroundColor);
    sizeRadius = 28;
    setDefaultProperties();
    icon = new ImageView(context);
    icon.setAdjustViewBounds(true);
    icon.setScaleType(ScaleType.CENTER_CROP);
    if (drawableIcon != null) {
        icon.setImageDrawable(drawableIcon);
    }
    RelativeLayout.LayoutParams params =
            new RelativeLayout.LayoutParams(Utils.dpToPx(sizeIcon, getResources()),
                    Utils.dpToPx(sizeIcon, getResources()));
    params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    icon.setLayoutParams(params);
    addView(icon);

}
 
Example 7
public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
	super(context, mode, scrollDirection, attrs);

	mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true);

	mHeaderImage.setScaleType(ScaleType.MATRIX);
	mHeaderImageMatrix = new Matrix();
	mHeaderImage.setImageMatrix(mHeaderImageMatrix);

	mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
			0.5f);
	mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
	mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION);
	mRotateAnimation.setRepeatCount(Animation.INFINITE);
	mRotateAnimation.setRepeatMode(Animation.RESTART);
}
 
Example 8
public RotateLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
	super(context, mode, scrollDirection, attrs);

	mRotateDrawableWhilePulling = attrs.getBoolean(R.styleable.PullToRefresh_ptrRotateDrawableWhilePulling, true);

	mHeaderImage.setScaleType(ScaleType.MATRIX);
	mHeaderImageMatrix = new Matrix();
	mHeaderImage.setImageMatrix(mHeaderImageMatrix);

	mRotateAnimation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
			0.5f);
	mRotateAnimation.setInterpolator(ANIMATION_INTERPOLATOR);
	mRotateAnimation.setDuration(ROTATION_ANIMATION_DURATION);
	mRotateAnimation.setRepeatCount(Animation.INFINITE);
	mRotateAnimation.setRepeatMode(Animation.RESTART);
}
 
Example 9
Source Project: GravityBox   Source File: AppPickerPreference.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onBindView(View view) {
    super.onBindView(view);

    LinearLayout widgetFrameView = ((LinearLayout) view.findViewById(android.R.id.widget_frame));
    mBtnAppIcon = new ImageButton(mContext);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(mAppIconPreviewSizePx, mAppIconPreviewSizePx);
    lp.gravity = Gravity.CENTER;
    mBtnAppIcon.setLayoutParams(lp);
    mBtnAppIcon.setScaleType(ScaleType.CENTER_CROP);
    mBtnAppIcon.setImageDrawable(mAppInfo.icon);
    mBtnAppIcon.setFocusable(false);
    if (mIconPickerEnabled) {
        mBtnAppIcon.setOnClickListener(this);
        mBtnAppIcon.setOnLongClickListener(this);
    } else {
        mBtnAppIcon.setEnabled(false);
    }
    widgetFrameView.addView(mBtnAppIcon);
    widgetFrameView.setVisibility(View.VISIBLE);
}
 
Example 10
Source Project: RotatePhotoView   Source File: PhotoViewAttacher.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set's the ImageView's ScaleType to Matrix.
 */
private static void setImageViewScaleTypeMatrix(ImageView imageView) {
    /**
     * PhotoView sets it's own ScaleType to Matrix, then diverts all calls
     * setScaleType to this.setScaleType automatically.
     */
    if (null != imageView && !(imageView instanceof IPhotoView)) {
        if (!ScaleType.MATRIX.equals(imageView.getScaleType())) {
            imageView.setScaleType(ScaleType.MATRIX);
        }
    }
}
 
Example 11
Source Project: Social   Source File: PhotoViewAttacher.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set's the ImageView's ScaleType to Matrix.
 */
private static void setImageViewScaleTypeMatrix(ImageView imageView) {
	if (null != imageView) {
		if (imageView instanceof EasePhotoView) {
			/**
			 * PhotoView sets it's own ScaleType to Matrix, then diverts all
			 * calls setScaleType to this.setScaleType. Basically we don't
			 * need to do anything here
			 */
		} else {
			imageView.setScaleType(ScaleType.MATRIX);
		}
	}
}
 
Example 12
Source Project: monolog-android   Source File: PhotoViewAttacher.java    License: MIT License 5 votes vote down vote up
@Override
public final void setScaleType(ScaleType scaleType) {
	if (isSupportedScaleType(scaleType) && scaleType != mScaleType) {
		mScaleType = scaleType;

		// Finally update
		update();
	}
}
 
Example 13
Source Project: jmessage-android-uikit   Source File: PhotoViewAttacher.java    License: MIT License 5 votes vote down vote up
/**
 * Set's the ImageView's ScaleType to Matrix.
 */
private static void setImageViewScaleTypeMatrix(ImageView imageView) {
	if (null != imageView) {
		if (imageView instanceof PhotoView) {
			/**
			 * PhotoView sets it's own ScaleType to Matrix, then diverts all
			 * calls setScaleType to this.setScaleType. Basically we don't
			 * need to do anything here
			 */
		} else {
			imageView.setScaleType(ScaleType.MATRIX);
		}
	}
}
 
Example 14
Source Project: monolog-android   Source 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 15
static public void setPic(ImageView mImageView, String pPath) {
    try {
        if (pPath == null) return;
        File f = new File(pPath);
        if (!f.exists() || f.isDirectory()) return;

        // Get the dimensions of the View
        int targetW = mImageView.getWidth();
        if (targetW == 0) targetW = mImageView.getMeasuredWidth();
        int targetH = mImageView.getHeight();
        if (targetH == 0) targetH = mImageView.getMeasuredHeight();

        // Get the dimensions of the bitmap
        BitmapFactory.Options bmOptions = new BitmapFactory.Options();
        bmOptions.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(pPath, bmOptions);
        int photoW = bmOptions.outWidth;
        int photoH = bmOptions.outHeight;

        // Determine how much to scale down the image
        int scaleFactor = photoW / targetW; //Math.min(photoW/targetW, photoH/targetH);

        // Decode the image file into a Bitmap sized to fill the View
        bmOptions.inJustDecodeBounds = false;
        bmOptions.inSampleSize = scaleFactor;
        bmOptions.inPurgeable = true;

        Bitmap bitmap = BitmapFactory.decodeFile(pPath, bmOptions);
        Bitmap orientedBitmap = ExifUtil.rotateBitmap(pPath, bitmap);
        mImageView.setImageBitmap(orientedBitmap);

        //mImageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
        mImageView.setAdjustViewBounds(true);
        mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 16
Source Project: RotatePhotoView   Source File: PhotoViewAttacher.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setScaleType(ScaleType scaleType) {
    if (isSupportedScaleType(scaleType) && scaleType != mScaleType) {
        mScaleType = scaleType;

        // Finally update
        update();
    }
}
 
Example 17
Source Project: MultiView   Source File: ImageViewScaler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set's the ImageView's ScaleType to Matrix.
 */
private static void setImageViewScaleTypeMatrix(ImageView imageView) {
    /**
     * PhotoView sets it's own ScaleType to Matrix, then diverts all calls
     * setScaleType to this.setScaleType automatically.
     */
    if (null != imageView && !(imageView instanceof ScaleImageView)) {
        if (!ScaleType.MATRIX.equals(imageView.getScaleType())) {
            imageView.setScaleType(ScaleType.MATRIX);
        }
    }
}
 
Example 18
Source Project: Dashboard   Source File: PhotoViewAttacher.java    License: MIT License 5 votes vote down vote up
/**
 * Set's the ImageView's ScaleType to Matrix.
 */
private static void setImageViewScaleTypeMatrix(ImageView imageView) {
    /**
     * PhotoView sets it's own ScaleType to Matrix, then diverts all calls
     * setScaleType to this.setScaleType automatically.
     */
    if (null != imageView && !(imageView instanceof PhotoView)) {
        if (!ScaleType.MATRIX.equals(imageView.getScaleType())) {
            imageView.setScaleType(ScaleType.MATRIX);
        }
    }
}
 
Example 19
Source Project: narrate-android   Source File: PhotoViewAttacher.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return true if the ScaleType is supported.
 */
private static boolean isSupportedScaleType(final ScaleType scaleType) {
    if (null == scaleType) {
        return false;
    }

    switch (scaleType) {
        case MATRIX:
            throw new IllegalArgumentException(scaleType.name()
                    + " is not supported in PhotoView");

        default:
            return true;
    }
}
 
Example 20
Source Project: SaveVolley   Source File: ImageLoader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Equivalent to calling {@link #get(String, ImageListener, int, int, ScaleType)} with
 * {@code Scaletype == ScaleType.CENTER_INSIDE}.
 */
/*
 * 默认 scaleType: ScaleType.CENTER_INSIDE
 */
public ImageContainer get(String requestUrl, ImageListener imageListener, int maxWidth, int maxHeight) {
    return get(requestUrl, imageListener, maxWidth, maxHeight, ScaleType.CENTER_INSIDE);
}
 
Example 21
Source Project: MoeGallery   Source File: PhotoViewAttacher.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set's the ImageView's ScaleType to Matrix.
 */
private static void setImageViewScaleTypeMatrix(ImageView imageView) {
    /**
     * PhotoView sets it's own ScaleType to Matrix, then diverts all calls
     * setScaleType to this.setScaleType automatically.
     */
    if (null != imageView && !(imageView instanceof IPhotoView)) {
        if (!ScaleType.MATRIX.equals(imageView.getScaleType())) {
            imageView.setScaleType(ScaleType.MATRIX);
        }
    }
}
 
Example 22
Source Project: imsdk-android   Source 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 IPhotoView)) {
        if (!ScaleType.MATRIX.equals(imageView.getScaleType())) {
            throw new IllegalStateException(
                    "The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
        }
    }
}
 
Example 23
Source Project: android-open-project-demo   Source File: MatrixActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_matrix);
	mImageView = (ImageView) findViewById(R.id.image);
	mImageView.setScaleType(ScaleType.MATRIX);
	updateMatrix(getIntent().getIntExtra(KEY_ACTION, -1));
}
 
Example 24
Source Project: MyBlogDemo   Source File: RoundedDrawable.java    License: 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 25
Source Project: MyHearts   Source File: PicViewerPage.java    License: Apache License 2.0 5 votes vote down vote up
public void onCreate() {
	activity.getWindow().setBackgroundDrawable(new ColorDrawable(0x4c000000));

	sivViewer = new ScaledImageView(activity);
	sivViewer.setScaleType(ScaleType.MATRIX);
	activity.setContentView(sivViewer);
	if (pic != null) {
		sivViewer.getViewTreeObserver().addOnGlobalLayoutListener(this);
	}
}
 
Example 26
Source Project: zen4android   Source File: PhotoViewAttacher.java    License: MIT License 5 votes vote down vote up
/**
 * @return true if the ScaleType is supported.
 */
private static boolean isSupportedScaleType(final ScaleType scaleType) {
    if (null == scaleType) {
        return false;
    }

    switch (scaleType) {
        case MATRIX:
            throw new IllegalArgumentException(scaleType.name()
                    + " is not supported in PhotoView");

        default:
            return true;
    }
}
 
Example 27
Source Project: SaveVolley   Source File: ImageLoader.java    License: Apache License 2.0 5 votes vote down vote up
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight, ScaleType scaleType, final String cacheKey) {
    return new ImageRequest(requestUrl, new Listener<Bitmap>() {
        @Override public void onResponse(Bitmap response) {
            onGetImageSuccess(cacheKey, response);
        }
    }, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() {
        @Override public void onErrorResponse(VolleyError error) {
            onGetImageError(cacheKey, error);
        }
    });
}
 
Example 28
Source Project: volley_demo   Source File: ImageLoader.java    License: Apache License 2.0 5 votes vote down vote up
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight,
        ScaleType scaleType, final String cacheKey) {
    return new ImageRequest(requestUrl, new Listener<Bitmap>() {
        @Override
        public void onResponse(Bitmap response) {
            onGetImageSuccess(cacheKey, response);
        }
    }, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            onGetImageError(cacheKey, error);
        }
    });
}
 
Example 29
@Override
public void setScaleType(ScaleType scaleType) {
    if (isSupportedScaleType(scaleType) && scaleType != mScaleType) {
        mScaleType = scaleType;

        // Finally update
        update();
    }
}
 
Example 30
Source Project: DeviceConnect-Android   Source File: CanvasProfileActivity.java    License: MIT License 5 votes vote down vote up
/**
 * 画面を更新します.
 * @param drawObj 更新する画像データ
 */
private void showDrawObject(final CanvasDrawImageObject drawObj) {
    switch (drawObj.getMode()) {
        default:
        case NON_SCALE_MODE:
            Matrix matrix = new Matrix();
            matrix.postTranslate((float) drawObj.getX(), (float) drawObj.getY());
            mCanvasView.setImageBitmap(mBitmap);
            mCanvasView.setScaleType(ScaleType.MATRIX);
            mCanvasView.setImageMatrix(matrix);
            break;
        case SCALE_MODE:
            mCanvasView.setImageBitmap(mBitmap);
            mCanvasView.setScaleType(ScaleType.FIT_CENTER);
            mCanvasView.setTranslationX((int) drawObj.getX());
            mCanvasView.setTranslationY((int) drawObj.getY());
            break;
        case FILL_MODE:
            BitmapDrawable bd = new BitmapDrawable(getResources(), mBitmap);
            bd.setTileModeX(Shader.TileMode.REPEAT);
            bd.setTileModeY(Shader.TileMode.REPEAT);
            mCanvasView.setImageDrawable(bd);
            mCanvasView.setScaleType(ScaleType.FIT_XY);
            mCanvasView.setTranslationX((int) drawObj.getX());
            mCanvasView.setTranslationY((int) drawObj.getY());
            break;
    }
}