Example usage for android.view View forceLayout

List of usage examples for android.view View forceLayout

Introduction

In this page you can find the example usage for android.view View forceLayout.

Prototype

public void forceLayout() 

Source Link

Document

Forces this view to be laid out during the next layout pass.

Usage

From source file:com.gruporaido.tasker_library.util.Helper.java

/**
 * Adds an extra bottom margin in case there is a Software Navigation Bar
 *
 * @param view//from  ww w.  ja  va 2  s.  c  o m
 */
public void addBottomMarginforSoftNavbar(View view) {
    if (!ViewConfiguration.get(mContext).hasPermanentMenuKey()) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        layoutParams.bottomMargin += navigationBarSize();
        view.forceLayout();
    }
}

From source file:com.gruporaido.tasker_library.util.Helper.java

/**
 * Removes extra bottom margin in case there is a Software Navigation Bar
 *
 * @param view//from w  w w. j a  va  2  s .c om
 */
public void removeBottomMarginforSoftNavbar(View view) {
    if (!ViewConfiguration.get(mContext).hasPermanentMenuKey()) {
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        layoutParams.bottomMargin -= navigationBarSize();
        view.forceLayout();
    }
}

From source file:com.groksolutions.grok.mobile.chart.AbstractAnomalyChartFragment.java

protected void updateUnit(final View parent, final AnomalyChartData data) {
    final TextView text = (TextView) parent.findViewById(R.id.metric_unit);
    if (text != null) {
        if (data == null) {
            text.setVisibility(View.GONE);
        } else {//from  w  w  w . j a va  2s . c om
            text.setVisibility(View.VISIBLE);
            text.setText(data.getUnit());
        }
        parent.forceLayout();
    }
}

From source file:com.groksolutions.grok.mobile.chart.AbstractAnomalyChartFragment.java

protected void updateName(final View parent, final AnomalyChartData data) {
    final TextView textView = (TextView) parent.findViewById(R.id.name);
    if (textView != null) {
        final CharSequence oldName = textView.getText();
        if (data == null) {
            textView.setText(null);/*from  w w  w .  j a  v  a  2s  .  c o m*/
            textView.setSelected(false);
        } else if (!oldName.equals(data.getName())) {
            textView.setText(data.getName());
            textView.setSelected(true);
        }
        parent.forceLayout();
    }
}

From source file:com.groksolutions.grok.mobile.chart.AbstractAnomalyChartFragment.java

protected void updateDate(final View parent, final AnomalyChartData data) {
    final TextView dateView = (TextView) parent.findViewById(R.id.date);
    if (dateView != null) {
        if (data == null) {
            dateView.setVisibility(View.GONE);
        } else {//from   w w w. ja v  a2  s  .  c  o  m
            Date endDate = data.getEndDate();
            if (endDate != null) {
                dateView.setVisibility(View.VISIBLE);
                dateView.setText(_sdf.format(data.getEndDate()));
            } else {
                dateView.setVisibility(View.GONE);
            }
        }
        parent.forceLayout();
    }
}

From source file:com.numenta.taurus.chart.AbstractAnomalyChartFragment.java

protected void updateDate(final View parent, final AnomalyChartData data) {
    final TextView dateView = (TextView) parent.findViewById(R.id.date);
    if (dateView != null) {
        if (data == null) {
            dateView.setVisibility(View.GONE);
        } else {// w  w  w. ja v  a2  s .  c  o  m
            Date endDate = data.getEndDate();
            if (endDate != null && endDate.getTime() > 0) {
                dateView.setVisibility(View.VISIBLE);
                dateView.setText(_sdf.format(data.getEndDate()));
            } else {
                dateView.setVisibility(View.GONE);
            }
        }
        parent.forceLayout();
    }
}

From source file:android.support.v7.widget.ListViewCompat.java

/**
 * Measures the height of the given range of children (inclusive) and returns the height
 * with this ListView's padding and divider heights included. If maxHeight is provided, the
 * measuring will stop when the current height reaches maxHeight.
 *
 * @param widthMeasureSpec             The width measure spec to be given to a child's
 *                                     {@link View#measure(int, int)}.
 * @param startPosition                The position of the first child to be shown.
 * @param endPosition                  The (inclusive) position of the last child to be
 *                                     shown. Specify {@link #NO_POSITION} if the last child
 *                                     should be the last available child from the adapter.
 * @param maxHeight                    The maximum height that will be returned (if all the
 *                                     children don't fit in this value, this value will be
 *                                     returned).
 * @param disallowPartialChildPosition In general, whether the returned height should only
 *                                     contain entire children. This is more powerful--it is
 *                                     the first inclusive position at which partial
 *                                     children will not be allowed. Example: it looks nice
 *                                     to have at least 3 completely visible children, and
 *                                     in portrait this will most likely fit; but in
 *                                     landscape there could be times when even 2 children
 *                                     can not be completely shown, so a value of 2
 *                                     (remember, inclusive) would be good (assuming
 *                                     startPosition is 0).
 * @return The height of this ListView with the given children.
 *///from ww  w  . j av  a  2 s. com
public int measureHeightOfChildrenCompat(int widthMeasureSpec, int startPosition, int endPosition,
        final int maxHeight, int disallowPartialChildPosition) {

    final int paddingTop = getListPaddingTop();
    final int paddingBottom = getListPaddingBottom();
    final int paddingLeft = getListPaddingLeft();
    final int paddingRight = getListPaddingRight();
    final int reportedDividerHeight = getDividerHeight();
    final Drawable divider = getDivider();

    final ListAdapter adapter = getAdapter();

    if (adapter == null) {
        return paddingTop + paddingBottom;
    }

    // Include the padding of the list
    int returnedHeight = paddingTop + paddingBottom;
    final int dividerHeight = ((reportedDividerHeight > 0) && divider != null) ? reportedDividerHeight : 0;

    // The previous height value that was less than maxHeight and contained
    // no partial children
    int prevHeightWithoutPartialChild = 0;

    View child = null;
    int viewType = 0;
    int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        int newType = adapter.getItemViewType(i);
        if (newType != viewType) {
            child = null;
            viewType = newType;
        }
        child = adapter.getView(i, child, this);

        // Compute child height spec
        int heightMeasureSpec;
        ViewGroup.LayoutParams childLp = child.getLayoutParams();

        if (childLp == null) {
            childLp = generateDefaultLayoutParams();
            child.setLayoutParams(childLp);
        }

        if (childLp.height > 0) {
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(childLp.height, MeasureSpec.EXACTLY);
        } else {
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
        }
        child.measure(widthMeasureSpec, heightMeasureSpec);

        // Since this view was measured directly aginst the parent measure
        // spec, we must measure it again before reuse.
        child.forceLayout();

        if (i > 0) {
            // Count the divider for all but one child
            returnedHeight += dividerHeight;
        }

        returnedHeight += child.getMeasuredHeight();

        if (returnedHeight >= maxHeight) {
            // We went over, figure out which height to return.  If returnedHeight >
            // maxHeight, then the i'th position did not fit completely.
            return (disallowPartialChildPosition >= 0) // Disallowing is enabled (> -1)
                    && (i > disallowPartialChildPosition) // We've past the min pos
                    && (prevHeightWithoutPartialChild > 0) // We have a prev height
                    && (returnedHeight != maxHeight) // i'th child did not fit completely
                            ? prevHeightWithoutPartialChild
                            : maxHeight;
        }

        if ((disallowPartialChildPosition >= 0) && (i >= disallowPartialChildPosition)) {
            prevHeightWithoutPartialChild = returnedHeight;
        }
    }

    // At this point, we went through the range of children, and they each
    // completely fit, so return the returnedHeight
    return returnedHeight;
}