Example usage for android.widget ImageView getMeasuredHeight

List of usage examples for android.widget ImageView getMeasuredHeight

Introduction

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

Prototype

public final int getMeasuredHeight() 

Source Link

Document

Like #getMeasuredHeightAndState() , but only returns the raw height component (that is the result is masked by #MEASURED_SIZE_MASK ).

Usage

From source file:Main.java

private static void updateImageViewAfterScaleTypeChange(ImageView imageView) {
    // enforcing imageView to update its internal bounds/matrix immediately
    imageView.measure(MeasureSpec.makeMeasureSpec(imageView.getMeasuredWidth(), MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(imageView.getMeasuredHeight(), MeasureSpec.EXACTLY));
    imageView.layout(imageView.getLeft(), imageView.getTop(), imageView.getRight(), imageView.getBottom());
}

From source file:net.naonedbus.card.impl.MapCard.java

private void fillView(final ImageView imageView) {
    final String url;
    if (mCurrentLocation == null) {
        url = String.format(Locale.ENGLISH, MAP_URL, imageView.getMeasuredWidth(),
                imageView.getMeasuredHeight(), mLatitude, mLongitude);
    } else {//from  w w w. java2  s. co m
        url = String.format(Locale.ENGLISH, MAP_URL_CURRENT_LOCATION, imageView.getMeasuredWidth(),
                imageView.getMeasuredHeight(), mLatitude, mLongitude, mCurrentLocation.getLatitude(),
                mCurrentLocation.getLongitude());
    }

    final Bundle bundle = new Bundle();
    bundle.putString(PARAM_URL, url);

    initLoader(bundle, this).forceLoad();
}

From source file:com.vuze.android.widget.SwipeRefreshLayoutExtra.java

private void layoutExtra(ImageView circleView) {
    if (mExtraView == null) {
        return;/*from  w w  w  .  j  a va2s  . c  o m*/
    }
    final int width = getMeasuredWidth();

    int tvHeight = mExtraView.getMeasuredHeight();

    int circleHeight = circleView.getMeasuredHeight();
    int offset = circleView.getTop();

    int tvTop = offset + circleHeight;
    if (DEBUG_FOLLOW_THE_CIRLCE_HACK) {
        Log.d(TAG, "layoutExtra: " + tvTop + ";" + circleView.getVisibility());
    }
    mExtraView.layout(0, tvTop, width, tvTop + tvHeight);

    int visibility = mExtraView.getVisibility();
    int newVisibility = tvTop <= 0 ? View.GONE : View.VISIBLE;

    if (visibility != newVisibility) {
        if (DEBUG_FOLLOW_THE_CIRLCE_HACK) {
            Log.d(TAG, "layoutExtra: set " + (tvTop <= 0 ? "GONE" : "VISIBLE") + ";"
                    + AndroidUtils.getCompressedStackTrace());
        }
        mExtraView.setVisibility(newVisibility);
        if (listenerOnExtraViewVisiblityChange != null) {
            listenerOnExtraViewVisiblityChange.onExtraViewVisibilityChange(mExtraView, newVisibility);
        }
    }
}

From source file:com.tigerpenguin.places.model.Photo.java

public void loadImage(Context context, ImageView imageView) {
    int width = imageView.getLayoutParams().width;
    if (width <= 0) {
        width = imageView.getMeasuredWidth();
    }/*from w  w w  . jav  a  2s .  co m*/

    int height = imageView.getLayoutParams().height;
    if (height <= 0) {
        height = imageView.getMeasuredHeight();
    }
    Picasso.with(context).load(getUrl(context, width, height)).into(imageView);
}

From source file:ru.tlrs.vincent.LightBox.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(TAG, "onCreateView: ");
    inflateView(inflater, container);/*  w w w . jav  a 2 s.c  o  m*/
    final ImageView fullImage = (ImageView) view.findViewById(R.id.fullImage);
    fullImage.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            fullImage.getViewTreeObserver().removeOnPreDrawListener(this);
            int height = fullImage.getMeasuredHeight();
            int width = fullImage.getMeasuredWidth();
            Log.d(TAG, "onPreDraw: " + String.format("height: %s, width: %s", height, width));
            //Rect view = new Rect(0,0,width, height);
            Drawable drawable = ((ImageView) getActivity().findViewById(parentId)).getDrawable();
            /*drawable = drawable.mutate();
            //Rect draw = drawable.getBounds();
            int h = drawable.getIntrinsicHeight();
            int w = drawable.getIntrinsicWidth();
            //drawable.setBounds(0,0,w,h);
            drawable.setBounds(new Rect(0,0,width,height));
            //ScaleDrawable sd = new ScaleDrawable(drawable, 0, 1.0f ,1.0f );*/
            //fullImage.setImageDrawable(drawable);
            //fullImage.setImageURI(null);
            Log.d(TAG, "onPreDraw: mSrc = " + mSrc);
            fullImage.setImageURI(Uri.parse("android.resource://com.example.vincent/" + mSrc)); //give "More than two path segments", instead of NullPointer
            return false;
        }
    });

    //((ImageView) view.findViewById(R.id.fullImage)).setImageDrawable(((ImageView) getActivity().findViewById(parentId)).getDrawable());
    ((TextView) view.findViewById(R.id.description)).setText(mDesc);
    return view;
}

From source file:org.dmfs.android.view.DrawablePagerTitleStrip.java

@SuppressLint("NewApi")
void updateDrawablePositions(int position, float positionOffset, boolean force) {
    if (mImageViews == null || mImageViews.length == 0) {
        return;//w w  w  .j  a va  2s.  c o m
    }

    if (position != mLastKnownCurrentPage) {
        updateImages(position, mPager.getAdapter());
    } else if (!force && positionOffset == mLastKnownPositionOffset) {
        return;
    }

    mUpdatingPositions = true;

    final int[] widths = new int[mImageViews.length];
    for (int i = 0, l = mImageViews.length; i < l; ++i) {
        widths[i] = mImageViews[i].getMeasuredWidth();
    }

    final int stripWidth = getWidth();
    final int stripHeight = getHeight();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int paddingTop = getPaddingTop();
    final int paddingBottom = getPaddingBottom();

    float currOffset = positionOffset + 0.5f;
    if (currOffset > 1.f) {
        currOffset -= 1.f;
    }
    final int currCenter = stripWidth / 2
            - (int) ((widths[widths.length / 2] + mScaledTextSpacing) * (currOffset - 0.5f));
    final int currLeft = currCenter - widths[widths.length / 2] / 2;

    int maxBaseline = 0;
    for (ImageView iv : mImageViews) {
        maxBaseline = Math.max(maxBaseline, iv.getBaseline());
    }

    int maxTextHeight = 0;
    for (ImageView iv : mImageViews) {
        maxTextHeight = Math.max(maxTextHeight, maxBaseline - iv.getBaseline() + iv.getMeasuredHeight());
    }

    final int vgrav = mGravity & Gravity.VERTICAL_GRAVITY_MASK;

    int left = currLeft;
    for (int i = mImageViews.length / 2, l = mImageViews.length; i < l; ++i) {
        int baseline = mImageViews[i].getBaseline();
        int top;
        switch (vgrav) {
        default:
        case Gravity.TOP:
            top = paddingTop + maxBaseline - baseline;
            break;
        case Gravity.CENTER_VERTICAL:
            final int paddedHeight = stripHeight - paddingTop - paddingBottom;
            final int centeredTop = (paddedHeight - maxTextHeight) / 2;
            top = centeredTop + maxBaseline - baseline;
            break;
        case Gravity.BOTTOM:
            final int bottomGravTop = stripHeight - paddingBottom - maxTextHeight;
            top = bottomGravTop + maxBaseline - baseline;
            break;
        }

        int right = left + widths[i];
        mImageViews[i].layout(left, top, right, top + mImageViews[i].getMeasuredHeight());
        left += widths[i] + mScaledTextSpacing;

        if (VERSION.SDK_INT >= 14) {
            if (stripWidth - right < paddingRight) {
                mImageViews[i].setAlpha(
                        1 - ((float) Math.abs(Math.min(stripWidth - right - paddingRight, 0))) / widths[i]);
            } else {
                mImageViews[i].setAlpha(1f);
            }
        }
    }

    left = currLeft;
    for (int i = mImageViews.length / 2 - 1; i >= 0; --i) {
        int baseline = mImageViews[i].getBaseline();
        int top;
        switch (vgrav) {
        default:
        case Gravity.TOP:
            top = paddingTop + maxBaseline - baseline;
            break;
        case Gravity.CENTER_VERTICAL:
            final int paddedHeight = stripHeight - paddingTop - paddingBottom;
            final int centeredTop = (paddedHeight - maxTextHeight) / 2;
            top = centeredTop + maxBaseline - baseline;
            break;
        case Gravity.BOTTOM:
            final int bottomGravTop = stripHeight - paddingBottom - maxTextHeight;
            top = bottomGravTop + maxBaseline - baseline;
            break;
        }
        left -= widths[i] + mScaledTextSpacing;

        mImageViews[i].layout(left, top, left + widths[i], top + mImageViews[i].getMeasuredHeight());

        if (VERSION.SDK_INT >= 14) {
            if (left < paddingLeft) {
                mImageViews[i].setAlpha(1 - ((float) Math.abs(Math.min(left - paddingLeft, 0))) / widths[i]);
            } else {
                mImageViews[i].setAlpha(1f);
            }
        }
    }

    mLastKnownPositionOffset = positionOffset;
    mUpdatingPositions = false;
}

From source file:com.squareup.picasso.RequestCreator.java

/**
 * Asynchronously fulfills the request into the specified {@link ImageView} and invokes the
 * target {@link Callback} if it's not {@code null}.
 * <p/>// w  w w . j  a  va 2 s  .  com
 * <em>Note:</em> The {@link Callback} param is a strong reference and will prevent your
 * {@link android.app.Activity} or {@link android.app.Fragment} from being garbage collected. If
 * you use this method, it is <b>strongly</b> recommended you invoke an adjacent
 * {@link Picasso#cancelRequest(android.widget.ImageView)} call to prevent temporary leaking.
 */
public void into(ImageView target, Callback callback) {
    if (target == null) {
        throw new IllegalArgumentException("Target must not be null.");
    }

    if (!data.hasImage()) {
        picasso.cancelRequest(target);
        PicassoDrawable.setPlaceholder(target, placeholderResId, placeholderDrawable);
        return;
    }

    if (deferred) {
        if (data.hasSize()) {
            throw new IllegalStateException("Fit cannot be used with resize.");
        }
        int measuredWidth = target.getMeasuredWidth();
        int measuredHeight = target.getMeasuredHeight();
        if (maxWidth != -1 && measuredWidth > maxWidth)
            measuredWidth = maxWidth;
        if (maxHeight != -1 && measuredHeight > maxHeight)
            measuredHeight = maxHeight;
        if (measuredWidth == 0 && measuredHeight == 0) {
            PicassoDrawable.setPlaceholder(target, placeholderResId, placeholderDrawable);
            picasso.defer(target, new DeferredRequestCreator(this, target, callback));
            return;
        }
        data.resize(measuredWidth, measuredHeight, false);
    }

    Request finalData = picasso.transformRequest(data.build());
    String requestKey = createKey(finalData);

    if (!skipMemoryCache) {
        Bitmap bitmap = picasso.quickMemoryCacheCheck(
                data.getCache() != null ? data.getCache() : picasso.getCache(), requestKey);
        if (bitmap != null) {
            picasso.cancelRequest(target);
            PicassoDrawable.setBitmap(target, picasso.context, bitmap, MEMORY, fadeTime, picasso.debugging);
            if (callback != null) {
                callback.onSuccess();
            }
            return;
        }
    }

    PicassoDrawable.setPlaceholder(target, placeholderResId, placeholderDrawable);

    Action<ImageView> action = new ImageViewAction(picasso, target, finalData, skipMemoryCache, fadeTime,
            errorResId, errorDrawable, requestKey, callback);

    picasso.enqueueAndSubmit(action, delayMillis);
}

From source file:com.keylesspalace.tusky.activity.MainActivity.java

private void fetchUserInfo() {
    SharedPreferences preferences = getSharedPreferences(getString(R.string.preferences_file_key),
            Context.MODE_PRIVATE);
    final String domain = preferences.getString("domain", null);
    String id = preferences.getString("loggedInAccountId", null);
    String username = preferences.getString("loggedInAccountUsername", null);

    if (id != null && username != null) {
        loggedInAccountId = id;//from   ww  w .j  ava2s. c om
        loggedInAccountUsername = username;
    }

    mastodonAPI.accountVerifyCredentials().enqueue(new Callback<Account>() {
        @Override
        public void onResponse(Call<Account> call, Response<Account> response) {
            if (!response.isSuccessful()) {
                onFetchUserInfoFailure(new Exception(response.message()));
                return;
            }

            Account me = response.body();
            ImageView background = headerResult.getHeaderBackgroundView();
            int backgroundWidth = background.getWidth();
            int backgroundHeight = background.getHeight();
            if (backgroundWidth == 0 || backgroundHeight == 0) {
                /* The header ImageView may not be layed out when the verify credentials call
                 * returns so measure the dimensions and use those. */
                background.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY);
                backgroundWidth = background.getMeasuredWidth();
                backgroundHeight = background.getMeasuredHeight();
            }

            Picasso.with(MainActivity.this).load(me.header).placeholder(R.drawable.account_header_missing)
                    .resize(backgroundWidth, backgroundHeight).centerCrop().into(background);

            headerResult.addProfiles(new ProfileDrawerItem().withName(me.getDisplayName())
                    .withEmail(String.format("%s@%s", me.username, domain)).withIcon(me.avatar));

            onFetchUserInfoSuccess(me.id, me.username);
        }

        @Override
        public void onFailure(Call<Account> call, Throwable t) {
            onFetchUserInfoFailure((Exception) t);
        }
    });
}

From source file:net.maa123.tatuky.MainActivity.java

private void onFetchUserInfoSuccess(Account me, String domain) {
    // Add the header image and avatar from the account, into the navigation drawer header.
    headerResult.clear();/* ww w.j av a2s.c o m*/

    ImageView background = headerResult.getHeaderBackgroundView();
    int backgroundWidth = background.getWidth();
    int backgroundHeight = background.getHeight();
    if (backgroundWidth == 0 || backgroundHeight == 0) {
        /* The header ImageView may not be layed out when the verify credentials call returns so
         * measure the dimensions and use those. */
        background.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY);
        backgroundWidth = background.getMeasuredWidth();
        backgroundHeight = background.getMeasuredHeight();
    }

    background.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark));

    Picasso.with(MainActivity.this).load(me.header).placeholder(R.drawable.account_header_default)
            .resize(backgroundWidth, backgroundHeight).centerCrop().into(background);

    headerResult.addProfiles(new ProfileDrawerItem().withName(me.getDisplayName())
            .withEmail(String.format("%s@%s", me.username, domain)).withIcon(me.avatar));

    // Show follow requests in the menu, if this is a locked account.
    if (me.locked) {
        PrimaryDrawerItem followRequestsItem = new PrimaryDrawerItem().withIdentifier(6)
                .withName(R.string.action_view_follow_requests).withSelectable(false)
                .withIcon(GoogleMaterial.Icon.gmd_person_add);
        drawer.addItemAtPosition(followRequestsItem, 3);
    }

    // Update the current login information.
    loggedInAccountId = me.id;
    loggedInAccountUsername = me.username;
    getPrivatePreferences().edit().putString("loggedInAccountId", loggedInAccountId)
            .putString("loggedInAccountUsername", loggedInAccountUsername)
            .putBoolean("loggedInAccountLocked", me.locked).apply();
}

From source file:com.fa.mastodon.activity.MainActivity.java

private void onFetchUserInfoSuccess(Account me, String domain) {
    // Add the header image and avatar from the account, into the navigation drawer header.
    headerResult.clear();/*w  w w . j av  a 2s  .  c o m*/

    ImageView background = headerResult.getHeaderBackgroundView();
    int backgroundWidth = background.getWidth();
    int backgroundHeight = background.getHeight();
    if (backgroundWidth == 0 || backgroundHeight == 0) {
        /* The header ImageView may not be layed out when the verify credentials call returns so
         * measure the dimensions and use those. */
        background.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY);
        backgroundWidth = background.getMeasuredWidth();
        backgroundHeight = background.getMeasuredHeight();
    }

    background.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark));

    if (backgroundWidth == 0 || backgroundHeight == 0) {
    } else {
        Picasso.with(MainActivity.this).load(me.header).placeholder(R.drawable.account_header_default)
                .resize(backgroundWidth, backgroundHeight).centerCrop().into(background);
    }

    headerResult.addProfiles(new ProfileDrawerItem().withName(me.getDisplayName())
            .withEmail(String.format("%s@%s", me.username, domain)).withIcon(me.avatar));

    // Show follow requests in the menu, if this is a locked account.
    if (me.locked) {
        PrimaryDrawerItem followRequestsItem = new PrimaryDrawerItem().withIdentifier(6)
                .withName(R.string.action_view_follow_requests).withSelectable(false)
                .withIcon(GoogleMaterial.Icon.gmd_person_add);
        drawer.addItemAtPosition(followRequestsItem, 3);
    }

    // Update the current login information.
    loggedInAccountId = me.id;
    loggedInAccountUsername = me.username;
    getPrivatePreferences().edit().putString("loggedInAccountId", loggedInAccountId)
            .putString("loggedInAccountUsername", loggedInAccountUsername)
            .putBoolean("loggedInAccountLocked", me.locked).apply();
}