Example #1
0
 /// <summary>Shows only the specified child.</summary>
 /// <remarks>
 /// Shows only the specified child. The other displays Views exit the screen,
 /// optionally with the with the
 /// <see cref="getOutAnimation()">out animation</see>
 /// and
 /// the specified child enters the screen, optionally with the
 /// <see cref="getInAnimation()">in animation</see>
 /// .
 /// </remarks>
 /// <param name="childIndex">The index of the child to be shown.</param>
 /// <param name="animate">
 /// Whether or not to use the in and out animations, defaults
 /// to true.
 /// </param>
 internal virtual void showOnly(int childIndex, bool animate_1)
 {
     int count = getChildCount();
     {
         for (int i = 0; i < count; i++)
         {
             android.view.View child = getChildAt(i);
             if (i == childIndex)
             {
                 if (animate_1 && mInAnimation != null)
                 {
                     child.startAnimation(mInAnimation);
                 }
                 child.setVisibility(android.view.View.VISIBLE);
                 mFirstTime = false;
             }
             else
             {
                 if (animate_1 && mOutAnimation != null && child.getVisibility() == android.view.View
                     .VISIBLE)
                 {
                     child.startAnimation(mOutAnimation);
                 }
                 else
                 {
                     if (child.getAnimation() == mInAnimation)
                     {
                         child.clearAnimation();
                     }
                 }
                 child.setVisibility(android.view.View.GONE);
             }
         }
     }
 }
Example #2
0
        /// <summary>Maps a point to a position in the list.</summary>
        /// <remarks>Maps a point to a position in the list.</remarks>
        /// <param name="x">X in local coordinate</param>
        /// <param name="y">Y in local coordinate</param>
        /// <returns>
        /// The position of the item which contains the specified point, or
        /// <see cref="android.widget.AdapterView.INVALID_POSITION">android.widget.AdapterView.INVALID_POSITION
        ///     </see>
        /// if the point does not intersect an item.
        /// </returns>
        public virtual int pointToPosition(int x, int y)
        {
            android.graphics.Rect frame = mTouchFrame;
            if (frame == null)
            {
                mTouchFrame = new android.graphics.Rect();
                frame       = mTouchFrame;
            }
            int count = getChildCount();

            {
                for (int i = count - 1; i >= 0; i--)
                {
                    android.view.View child = getChildAt(i);
                    if (child.getVisibility() == android.view.View.VISIBLE)
                    {
                        child.getHitRect(frame);
                        if (frame.contains(x, y))
                        {
                            return(mFirstPosition + i);
                        }
                    }
                }
            }
            return(android.widget.AdapterView.INVALID_POSITION);
        }
Example #3
0
        /// <summary><p>Measures the preferred width of each child, including its margins.</p>
        ///     </summary>
        /// <param name="widthMeasureSpec">the width constraint imposed by our parent</param>
        /// <returns>
        /// an array of integers corresponding to the width of each cell, or
        /// column, in this row
        /// <hide></hide>
        /// </returns>
        internal virtual int[] getColumnsWidths(int widthMeasureSpec)
        {
            int numColumns = getVirtualChildCount();

            if (mColumnWidths == null || numColumns != mColumnWidths.Length)
            {
                mColumnWidths = new int[numColumns];
            }
            int[] columnWidths = mColumnWidths;
            {
                for (int i = 0; i < numColumns; i++)
                {
                    android.view.View child = getVirtualChildAt(i);
                    if (child != null && child.getVisibility() != GONE)
                    {
                        android.widget.TableRow.LayoutParams layoutParams = (android.widget.TableRow.LayoutParams
                                                                             )child.getLayoutParams();
                        if (layoutParams.span == 1)
                        {
                            int spec;
                            switch (layoutParams.width)
                            {
                            case android.view.ViewGroup.LayoutParams.WRAP_CONTENT:
                            {
                                spec = getChildMeasureSpec(widthMeasureSpec, 0, android.view.ViewGroup.LayoutParams
                                                           .WRAP_CONTENT);
                                break;
                            }

                            case android.view.ViewGroup.LayoutParams.MATCH_PARENT:
                            {
                                spec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View.MeasureSpec
                                                                                     .UNSPECIFIED);
                                break;
                            }

                            default:
                            {
                                spec = android.view.View.MeasureSpec.makeMeasureSpec(layoutParams.width, android.view.View
                                                                                     .MeasureSpec.EXACTLY);
                                break;
                            }
                            }
                            child.measure(spec, spec);
                            int width = child.getMeasuredWidth() + layoutParams.leftMargin + layoutParams.rightMargin;
                            columnWidths[i] = width;
                        }
                        else
                        {
                            columnWidths[i] = 0;
                        }
                    }
                    else
                    {
                        columnWidths[i] = 0;
                    }
                }
            }
            return(columnWidths);
        }
Example #4
0
        /// <summary>Returns the View that should receive a touch at the given coordinates.</summary>
        /// <remarks>Returns the View that should receive a touch at the given coordinates.</remarks>
        /// <param name="rawX">The raw X.</param>
        /// <param name="rawY">The raw Y.</param>
        /// <returns>The view that should receive the touches, or null if there is not one.</returns>
        private android.view.View findViewForTouch(int rawX, int rawY)
        {
            // Reverse order so the child drawn on top gets first dibs.
            int containerCoordsX = rawX - mContainerRawLocation[0];
            int containerCoordsY = rawY - mContainerRawLocation[1];

            android.graphics.Rect frame        = mTempRect;
            android.view.View     closestChild = null;
            int closestChildDistanceSq         = int.MaxValue;

            {
                for (int i = mContainer.getChildCount() - 1; i >= 0; i--)
                {
                    android.view.View child = mContainer.getChildAt(i);
                    if (child.getVisibility() != android.view.View.VISIBLE)
                    {
                        continue;
                    }
                    child.getHitRect(frame);
                    if (frame.contains(containerCoordsX, containerCoordsY))
                    {
                        return(child);
                    }
                    int distanceX;
                    if (containerCoordsX >= frame.left && containerCoordsX <= frame.right)
                    {
                        distanceX = 0;
                    }
                    else
                    {
                        distanceX = System.Math.Min(System.Math.Abs(frame.left - containerCoordsX), System.Math.Abs
                                                        (containerCoordsX - frame.right));
                    }
                    int distanceY;
                    if (containerCoordsY >= frame.top && containerCoordsY <= frame.bottom)
                    {
                        distanceY = 0;
                    }
                    else
                    {
                        distanceY = System.Math.Min(System.Math.Abs(frame.top - containerCoordsY), System.Math.Abs
                                                        (containerCoordsY - frame.bottom));
                    }
                    int distanceSq = distanceX * distanceX + distanceY * distanceY;
                    if ((distanceSq < mTouchPaddingScaledSq) && (distanceSq < closestChildDistanceSq))
                    {
                        closestChild           = child;
                        closestChildDistanceSq = distanceSq;
                    }
                }
            }
            return(closestChild);
        }
        protected internal override void onMeasure(int widthMeasureSpec, int heightMeasureSpec
                                                   )
        {
            base.onMeasure(widthMeasureSpec, heightMeasureSpec);
            if (mActionBarView == null)
            {
                return;
            }
            android.widget.FrameLayout.LayoutParams lp = (android.widget.FrameLayout.LayoutParams
                                                          )mActionBarView.getLayoutParams();
            int actionBarViewHeight = mActionBarView.isCollapsed() ? 0 : mActionBarView.getMeasuredHeight
                                          () + lp.topMargin + lp.bottomMargin;

            if (mTabContainer != null && mTabContainer.getVisibility() != GONE)
            {
                int mode = android.view.View.MeasureSpec.getMode(heightMeasureSpec);
                if (mode == android.view.View.MeasureSpec.AT_MOST)
                {
                    int maxHeight = android.view.View.MeasureSpec.getSize(heightMeasureSpec);
                    setMeasuredDimension(getMeasuredWidth(), System.Math.Min(actionBarViewHeight + mTabContainer
                                                                             .getMeasuredHeight(), maxHeight));
                }
            }
        }
Example #6
0
 public override bool dispatchPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent
                                                         @event)
 {
     onPopulateAccessibilityEvent(@event);
     // Dispatch only to the selected tab.
     if (mSelectedTab != -1)
     {
         android.view.View tabView = getChildTabViewAt(mSelectedTab);
         if (tabView != null && tabView.getVisibility() == VISIBLE)
         {
             return(tabView.dispatchPopulateAccessibilityEvent(@event));
         }
     }
     return(false);
 }
Example #7
0
 protected internal override void onLayout(bool changed, int l, int t, int r, int
                                           b)
 {
     int count = getChildCount();
     {
         for (int i = 0; i < count; i++)
         {
             android.view.View child = getChildAt(i);
             if (child.getVisibility() != GONE)
             {
                 android.widget.AbsoluteLayout.LayoutParams lp = (android.widget.AbsoluteLayout.LayoutParams
                                                                  )child.getLayoutParams();
                 int childLeft = mPaddingLeft + lp.x;
                 int childTop  = mPaddingTop + lp.y;
                 child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop
                              + child.getMeasuredHeight());
             }
         }
     }
 }
Example #8
0
        protected internal override void onMeasure(int widthMeasureSpec, int heightMeasureSpec
                                                   )
        {
            int count     = getChildCount();
            int maxHeight = 0;
            int maxWidth  = 0;

            // Find out how big everyone wants to be
            measureChildren(widthMeasureSpec, heightMeasureSpec);
            {
                // Find rightmost and bottom-most child
                for (int i = 0; i < count; i++)
                {
                    android.view.View child = getChildAt(i);
                    if (child.getVisibility() != GONE)
                    {
                        int childRight;
                        int childBottom;
                        android.widget.AbsoluteLayout.LayoutParams lp = (android.widget.AbsoluteLayout.LayoutParams
                                                                         )child.getLayoutParams();
                        childRight  = lp.x + child.getMeasuredWidth();
                        childBottom = lp.y + child.getMeasuredHeight();
                        maxWidth    = System.Math.Max(maxWidth, childRight);
                        maxHeight   = System.Math.Max(maxHeight, childBottom);
                    }
                }
            }
            // Account for padding too
            maxWidth  += mPaddingLeft + mPaddingRight;
            maxHeight += mPaddingTop + mPaddingBottom;
            // Check against minimum height and width
            maxHeight = System.Math.Max(maxHeight, getSuggestedMinimumHeight());
            maxWidth  = System.Math.Max(maxWidth, getSuggestedMinimumWidth());
            setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, 0), resolveSizeAndState
                                     (maxHeight, heightMeasureSpec, 0));
        }
Example #9
0
        protected internal override void onLayout(bool changed, int l, int t, int r, int
                                                  b)
        {
            int x             = getPaddingLeft();
            int y             = getPaddingTop();
            int contentHeight = b - t - getPaddingTop() - getPaddingBottom();

            if (mClose != null && mClose.getVisibility() != GONE)
            {
                android.view.ViewGroup.MarginLayoutParams lp = (android.view.ViewGroup.MarginLayoutParams
                                                                )mClose.getLayoutParams();
                x += lp.leftMargin;
                x += positionChild(mClose, x, y, contentHeight);
                x += lp.rightMargin;
                if (mAnimateInOnLayout)
                {
                    mAnimationMode    = ANIMATE_IN;
                    mCurrentAnimation = makeInAnimation();
                    mCurrentAnimation.start();
                    mAnimateInOnLayout = false;
                }
            }
            if (mTitleLayout != null && mCustomView == null)
            {
                x += positionChild(mTitleLayout, x, y, contentHeight);
            }
            if (mCustomView != null)
            {
                x += positionChild(mCustomView, x, y, contentHeight);
            }
            x = r - l - getPaddingRight();
            if (mMenuView != null)
            {
                x -= positionChildInverse(mMenuView, x, y, contentHeight);
            }
        }
Example #10
0
        protected internal override void onLayout(bool changed, int left, int top, int right
                                                  , int bottom)
        {
            if (!mFormatItems)
            {
                base.onLayout(changed, left, top, right, bottom);
                return;
            }
            int  childCount       = getChildCount();
            int  midVertical      = (top + bottom) / 2;
            int  dividerWidth     = getDividerWidth();
            int  overflowWidth    = 0;
            int  nonOverflowWidth = 0;
            int  nonOverflowCount = 0;
            int  widthRemaining   = right - left - getPaddingRight() - getPaddingLeft();
            bool hasOverflow      = false;

            {
                for (int i = 0; i < childCount; i++)
                {
                    android.view.View v = getChildAt(i);
                    if (v.getVisibility() == GONE)
                    {
                        continue;
                    }
                    [email protected] p = ([email protected]
                                                                                 .LayoutParams)v.getLayoutParams();
                    if (p.isOverflowButton)
                    {
                        overflowWidth = v.getMeasuredWidth();
                        if (hasDividerBeforeChildAt(i))
                        {
                            overflowWidth += dividerWidth;
                        }
                        int height = v.getMeasuredHeight();
                        int r      = getWidth() - getPaddingRight() - p.rightMargin;
                        int l      = r - overflowWidth;
                        int t      = midVertical - (height / 2);
                        int b      = t + height;
                        v.layout(l, t, r, b);
                        widthRemaining -= overflowWidth;
                        hasOverflow     = true;
                    }
                    else
                    {
                        int size = v.getMeasuredWidth() + p.leftMargin + p.rightMargin;
                        nonOverflowWidth += size;
                        widthRemaining   -= size;
                        if (hasDividerBeforeChildAt(i))
                        {
                            nonOverflowWidth += dividerWidth;
                        }
                        nonOverflowCount++;
                    }
                }
            }
            if (childCount == 1 && !hasOverflow)
            {
                // Center a single child
                android.view.View v = getChildAt(0);
                int width           = v.getMeasuredWidth();
                int height          = v.getMeasuredHeight();
                int midHorizontal   = (right - left) / 2;
                int l = midHorizontal - width / 2;
                int t = midVertical - height / 2;
                v.layout(l, t, l + width, t + height);
                return;
            }
            int spacerCount = nonOverflowCount - (hasOverflow ? 0 : 1);
            int spacerSize  = System.Math.Max(0, spacerCount > 0 ? widthRemaining / spacerCount
                                 : 0);
            int startLeft = getPaddingLeft();
            {
                for (int i_1 = 0; i_1 < childCount; i_1++)
                {
                    android.view.View v = getChildAt(i_1);
                    [email protected] lp = ([email protected]
                                                                                  .LayoutParams)v.getLayoutParams();
                    if (v.getVisibility() == GONE || lp.isOverflowButton)
                    {
                        continue;
                    }
                    startLeft += lp.leftMargin;
                    int width  = v.getMeasuredWidth();
                    int height = v.getMeasuredHeight();
                    int t      = midVertical - height / 2;
                    v.layout(startLeft, t, startLeft + width, t + height);
                    startLeft += width + lp.rightMargin + spacerSize;
                }
            }
        }
Example #11
0
        private void onMeasureExactFormat(int widthMeasureSpec, int heightMeasureSpec)
        {
            // We already know the width mode is EXACTLY if we're here.
            int heightMode    = android.view.View.MeasureSpec.getMode(heightMeasureSpec);
            int widthSize     = android.view.View.MeasureSpec.getSize(widthMeasureSpec);
            int heightSize    = android.view.View.MeasureSpec.getSize(heightMeasureSpec);
            int widthPadding  = getPaddingLeft() + getPaddingRight();
            int heightPadding = getPaddingTop() + getPaddingBottom();

            widthSize -= widthPadding;
            // Divide the view into cells.
            int cellCount         = widthSize / mMinCellSize;
            int cellSizeRemaining = widthSize % mMinCellSize;

            if (cellCount == 0)
            {
                // Give up, nothing fits.
                setMeasuredDimension(widthSize, 0);
                return;
            }
            int  cellSize            = mMinCellSize + cellSizeRemaining / cellCount;
            int  cellsRemaining      = cellCount;
            int  maxChildHeight      = 0;
            int  maxCellsUsed        = 0;
            int  expandableItemCount = 0;
            int  visibleItemCount    = 0;
            bool hasOverflow         = false;
            // This is used as a bitfield to locate the smallest items present. Assumes childCount < 64.
            long smallestItemsAt = 0;
            int  childCount      = getChildCount();
            {
                for (int i = 0; i < childCount; i++)
                {
                    android.view.View child = getChildAt(i);
                    if (child.getVisibility() == GONE)
                    {
                        continue;
                    }
                    bool isGeneratedItem = child is [email protected];
                    visibleItemCount++;
                    if (isGeneratedItem)
                    {
                        // Reset padding for generated menu item views; it may change below
                        // and views are recycled.
                        child.setPadding(mGeneratedItemPadding, 0, mGeneratedItemPadding, 0);
                    }
                    [email protected] lp = ([email protected]
                                                                                  .LayoutParams)child.getLayoutParams();
                    lp.expanded          = false;
                    lp.extraPixels       = 0;
                    lp.cellsUsed         = 0;
                    lp.expandable        = false;
                    lp.leftMargin        = 0;
                    lp.rightMargin       = 0;
                    lp.preventEdgeOffset = isGeneratedItem && (([email protected]
                                                                )child).hasText();
                    // Overflow always gets 1 cell. No more, no less.
                    int cellsAvailable = lp.isOverflowButton ? 1 : cellsRemaining;
                    int cellsUsed      = measureChildForCells(child, cellSize, cellsAvailable, heightMeasureSpec
                                                              , heightPadding);
                    maxCellsUsed = System.Math.Max(maxCellsUsed, cellsUsed);
                    if (lp.expandable)
                    {
                        expandableItemCount++;
                    }
                    if (lp.isOverflowButton)
                    {
                        hasOverflow = true;
                    }
                    cellsRemaining -= cellsUsed;
                    maxChildHeight  = System.Math.Max(maxChildHeight, child.getMeasuredHeight());
                    if (cellsUsed == 1)
                    {
                        smallestItemsAt |= (1 << i);
                    }
                }
            }
            // When we have overflow and a single expanded (text) item, we want to try centering it
            // visually in the available space even though overflow consumes some of it.
            bool centerSingleExpandedItem = hasOverflow && visibleItemCount == 2;
            // Divide space for remaining cells if we have items that can expand.
            // Try distributing whole leftover cells to smaller items first.
            bool needsExpansion = false;

            while (expandableItemCount > 0 && cellsRemaining > 0)
            {
                int  minCells   = int.MaxValue;
                long minCellsAt = 0;
                // Bit locations are indices of relevant child views
                int minCellsItemCount = 0;
                {
                    for (int i_1 = 0; i_1 < childCount; i_1++)
                    {
                        android.view.View child = getChildAt(i_1);
                        [email protected] lp = ([email protected]
                                                                                      .LayoutParams)child.getLayoutParams();
                        // Don't try to expand items that shouldn't.
                        if (!lp.expandable)
                        {
                            continue;
                        }
                        // Mark indices of children that can receive an extra cell.
                        if (lp.cellsUsed < minCells)
                        {
                            minCells          = lp.cellsUsed;
                            minCellsAt        = 1 << i_1;
                            minCellsItemCount = 1;
                        }
                        else
                        {
                            if (lp.cellsUsed == minCells)
                            {
                                minCellsAt |= 1 << i_1;
                                minCellsItemCount++;
                            }
                        }
                    }
                }
                // Items that get expanded will always be in the set of smallest items when we're done.
                smallestItemsAt |= minCellsAt;
                if (minCellsItemCount > cellsRemaining)
                {
                    break;
                }
                // Couldn't expand anything evenly. Stop.
                // We have enough cells, all minimum size items will be incremented.
                minCells++;
                {
                    for (int i_2 = 0; i_2 < childCount; i_2++)
                    {
                        android.view.View child = getChildAt(i_2);
                        [email protected] lp = ([email protected]
                                                                                      .LayoutParams)child.getLayoutParams();
                        if ((minCellsAt & (1 << i_2)) == 0)
                        {
                            // If this item is already at our small item count, mark it for later.
                            if (lp.cellsUsed == minCells)
                            {
                                smallestItemsAt |= 1 << i_2;
                            }
                            continue;
                        }
                        if (centerSingleExpandedItem && lp.preventEdgeOffset && cellsRemaining == 1)
                        {
                            // Add padding to this item such that it centers.
                            child.setPadding(mGeneratedItemPadding + cellSize, 0, mGeneratedItemPadding, 0);
                        }
                        lp.cellsUsed++;
                        lp.expanded = true;
                        cellsRemaining--;
                    }
                }
                needsExpansion = true;
            }
            // Divide any space left that wouldn't divide along cell boundaries
            // evenly among the smallest items
            bool singleItem = !hasOverflow && visibleItemCount == 1;

            if (cellsRemaining > 0 && smallestItemsAt != 0 && (cellsRemaining < visibleItemCount
                                                               - 1 || singleItem || maxCellsUsed > 1))
            {
                float expandCount = Sharpen.Util.Long_GetBitCount(smallestItemsAt);
                if (!singleItem)
                {
                    // The items at the far edges may only expand by half in order to pin to either side.
                    if ((smallestItemsAt & 1) != 0)
                    {
                        [email protected] lp = ([email protected]
                                                                                      .LayoutParams)getChildAt(0).getLayoutParams();
                        if (!lp.preventEdgeOffset)
                        {
                            expandCount -= 0.5f;
                        }
                    }
                    if ((smallestItemsAt & (1 << (childCount - 1))) != 0)
                    {
                        [email protected] lp = (([email protected]
                                                                                       .LayoutParams)getChildAt(childCount - 1).getLayoutParams());
                        if (!lp.preventEdgeOffset)
                        {
                            expandCount -= 0.5f;
                        }
                    }
                }
                int extraPixels = expandCount > 0 ? (int)(cellsRemaining * cellSize / expandCount
                                                          ) : 0;
                {
                    for (int i_1 = 0; i_1 < childCount; i_1++)
                    {
                        if ((smallestItemsAt & (1 << i_1)) == 0)
                        {
                            continue;
                        }
                        android.view.View child = getChildAt(i_1);
                        [email protected] lp = ([email protected]
                                                                                      .LayoutParams)child.getLayoutParams();
                        if (child is [email protected])
                        {
                            // If this is one of our views, expand and measure at the larger size.
                            lp.extraPixels = extraPixels;
                            lp.expanded    = true;
                            if (i_1 == 0 && !lp.preventEdgeOffset)
                            {
                                // First item gets part of its new padding pushed out of sight.
                                // The last item will get this implicitly from layout.
                                lp.leftMargin = -extraPixels / 2;
                            }
                            needsExpansion = true;
                        }
                        else
                        {
                            if (lp.isOverflowButton)
                            {
                                lp.extraPixels = extraPixels;
                                lp.expanded    = true;
                                lp.rightMargin = -extraPixels / 2;
                                needsExpansion = true;
                            }
                            else
                            {
                                // If we don't know what it is, give it some margins instead
                                // and let it center within its space. We still want to pin
                                // against the edges.
                                if (i_1 != 0)
                                {
                                    lp.leftMargin = extraPixels / 2;
                                }
                                if (i_1 != childCount - 1)
                                {
                                    lp.rightMargin = extraPixels / 2;
                                }
                            }
                        }
                    }
                }
                cellsRemaining = 0;
            }
            // Remeasure any items that have had extra space allocated to them.
            if (needsExpansion)
            {
                int heightSpec = android.view.View.MeasureSpec.makeMeasureSpec(heightSize - heightPadding
                                                                               , heightMode);
                {
                    for (int i_1 = 0; i_1 < childCount; i_1++)
                    {
                        android.view.View child = getChildAt(i_1);
                        [email protected] lp = ([email protected]
                                                                                      .LayoutParams)child.getLayoutParams();
                        if (!lp.expanded)
                        {
                            continue;
                        }
                        int width = lp.cellsUsed * cellSize + lp.extraPixels;
                        child.measure(android.view.View.MeasureSpec.makeMeasureSpec(width, android.view.View
                                                                                    .MeasureSpec.EXACTLY), heightSpec);
                    }
                }
            }
            if (heightMode != android.view.View.MeasureSpec.EXACTLY)
            {
                heightSize = maxChildHeight;
            }
            setMeasuredDimension(widthSize, heightSize);
            mMeasuredExtraWidth = cellsRemaining * cellSize;
        }
Example #12
0
 /// <summary><p>Finds the largest cell in each column.</summary>
 /// <remarks>
 /// <p>Finds the largest cell in each column. For each column, the width of
 /// the largest cell is applied to all the other cells.</p>
 /// </remarks>
 /// <param name="widthMeasureSpec">the measure constraint imposed by our parent</param>
 private void findLargestCells(int widthMeasureSpec)
 {
     bool firstRow = true;
     // find the maximum width for each column
     // the total number of columns is dynamically changed if we find
     // wider rows as we go through the children
     // the array is reused for each layout operation; the array can grow
     // but never shrinks. Unused extra cells in the array are just ignored
     // this behavior avoids to unnecessary grow the array after the first
     // layout operation
     int count = getChildCount();
     {
         for (int i = 0; i < count; i++)
         {
             android.view.View child = getChildAt(i);
             if (child.getVisibility() == GONE)
             {
                 continue;
             }
             if (child is android.widget.TableRow)
             {
                 android.widget.TableRow row = (android.widget.TableRow)child;
                 // forces the row's height
                 android.view.ViewGroup.LayoutParams layoutParams = row.getLayoutParams();
                 layoutParams.height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
                 int[] widths    = row.getColumnsWidths(widthMeasureSpec);
                 int   newLength = widths.Length;
                 // this is the first row, we just need to copy the values
                 if (firstRow)
                 {
                     if (mMaxWidths == null || mMaxWidths.Length != newLength)
                     {
                         mMaxWidths = new int[newLength];
                     }
                     System.Array.Copy(widths, 0, mMaxWidths, 0, newLength);
                     firstRow = false;
                 }
                 else
                 {
                     int length     = mMaxWidths.Length;
                     int difference = newLength - length;
                     // the current row is wider than the previous rows, so
                     // we just grow the array and copy the values
                     if (difference > 0)
                     {
                         int[] oldMaxWidths = mMaxWidths;
                         mMaxWidths = new int[newLength];
                         System.Array.Copy(oldMaxWidths, 0, mMaxWidths, 0, oldMaxWidths.Length);
                         System.Array.Copy(widths, oldMaxWidths.Length, mMaxWidths, oldMaxWidths.Length, difference
                                           );
                     }
                     // the row is narrower or of the same width as the previous
                     // rows, so we find the maximum width for each column
                     // if the row is narrower than the previous ones,
                     // difference will be negative
                     int[] maxWidths = mMaxWidths;
                     length = System.Math.Min(length, newLength);
                     {
                         for (int j = 0; j < length; j++)
                         {
                             maxWidths[j] = System.Math.Max(maxWidths[j], widths[j]);
                         }
                     }
                 }
             }
         }
     }
 }
Example #13
0
        protected internal override void onLayout(bool changed, int left, int top, int right
                                                  , int bottom)
        {
            int count        = getChildCount();
            int parentLeft   = getPaddingLeftWithForeground();
            int parentRight  = right - left - getPaddingRightWithForeground();
            int parentTop    = getPaddingTopWithForeground();
            int parentBottom = bottom - top - getPaddingBottomWithForeground();

            mForegroundBoundsChanged = true;
            {
                for (int i = 0; i < count; i++)
                {
                    android.view.View child = getChildAt(i);
                    if (child.getVisibility() != GONE)
                    {
                        android.widget.FrameLayout.LayoutParams lp = (android.widget.FrameLayout.LayoutParams
                                                                      )child.getLayoutParams();
                        int width  = child.getMeasuredWidth();
                        int height = child.getMeasuredHeight();
                        int childLeft;
                        int childTop;
                        int gravity = lp.gravity;
                        if (gravity == -1)
                        {
                            gravity = DEFAULT_CHILD_GRAVITY;
                        }
                        int layoutDirection = getResolvedLayoutDirection();
                        int absoluteGravity = android.view.Gravity.getAbsoluteGravity(gravity, layoutDirection
                                                                                      );
                        int verticalGravity = gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK;
                        switch (absoluteGravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK)
                        {
                        case android.view.Gravity.LEFT:
                        {
                            childLeft = parentLeft + lp.leftMargin;
                            break;
                        }

                        case android.view.Gravity.CENTER_HORIZONTAL:
                        {
                            childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin -
                                        lp.rightMargin;
                            break;
                        }

                        case android.view.Gravity.RIGHT:
                        {
                            childLeft = parentRight - width - lp.rightMargin;
                            break;
                        }

                        default:
                        {
                            childLeft = parentLeft + lp.leftMargin;
                            break;
                        }
                        }
                        switch (verticalGravity)
                        {
                        case android.view.Gravity.TOP:
                        {
                            childTop = parentTop + lp.topMargin;
                            break;
                        }

                        case android.view.Gravity.CENTER_VERTICAL:
                        {
                            childTop = parentTop + (parentBottom - parentTop - height) / 2 + lp.topMargin - lp
                                       .bottomMargin;
                            break;
                        }

                        case android.view.Gravity.BOTTOM:
                        {
                            childTop = parentBottom - height - lp.bottomMargin;
                            break;
                        }

                        default:
                        {
                            childTop = parentTop + lp.topMargin;
                            break;
                        }
                        }
                        child.layout(childLeft, childTop, childLeft + width, childTop + height);
                    }
                }
            }
        }
Example #14
0
        protected internal override void onMeasure(int widthMeasureSpec, int heightMeasureSpec
                                                   )
        {
            int  count = getChildCount();
            bool measureMatchParentChildren = android.view.View.MeasureSpec.getMode(widthMeasureSpec
                                                                                    ) != android.view.View.MeasureSpec.EXACTLY || android.view.View.MeasureSpec.getMode
                                                  (heightMeasureSpec) != android.view.View.MeasureSpec.EXACTLY;

            mMatchParentChildren.clear();
            int maxHeight  = 0;
            int maxWidth   = 0;
            int childState = 0;

            {
                for (int i = 0; i < count; i++)
                {
                    android.view.View child = getChildAt(i);
                    if (mMeasureAllChildren || child.getVisibility() != GONE)
                    {
                        measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
                        android.widget.FrameLayout.LayoutParams lp = (android.widget.FrameLayout.LayoutParams
                                                                      )child.getLayoutParams();
                        maxWidth = System.Math.Max(maxWidth, child.getMeasuredWidth() + lp.leftMargin + lp
                                                   .rightMargin);
                        maxHeight = System.Math.Max(maxHeight, child.getMeasuredHeight() + lp.topMargin +
                                                    lp.bottomMargin);
                        childState = combineMeasuredStates(childState, child.getMeasuredState());
                        if (measureMatchParentChildren)
                        {
                            if (lp.width == android.view.ViewGroup.LayoutParams.MATCH_PARENT || lp.height ==
                                android.view.ViewGroup.LayoutParams.MATCH_PARENT)
                            {
                                mMatchParentChildren.add(child);
                            }
                        }
                    }
                }
            }
            // Account for padding too
            maxWidth  += getPaddingLeftWithForeground() + getPaddingRightWithForeground();
            maxHeight += getPaddingTopWithForeground() + getPaddingBottomWithForeground();
            // Check against our minimum height and width
            maxHeight = System.Math.Max(maxHeight, getSuggestedMinimumHeight());
            maxWidth  = System.Math.Max(maxWidth, getSuggestedMinimumWidth());
            // Check against our foreground's minimum height and width
            android.graphics.drawable.Drawable drawable = getForeground();
            if (drawable != null)
            {
                maxHeight = System.Math.Max(maxHeight, drawable.getMinimumHeight());
                maxWidth  = System.Math.Max(maxWidth, drawable.getMinimumWidth());
            }
            setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState),
                                 resolveSizeAndState(maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT
                                                     ));
            count = mMatchParentChildren.size();
            if (count > 1)
            {
                {
                    for (int i_1 = 0; i_1 < count; i_1++)
                    {
                        android.view.View child = mMatchParentChildren.get(i_1);
                        android.view.ViewGroup.MarginLayoutParams lp = (android.view.ViewGroup.MarginLayoutParams
                                                                        )child.getLayoutParams();
                        int childWidthMeasureSpec;
                        int childHeightMeasureSpec;
                        if (lp.width == android.view.ViewGroup.LayoutParams.MATCH_PARENT)
                        {
                            childWidthMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(getMeasuredWidth
                                                                                                      () - getPaddingLeftWithForeground() - getPaddingRightWithForeground() - lp.leftMargin
                                                                                                  - lp.rightMargin, android.view.View.MeasureSpec.EXACTLY);
                        }
                        else
                        {
                            childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, getPaddingLeftWithForeground
                                                                            () + getPaddingRightWithForeground() + lp.leftMargin + lp.rightMargin, lp.width);
                        }
                        if (lp.height == android.view.ViewGroup.LayoutParams.MATCH_PARENT)
                        {
                            childHeightMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(getMeasuredHeight
                                                                                                       () - getPaddingTopWithForeground() - getPaddingBottomWithForeground() - lp.topMargin
                                                                                                   - lp.bottomMargin, android.view.View.MeasureSpec.EXACTLY);
                        }
                        else
                        {
                            childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, getPaddingTopWithForeground
                                                                             () + getPaddingBottomWithForeground() + lp.topMargin + lp.bottomMargin, lp.height
                                                                         );
                        }
                        child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
                    }
                }
            }
        }
Example #15
0
        internal override void measureHorizontal(int widthMeasureSpec, int heightMeasureSpec
                                                 )
        {
            if (android.view.View.MeasureSpec.getMode(widthMeasureSpec) == android.view.View.
                MeasureSpec.UNSPECIFIED)
            {
                base.measureHorizontal(widthMeasureSpec, heightMeasureSpec);
                return;
            }
            // First, measure with no constraint
            int unspecifiedWidth = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View
                                                                                 .MeasureSpec.UNSPECIFIED);

            mImposedTabsHeight = -1;
            base.measureHorizontal(unspecifiedWidth, heightMeasureSpec);
            int extraWidth = getMeasuredWidth() - android.view.View.MeasureSpec.getSize(widthMeasureSpec
                                                                                        );

            if (extraWidth > 0)
            {
                int count      = getChildCount();
                int childCount = 0;
                {
                    for (int i = 0; i < count; i++)
                    {
                        android.view.View child = getChildAt(i);
                        if (child.getVisibility() == GONE)
                        {
                            continue;
                        }
                        childCount++;
                    }
                }
                if (childCount > 0)
                {
                    if (mImposedTabWidths == null || mImposedTabWidths.Length != count)
                    {
                        mImposedTabWidths = new int[count];
                    }
                    {
                        for (int i_1 = 0; i_1 < count; i_1++)
                        {
                            android.view.View child = getChildAt(i_1);
                            if (child.getVisibility() == GONE)
                            {
                                continue;
                            }
                            int childWidth = child.getMeasuredWidth();
                            int delta      = extraWidth / childCount;
                            int newWidth   = System.Math.Max(0, childWidth - delta);
                            mImposedTabWidths[i_1] = newWidth;
                            // Make sure the extra width is evenly distributed, no int division remainder
                            extraWidth -= childWidth - newWidth;
                            // delta may have been clamped
                            childCount--;
                            mImposedTabsHeight = System.Math.Max(mImposedTabsHeight, child.getMeasuredHeight(
                                                                     ));
                        }
                    }
                }
            }
            // Measure again, this time with imposed tab widths and respecting initial spec request
            base.measureHorizontal(widthMeasureSpec, heightMeasureSpec);
        }