Example usage for android.widget ImageView getHeight

List of usage examples for android.widget ImageView getHeight

Introduction

In this page you can find the example usage for android.widget ImageView getHeight.

Prototype

@ViewDebug.ExportedProperty(category = "layout")
public final int getHeight() 

Source Link

Document

Return the height of your view.

Usage

From source file:Main.java

public static int[] mapBitmapCoordinatesFromImageView(int posX, int posY, ImageView imageView) {
    Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();

    int ivW = imageView.getWidth();
    int ivH = imageView.getHeight();
    int bW = bitmap.getWidth();
    int bH = bitmap.getHeight();

    int newX = posX * bW / ivW;
    int newH = posY * bH / ivH;

    return new int[] { newX, newH };
}

From source file:Main.java

public static Point calcDecodeSizeHint(ImageView imageView) {
    Point p = new Point();
    LayoutParams params = imageView.getLayoutParams();
    p.x = (params != null) ? params.width : imageView.getWidth();
    p.y = (params != null) ? params.height : imageView.getHeight();
    return p;//  w ww. j a v  a  2  s . c  om
}

From source file:Main.java

/**
 * {@inheritDoc}/*from   w  w w  .ja  v a 2 s  .com*/
 * <p/>
 * Height is defined by target {@link ImageView view} parameters,
 * configuration parameters or device display dimensions.<br />
 * Size computing algorithm:<br />
 * 1) Get the actual drawn <b>getHeight()</b> of the View. If view haven't
 * drawn yet then go to step #2.<br />
 * 2) Get <b>layout_height</b>. If it hasn't exact value then go to step #3.
 * <br />
 * 3) Get <b>maxHeight</b>.
 */
public static int getImageViewHeight(ImageView imageView) {
    if (imageView != null) {
        final ViewGroup.LayoutParams params = imageView.getLayoutParams();
        int height = 0;
        if (params != null && params.height != ViewGroup.LayoutParams.WRAP_CONTENT) {
            height = imageView.getHeight(); // Get actual image height
        }
        if (height <= 0 && params != null) {
            // Get layout height parameter
            height = params.height;
        }
        if (height <= 0) {
            height = getImageViewFieldValue(imageView, "mMaxHeight");
        }
        return height;
    }
    return DEFAULT_HEIGHT;
}

From source file:Main.java

public static Rect getBitmapRectFromImageView(ImageView imageView) {
    Drawable drawable = imageView.getDrawable();
    Bitmap bitmap = null;/*from   w ww. ja  v a2  s  . c o  m*/
    if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }

    Rect rect = new Rect();
    boolean isVisible = imageView.getGlobalVisibleRect(rect);
    if (!isVisible) {
        int[] location = new int[2];
        imageView.getLocationOnScreen(location);

        rect.left = location[0];
        rect.top = location[1];
        rect.right = rect.left + imageView.getWidth();
        rect.bottom = rect.top + imageView.getHeight();
    }

    if (bitmap != null) {

        int bitmapWidth = bitmap.getWidth();
        int bitmapHeight = bitmap.getHeight();

        int imageViewWidth = imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
        int imageviewHeight = imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();

        float startScale;
        if ((float) imageViewWidth / bitmapWidth > (float) imageviewHeight / bitmapHeight) {
            // Extend start bounds horizontally
            startScale = (float) imageviewHeight / bitmapHeight;
        } else {
            startScale = (float) imageViewWidth / bitmapWidth;
        }

        bitmapHeight = (int) (bitmapHeight * startScale);
        bitmapWidth = (int) (bitmapWidth * startScale);

        int deltaX = (imageViewWidth - bitmapWidth) / 2;
        int deltaY = (imageviewHeight - bitmapHeight) / 2;

        rect.set(rect.left + deltaX, rect.top + deltaY, rect.right - deltaX, rect.bottom - deltaY);

        return rect;
    } else {
        return null;
    }
}

From source file:android.support.v7.testutils.TestUtilsMatchers.java

/**
 * Returns a matcher that matches <code>ImageView</code>s which have drawable flat-filled
 * with the specific color.//from  ww w  .j  ava 2  s .  com
 */
public static Matcher drawable(@ColorInt final int color) {
    return new BoundedMatcher<View, ImageView>(ImageView.class) {
        private String failedComparisonDescription;

        @Override
        public void describeTo(final Description description) {
            description.appendText("with drawable of color: ");

            description.appendText(failedComparisonDescription);
        }

        @Override
        public boolean matchesSafely(final ImageView view) {
            Drawable drawable = view.getDrawable();
            if (drawable == null) {
                return false;
            }

            // One option is to check if we have a ColorDrawable and then call getColor
            // but that API is v11+. Instead, we call our helper method that checks whether
            // all pixels in a Drawable are of the same specified color.
            try {
                TestUtils.assertAllPixelsOfColor("", drawable, view.getWidth(), view.getHeight(), true, color,
                        0, true);
                // If we are here, the color comparison has passed.
                failedComparisonDescription = null;
                return true;
            } catch (Throwable t) {
                // If we are here, the color comparison has failed.
                failedComparisonDescription = t.getMessage();
                return false;
            }
        }
    };
}

From source file:com.miz.utils.ViewUtils.java

public static void setLayoutParamsForDetailsEmptyView(Context context, View layout, ImageView background,
        ObservableScrollView scrollView, ViewTreeObserver.OnGlobalLayoutListener listener) {
    if (!MizLib.isPortrait(context)) {
        // Let's set the size of the empty view on the scroll container
        View empty = layout.findViewById(R.id.empty_view);

        if (empty == null)
            return;

        // First, we get the height of the background image, since that
        // fills the available screen estate in its entirety
        int fullHeight = background.getHeight();

        // Then we get the content height - this is how much of the content
        // will be shown on the screen at a minimum
        int contentHeight = context.getResources().getDimensionPixelSize(R.dimen.content_details_main_height);

        // Finally we set the empty view to fill the width and have a height
        // that fills the gap between the full height and content height
        empty.setLayoutParams(/*from ww  w  .  j a  v a2 s .  co  m*/
                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, fullHeight - contentHeight));
    }

    // Remove the ViewTreeObserver when we're done :-)
    MizLib.removeViewTreeObserver(scrollView.getViewTreeObserver(), listener);
}

From source file:my.home.lehome.asynctask.LoadProfileHeaderBgAsyncTask.java

@Override
protected void onPreExecute() {
    ImageView imageView = mImageView.get();
    if (imageView != null) {
        imageView.setImageURI(null);/*ww w. j  av a  2s . c  o  m*/
        this.mWidth = imageView.getWidth();
        this.mHeight = imageView.getHeight();
        this.mScaleType = imageView.getScaleType();
    }
    ProgressBar progressBar = mProgressBar.get();
    if (progressBar != null) {
        progressBar.setVisibility(View.VISIBLE);
    }
}

From source file:com.quran.labs.androidquran.widgets.IconPageIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int count = mIconsLayout.getChildCount();
    ImageView v = (ImageView) mIconsLayout.getChildAt(mSelectedIndex);
    final int bottom = v.getHeight();
    final int top = bottom - mIndicatorHeight;
    int left = v.getLeft();
    int right = v.getRight();

    if (mSelectedIndex + 1 < count) {
        View nextIcon = mIconsLayout.getChildAt(mSelectedIndex + 1);
        left = (int) (mSelectionOffset * nextIcon.getLeft() + (1.0f - mSelectionOffset) * left);
        right = (int) (mSelectionOffset * nextIcon.getRight() + (1.0f - mSelectionOffset) * right);
    }//from  ww  w  . ja va  2s.  co m

    mIndicatorPaint.setColor(mIndicatorColor);
    canvas.drawRect(left, top, right, bottom, mIndicatorPaint);
}

From source file:nz.ac.otago.psyanlab.common.util.BitmapCache.java

/**
 * Prepares parameters for loading a bitmap into the cache. The parameters
 * are themselves cached so many ImageViews can be run through generating
 * only one set of parameters to fit all ImageViews using the same image.
 * /*w  w w .  j av  a2  s .c  o  m*/
 * @param path
 *            Path to bitmap.
 * @param imageView
 *            ImageView to use the bitmap.
 * @return
 */
public BitmapParams prepareBitmapParams(String path, ImageView imageView) {
    BitmapParams param = map.get(path);
    if (param == null) {
        param = new BitmapParams(path, imageView.getWidth(), imageView.getHeight());
        map.put(path, param);
    } else {
        if (param.height < imageView.getHeight()) {
            param.height = imageView.getHeight();
        }
        if (param.width < imageView.getWidth()) {
            param.width = imageView.getWidth();
        }
    }

    return param;
}

From source file:camera.AnotherCamera.java

/**
 * Scale the photo down and fit it to our image views.
 *
 * "Drastically increases performance" to set images using this technique.
 * Read more:http://developer.android.com/training/camera/photobasics.html
 *//*from   ww w .j  a  v  a  2s . co m*/
private void setFullImageFromFilePath(String imagePath, ImageView imageView) {
    // Get the dimensions of the View
    int targetW = imageView.getWidth();
    int targetH = imageView.getHeight();

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

    // Determine how much to scale down the image
    int scaleFactor = 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(imagePath, bmOptions);
    imageView.setImageBitmap(bitmap);
}