Exemple #1
0
 /// <summary>
 /// For each item, calculates the most dense row that fully shows the item's
 /// title.
 /// </summary>
 /// <remarks>
 /// For each item, calculates the most dense row that fully shows the item's
 /// title.
 /// </remarks>
 /// <param name="width">The available width of the icon menu.</param>
 private void calculateItemFittingMetadata(int width)
 {
     int maxNumItemsPerRow = mMaxItemsPerRow;
     int numItems          = getChildCount();
     {
         for (int i = 0; i < numItems; i++)
         {
             [email protected] lp = ([email protected]
                                                                         .LayoutParams)getChildAt(i).getLayoutParams();
             // Start with 1, since that case does not get covered in the loop below
             lp.maxNumItemsOnRow = 1;
             {
                 for (int curNumItemsPerRow = maxNumItemsPerRow; curNumItemsPerRow > 0; curNumItemsPerRow
                      --)
                 {
                     // Check whether this item can fit into a row containing curNumItemsPerRow
                     if (lp.desiredWidth < width / curNumItemsPerRow)
                     {
                         // It can, mark this value as the most dense row it can fit into
                         lp.maxNumItemsOnRow = curNumItemsPerRow;
                         break;
                     }
                 }
             }
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Checks whether each item's title is fully visible using the current
        /// layout.
        /// </summary>
        /// <remarks>
        /// Checks whether each item's title is fully visible using the current
        /// layout.
        /// </remarks>
        /// <returns>
        /// True if the items fit (each item's text is fully visible), false
        /// otherwise.
        /// </returns>
        private bool doItemsFit()
        {
            int itemPos = 0;

            int[] layout_1 = mLayout;
            int   numRows  = mLayoutNumRows;

            {
                for (int row = 0; row < numRows; row++)
                {
                    int numItemsOnRow = layout_1[row];
                    if (numItemsOnRow == 1)
                    {
                        itemPos++;
                        continue;
                    }
                    {
                        for (int itemsOnRowCounter = numItemsOnRow; itemsOnRowCounter > 0; itemsOnRowCounter
                             --)
                        {
                            android.view.View child = getChildAt(itemPos++);
                            [email protected] lp = ([email protected]
                                                                                        .LayoutParams)child.getLayoutParams();
                            if (lp.maxNumItemsOnRow < numItemsOnRow)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            return(true);
        }
 /// <returns>
 /// layout params appropriate for this view.  If layout params already exist, it will
 /// augment them to be appropriate to the current text size.
 /// </returns>
 internal [email protected] getTextAppropriateLayoutParams
     ()
 {
     [email protected] lp = ([email protected]
                                                                 .LayoutParams)getLayoutParams();
     if (lp == null)
     {
         // Default layout parameters
         lp = new [email protected](android.view.ViewGroup
                                                                        .LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT);
     }
     // Set the desired width of item
     lp.desiredWidth = (int)android.text.Layout.getDesiredWidth(getText(), getPaint());
     return(lp);
 }
Exemple #4
0
		/// <returns>
		/// layout params appropriate for this view.  If layout params already exist, it will
		/// augment them to be appropriate to the current text size.
		/// </returns>
		internal [email protected] getTextAppropriateLayoutParams
			()
		{
			[email protected] lp = ([email protected]
				.LayoutParams)getLayoutParams();
			if (lp == null)
			{
				// Default layout parameters
				lp = new [email protected](android.view.ViewGroup
					.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT);
			}
			// Set the desired width of item
			lp.desiredWidth = (int)android.text.Layout.getDesiredWidth(getText(), getPaint());
			return lp;
		}
Exemple #5
0
        /// <summary>The positioning algorithm that gets called from onMeasure.</summary>
        /// <remarks>
        /// The positioning algorithm that gets called from onMeasure.  It
        /// just computes positions for each child, and then stores them in the child's layout params.
        /// </remarks>
        /// <param name="menuWidth">The width of this menu to assume for positioning</param>
        /// <param name="menuHeight">The height of this menu to assume for positioning</param>
        private void positionChildren(int menuWidth, int menuHeight)
        {
            // Clear the containers for the positions where the dividers should be drawn
            if (mHorizontalDivider != null)
            {
                mHorizontalDividerRects.clear();
            }
            if (mVerticalDivider != null)
            {
                mVerticalDividerRects.clear();
            }
            // Get the minimum number of rows needed
            int numRows       = mLayoutNumRows;
            int numRowsMinus1 = numRows - 1;

            int[] numItemsForRow = mLayout;
            // The item position across all rows
            int itemPos = 0;

            android.view.View child;
            [email protected] childLayoutParams = null;
            // Use float for this to get precise positions (uniform item widths
            // instead of last one taking any slack), and then convert to ints at last opportunity
            float itemLeft;
            float itemTop = 0;
            // Since each row can have a different number of items, this will be computed per row
            float itemWidth;
            // Subtract the space needed for the horizontal dividers
            float itemHeight = (menuHeight - mHorizontalDividerHeight * (numRows - 1)) / (float
                                                                                          )numRows;
            {
                for (int row = 0; row < numRows; row++)
                {
                    // Start at the left
                    itemLeft = 0;
                    // Subtract the space needed for the vertical dividers, and divide by the number of items
                    itemWidth = (menuWidth - mVerticalDividerWidth * (numItemsForRow[row] - 1)) / (float
                                                                                                   )numItemsForRow[row];
                    {
                        for (int itemPosOnRow = 0; itemPosOnRow < numItemsForRow[row]; itemPosOnRow++)
                        {
                            // Tell the child to be exactly this size
                            child = getChildAt(itemPos);
                            child.measure(android.view.View.MeasureSpec.makeMeasureSpec((int)itemWidth, android.view.View
                                                                                        .MeasureSpec.EXACTLY), android.view.View.MeasureSpec.makeMeasureSpec((int)itemHeight
                                                                                                                                                             , android.view.View.MeasureSpec.EXACTLY));
                            // Remember the child's position for layout
                            childLayoutParams = ([email protected])child.
                                                getLayoutParams();
                            childLayoutParams.left   = (int)itemLeft;
                            childLayoutParams.right  = (int)(itemLeft + itemWidth);
                            childLayoutParams.top    = (int)itemTop;
                            childLayoutParams.bottom = (int)(itemTop + itemHeight);
                            // Increment by item width
                            itemLeft += itemWidth;
                            itemPos++;
                            // Add a vertical divider to draw
                            if (mVerticalDivider != null)
                            {
                                mVerticalDividerRects.add(new android.graphics.Rect((int)itemLeft, (int)itemTop,
                                                                                    (int)(itemLeft + mVerticalDividerWidth), (int)(itemTop + itemHeight)));
                            }
                            // Increment by divider width (even if we're not computing
                            // dividers, since we need to leave room for them when
                            // calculating item positions)
                            itemLeft += mVerticalDividerWidth;
                        }
                    }
                    // Last child on each row should extend to very right edge
                    if (childLayoutParams != null)
                    {
                        childLayoutParams.right = menuWidth;
                    }
                    itemTop += itemHeight;
                    // Add a horizontal divider to draw
                    if ((mHorizontalDivider != null) && (row < numRowsMinus1))
                    {
                        mHorizontalDividerRects.add(new android.graphics.Rect(0, (int)itemTop, menuWidth,
                                                                              (int)(itemTop + mHorizontalDividerHeight)));
                        itemTop += mHorizontalDividerHeight;
                    }
                }
            }
        }