Example usage for android.view ViewGroup measure

List of usage examples for android.view ViewGroup measure

Introduction

In this page you can find the example usage for android.view ViewGroup measure.

Prototype

public final void measure(int widthMeasureSpec, int heightMeasureSpec) 

Source Link

Document

This is called to find out how big a view should be.

Usage

From source file:Main.java

public static void expand(final ViewGroup v) {
    v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    // Older versions of android (pre API 21) cancel animations for views with a height of 0.
    v.getLayoutParams().height = 1;/*w  w w.  java 2  s.  c  o m*/
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1 ? ViewGroup.LayoutParams.WRAP_CONTENT
                    : (int) (targetHeight * interpolatedTime);
            v.setAlpha(interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:com.android.mail.browse.ConversationItemViewCoordinates.java

private ConversationItemViewCoordinates(final Context context, final Config config,
        final CoordinatesCache cache) {
    Utils.traceBeginSection("CIV coordinates constructor");
    final Resources res = context.getResources();

    final int layoutId = R.layout.conversation_item_view;

    ViewGroup view = (ViewGroup) cache.getView(layoutId);
    if (view == null) {
        view = (ViewGroup) LayoutInflater.from(context).inflate(layoutId, null);
        cache.put(layoutId, view);/*w  w w  . j ava2 s  . com*/
    }

    // Show/hide optional views before measure/layout call
    final TextView folders = (TextView) view.findViewById(R.id.folders);
    folders.setVisibility(config.areFoldersVisible() ? View.VISIBLE : View.GONE);

    View contactImagesView = view.findViewById(R.id.contact_image);

    switch (config.getGadgetMode()) {
    case GADGET_CONTACT_PHOTO:
        contactImagesView.setVisibility(View.VISIBLE);
        break;
    case GADGET_CHECKBOX:
        contactImagesView.setVisibility(View.GONE);
        contactImagesView = null;
        break;
    default:
        contactImagesView.setVisibility(View.GONE);
        contactImagesView = null;
        break;
    }

    final View replyState = view.findViewById(R.id.reply_state);
    replyState.setVisibility(config.isReplyStateVisible() ? View.VISIBLE : View.GONE);

    final View personalIndicator = view.findViewById(R.id.personal_indicator);
    personalIndicator.setVisibility(config.isPersonalIndicatorVisible() ? View.VISIBLE : View.GONE);

    setFramePadding(context, view, config.useFullPadding());

    // Layout the appropriate view.
    ViewCompat.setLayoutDirection(view, config.getLayoutDirection());
    final int widthSpec = MeasureSpec.makeMeasureSpec(config.getWidth(), MeasureSpec.EXACTLY);
    final int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

    view.measure(widthSpec, heightSpec);
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());

    // Once the view is measured, let's calculate the dynamic width variables.
    folderLayoutWidth = (int) (view.getWidth() * res.getInteger(R.integer.folder_max_width_proportion) / 100.0);
    folderCellWidth = (int) (view.getWidth() * res.getInteger(R.integer.folder_cell_max_width_proportion)
            / 100.0);

    //        Utils.dumpViewTree((ViewGroup) view);

    // Records coordinates.

    // Contact images view
    if (contactImagesView != null) {
        contactImagesWidth = contactImagesView.getWidth();
        contactImagesHeight = contactImagesView.getHeight();
        contactImagesX = getX(contactImagesView);
        contactImagesY = getY(contactImagesView);
    } else {
        contactImagesX = contactImagesY = contactImagesWidth = contactImagesHeight = 0;
    }

    final boolean isRtl = ViewUtils.isViewRtl(view);

    final View star = view.findViewById(R.id.star);
    final int starPadding = res.getDimensionPixelSize(R.dimen.conv_list_star_padding_start);
    starX = getX(star) + (isRtl ? 0 : starPadding);
    starY = getY(star);
    starWidth = star.getWidth();

    final TextView senders = (TextView) view.findViewById(R.id.senders);
    final int sendersTopAdjust = getLatinTopAdjustment(senders);
    sendersX = getX(senders);
    sendersY = getY(senders) + sendersTopAdjust;
    sendersWidth = senders.getWidth();
    sendersHeight = senders.getHeight();
    sendersLineCount = SINGLE_LINE;
    sendersFontSize = senders.getTextSize();

    final TextView subject = (TextView) view.findViewById(R.id.subject);
    final int subjectTopAdjust = getLatinTopAdjustment(subject);
    subjectX = getX(subject);
    subjectY = getY(subject) + subjectTopAdjust;
    subjectWidth = subject.getWidth();
    subjectHeight = subject.getHeight();
    subjectFontSize = subject.getTextSize();

    final TextView snippet = (TextView) view.findViewById(R.id.snippet);
    final int snippetTopAdjust = getLatinTopAdjustment(snippet);
    snippetX = getX(snippet);
    snippetY = getY(snippet) + snippetTopAdjust;
    maxSnippetWidth = snippet.getWidth();
    snippetHeight = snippet.getHeight();
    snippetFontSize = snippet.getTextSize();

    if (config.areFoldersVisible()) {
        foldersLeft = getX(folders);
        foldersRight = foldersLeft + folders.getWidth();
        foldersY = getY(folders);
        foldersTypeface = folders.getTypeface();
        foldersFontSize = folders.getTextSize();
    } else {
        foldersLeft = 0;
        foldersRight = 0;
        foldersY = 0;
        foldersTypeface = null;
        foldersFontSize = 0;
    }

    final View colorBlock = view.findViewById(R.id.color_block);
    if (config.isColorBlockVisible() && colorBlock != null) {
        colorBlockX = getX(colorBlock);
        colorBlockY = getY(colorBlock);
        colorBlockWidth = colorBlock.getWidth();
        colorBlockHeight = colorBlock.getHeight();
    } else {
        colorBlockX = colorBlockY = colorBlockWidth = colorBlockHeight = 0;
    }

    if (config.isReplyStateVisible()) {
        replyStateX = getX(replyState);
        replyStateY = getY(replyState);
    } else {
        replyStateX = replyStateY = 0;
    }

    if (config.isPersonalIndicatorVisible()) {
        personalIndicatorX = getX(personalIndicator);
        personalIndicatorY = getY(personalIndicator);
    } else {
        personalIndicatorX = personalIndicatorY = 0;
    }

    final View infoIcon = view.findViewById(R.id.info_icon);
    infoIconX = getX(infoIcon);
    infoIconXRight = infoIconX + infoIcon.getWidth();
    infoIconY = getY(infoIcon);

    final TextView date = (TextView) view.findViewById(R.id.date);
    dateX = getX(date);
    dateXRight = dateX + date.getWidth();
    dateY = getY(date);
    datePaddingStart = ViewUtils.getPaddingStart(date);
    dateFontSize = date.getTextSize();
    dateYBaseline = dateY + getLatinTopAdjustment(date) + date.getBaseline();

    final View paperclip = view.findViewById(R.id.paperclip);
    paperclipY = getY(paperclip);
    paperclipPaddingStart = ViewUtils.getPaddingStart(paperclip);

    height = view.getHeight() + sendersTopAdjust;
    Utils.traceEndSection();
}

From source file:com.tct.mail.browse.ConversationItemViewCoordinates.java

private ConversationItemViewCoordinates(final Context context, final Config config,
        final CoordinatesCache cache) {
    Utils.traceBeginSection("CIV coordinates constructor");
    final Resources res = context.getResources();
    mMinListWidthForWide = res.getDimensionPixelSize(R.dimen.list_min_width_is_wide);

    mMode = calculateMode(res, config);//w ww.  ja va 2 s . c om

    final int layoutId = R.layout.conversation_item_view;

    ViewGroup view = (ViewGroup) cache.getView(layoutId);
    if (view == null) {
        view = (ViewGroup) LayoutInflater.from(context).inflate(layoutId, null);
        cache.put(layoutId, view);
    }

    // Show/hide optional views before measure/layout call
    final TextView folders = (TextView) view.findViewById(R.id.folders);
    folders.setVisibility(config.areFoldersVisible() ? View.VISIBLE : View.GONE);

    View contactImagesView = view.findViewById(R.id.contact_image);

    switch (config.getGadgetMode()) {
    case GADGET_CONTACT_PHOTO:
        contactImagesView.setVisibility(View.VISIBLE);
        break;
    case GADGET_CHECKBOX:
        contactImagesView.setVisibility(View.GONE);
        contactImagesView = null;
        break;
    default:
        contactImagesView.setVisibility(View.GONE);
        contactImagesView = null;
        break;
    }

    final View replyState = view.findViewById(R.id.reply_state);
    replyState.setVisibility(config.isReplyStateVisible() ? View.VISIBLE : View.GONE);

    final View personalIndicator = view.findViewById(R.id.personal_indicator);
    personalIndicator.setVisibility(config.isPersonalIndicatorVisible() ? View.VISIBLE : View.GONE);

    setFramePadding(context, view, config.useFullPadding());

    // Layout the appropriate view.
    ViewCompat.setLayoutDirection(view, config.getLayoutDirection());
    final int widthSpec = MeasureSpec.makeMeasureSpec(config.getWidth(), MeasureSpec.EXACTLY);
    final int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

    view.measure(widthSpec, heightSpec);
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());

    // Once the view is measured, let's calculate the dynamic width variables.
    folderLayoutWidth = (int) (view.getWidth() * res.getInteger(R.integer.folder_max_width_proportion) / 100.0);
    folderCellWidth = (int) (view.getWidth() * res.getInteger(R.integer.folder_cell_max_width_proportion)
            / 100.0);

    //        Utils.dumpViewTree((ViewGroup) view);

    // Records coordinates.

    // Contact images view
    if (contactImagesView != null) {
        contactImagesWidth = contactImagesView.getWidth();
        contactImagesHeight = contactImagesView.getHeight();
        contactImagesX = getX(contactImagesView);
        contactImagesY = getY(contactImagesView);
    } else {
        contactImagesX = contactImagesY = contactImagesWidth = contactImagesHeight = 0;
    }

    final boolean isRtl = ViewUtils.isViewRtl(view);

    final View star = view.findViewById(R.id.star);
    final int starPadding = res.getDimensionPixelSize(R.dimen.conv_list_star_padding_start);
    starX = getX(star) + (isRtl ? 0 : starPadding);
    starY = getY(star);
    starWidth = star.getWidth();

    final TextView senders = (TextView) view.findViewById(R.id.senders);
    final int sendersTopAdjust = getLatinTopAdjustment(senders);
    sendersX = getX(senders);
    sendersY = getY(senders) + sendersTopAdjust;
    sendersWidth = senders.getWidth();
    sendersHeight = senders.getHeight();
    sendersLineCount = SINGLE_LINE;
    sendersFontSize = senders.getTextSize();

    final TextView subject = (TextView) view.findViewById(R.id.subject);
    final int subjectTopAdjust = getLatinTopAdjustment(subject);
    subjectX = getX(subject);
    subjectY = getY(subject) + subjectTopAdjust;
    subjectWidth = subject.getWidth();
    subjectHeight = subject.getHeight();
    subjectFontSize = subject.getTextSize();
    // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_S
    final TextView status = (TextView) view.findViewById(R.id.status);
    final int statusTopAdjust = getLatinTopAdjustment(status);
    statusX = getX(status);
    statusY = getY(status) + statusTopAdjust;
    statusWidth = status.getWidth();
    statusHeight = status.getHeight();
    statusFontSize = status.getTextSize();
    statusPaddingStart = ViewUtils.getPaddingStart(status);
    statusPanddingEnd = ViewUtils.getPaddingEnd(status);
    // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_E
    final TextView snippet = (TextView) view.findViewById(R.id.snippet);
    final int snippetTopAdjust = getLatinTopAdjustment(snippet);
    snippetX = getX(snippet);
    snippetY = getY(snippet) + snippetTopAdjust;
    maxSnippetWidth = snippet.getWidth();
    snippetHeight = snippet.getHeight();
    snippetFontSize = snippet.getTextSize();

    if (config.areFoldersVisible()) {
        // vertically align folders min left edge with subject
        foldersLeft = getX(folders);
        foldersRight = foldersLeft + folders.getWidth();
        foldersY = getY(folders) + sendersTopAdjust;
        foldersHeight = folders.getHeight();
        foldersTypeface = folders.getTypeface();
        foldersTextBottomPadding = res.getDimensionPixelSize(R.dimen.folders_text_bottom_padding);
        foldersFontSize = folders.getTextSize();
    } else {
        foldersLeft = 0;
        foldersRight = 0;
        foldersY = 0;
        foldersHeight = 0;
        foldersTypeface = null;
        foldersTextBottomPadding = 0;
        foldersFontSize = 0;
    }

    final View colorBlock = view.findViewById(R.id.color_block);
    if (config.isColorBlockVisible() && colorBlock != null) {
        colorBlockX = getX(colorBlock);
        colorBlockY = getY(colorBlock);
        colorBlockWidth = colorBlock.getWidth();
        colorBlockHeight = colorBlock.getHeight();
    } else {
        colorBlockX = colorBlockY = colorBlockWidth = colorBlockHeight = 0;
    }

    if (config.isReplyStateVisible()) {
        replyStateX = getX(replyState);
        replyStateY = getY(replyState);
    } else {
        replyStateX = replyStateY = 0;
    }

    if (config.isPersonalIndicatorVisible()) {
        personalIndicatorX = getX(personalIndicator);
        personalIndicatorY = getY(personalIndicator);
    } else {
        personalIndicatorX = personalIndicatorY = 0;
    }

    final View infoIcon = view.findViewById(R.id.info_icon);
    infoIconX = getX(infoIcon);
    infoIconXRight = infoIconX + infoIcon.getWidth();
    infoIconY = getY(infoIcon);

    final TextView date = (TextView) view.findViewById(R.id.date);
    dateX = getX(date);
    dateXRight = dateX + date.getWidth();
    dateY = getY(date);
    datePaddingStart = ViewUtils.getPaddingStart(date);
    dateFontSize = date.getTextSize();
    dateYBaseline = dateY + getLatinTopAdjustment(date) + date.getBaseline();

    final View paperclip = view.findViewById(R.id.paperclip);
    paperclipY = getY(paperclip);
    paperclipPaddingStart = ViewUtils.getPaddingStart(paperclip);

    height = view.getHeight() + sendersTopAdjust;
    Utils.traceEndSection();
}

From source file:com.juick.android.JuickMessagesAdapter.java

public void recycleView(View view) {
    if (view instanceof ViewGroup) {
        ListRowRuntime lrr = (ListRowRuntime) view.getTag();
        if (lrr != null) {
            if (lrr.userpicListener != null) {
                lrr.removeListenerIfExists();
            }//ww  w  .  j  a v a  2 s .  c om
        }
        ViewGroup vg = (ViewGroup) view;
        if (vg.getChildCount() > 1 && vg.getChildAt(1) instanceof ImageGallery
                && vg instanceof PressableLinearLayout) {
            PressableLinearLayout pll = (PressableLinearLayout) vg;
            // our view
            ImageGallery gallery = (ImageGallery) vg.getChildAt(1);
            Object tag = gallery.getTag();
            if (tag instanceof HashMap) {
                HashMap<Integer, ImageLoaderConfiguration> loaders = (HashMap<Integer, ImageLoaderConfiguration>) tag;
                for (ImageLoaderConfiguration imageLoader : loaders.values()) {
                    imageLoader.loader.terminate();
                }
            }
            pll.blockLayoutRequests = true;
            gallery.cleanup();
            gallery.setTag(null);
            vg.removeViewAt(1);
            vg.measure(View.MeasureSpec.makeMeasureSpec(vg.getRight() - vg.getLeft(), View.MeasureSpec.EXACTLY),
                    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            vg.layout(vg.getLeft(), vg.getTop(), vg.getRight(), vg.getTop() + vg.getMeasuredHeight());
            pll.blockLayoutRequests = false;
        }
    }
}