Example #1
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 #2
0
 public virtual void updateViewLayout(android.view.View view, android.view.ViewGroup
                                      .LayoutParams @params)
 {
     if (!(@params is android.view.WindowManagerClass.LayoutParams))
     {
         throw new System.ArgumentException("Params must be WindowManager.LayoutParams");
     }
     android.view.WindowManagerClass.LayoutParams wparams = (android.view.WindowManagerClass
                                                             .LayoutParams)@params;
     view.setLayoutParams(wparams);
     lock (this)
     {
         int index = findViewLocked(view, true);
         android.view.ViewRootImpl root = mRoots[index];
         mParams[index] = wparams;
         root.setLayoutParams(wparams, false);
     }
 }
Example #3
0
 public override void addView(android.view.View child)
 {
     if (child.getLayoutParams() == null)
     {
         android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams
                                                           (0, android.view.ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
         lp.setMargins(0, 0, 0, 0);
         child.setLayoutParams(lp);
     }
     // Ensure you can navigate to the tab with the keyboard, and you can touch it
     child.setFocusable(true);
     child.setClickable(true);
     base.addView(child);
     // TODO: detect this via geometry with a tabwidget listener rather
     // than potentially interfere with the view's listener
     child.setOnClickListener(new android.widget.TabWidget.TabClickListener(this, getTabCount
                                                                                () - 1));
     child.setOnFocusChangeListener(this);
 }
Example #4
0
 public override android.view.View getItemView([email protected]
                                               item, android.view.View convertView, android.view.ViewGroup parent)
 {
     android.view.View actionView = item.getActionView();
     if (actionView == null || item.hasCollapsibleActionView())
     {
         if (!(convertView is [email protected]))
         {
             convertView = null;
         }
         actionView = base.getItemView(item, convertView, parent);
     }
     actionView.setVisibility(item.isActionViewExpanded() ? android.view.View.GONE : android.view.View
                              .VISIBLE);
     [email protected] menuParent = ([email protected]
                                                              )parent;
     android.view.ViewGroup.LayoutParams lp = actionView.getLayoutParams();
     if (!menuParent.checkLayoutParams(lp))
     {
         actionView.setLayoutParams((([email protected]
                                      )menuParent.generateLayoutParams(lp)));
     }
     return(actionView);
 }
Example #5
0
        protected internal override void onMeasure(int widthMeasureSpec, int heightMeasureSpec
                                                   )
        {
            int widthMode = android.view.View.MeasureSpec.getMode(widthMeasureSpec);
            int widthSize;
            int heightSize;

            mSpinnerPadding.left  = mPaddingLeft > mSelectionLeftPadding ? mPaddingLeft : mSelectionLeftPadding;
            mSpinnerPadding.top   = mPaddingTop > mSelectionTopPadding ? mPaddingTop : mSelectionTopPadding;
            mSpinnerPadding.right = mPaddingRight > mSelectionRightPadding ? mPaddingRight :
                                    mSelectionRightPadding;
            mSpinnerPadding.bottom = mPaddingBottom > mSelectionBottomPadding ? mPaddingBottom
                                 : mSelectionBottomPadding;
            if (mDataChanged)
            {
                handleDataChanged();
            }
            int  preferredHeight  = 0;
            int  preferredWidth   = 0;
            bool needsMeasuring   = true;
            int  selectedPosition = getSelectedItemPosition();

            if (selectedPosition >= 0 && mAdapter != null && selectedPosition < mAdapter.getCount
                    ())
            {
                // Try looking in the recycler. (Maybe we were measured once already)
                android.view.View view = mRecycler.get(selectedPosition);
                if (view == null)
                {
                    // Make a new one
                    view = mAdapter.getView(selectedPosition, null, this);
                }
                if (view != null)
                {
                    // Put in recycler for re-measuring and/or layout
                    mRecycler.put(selectedPosition, view);
                }
                if (view != null)
                {
                    if (view.getLayoutParams() == null)
                    {
                        mBlockLayoutRequests = true;
                        view.setLayoutParams(generateDefaultLayoutParams());
                        mBlockLayoutRequests = false;
                    }
                    measureChild(view, widthMeasureSpec, heightMeasureSpec);
                    preferredHeight = getChildHeight(view) + mSpinnerPadding.top + mSpinnerPadding.bottom;
                    preferredWidth  = getChildWidth(view) + mSpinnerPadding.left + mSpinnerPadding.right;
                    needsMeasuring  = false;
                }
            }
            if (needsMeasuring)
            {
                // No views -- just use padding
                preferredHeight = mSpinnerPadding.top + mSpinnerPadding.bottom;
                if (widthMode == android.view.View.MeasureSpec.UNSPECIFIED)
                {
                    preferredWidth = mSpinnerPadding.left + mSpinnerPadding.right;
                }
            }
            preferredHeight = System.Math.Max(preferredHeight, getSuggestedMinimumHeight());
            preferredWidth  = System.Math.Max(preferredWidth, getSuggestedMinimumWidth());
            heightSize      = resolveSizeAndState(preferredHeight, heightMeasureSpec, 0);
            widthSize       = resolveSizeAndState(preferredWidth, widthMeasureSpec, 0);
            setMeasuredDimension(widthSize, heightSize);
            mHeightMeasureSpec = heightMeasureSpec;
            mWidthMeasureSpec  = widthMeasureSpec;
        }
Example #6
0
 private void addView(android.view.View view, android.view.ViewGroup.LayoutParams
                      @params, android.view.CompatibilityInfoHolder cih, bool nest)
 {
     if (false)
     {
         android.util.Log.v("WindowManager", "addView view=" + view);
     }
     if (!(@params is android.view.WindowManagerClass.LayoutParams))
     {
         throw new System.ArgumentException("Params must be WindowManager.LayoutParams");
     }
     android.view.WindowManagerClass.LayoutParams wparams = (android.view.WindowManagerClass
                                                             .LayoutParams)@params;
     android.view.ViewRootImpl root;
     android.view.View         panelParentView = null;
     lock (this)
     {
         // Here's an odd/questionable case: if someone tries to add a
         // view multiple times, then we simply bump up a nesting count
         // and they need to remove the view the corresponding number of
         // times to have it actually removed from the window manager.
         // This is useful specifically for the notification manager,
         // which can continually add/remove the same view as a
         // notification gets updated.
         int index = findViewLocked(view, false);
         if (index >= 0)
         {
             if (!nest)
             {
                 throw new System.InvalidOperationException("View " + view + " has already been added to the window manager."
                                                            );
             }
             root = mRoots[index];
             root.mAddNesting++;
             // Update layout parameters.
             view.setLayoutParams(wparams);
             root.setLayoutParams(wparams, true);
             return;
         }
         // If this is a panel window, then find the window it is being
         // attached to for future reference.
         if (wparams.type >= android.view.WindowManagerClass.LayoutParams.FIRST_SUB_WINDOW &&
             wparams.type <= android.view.WindowManagerClass.LayoutParams.LAST_SUB_WINDOW)
         {
             int count = mViews != null ? mViews.Length : 0;
             {
                 for (int i = 0; i < count; i++)
                 {
                     if (mRoots[i].mWindow.asBinder() == wparams.token)
                     {
                         panelParentView = mViews[i];
                     }
                 }
             }
         }
         root             = new android.view.ViewRootImpl(view.getContext());
         root.mAddNesting = 1;
         if (cih == null)
         {
             root.mCompatibilityInfo = new android.view.CompatibilityInfoHolder();
         }
         else
         {
             root.mCompatibilityInfo = cih;
         }
         view.setLayoutParams(wparams);
         if (mViews == null)
         {
             index   = 1;
             mViews  = new android.view.View[1];
             mRoots  = new android.view.ViewRootImpl[1];
             mParams = new android.view.WindowManagerClass.LayoutParams[1];
         }
         else
         {
             index = mViews.Length + 1;
             object[] old = mViews;
             mViews = new android.view.View[index];
             System.Array.Copy(old, 0, mViews, 0, index - 1);
             old    = mRoots;
             mRoots = new android.view.ViewRootImpl[index];
             System.Array.Copy(old, 0, mRoots, 0, index - 1);
             old     = mParams;
             mParams = new android.view.WindowManagerClass.LayoutParams[index];
             System.Array.Copy(old, 0, mParams, 0, index - 1);
         }
         index--;
         mViews[index]  = view;
         mRoots[index]  = root;
         mParams[index] = wparams;
     }
     // do this last because it fires off messages to start doing things
     root.setView(view, wparams, panelParentView);
 }
Example #7
0
 public override void setCustomView(android.view.View view, android.app.ActionBar.
                                    LayoutParams layoutParams)
 {
     view.setLayoutParams(layoutParams);
     mActionView.setCustomNavigationView(view);
 }