Example usage for android.widget ImageView getPaddingTop

List of usage examples for android.widget ImageView getPaddingTop

Introduction

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

Prototype

public int getPaddingTop() 

Source Link

Document

Returns the top padding of this view.

Usage

From source file:Main.java

public static Rect getBitmapRectFromImageView(ImageView imageView) {
    Drawable drawable = imageView.getDrawable();
    Bitmap bitmap = null;// w  w w . j av  a 2  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:gov.wa.wsdot.android.wsdot.ui.mountainpasses.passitem.MountainPassItemActivity.java

private void startRefreshAnimation() {
    MenuItem item = mToolbar.getMenu().findItem(MENU_ITEM_REFRESH);
    if (item == null) {
        Log.e(TAG, "null");
        return;/*from   w ww  . j  a  v  a  2s . c  o m*/
    }
    // define the animation for rotation
    Animation animation = new RotateAnimation(360.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    animation.setDuration(1000);

    animation.setRepeatCount(Animation.INFINITE);

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mToolbar.getMenu().getItem(MENU_ITEM_REFRESH).setActionView(null);
            mToolbar.getMenu().getItem(MENU_ITEM_REFRESH).setIcon(R.drawable.ic_menu_refresh);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });

    ImageView imageView = new ImageView(this, null, android.R.style.Widget_Material_ActionButton);
    imageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_menu_refresh));

    imageView.setPadding(31, imageView.getPaddingTop(), 32, imageView.getPaddingBottom());

    imageView.startAnimation(animation);
    item.setActionView(imageView);

}

From source file:com.frank.protean.photoview.PhotoViewAttacher.java

private int getImageViewHeight(ImageView imageView) {
    return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
}

From source file:com.github.lakeshire.photoview.PhotoViewAttacher.java

private int getImageViewHeight(ImageView imageView) {
    if (null == imageView) {
        return 0;
    }//from w ww . ja  v a2s.  c  o  m
    return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
}

From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java

private int getImageViewHeight(ImageView imageView) {
    if (null == imageView)
        return 0;
    return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
}

From source file:com.meiqia.meiqiasdk.third.photoview.PhotoViewAttacher.java

protected int getImageViewHeight(ImageView imageView) {
    if (null == imageView)
        return 0;
    return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
}

From source file:com.ndn.menurandom.ImageDownloader.java

private void makeFrameLayout(ImageView imageView) {
    boolean isExist = false;
    ViewGroup vg = (ViewGroup) imageView.getParent();
    if (vg instanceof FrameLayout) {
        FrameLayout frameLayout = (FrameLayout) vg;
        String tag = (String) frameLayout.getTag();
        if (tag != null && tag.equals("fl_imagedownloader")) {
            isExist = true;//from w w w .j a  v a2s . c o  m
        }
    }

    if (!isExist) {
        int childCount = vg.getChildCount();
        int index = 0;
        while (index < childCount) {
            if (imageView == vg.getChildAt(index)) {
                break;
            }
            index++;
        }
        vg.removeViewAt(index);

        FrameLayout frameLayout = new FrameLayout(vg.getContext().getApplicationContext());
        frameLayout.setTag("fl_imagedownloader");
        ViewGroup.LayoutParams lpImageView = (ViewGroup.LayoutParams) imageView.getLayoutParams();
        frameLayout.setLayoutParams(lpImageView);
        imageView.setLayoutParams(new LayoutParams(lpImageView.width, lpImageView.height));
        frameLayout.setPadding(imageView.getPaddingLeft(), imageView.getPaddingTop(),
                imageView.getPaddingRight(), imageView.getPaddingBottom());
        imageView.setPadding(0, 0, 0, 0);
        frameLayout.addView(imageView);
        vg.addView(frameLayout, index);

        ProgressBar progressBar = new ProgressBar(frameLayout.getContext());
        progressBar.setTag("pb_imagedownloader");
        int leftRightPadding = (imageView.getLayoutParams().width - 50) / 2;
        int topBottomPadding = (imageView.getLayoutParams().height - 50) / 2;
        progressBar.setPadding(leftRightPadding, topBottomPadding, leftRightPadding, topBottomPadding);
        frameLayout.addView(progressBar);

    }
}

From source file:gov.wa.wsdot.android.wsdot.ui.trafficmap.TrafficMapActivity.java

private void refreshOverlays(final MenuItem item) {

    // define the animation for rotation
    Animation animation = new RotateAnimation(360.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    animation.setDuration(1000);/* ww  w  . j a  v a 2  s  .com*/
    animation.setRepeatCount(Animation.INFINITE);

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            mToolbar.getMenu().getItem(menu_item_refresh).setActionView(null);
            mToolbar.getMenu().getItem(menu_item_refresh).setIcon(R.drawable.ic_menu_refresh);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    ImageView imageView = new ImageView(this, null, android.R.style.Widget_Material_ActionButton);
    imageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_menu_refresh));
    imageView.setPadding(31, imageView.getPaddingTop(), 32, imageView.getPaddingBottom());
    imageView.startAnimation(animation);
    item.setActionView(imageView);

    if (mMap != null) {
        mapCameraViewModel.refreshCameras();
        mapHighwayAlertViewModel.refreshAlerts();
    }
}