Java Code Examples for android.widget.ImageView.getWidth()

The following are Jave code examples for showing how to use getWidth() of the android.widget.ImageView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ImageLoaderLibrary   File: ImageHelper.java   View Source Code Vote up 7 votes
public static int getImageWidth(ImageView imageView){
    if (imageView != null){
        int width = 0;
        ViewGroup.LayoutParams params = imageView.getLayoutParams();
        if (params != null && params.width != ViewGroup.LayoutParams.WRAP_CONTENT){
            width = imageView.getWidth();
        }

        if (width <= 0 && params != null){
            width = params.width;
        }

        if (width <= 0 ){
            width = getImageViewFieldValue(imageView,"mMaxWidth");
        }
        return width;
    }
    return DEFAULT_WIDTH;

}
 
Example 2
Project: magic_imageloader_network   File: ImageViewAware.java   View Source Code Vote up 7 votes
public int getDefaultWidth() {
    ImageView imageView = this.mViewRef.get();
    if (imageView != null) {
        ViewGroup.LayoutParams params = imageView.getLayoutParams();
        int width = 0;
        if (this.checkActualViewSize && params != null && params.width != -2) {
            width = imageView.getWidth();
        }
        if (width <= 0 && params != null) {
            width = params.width;
        }
        if (width <= 0) {
            width = getImageViewFieldValue(imageView, "mMaxWidth");
        }

        return width;
    } else {
        return 0;
    }
}
 
Example 3
Project: Widgets   File: ImgPreCfg.java   View Source Code Vote up 7 votes
/**
 * 计算点击的ImageView的大小
 *
 * @param iv 点击的ImageView
 */
private void calculateIv(ImageView iv) {
    if (null != iv) {
        // 如果传入ImageView,就按该ImageView计算
        mIvWidth = iv.getWidth();
        mIvHeight = iv.getHeight();

        int[] points = new int[2];
        iv.getLocationInWindow(points);
        mIvX = points[0];
        mIvY = points[1];
    } else {
        // 如果ImageView为空,就宽高设置为0
        mIvWidth = 0;
        mIvHeight = 0;
        // 并且把起点坐标设置0
        mIvX = 0;
        mIvY = 0;
    }
}
 
Example 4
Project: PhotoApp   File: ImageUtil.java   View Source Code Vote up 6 votes
/**
 * Ação de ZoomOut - Diminuir imagem
 */
public static void handleZoomOut(ImageView mImageSelected) {
    if (mImageSelected.getWidth() < 50)
        return;

    ViewGroup.LayoutParams params = mImageSelected.getLayoutParams();
    params.width = (int) (mImageSelected.getWidth() - (mImageSelected.getWidth() * 0.1));
    params.height = (int) (mImageSelected.getHeight() - (mImageSelected.getHeight() * 0.1));
    mImageSelected.setLayoutParams(params);
}
 
Example 5
Project: PhotoApp   File: ImageUtil.java   View Source Code Vote up 6 votes
/**
 * Ação de ZoomIn - Aumentar imagem
 */
public static void handleZoomIn(ImageView mImageSelected) {
    if (mImageSelected.getWidth() > 800)
        return;

    ViewGroup.LayoutParams params = mImageSelected.getLayoutParams();
    params.width = (int) (mImageSelected.getWidth() + (mImageSelected.getWidth() * 0.1));
    params.height = (int) (mImageSelected.getHeight() + (mImageSelected.getHeight() * 0.1));
    mImageSelected.setLayoutParams(params);
}
 
Example 6
Project: stynico   File: ImageLoader.java   View Source Code Vote up 6 votes
private ImageSize getImageViewSize(ImageView imageView) {

        ImageSize imageSize = new ImageSize();
        ViewGroup.LayoutParams lp = imageView.getLayoutParams();
        DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics();
        int width = imageView.getWidth();
        if (width <= 0) {
            width = lp.width;
        }
        if (width <= 0) {
            width = getImageViewFieldValue(imageView, "mMaxWidth");
        }
        if (width <= 0) {
            width = displayMetrics.widthPixels;
        }

        int height = imageView.getHeight();
        if (height <= 0) {
            height = lp.height;
        }
        if (height <= 0) {
            height = getImageViewFieldValue(imageView, "mMaxHeight");
        }
        if (height <= 0) {
            height = displayMetrics.heightPixels;
        }
        imageSize.width = width;
        imageSize.height = height;
        return imageSize;
    }
 
Example 7
Project: CSipSimple   File: QuickContactBadge.java   View Source Code Vote up 6 votes
public void overlay(Canvas c, ImageView img) {
    if (arrowPos != ArrowPosition.NONE) {
        
        int x_border = (arrowPos == ArrowPosition.LEFT) ? 0 : img.getWidth();
        int x_inside = x_border + ((arrowPos == ArrowPosition.LEFT) ? 1 : -1 ) * (int)(img.getWidth() * 0.2f);
        int y_top = (int) (img.getHeight() * 0.2f);
        int y_bottom = (int) (img.getHeight() * 0.6f);
        c.save();
        
        Path path = new Path();   
        path.setFillType(Path.FillType.EVEN_ODD);
        path.moveTo(x_border, y_top);
        path.lineTo(x_inside, (y_top + y_bottom)/2);
        path.lineTo(x_border, y_bottom);
        path.lineTo(x_border, y_top);
        path.close();

        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setStrokeWidth(0);
        paint.setColor(android.graphics.Color.BLACK);     
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setAntiAlias(true);

        
        c.drawPath(path, paint);
        c.restore();
    }
}
 
Example 8
Project: FLFloatingButton   File: TrashView.java   View Source Code Vote up 6 votes
/**
 * 削除アイコンの中心X座標を取得します。
 *
 * @return 削除アイコンの中心X座標
 */
float getTrashIconCenterX() {
    final ImageView iconView = hasActionTrashIcon() ? mActionTrashIconView : mFixedTrashIconView;
    final float iconViewPaddingLeft = iconView.getPaddingLeft();
    final float iconWidth = iconView.getWidth() - iconViewPaddingLeft - iconView.getPaddingRight();
    final float x = mTrashIconRootView.getX() + iconViewPaddingLeft;
    return x + iconWidth / 2;
}
 
Example 9
Project: polling-station-app   File: CameraFragmentUtil.java   View Source Code Vote up 6 votes
/**
 * Crop the bitmap to only the part of the scansegment. The bitmap should only contain the part
 * that displays the MRZ of a travel document.
 * @param bitmap - The bitmap created from the camerapreview
 * @param scanSegment - Scansegment, the segment that should be scanned with OCR
 * @return
 */
public static Bitmap cropBitmap(Bitmap bitmap, ImageView scanSegment) {
    int startX = (int) scanSegment.getX();
    int startY = (int) scanSegment.getY();
    int width = scanSegment.getWidth();
    int length = scanSegment.getHeight();
    return Bitmap.createBitmap(bitmap, startX, startY, width, length);
}
 
Example 10
Project: ECardFlow   File: CrossMoveAnimMode.java   View Source Code Vote up 6 votes
@Override
public void transformPage(ImageView ivBg, float position, int direction) {
    ivBg.setScaleX(mScale);
    ivBg.setScaleY(mScale);
    float totalMoveWidth = ivBg.getWidth() * ((mScale - 1) / 2);
    int lastPosition = Math.round(position);
    float mFraction;
    if (lastPosition % 2 == 0) {
        mFraction = -1 * (float) Math.sin(Math.PI * position);
    } else {
        mFraction = (float) Math.sin(Math.PI * position);
    }
    ivBg.setTranslationY(totalMoveWidth * mFraction);
}
 
Example 11
Project: GitHub   File: PhotoViewAttacher.java   View Source Code Vote up 5 votes
private void checkMatrixBounds() {
	final ImageView imageView = getImageView();
	if (null == imageView) {
		return;
	}

	final RectF rect = getDisplayRect(getDisplayMatrix());
	if (null == rect) {
		return;
	}

	final float height = rect.height(), width = rect.width();
	float deltaX = 0, deltaY = 0;

	final int viewHeight = imageView.getHeight();
	if (height <= viewHeight) {
		switch (mScaleType) {
		case FIT_START:
			deltaY = -rect.top;
			break;
		case FIT_END:
			deltaY = viewHeight - height - rect.top;
			break;
		default:
			deltaY = (viewHeight - height) / 2 - rect.top;
			break;
		}
	} else if (rect.top > 0) {
		deltaY = -rect.top;
	} else if (rect.bottom < viewHeight) {
		deltaY = viewHeight - rect.bottom;
	}

	final int viewWidth = imageView.getWidth();
	if (width <= viewWidth) {
		switch (mScaleType) {
		case FIT_START:
			deltaX = -rect.left;
			break;
		case FIT_END:
			deltaX = viewWidth - width - rect.left;
			break;
		default:
			deltaX = (viewWidth - width) / 2 - rect.left;
			break;
		}
		mScrollEdge = EDGE_BOTH;
	} else if (rect.left > 0) {
		mScrollEdge = EDGE_LEFT;
		deltaX = -rect.left;
	} else if (rect.right < viewWidth) {
		deltaX = viewWidth - rect.right;
		mScrollEdge = EDGE_RIGHT;
	} else {
		mScrollEdge = EDGE_NONE;
	}

	// Finally actually translate the matrix
	mSuppMatrix.postTranslate(deltaX, deltaY);
}
 
Example 12
Project: android-project-gallery   File: PhotoViewAttacher.java   View Source Code Vote up 5 votes
private int getImageViewWidth(ImageView imageView) {
    if (null == imageView)
        return 0;
    return imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
}
 
Example 13
Project: GitHub   File: ImageOptions.java   View Source Code Vote up 5 votes
final void optimizeMaxSize(ImageView view) {
    if (width > 0 && height > 0) {
        maxWidth = width;
        maxHeight = height;
        return;
    }

    int screenWidth = DensityUtil.getScreenWidth();
    int screenHeight = DensityUtil.getScreenHeight();

    if (width < 0) {
        maxWidth = screenWidth * 3 / 2; //Integer.MAX_VALUE;
        compress = false;
    }
    if (height < 0) {
        maxHeight = screenHeight * 3 / 2; //Integer.MAX_VALUE;
        compress = false;
    }

    if (view == null && maxWidth <= 0 && maxHeight <= 0) {
        maxWidth = screenWidth;
        maxHeight = screenHeight;
    } else {
        int tempWidth = maxWidth;
        int tempHeight = maxHeight;

        if (view != null) {
            final ViewGroup.LayoutParams params = view.getLayoutParams();
            if (params != null) {

                if (tempWidth <= 0) {
                    if (params.width > 0) {
                        tempWidth = params.width;
                        if (this.width <= 0) {
                            this.width = tempWidth;
                        }
                    } else if (params.width != ViewGroup.LayoutParams.WRAP_CONTENT) {
                        tempWidth = view.getWidth();
                    }
                }

                if (tempHeight <= 0) {
                    if (params.height > 0) {
                        tempHeight = params.height;
                        if (this.height <= 0) {
                            this.height = tempHeight;
                        }
                    } else if (params.height != ViewGroup.LayoutParams.WRAP_CONTENT) {
                        tempHeight = view.getHeight();
                    }
                }
            }

            if (tempWidth <= 0) tempWidth = getImageViewFieldValue(view, "mMaxWidth");
            if (tempHeight <= 0) tempHeight = getImageViewFieldValue(view, "mMaxHeight");
        }

        if (tempWidth <= 0) tempWidth = screenWidth;
        if (tempHeight <= 0) tempHeight = screenHeight;

        maxWidth = tempWidth;
        maxHeight = tempHeight;
    }
}
 
Example 14
Project: PicShow-zhaipin   File: PhotoViewAttacher.java   View Source Code Vote up 5 votes
private int getImageViewWidth(ImageView imageView) {
    if (null == imageView)
        return 0;
    return imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
}
 
Example 15
Project: DailyStudy   File: PhotoViewAttacher.java   View Source Code Vote up 5 votes
private int getImageViewWidth(ImageView imageView) {
    if (null == imageView)
        return 0;
    return imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
}
 
Example 16
Project: PhotoPickApp   File: PhotoViewAttacher.java   View Source Code Vote up 5 votes
private int getImageViewWidth(ImageView imageView) {
    return imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
}
 
Example 17
Project: Recognize-it   File: PhotoViewAttacher.java   View Source Code Vote up 5 votes
private int getImageViewWidth(ImageView imageView) {
    if (null == imageView)
        return 0;
    return imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
}
 
Example 18
Project: Watermark   File: PhotoViewAttacher.java   View Source Code Vote up 5 votes
private int getImageViewWidth(ImageView imageView) {
    if (null == imageView)
        return 0;
    return imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
}
 
Example 19
Project: filepicker   File: PhotoViewAttacher.java   View Source Code Vote up 5 votes
private void checkMatrixBounds() {
    final ImageView imageView = getImageView();
    if (null == imageView) {
        return;
    }

    final RectF rect = getDisplayRect(getDisplayMatrix());
    if (null == rect) {
        return;
    }

    final float height = rect.height(), width = rect.width();
    float deltaX = 0, deltaY = 0;

    final int viewHeight = imageView.getHeight();
    if (height <= viewHeight) {
        switch (mScaleType) {
            case FIT_START:
                deltaY = -rect.top;
                break;
            case FIT_END:
                deltaY = viewHeight - height - rect.top;
                break;
            default:
                deltaY = (viewHeight - height) / 2 - rect.top;
                break;
        }
    } else if (rect.top > 0) {
        deltaY = -rect.top;
    } else if (rect.bottom < viewHeight) {
        deltaY = viewHeight - rect.bottom;
    }

    final int viewWidth = imageView.getWidth();
    if (width <= viewWidth) {
        switch (mScaleType) {
            case FIT_START:
                deltaX = -rect.left;
                break;
            case FIT_END:
                deltaX = viewWidth - width - rect.left;
                break;
            default:
                deltaX = (viewWidth - width) / 2 - rect.left;
                break;
        }
        mScrollEdge = EDGE_BOTH;
    } else if (rect.left > 0) {
        mScrollEdge = EDGE_LEFT;
        deltaX = -rect.left;
    } else if (rect.right < viewWidth) {
        deltaX = viewWidth - rect.right;
        mScrollEdge = EDGE_RIGHT;
    } else {
        mScrollEdge = EDGE_NONE;
    }

    // Finally actually translate the matrix
    mSuppMatrix.postTranslate(deltaX, deltaY);
}
 
Example 20
Project: TinyPlanetMaker   File: OnPlanetTouchListener.java   View Source Code Vote up 5 votes
@Override
public boolean onTouch(View v, MotionEvent event) {

    ImageView view = (ImageView) v;

    // Dump touch event to log
    dumpEvent(event);

    // Handle touch events here...
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            lastPoint.set(event.getX(), event.getY());
            mode = DRAG;
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            oldDist = spacing(event);
            mode = ZOOM;
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
            mode = NONE;
            break;
        case MotionEvent.ACTION_MOVE:

            if (mode == DRAG) {

                // Do nothing at the outer left side. Probably the user opened the navigation drawer:
                if (event.getX() < LEFT_MARGIN)
                    return false;

                float xDiff = event.getX() - lastPoint.x;
                float yDiff = event.getY() - lastPoint.y;

                float diff;

                if (Math.abs(xDiff) > Math.abs(yDiff)) {
                    diff = xDiff;
                    if (event.getY() < view.getHeight() / 2)
                        diff *= -1;
                }
                else {
                    diff = yDiff;
                    if (event.getX() > view.getWidth() / 2)
                        diff *= -1;
                }

                float fac = .25f;
                int iDiff = Math.round(diff * fac);

                mPlanetChangeCallBacks.addAngle(iDiff);

                lastPoint.set(event.getX(), event.getY());


            } else if (mode == ZOOM) {

                float newDist = spacing(event);

                float scale = newDist / oldDist;
                mPlanetChangeCallBacks.addScaleLog(scale * scale);

                oldDist = newDist;

            }
            break;
    }


    return true; // indicate event was handled
}