Example #1
0
        /// <summary>
        /// Helper for makeAndAddView to set the position of a view
        /// and fill out its layout paramters.
        /// </summary>
        /// <remarks>
        /// Helper for makeAndAddView to set the position of a view
        /// and fill out its layout paramters.
        /// </remarks>
        /// <param name="child">The view to position</param>
        private void setUpChild(android.view.View child)
        {
            // Respect layout params that are already in the view. Otherwise
            // make some up...
            android.view.ViewGroup.LayoutParams lp = child.getLayoutParams();
            if (lp == null)
            {
                lp = generateDefaultLayoutParams();
            }
            addViewInLayout(child, 0, lp);
            child.setSelected(hasFocus());
            // Get measure specs
            int childHeightSpec = android.view.ViewGroup.getChildMeasureSpec(mHeightMeasureSpec
                                                                             , mSpinnerPadding.top + mSpinnerPadding.bottom, lp.height);
            int childWidthSpec = android.view.ViewGroup.getChildMeasureSpec(mWidthMeasureSpec
                                                                            , mSpinnerPadding.left + mSpinnerPadding.right, lp.width);

            // Measure child
            child.measure(childWidthSpec, childHeightSpec);
            int childLeft;
            int childRight;
            // Position vertically based on gravity setting
            int childTop = mSpinnerPadding.top + ((getMeasuredHeight() - mSpinnerPadding.bottom
                                                   - mSpinnerPadding.top - child.getMeasuredHeight()) / 2);
            int childBottom = childTop + child.getMeasuredHeight();
            int width       = child.getMeasuredWidth();

            childLeft  = 0;
            childRight = childLeft + width;
            child.layout(childLeft, childTop, childRight, childBottom);
        }
Example #2
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 #3
0
        /// <summary>
        /// @brief Create animator to hide specified app actions
        /// </summary>
        /// <param name="toShow">        View to be shown </param>
        /// <param name="duration">      Animation duration of each sub animator
        /// </param>
        /// <returns>  Sequential animator to show the hidden element </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public android.animation.Animator createExpandAnimator(final android.view.View toShow, long duration)
        public virtual Animator createExpandAnimator(View toShow, long duration)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int fromWidth = toShow.getWidth();
            int fromWidth = toShow.Width;

            toShow.LayoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            toShow.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int toWidth = toShow.getMeasuredWidth();
            int toWidth = toShow.MeasuredWidth;

            if (FcConstants.OPT_DETAILED_LOGS)
            {
                Log.d(TAG, "createExpandAnimator(" + toShow + ")");
                Log.d(TAG, "    duration: " + duration);
                Log.d(TAG, "    width: " + fromWidth + " -> " + toWidth);
            }

            ValueAnimator expandAnimator = ValueAnimator.ofFloat(0f, 1f);

            expandAnimator.Duration = duration;
            expandAnimator.addUpdateListener(new AnimatorUpdateListenerAnonymousInnerClassHelper3(this, toShow, fromWidth, toWidth));
            expandAnimator.addListener(new FcAnimatorListenerAnonymousInnerClassHelper3(this, toShow, fromWidth));

            return(expandAnimator);
        }
Example #4
0
        /// <summary>
        /// @brief Create animator to hide specified app actions
        /// </summary>
        /// <param name="toShow">        View to be shown </param>
        /// <param name="toDimension"> </param>
        /// <param name="duration">      Animation duration of each sub animator
        /// </param>
        /// <returns>  Sequential animator to show the hidden element </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public android.animation.Animator createExpandAnimator(final android.view.View toShow, final int toDimension, long duration)
        public virtual Animator createExpandAnimator(View toShow, int toDimension, long duration)
        {
            Log.d(TAG, "View params:");
            Log.d(TAG, "  before measure getWidth: " + toShow.Width);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final float fromWidth = toShow.getWidth();
            float fromWidth = toShow.Width;

            toShow.LayoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            toShow.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

            float toMeasuredWidth = toShow.MeasuredWidth;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final float toWidth = (toDimension < toMeasuredWidth) ? toDimension : toMeasuredWidth;
            float toWidth = (toDimension < toMeasuredWidth) ? toDimension : toMeasuredWidth;

            ValueAnimator expandAnimator = ValueAnimator.ofFloat(0f, 1f);

            expandAnimator.Duration = duration;
            expandAnimator.addUpdateListener(new AnimatorUpdateListenerAnonymousInnerClassHelper2(this, toShow, toWidth));

            expandAnimator.addListener(new FcAnimatorListenerAnonymousInnerClassHelper2(this, toShow));

            return(expandAnimator);
        }
Example #5
0
        private int measureContentWidth(android.widget.ListAdapter adapter)
        {
            // Menus don't tend to be long, so this is more sane than it looks.
            int width = 0;

            android.view.View itemView = null;
            int itemType         = 0;
            int widthMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View
                                                                                 .MeasureSpec.UNSPECIFIED);
            int heightMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View
                                                                                  .MeasureSpec.UNSPECIFIED);
            int count = adapter.getCount();

            {
                for (int i = 0; i < count; i++)
                {
                    int positionType = adapter.getItemViewType(i);
                    if (positionType != itemType)
                    {
                        itemType = positionType;
                        itemView = null;
                    }
                    if (mMeasureParent == null)
                    {
                        mMeasureParent = new android.widget.FrameLayout(mContext);
                    }
                    itemView = adapter.getView(i, itemView, mMeasureParent);
                    itemView.measure(widthMeasureSpec, heightMeasureSpec);
                    width = System.Math.Max(width, itemView.getMeasuredWidth());
                }
            }
            return(width);
        }
Example #6
0
            public virtual int measureContentWidth()
            {
                // The user may have specified some of the target not to be shown but we
                // want to measure all of them since after expansion they should fit.
                int oldMaxActivityCount = this.mMaxActivityCount;

                this.mMaxActivityCount = MAX_ACTIVITY_COUNT_UNLIMITED;
                int contentWidth = 0;

                android.view.View itemView = null;
                int widthMeasureSpec       = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View
                                                                                           .MeasureSpec.UNSPECIFIED);
                int heightMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View
                                                                                      .MeasureSpec.UNSPECIFIED);
                int count = this.getCount();

                {
                    for (int i = 0; i < count; i++)
                    {
                        itemView = this.getView(i, itemView, null);
                        itemView.measure(widthMeasureSpec, heightMeasureSpec);
                        contentWidth = System.Math.Max(contentWidth, itemView.getMeasuredWidth());
                    }
                }
                this.mMaxActivityCount = oldMaxActivityCount;
                return(contentWidth);
            }
Example #7
0
 protected internal virtual int measureChildView(android.view.View child, int availableWidth
                                                 , int childSpecHeight, int spacing)
 {
     child.measure(android.view.View.MeasureSpec.makeMeasureSpec(availableWidth, android.view.View
                                                                 .MeasureSpec.AT_MOST), childSpecHeight);
     availableWidth -= child.getMeasuredWidth();
     availableWidth -= spacing;
     return(System.Math.Max(0, availableWidth));
 }
Example #8
0
        /// <summary>Measure a child view to fit within cell-based formatting.</summary>
        /// <remarks>
        /// Measure a child view to fit within cell-based formatting. The child's width
        /// will be measured to a whole multiple of cellSize.
        /// <p>Sets the expandable and cellsUsed fields of LayoutParams.
        /// </remarks>
        /// <param name="child">Child to measure</param>
        /// <param name="cellSize">Size of one cell</param>
        /// <param name="cellsRemaining">Number of cells remaining that this view can expand to fill
        ///     </param>
        /// <param name="parentHeightMeasureSpec">MeasureSpec used by the parent view</param>
        /// <param name="parentHeightPadding">Padding present in the parent view</param>
        /// <returns>Number of cells this child was measured to occupy</returns>
        internal static int measureChildForCells(android.view.View child, int cellSize, int
                                                 cellsRemaining, int parentHeightMeasureSpec, int parentHeightPadding)
        {
            [email protected] lp = ([email protected]
                                                                          .LayoutParams)child.getLayoutParams();
            int childHeightSize = android.view.View.MeasureSpec.getSize(parentHeightMeasureSpec
                                                                        ) - parentHeightPadding;
            int childHeightMode = android.view.View.MeasureSpec.getMode(parentHeightMeasureSpec
                                                                        );
            int childHeightSpec = android.view.View.MeasureSpec.makeMeasureSpec(childHeightSize
                                                                                , childHeightMode);
            int cellsUsed = 0;

            if (cellsRemaining > 0)
            {
                int childWidthSpec = android.view.View.MeasureSpec.makeMeasureSpec(cellSize * cellsRemaining
                                                                                   , android.view.View.MeasureSpec.AT_MOST);
                child.measure(childWidthSpec, childHeightSpec);
                int measuredWidth = child.getMeasuredWidth();
                cellsUsed = measuredWidth / cellSize;
                if (measuredWidth % cellSize != 0)
                {
                    cellsUsed++;
                }
            }
            [email protected] itemView = child is [email protected]
                                 ? ([email protected])child : null;
            bool expandable = !lp.isOverflowButton && itemView != null && itemView.hasText();

            lp.expandable = expandable;
            lp.cellsUsed  = cellsUsed;
            int targetWidth = cellsUsed * cellSize;

            child.measure(android.view.View.MeasureSpec.makeMeasureSpec(targetWidth, android.view.View
                                                                        .MeasureSpec.EXACTLY), childHeightSpec);
            return(cellsUsed);
        }
Example #9
0
        internal virtual int measureContentWidth(android.widget.SpinnerAdapter adapter, android.graphics.drawable.Drawable
                                                 background)
        {
            if (adapter == null)
            {
                return(0);
            }
            int width = 0;

            android.view.View itemView = null;
            int itemType         = 0;
            int widthMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View
                                                                                 .MeasureSpec.UNSPECIFIED);
            int heightMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View
                                                                                  .MeasureSpec.UNSPECIFIED);
            // Make sure the number of items we'll measure is capped. If it's a huge data set
            // with wildly varying sizes, oh well.
            int start = System.Math.Max(0, getSelectedItemPosition());
            int end   = System.Math.Min(adapter.getCount(), start + MAX_ITEMS_MEASURED);
            int count = end - start;

            start = System.Math.Max(0, start - (MAX_ITEMS_MEASURED - count));
            {
                for (int i = start; i < end; i++)
                {
                    int positionType = adapter.getItemViewType(i);
                    if (positionType != itemType)
                    {
                        itemType = positionType;
                        itemView = null;
                    }
                    itemView = adapter.getView(i, itemView, this);
                    if (itemView.getLayoutParams() == null)
                    {
                        itemView.setLayoutParams(new android.view.ViewGroup.LayoutParams(android.view.ViewGroup
                                                                                         .LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
                    }
                    itemView.measure(widthMeasureSpec, heightMeasureSpec);
                    width = System.Math.Max(width, itemView.getMeasuredWidth());
                }
            }
            // Add background padding to measured width
            if (background != null)
            {
                background.getPadding(mTempRect);
                width += mTempRect.left + mTempRect.right;
            }
            return(width);
        }
Example #10
0
        public override void initForMenu(android.content.Context context, [email protected]
                                         menu)
        {
            base.initForMenu(context, menu);
            android.content.res.Resources res = context.getResources();
            if (!mReserveOverflowSet)
            {
                mReserveOverflow = !android.view.ViewConfiguration.get(context).hasPermanentMenuKey
                                       ();
            }
            if (!mWidthLimitSet)
            {
                mWidthLimit = res.getDisplayMetrics().widthPixels / 2;
            }
            // Measure for initial configuration
            if (!mMaxItemsSet)
            {
                mMaxItems = res.getInteger([email protected]_action_buttons);
            }
            int width = mWidthLimit;

            if (mReserveOverflow)
            {
                if (mOverflowButton == null)
                {
                    mOverflowButton = new android.view.@internal.menu.ActionMenuPresenter.OverflowMenuButton
                                          (this, mSystemContext);
                    int spec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View.MeasureSpec
                                                                             .UNSPECIFIED);
                    mOverflowButton.measure(spec, spec);
                }
                width -= mOverflowButton.getMeasuredWidth();
            }
            else
            {
                mOverflowButton = null;
            }
            mActionItemWidthLimit = width;
            mMinCellSize          = (int)([email protected]_CELL_SIZE * res
                                          .getDisplayMetrics().density);
            // Drop a scrap view as it may no longer reflect the proper context/config.
            mScrapActionButtonView = null;
        }
Example #11
0
        public override bool flagActionItems()
        {
            java.util.ArrayList <*****@*****.**> visibleItems = mMenu
                                                                                          .getVisibleItems();
            int itemsSize  = visibleItems.size();
            int maxActions = mMaxItems;
            int widthLimit = mActionItemWidthLimit;
            int querySpec  = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View
                                                                           .MeasureSpec.UNSPECIFIED);

            android.view.ViewGroup parent = (android.view.ViewGroup)mMenuView;
            int  requiredItems            = 0;
            int  requestedItems           = 0;
            int  firstActionWidth         = 0;
            bool hasOverflow = false;

            {
                for (int i = 0; i < itemsSize; i++)
                {
                    [email protected] item = visibleItems.get(i);
                    if (item.requiresActionButton())
                    {
                        requiredItems++;
                    }
                    else
                    {
                        if (item.requestsActionButton())
                        {
                            requestedItems++;
                        }
                        else
                        {
                            hasOverflow = true;
                        }
                    }
                    if (mExpandedActionViewsExclusive && item.isActionViewExpanded())
                    {
                        // Overflow everything if we have an expanded action view and we're
                        // space constrained.
                        maxActions = 0;
                    }
                }
            }
            // Reserve a spot for the overflow item if needed.
            if (mReserveOverflow && (hasOverflow || requiredItems + requestedItems > maxActions
                                     ))
            {
                maxActions--;
            }
            maxActions -= requiredItems;
            android.util.SparseBooleanArray seenGroups = mActionButtonGroups;
            seenGroups.clear();
            int cellSize       = 0;
            int cellsRemaining = 0;

            if (mStrictWidthLimit)
            {
                cellsRemaining = widthLimit / mMinCellSize;
                int cellSizeRemaining = widthLimit % mMinCellSize;
                cellSize = mMinCellSize + cellSizeRemaining / cellsRemaining;
            }
            {
                // Flag as many more requested items as will fit.
                for (int i_1 = 0; i_1 < itemsSize; i_1++)
                {
                    [email protected] item = visibleItems.get(i_1);
                    if (item.requiresActionButton())
                    {
                        android.view.View v = getItemView(item, mScrapActionButtonView, parent);
                        if (mScrapActionButtonView == null)
                        {
                            mScrapActionButtonView = v;
                        }
                        if (mStrictWidthLimit)
                        {
                            cellsRemaining -= [email protected]
                                                  (v, cellSize, cellsRemaining, querySpec, 0);
                        }
                        else
                        {
                            v.measure(querySpec, querySpec);
                        }
                        int measuredWidth = v.getMeasuredWidth();
                        widthLimit -= measuredWidth;
                        if (firstActionWidth == 0)
                        {
                            firstActionWidth = measuredWidth;
                        }
                        int groupId = item.getGroupId();
                        if (groupId != 0)
                        {
                            seenGroups.put(groupId, true);
                        }
                        item.setIsActionButton(true);
                    }
                    else
                    {
                        if (item.requestsActionButton())
                        {
                            // Items in a group with other items that already have an action slot
                            // can break the max actions rule, but not the width limit.
                            int  groupId  = item.getGroupId();
                            bool inGroup  = seenGroups.get(groupId);
                            bool isAction = (maxActions > 0 || inGroup) && widthLimit > 0 && (!mStrictWidthLimit ||
                                                                                              cellsRemaining > 0);
                            if (isAction)
                            {
                                android.view.View v = getItemView(item, mScrapActionButtonView, parent);
                                if (mScrapActionButtonView == null)
                                {
                                    mScrapActionButtonView = v;
                                }
                                if (mStrictWidthLimit)
                                {
                                    int cells = [email protected](v, cellSize
                                                                                                                , cellsRemaining, querySpec, 0);
                                    cellsRemaining -= cells;
                                    if (cells == 0)
                                    {
                                        isAction = false;
                                    }
                                }
                                else
                                {
                                    v.measure(querySpec, querySpec);
                                }
                                int measuredWidth = v.getMeasuredWidth();
                                widthLimit -= measuredWidth;
                                if (firstActionWidth == 0)
                                {
                                    firstActionWidth = measuredWidth;
                                }
                                if (mStrictWidthLimit)
                                {
                                    isAction &= widthLimit >= 0;
                                }
                                else
                                {
                                    // Did this push the entire first item past the limit?
                                    isAction &= widthLimit + firstActionWidth > 0;
                                }
                            }
                            if (isAction && groupId != 0)
                            {
                                seenGroups.put(groupId, true);
                            }
                            else
                            {
                                if (inGroup)
                                {
                                    // We broke the width limit. Demote the whole group, they all overflow now.
                                    seenGroups.put(groupId, false);
                                    {
                                        for (int j = 0; j < i_1; j++)
                                        {
                                            [email protected] areYouMyGroupie = visibleItems.get(j);
                                            if (areYouMyGroupie.getGroupId() == groupId)
                                            {
                                                // Give back the action slot
                                                if (areYouMyGroupie.isActionButton())
                                                {
                                                    maxActions++;
                                                }
                                                areYouMyGroupie.setIsActionButton(false);
                                            }
                                        }
                                    }
                                }
                            }
                            if (isAction)
                            {
                                maxActions--;
                            }
                            item.setIsActionButton(isAction);
                        }
                    }
                }
            }
            return(true);
        }
Example #12
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 #13
0
        protected internal override void onMeasure(int widthMeasureSpec, int heightMeasureSpec
                                                   )
        {
            int widthMode = android.view.View.MeasureSpec.getMode(widthMeasureSpec);

            if (widthMode != android.view.View.MeasureSpec.EXACTLY)
            {
                throw new System.InvalidOperationException(GetType().Name + " can only be used "
                                                           + "with android:layout_width=\"match_parent\" (or fill_parent)");
            }
            int heightMode = android.view.View.MeasureSpec.getMode(heightMeasureSpec);

            if (heightMode == android.view.View.MeasureSpec.UNSPECIFIED)
            {
                throw new System.InvalidOperationException(GetType().Name + " can only be used "
                                                           + "with android:layout_height=\"wrap_content\"");
            }
            int contentWidth = android.view.View.MeasureSpec.getSize(widthMeasureSpec);
            int maxHeight    = mContentHeight > 0 ? mContentHeight : android.view.View.MeasureSpec
                               .getSize(heightMeasureSpec);
            int verticalPadding = getPaddingTop() + getPaddingBottom();
            int availableWidth  = contentWidth - getPaddingLeft() - getPaddingRight();
            int height          = maxHeight - verticalPadding;
            int childSpecHeight = android.view.View.MeasureSpec.makeMeasureSpec(height, android.view.View
                                                                                .MeasureSpec.AT_MOST);

            if (mClose != null)
            {
                availableWidth = measureChildView(mClose, availableWidth, childSpecHeight, 0);
                android.view.ViewGroup.MarginLayoutParams lp = (android.view.ViewGroup.MarginLayoutParams
                                                                )mClose.getLayoutParams();
                availableWidth -= lp.leftMargin + lp.rightMargin;
            }
            if (mMenuView != null && mMenuView.getParent() == this)
            {
                availableWidth = measureChildView(mMenuView, availableWidth, childSpecHeight, 0);
            }
            if (mTitleLayout != null && mCustomView == null)
            {
                availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight,
                                                  0);
            }
            if (mCustomView != null)
            {
                android.view.ViewGroup.LayoutParams lp = mCustomView.getLayoutParams();
                int customWidthMode = lp.width != android.view.ViewGroup.LayoutParams.WRAP_CONTENT
                                         ? android.view.View.MeasureSpec.EXACTLY : android.view.View.MeasureSpec.AT_MOST;
                int customWidth      = lp.width >= 0 ? System.Math.Min(lp.width, availableWidth) : availableWidth;
                int customHeightMode = lp.height != android.view.ViewGroup.LayoutParams.WRAP_CONTENT
                                         ? android.view.View.MeasureSpec.EXACTLY : android.view.View.MeasureSpec.AT_MOST;
                int customHeight = lp.height >= 0 ? System.Math.Min(lp.height, height) : height;
                mCustomView.measure(android.view.View.MeasureSpec.makeMeasureSpec(customWidth, customWidthMode
                                                                                  ), android.view.View.MeasureSpec.makeMeasureSpec(customHeight, customHeightMode)
                                    );
            }
            if (mContentHeight <= 0)
            {
                int measuredHeight = 0;
                int count          = getChildCount();
                {
                    for (int i = 0; i < count; i++)
                    {
                        android.view.View v  = getChildAt(i);
                        int paddedViewHeight = v.getMeasuredHeight() + verticalPadding;
                        if (paddedViewHeight > measuredHeight)
                        {
                            measuredHeight = paddedViewHeight;
                        }
                    }
                }
                setMeasuredDimension(contentWidth, measuredHeight);
            }
            else
            {
                setMeasuredDimension(contentWidth, maxHeight);
            }
        }
Example #14
0
		/// <summary>
		/// @brief Create animator to hide specified app actions
		/// </summary>
		/// <param name="toShow">        View to be shown </param>
		/// <param name="duration">      Animation duration of each sub animator
		/// </param>
		/// <returns>  Sequential animator to show the hidden element </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public android.animation.Animator createExpandAnimator(final android.view.View toShow, long duration)
		public virtual Animator createExpandAnimator(View toShow, long duration)
		{
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int fromWidth = toShow.getWidth();
			int fromWidth = toShow.Width;
			toShow.LayoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
			toShow.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int toWidth = toShow.getMeasuredWidth();
			int toWidth = toShow.MeasuredWidth;

			if (FcConstants.OPT_DETAILED_LOGS)
			{
				Log.d(TAG, "createExpandAnimator(" + toShow + ")");
				Log.d(TAG, "    duration: " + duration);
				Log.d(TAG, "    width: " + fromWidth + " -> " + toWidth);
			}

			ValueAnimator expandAnimator = ValueAnimator.ofFloat(0f, 1f);
			expandAnimator.Duration = duration;
			expandAnimator.addUpdateListener(new AnimatorUpdateListenerAnonymousInnerClassHelper3(this, toShow, fromWidth, toWidth));
			expandAnimator.addListener(new FcAnimatorListenerAnonymousInnerClassHelper3(this, toShow, fromWidth));

			return expandAnimator;
		}
Example #15
0
		/// <summary>
		/// @brief Create animator to hide specified app actions
		/// </summary>
		/// <param name="toShow">        View to be shown </param>
		/// <param name="toDimension"> </param>
		/// <param name="duration">      Animation duration of each sub animator
		/// </param>
		/// <returns>  Sequential animator to show the hidden element </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public android.animation.Animator createExpandAnimator(final android.view.View toShow, final int toDimension, long duration)
		public virtual Animator createExpandAnimator(View toShow, int toDimension, long duration)
		{

			Log.d(TAG, "View params:");
			Log.d(TAG, "  before measure getWidth: " + toShow.Width);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final float fromWidth = toShow.getWidth();
			float fromWidth = toShow.Width;

			toShow.LayoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
			toShow.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

			float toMeasuredWidth = toShow.MeasuredWidth;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final float toWidth = (toDimension < toMeasuredWidth) ? toDimension : toMeasuredWidth;
			float toWidth = (toDimension < toMeasuredWidth) ? toDimension : toMeasuredWidth;

			ValueAnimator expandAnimator = ValueAnimator.ofFloat(0f, 1f);
			expandAnimator.Duration = duration;
			expandAnimator.addUpdateListener(new AnimatorUpdateListenerAnonymousInnerClassHelper2(this, toShow, toWidth));

			expandAnimator.addListener(new FcAnimatorListenerAnonymousInnerClassHelper2(this, toShow));

			return expandAnimator;
		}
Example #16
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 #17
0
        internal override void measureChildBeforeLayout(android.view.View child, int childIndex
                                                        , int widthMeasureSpec, int totalWidth, int heightMeasureSpec, int totalHeight)
        {
            if (mConstrainedColumnWidths != null)
            {
                android.widget.TableRow.LayoutParams lp = (android.widget.TableRow.LayoutParams)child
                                                          .getLayoutParams();
                int   measureMode             = android.view.View.MeasureSpec.EXACTLY;
                int   columnWidth             = 0;
                int   span                    = lp.span;
                int[] constrainedColumnWidths = mConstrainedColumnWidths;
                {
                    for (int i = 0; i < span; i++)
                    {
                        columnWidth += constrainedColumnWidths[childIndex + i];
                    }
                }
                int  gravity             = lp.gravity;
                bool isHorizontalGravity = android.view.Gravity.isHorizontal(gravity);
                if (isHorizontalGravity)
                {
                    measureMode = android.view.View.MeasureSpec.AT_MOST;
                }
                // no need to care about padding here,
                // ViewGroup.getChildMeasureSpec() would get rid of it anyway
                // because of the EXACTLY measure spec we use
                int childWidthMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(System.Math.Max
                                                                                              (0, columnWidth - lp.leftMargin - lp.rightMargin), measureMode);
                int childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, mPaddingTop +
                                                                 mPaddingBottom + lp.topMargin + lp.bottomMargin + totalHeight, lp.height);
                child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
                if (isHorizontalGravity)
                {
                    int childWidth = child.getMeasuredWidth();
                    lp.mOffset[android.widget.TableRow.LayoutParams.LOCATION_NEXT] = columnWidth - childWidth;
                    int layoutDirection = getResolvedLayoutDirection();
                    int absoluteGravity = android.view.Gravity.getAbsoluteGravity(gravity, layoutDirection
                                                                                  );
                    switch (absoluteGravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK)
                    {
                    case android.view.Gravity.LEFT:
                    {
                        // don't offset on X axis
                        break;
                    }

                    case android.view.Gravity.RIGHT:
                    {
                        lp.mOffset[android.widget.TableRow.LayoutParams.LOCATION] = lp.mOffset[android.widget.TableRow
                                                                                               .LayoutParams.LOCATION_NEXT];
                        break;
                    }

                    case android.view.Gravity.CENTER_HORIZONTAL:
                    {
                        lp.mOffset[android.widget.TableRow.LayoutParams.LOCATION] = lp.mOffset[android.widget.TableRow
                                                                                               .LayoutParams.LOCATION_NEXT] / 2;
                        break;
                    }
                    }
                }
                else
                {
                    lp.mOffset[android.widget.TableRow.LayoutParams.LOCATION] = lp.mOffset[android.widget.TableRow
                                                                                           .LayoutParams.LOCATION_NEXT] = 0;
                }
            }
            else
            {
                // fail silently when column widths are not available
                base.measureChildBeforeLayout(child, childIndex, widthMeasureSpec, totalWidth, heightMeasureSpec
                                              , totalHeight);
            }
        }