Exemplo n.º 1
0
        private int ResolveSizeAndState2(int size, int measureSpec, int childMeasuredState)
        {
            int result   = size;
            var specMode = MeasureSpec.GetMode(measureSpec);
            var specSize = MeasureSpec.GetSize(measureSpec);

            switch (specMode)
            {
            case MeasureSpecMode.Unspecified:
                result = size;
                break;

            case MeasureSpecMode.AtMost:
                if (specSize < size)
                {
                    result = specSize | View.MeasuredStateTooSmall;
                }
                else
                {
                    result = size;
                }
                break;

            case MeasureSpecMode.Exactly:
                result = specSize;
                break;
            }
            return(result | (childMeasuredState & View.MeasuredStateMask));
        }
Exemplo n.º 2
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            //Measure our width in whatever mode specified
            int measuredWidth = MeasureSpec.GetSize(widthMeasureSpec);

            //Determine our height
            float height         = 0;
            var   heightSpecMode = MeasureSpec.GetMode(heightMeasureSpec);

            if (heightSpecMode == MeasureSpecMode.Exactly)
            {
                //We were told how big to be
                height = MeasureSpec.GetSize(heightMeasureSpec);
            }
            else
            {
                //Calculate the text bounds
                RectF bounds = new RectF();
                bounds.Bottom = mPaintText.Descent() - mPaintText.Ascent();
                height        = bounds.Bottom - bounds.Top + mFooterLineHeight + mFooterPadding + mTopPadding;
                if (mFooterIndicatorStyle != IndicatorStyle.None)
                {
                    height += mFooterIndicatorHeight;
                }
            }
            int measuredHeight = (int)height;

            SetMeasuredDimension(measuredWidth, measuredHeight);
        }
Exemplo n.º 3
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            int totalWidth = MeasureSpec.GetSize(widthMeasureSpec);

            _cellSize = totalWidth / 7;
            int heightSize     = (int)Math.Round(35 * Resources.DisplayMetrics.Density);
            int cellWidthSpec  = MeasureSpec.MakeMeasureSpec(_cellSize, MeasureSpecMode.Exactly);
            int cellHeightSpec = IsHeaderRow
                ? MeasureSpec.MakeMeasureSpec(heightSize, MeasureSpecMode.AtMost)
                : MeasureSpec.MakeMeasureSpec(heightSize, MeasureSpecMode.Exactly);
            int rowHeight = 0;

            for (int c = 0; c < ChildCount; c++)
            {
                var child = GetChildAt(c);
                child.Measure(cellWidthSpec, cellHeightSpec);
                //The row height is the height of the tallest cell.
                if (child.MeasuredHeight > rowHeight)
                {
                    rowHeight = child.MeasuredHeight;
                }
            }
            int widthWithPadding  = totalWidth + PaddingLeft + PaddingRight;
            int heightWithPadding = rowHeight + PaddingTop + PaddingBottom;

            SetMeasuredDimension(widthWithPadding, heightWithPadding);

            stopwatch.Stop();
            Logr.D("Row.OnMeasure {0} ms", stopwatch.ElapsedMilliseconds);
        }
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            int widthSize  = MeasureSpec.GetSize(widthMeasureSpec);
            int heightSize = MeasureSpec.GetSize(heightMeasureSpec);

            if (widthSize == 0 && heightSize == 0)
            {
                // If there are no constraints on size, let FrameLayout measure
                base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

                // Now use the smallest of the measured dimensions for both dimensions
                int minSize = Math.Min(MeasuredWidth, MeasuredHeight);
                SetMeasuredDimension(minSize, minSize);
                return;
            }

            int size;

            if (widthSize == 0 || heightSize == 0)
            {
                // If one of the dimensions has no restriction on size, set both dimensions to be the
                // on that does
                size = Math.Max(widthSize, heightSize);
            }
            else
            {
                // Both dimensions have restrictions on size, set both dimensions to be the
                // smallest of the two
                size = Math.Min(widthSize, heightSize);
            }

            int newMeasureSpec = MeasureSpec.MakeMeasureSpec(size, MeasureSpecMode.Exactly);

            base.OnMeasure(newMeasureSpec, newMeasureSpec);
        }
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            var measuredWidth = MeasureSpec.GetSize(widthMeasureSpec);

            //Determine the height
            float height;
            var   heightSpecMode = MeasureSpec.GetMode(heightMeasureSpec);

            if (heightSpecMode == MeasureSpecMode.Exactly)
            {
                height = MeasureSpec.GetSize(heightMeasureSpec);
            }
            else
            {
                //Calculate text bounds
                _bounds.SetEmpty();
                _bounds.Bottom = (int)(_paintText.Descent() - _paintText.Ascent());
                height         = _bounds.Bottom - _bounds.Top + _footerLineHeight + _footerPadding + _topPadding;
                if (_footerIndicatorStyle != IndicatorStyle.None)
                {
                    height += _footerIndicatorHeight;
                }
            }
            var measuredHeight = (int)height;

            SetMeasuredDimension(measuredWidth, measuredHeight);
        }
Exemplo n.º 6
0
		protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
		{
			base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

			int width = MeasureSpec.GetSize(widthMeasureSpec);
			int height = MeasureSpec.GetSize(heightMeasureSpec);

			//get current settings from MirrorController
			mZoomRatio = MirrorController.GetInstance().GetZoomRatio();//from 1 to 4
			mMirrorFlip = MirrorController.GetInstance().GetMirrorFlip();//true:flip image, flase:default

			if (0 == mRatioWidth || 0 == mRatioHeight)
			{
				SetMeasuredDimension(width, height);
			} else {
				int newHeight = width * mRatioHeight / mRatioWidth;
				Matrix mat = new Matrix();
				if (mMirrorFlip)
				{
					//flip image
					mat.PostTranslate(-(float)(width / 2.0), -(float)(newHeight / 2.0));
					mat.PostScale((float)-1.0 * mZoomRatio, (float)1.0 * mZoomRatio);
					mat.PostTranslate((float)(width / 2.0), (float)(newHeight / 2.0));
				} else {
					//normal image
					mat.PostTranslate(-(float)(width / 2.0), -(float)(newHeight / 2.0));
					mat.PostScale((float)1.0 * mZoomRatio, (float)1.0 * mZoomRatio);
					mat.PostTranslate((float)(width / 2.0), (float)(newHeight / 2.0));
				}
				SetTransform(mat);
				mat.Reset();
				SetMeasuredDimension(width, newHeight);
			}
		}
Exemplo n.º 7
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            int width  = MeasureSpec.GetSize(widthMeasureSpec);
            int height = MeasureSpec.GetSize(heightMeasureSpec);

            SetMeasuredDimension(width, height);
        }
        /// <summary>
        /// Called when [measure].
        /// </summary>
        /// <param name="widthMeasureSpec">horizontal space requirements as imposed by the parent.
        /// The requirements are encoded with
        /// <c><see cref="T:Android.Views.View+MeasureSpec" /></c>.</param>
        /// <param name="heightMeasureSpec">vertical space requirements as imposed by the parent.
        /// The requirements are encoded with
        /// <c><see cref="T:Android.Views.View+MeasureSpec" /></c>.</param>
        /// <since version="Added in API level 1" />
        /// <altmember cref="P:Android.Views.View.MeasuredWidth" />
        /// <altmember cref="P:Android.Views.View.MeasuredHeight" />
        /// <altmember cref="M:Android.Views.View.SetMeasuredDimension(System.Int32, System.Int32)" />
        /// <altmember cref="M:Android.Views.View.get_SuggestedMinimumHeight" />
        /// <altmember cref="M:Android.Views.View.get_SuggestedMinimumWidth" />
        /// <altmember cref="M:Android.Views.View.MeasureSpec.GetMode(System.Int32)" />
        /// <altmember cref="M:Android.Views.View.MeasureSpec.GetSize(System.Int32)" />
        /// <remarks><para tool="javadoc-to-mdoc" />
        /// <para tool="javadoc-to-mdoc">
        /// Measure the view and its content to determine the measured width and the
        /// measured height. This method is invoked by <c><see cref="M:Android.Views.View.Measure(System.Int32, System.Int32)" /></c> and
        /// should be overriden by subclasses to provide accurate and efficient
        /// measurement of their contents.
        /// </para>
        /// <para tool="javadoc-to-mdoc">
        ///   <i>CONTRACT:</i> When overriding this method, you
        /// <i>must</i> call <c><see cref="M:Android.Views.View.SetMeasuredDimension(System.Int32, System.Int32)" /></c> to store the
        /// measured width and height of this view. Failure to do so will trigger an
        /// <c>IllegalStateException</c>, thrown by
        /// <c><see cref="M:Android.Views.View.Measure(System.Int32, System.Int32)" /></c>. Calling the superclass'
        /// <c><see cref="M:Android.Views.View.OnMeasure(System.Int32, System.Int32)" /></c> is a valid use.
        /// </para>
        /// <para tool="javadoc-to-mdoc">
        /// The base class implementation of measure defaults to the background size,
        /// unless a larger size is allowed by the MeasureSpec. Subclasses should
        /// override <c><see cref="M:Android.Views.View.OnMeasure(System.Int32, System.Int32)" /></c> to provide better measurements of
        /// their content.
        /// </para>
        /// <para tool="javadoc-to-mdoc">
        /// If this method is overridden, it is the subclass's responsibility to make
        /// sure the measured height and width are at least the view's minimum height
        /// and width (<c><see cref="M:Android.Views.View.get_SuggestedMinimumHeight" /></c> and
        /// <c><see cref="M:Android.Views.View.get_SuggestedMinimumWidth" /></c>).
        /// </para>
        /// <para tool="javadoc-to-mdoc">
        ///   <format type="text/html">
        ///     <a href="http://developer.android.com/reference/android/view/View.html#onMeasure(int, int)" target="_blank">[Android Documentation]</a>
        ///   </format>
        /// </para></remarks>
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            int totalHeight       = HeightCell();
            int totalHeightHeader = 40;
            int totalWidth        = MeasureSpec.GetSize(widthMeasureSpec);
            int rowHeight         = totalHeight;

            for (int c = 0, numChildren = ChildCount; c < numChildren; c++)
            {
                var child          = GetChildAt(c);
                int l              = ((c + 0) * totalWidth) / 7;
                int r              = ((c + 1) * totalWidth) / 7;
                int cellSize       = r - l;
                int cellWidthSpec  = MeasureSpec.MakeMeasureSpec(cellSize, MeasureSpecMode.Exactly);
                int cellHeightSpec = IsHeaderRow
                                        ? MeasureSpec.MakeMeasureSpec(totalHeightHeader, MeasureSpecMode.Exactly)
                                        : MeasureSpec.MakeMeasureSpec(rowHeight, MeasureSpecMode.Exactly);
                child.Measure(cellWidthSpec, cellHeightSpec);
                rowHeight = IsHeaderRow ? totalHeightHeader : totalHeight;
            }
            int widthWithPadding  = totalWidth + PaddingLeft + PaddingRight;
            int heightWithPadding = rowHeight + PaddingTop + PaddingBottom;

            SetMeasuredDimension(widthWithPadding, heightWithPadding);

            stopwatch.Stop();
            Logr.D("Row.OnMeasure {0} ms", stopwatch.ElapsedMilliseconds);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Ons the measure.
        /// </summary>
        /// <param name="widthMeasureSpec">Width measure spec.</param>
        /// <param name="heightMeasureSpec">Height measure spec.</param>
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

            int width  = MeasureSpec.GetSize(widthMeasureSpec);
            int height = MeasureSpec.GetSize(heightMeasureSpec);

            //SetMeasuredDimension(width, height);

            if (0 == mRatioWidth || 0 == mRatioHeight)
            {
                SetMeasuredDimension(width, height);
            }
            else
            {
                if (width < (float)height * mRatioWidth / (float)mRatioHeight)
                {
                    SetMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
                }
                else
                {
                    SetMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
                }
            }
        }
Exemplo n.º 10
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
            width  = MeasureSpec.GetSize(widthMeasureSpec);
            height = MeasureSpec.GetSize(heightMeasureSpec);
            //Fit to screen.
            float scale;
            float scaleX = width / bmWidth;
            float scaleY = height / bmHeight;

            scale = Math.Min(scaleX, scaleY);
            matrix.SetScale(scale, scale);
            ImageMatrix = matrix;
            saveScale   = 1f;

            // Center the image
            redundantYSpace  = height - (scale * bmHeight);
            redundantXSpace  = width - (scale * bmWidth);
            redundantYSpace /= 2;
            redundantXSpace /= 2;

            matrix.PostTranslate(redundantXSpace, redundantYSpace);

            origWidth   = width - 2 * redundantXSpace;
            origHeight  = height - 2 * redundantYSpace;
            right       = width * saveScale - width - (2 * redundantXSpace * saveScale);
            bottom      = height * saveScale - height - (2 * redundantYSpace * saveScale);
            ImageMatrix = matrix;
        }
Exemplo n.º 11
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

            var width     = MeasureSpec.GetSize(widthMeasureSpec);
            var widthMode = MeasureSpec.GetMode(widthMeasureSpec);

            if (widthMode != MeasureSpecMode.Exactly)
            {
                throw new NotSupportedException("ViewSwitcher can only be used in EXACTLY mode.");
            }

            var heightMode = MeasureSpec.GetMode(heightMeasureSpec);

            if (heightMode != MeasureSpecMode.Exactly)
            {
                throw new NotSupportedException("ViewSwitcher can only be used in EXACTLY mode.");
            }

            // The children are given the same width and height as the workspace
            var count = ChildCount;

            for (int i = 0; i < count; i++)
            {
                GetChildAt(i).Measure(widthMeasureSpec, heightMeasureSpec);
            }

            if (_firstLayout)
            {
                ScrollTo(_currentScreen * width, 0);
                _firstLayout = false;
            }
        }
Exemplo n.º 12
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            if (Content == null)
            {
                SetMeasuredDimension(0, 0);
                return;
            }

            int pixelWidth  = MeasureSpec.GetSize(widthMeasureSpec);
            int pixelHeight = MeasureSpec.GetSize(heightMeasureSpec);

            var width  = Context.FromPixels(pixelWidth);
            var height = Context.FromPixels(pixelHeight);

            SizeRequest measure = Content.Element.Measure(width, height, MeasureFlags.IncludeMargins);

            // When we implement ItemSizingStrategy.MeasureFirstItem for Android, these next two clauses will need to
            // be updated to use the static width/height

            if (pixelWidth == 0)
            {
                pixelWidth = (int)Context.ToPixels(measure.Request.Width);
            }

            if (pixelHeight == 0)
            {
                pixelHeight = (int)Context.ToPixels(measure.Request.Height);
            }

            SetMeasuredDimension(pixelWidth, pixelHeight);
        }
Exemplo n.º 13
0
        /** Create shadow wrapper with a pinned view for a view at given position */
        void createPinnedShadow(int position)
        {
            // try to recycle shadow
            PinnedSection pinnedShadow = mRecycleSection;

            mRecycleSection = null;
            // create new shadow, if needed
            if (pinnedShadow == null)
            {
                pinnedShadow = new PinnedSection();
            }
            // request new view using recycled view, if such
            View pinnedView = Adapter.GetView(position, pinnedShadow.view, this);
            // read layout parameters
            LayoutParams layoutParams = (LayoutParams)pinnedView.LayoutParameters;

            if (layoutParams == null)               // create default layout params
            {
                layoutParams = new LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
                //layoutParams = (LayoutParams) GenerateDefaultLayoutParams (); //generateDefaultLayoutParams();
                layoutParams = new LayoutParams(GenerateDefaultLayoutParams());
                pinnedView.LayoutParameters = layoutParams;
            }

            MeasureSpecMode heightMode = MeasureSpec.GetMode(layoutParams.Height);
            int             heightSize = MeasureSpec.GetSize(layoutParams.Height);

            if (heightMode == MeasureSpecMode.Unspecified)
            {
                heightMode = MeasureSpecMode.Exactly;
            }
            int maxHeight = Height - ListPaddingTop - ListPaddingBottom;

            if (heightSize > maxHeight)
            {
                heightSize = maxHeight;
            }
            //---------------------------------------------
            // measure & layout
            try{
                int ws = MeasureSpec.MakeMeasureSpec(Width - ListPaddingLeft - ListPaddingRight, MeasureSpecMode.Exactly);
                //int hs = MeasureSpec.MakeMeasureSpec(heightSize, heightMode);
                int myNegInt = System.Math.Abs(heightSize) * (-1);
                int hs       = MeasureSpec.MakeMeasureSpec(heightSize, heightMode);
                pinnedView.Measure(Convert.ToInt32(ws), Convert.ToInt32(hs));
            }
            catch (Exception ex) {
                System.Console.WriteLine(ex.Message.ToString());
            }
            mTranslateY = 0;
            pinnedView.Layout(0, 0, pinnedView.MeasuredWidth, pinnedView.MeasuredHeight);

            // initialize pinned shadow
            pinnedShadow.view     = pinnedView;
            pinnedShadow.position = position;
            pinnedShadow.id       = Adapter.GetItemId(position);

            // store pinned shadow
            mPinnedSection = pinnedShadow;
        }
Exemplo n.º 14
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            MeasureSpecMode widthSpecMode = MeasureSpec.GetMode(widthMeasureSpec);
            int             widthSpecSize = MeasureSpec.GetSize(widthMeasureSpec);

            MeasureSpecMode heightSpecMode = MeasureSpec.GetMode(heightMeasureSpec);
            int             heightSpecSize = MeasureSpec.GetSize(heightMeasureSpec);

            if (widthSpecMode == MeasureSpecMode.Unspecified || heightSpecMode == MeasureSpecMode.Unspecified)
            {
                throw new Java.Lang.RuntimeException(
                          "SlidingDrawer cannot have UNSPECIFIED dimensions");
            }

            View handle = mHandle;

            MeasureChild(handle, widthMeasureSpec, heightMeasureSpec);

            if (mVertical)
            {
                int height = heightSpecSize - handle.MeasuredHeight - mTopOffset;
                mContent.Measure(MeasureSpec.MakeMeasureSpec(widthSpecSize, MeasureSpecMode.Exactly), MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.Exactly));
            }
            else
            {
                int width = widthSpecSize - handle.MeasuredWidth - mTopOffset;
                mContent.Measure(MeasureSpec.MakeMeasureSpec(width, MeasureSpecMode.Exactly), MeasureSpec.MakeMeasureSpec(heightSpecSize, MeasureSpecMode.Exactly));
            }
            SetMeasuredDimension(widthSpecSize, heightSpecSize);
        }
Exemplo n.º 15
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            int width  = MeasureSpec.GetSize(widthMeasureSpec);
            int height = width * Drawable.IntrinsicHeight / Drawable.IntrinsicWidth;

            SetMeasuredDimension(width, height);
        }
Exemplo n.º 16
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            int pixelWidth  = MeasureSpec.GetSize(widthMeasureSpec);
            int pixelHeight = MeasureSpec.GetSize(heightMeasureSpec);

            var width  = Context.FromPixels(pixelWidth);
            var height = Context.FromPixels(pixelHeight);

            SizeRequest measure = Content.Element.Measure(width, height, MeasureFlags.IncludeMargins);

            if (pixelWidth == 0)
            {
                pixelWidth = (int)Context.ToPixels(Content.Element.Width > 0
                                        ? Content.Element.Width
                                        : measure.Request.Width);
            }

            if (pixelHeight == 0)
            {
                pixelHeight = (int)Context.ToPixels(Content.Element.Height > 0
                                        ? Content.Element.Height
                                        : measure.Request.Height);
            }

            SetMeasuredDimension(pixelWidth, pixelHeight);
        }
Exemplo n.º 17
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

            if (_scrollView != null)
            {
                MeasureChild(_scrollView, MeasureSpec.MakeMeasureSpec(
                                 MeasureSpec.GetSize(widthMeasureSpec), MeasureSpecMode.AtMost),
                             MeasureSpec.MakeMeasureSpec(MeasureSpec.GetSize(heightMeasureSpec),
                                                         MeasureSpecMode.AtMost));

                _scrollContentHeight = _scrollView.GetChildAt(0).MeasuredHeight;
                _scrollViewHeight    = _scrollView.MeasuredHeight;
            }
            if (_background != null)
            {
                var minHeight = (int)(_scrollViewHeight + _parallaxOffset
                                      * (_scrollContentHeight - _scrollViewHeight));
                minHeight = Math.Max(minHeight, MeasureSpec.GetSize(heightMeasureSpec));

                MeasureChild(_background, MeasureSpec.MakeMeasureSpec(
                                 MeasureSpec.GetSize(widthMeasureSpec), MeasureSpecMode.Exactly),
                             MeasureSpec.MakeMeasureSpec(minHeight, MeasureSpecMode.Exactly));

                _backgroundRight  = Left + _background.MeasuredWidth;
                _backgroundBottom = Top + _background.MeasuredHeight;

                _scrollDiff = (_background.MeasuredHeight - _scrollViewHeight)
                              / (float)(_scrollContentHeight - _scrollViewHeight);
            }
        }
Exemplo n.º 18
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

            int  k         = MeasureSpec.GetSize(widthMeasureSpec) - HorizontalSpacing - PaddingLeft - PaddingRight;
            int  i         = ColumnWidth + HorizontalSpacing;
            View localView = GetChildAt(0);
            int  j;

            if (localView != null)
            {
                j = localView.MeasuredHeight;
            }
            else
            {
                j = 16;
            }
            int m = ChildCount;

            if (NumColumns > 0)
            {
                k = Math.Max(NumColumns, 1);
            }
            else
            {
                k = Math.Max(k / i, 1);
            }
            m = 1 + m / k;

            int width  = (k * i + HorizontalSpacing);
            int height = (m * (j + VerticalSpacing) + VerticalSpacing);

            SetMeasuredDimension(width, height);
        }
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

            var widthMode  = MeasureSpec.GetMode(widthMeasureSpec);
            var heightMode = MeasureSpec.GetMode(heightMeasureSpec);

            int widthSize  = MeasureSpec.GetSize(widthMeasureSpec);
            int heightSize = MeasureSpec.GetSize(heightMeasureSpec);

            if (widthMode == MeasureSpecMode.Exactly &&
                (heightMode == MeasureSpecMode.AtMost || heightMode == MeasureSpecMode.Unspecified))
            {
                SetMeasuredDimension(widthSize, (int)((double)widthSize / XRatio * YRatio));
            }
            else if (heightMode == MeasureSpecMode.Exactly &&
                     (widthMode == MeasureSpecMode.AtMost || widthMode == MeasureSpecMode.Unspecified))
            {
                SetMeasuredDimension((int)((double)heightSize / YRatio * XRatio), heightSize);
            }
            else
            {
                SetMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
            }
        }
Exemplo n.º 20
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            var dm = Resources.DisplayMetrics;

            // Let various labels measure themselves
            var unspecifiedMeasureSpec = MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified);

            foreach (var row in rows)
            {
                row.YAxisTextView.Measure(unspecifiedMeasureSpec, unspecifiedMeasureSpec);
                row.ValueTextView.Measure(unspecifiedMeasureSpec, unspecifiedMeasureSpec);
            }

            var width = (int)Math.Max(
                TypedValue.ApplyDimension(ComplexUnitType.Dip, 300, dm),
                MeasureSpec.GetSize(widthMeasureSpec)
                );
            var height = (int)Math.Max(
                TypedValue.ApplyDimension(ComplexUnitType.Dip, 250, dm),
                MeasureSpec.GetSize(heightMeasureSpec)
                );

            // Measure overlays
            var overlayWidthSpec  = MeasureSpec.MakeMeasureSpec(width - leftMargin, MeasureSpecMode.Exactly);
            var overlayHeightSpec = MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.Exactly);

            loadingOverlayView.Measure(overlayWidthSpec, overlayHeightSpec);
            emptyOverlayView.Measure(overlayWidthSpec, overlayHeightSpec);

            SetMeasuredDimension(width, height);
        }
Exemplo n.º 21
0
            protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
            {
                Performance.Start(out string reference);

                int width = MeasureSpec.GetSize(widthMeasureSpec);
                int height;

                if (ParentHasUnevenRows)
                {
                    if (_viewHandler.PlatformView == null)
                    {
                        SetMeasuredDimension(0, 0);
                        return;
                    }

                    var size = _viewHandler.MeasureVirtualView(widthMeasureSpec, heightMeasureSpec);
                    height = (int)size.Height;
                }
                else
                {
                    height = (int)Context.ToPixels(ParentRowHeight == -1 ? BaseCellView.DefaultMinHeight : ParentRowHeight);
                    var size = _viewHandler.MeasureVirtualView(widthMeasureSpec, MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.Exactly));
                    width = (int)size.Width;
                }

                SetMeasuredDimension(width, height);

                Performance.Stop(reference);
            }
Exemplo n.º 22
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            if (_hasDrawable && _width == MeasureSpec.GetSize(widthMeasureSpec))
            {
                base.OnMeasure(MeasureSpec.MakeMeasureSpec(_width, MeasureSpecMode.Exactly),
                               MeasureSpec.MakeMeasureSpec((int)_height, MeasureSpecMode.Exactly));
                return;
            }

            _width  = MeasureSpec.GetSize(widthMeasureSpec);
            _height = MeasureSpec.GetSize(widthMeasureSpec);

            var drawable = Background as BitmapDrawable;

            if (drawable?.Bitmap != null && _width > 0)
            {
                _hasDrawable = true;
                var ratio = (double)drawable.Bitmap.Width / _width;
                _height = drawable.Bitmap.Height / ratio;
            }
            else             // Recycler resize fix
            {
                _height = 1;
            }

            base.OnMeasure(MeasureSpec.MakeMeasureSpec(_width, MeasureSpecMode.Exactly),
                           MeasureSpec.MakeMeasureSpec((int)_height, MeasureSpecMode.Exactly));
        }
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
            int width  = MeasureSpec.GetSize(widthMeasureSpec);
            int height = MeasureSpec.GetSize(heightMeasureSpec);

            if (0 == _ratioWidth || 0 == _ratioHeight)
            {
                SetMeasuredDimension(width, height);
            }
            else
            {
                if (width < (float)height * _ratioWidth / _ratioHeight)
                {
                    var w = width;
                    var h = height;
                    SetMeasuredDimension(w, h);
                    ConfigureTransform(w, h, _ratioWidth, _ratioHeight);
                }
                else
                {
                    var w = width;
                    var h = height;
                    SetMeasuredDimension(w, h);
                    ConfigureTransform(w, h, _ratioWidth, _ratioHeight);
                }
            }
        }
Exemplo n.º 24
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
            var widthSpecMode  = MeasureSpec.GetMode(widthMeasureSpec);
            var widthSpecSize  = MeasureSpec.GetSize(widthMeasureSpec);
            var heightSpecMode = MeasureSpec.GetMode(heightMeasureSpec);
            var heightSpecSize = MeasureSpec.GetSize(heightMeasureSpec);
            var width          = (int)Dp2Px(CircleDiameter);
            var height         = (int)Dp2Px(CircleDiameter);

            switch (widthSpecMode)
            {
            case MeasureSpecMode.AtMost when heightSpecMode == MeasureSpecMode.AtMost:
                SetMeasuredDimension(width, height);
                break;

            case MeasureSpecMode.AtMost:
                SetMeasuredDimension(width, heightSpecSize);
                break;

            default:
            {
                if (heightSpecMode == MeasureSpecMode.AtMost)
                {
                    SetMeasuredDimension(widthSpecSize, height);
                }

                break;
            }
            }
        }
Exemplo n.º 25
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            var drawable = Drawable;

            if (drawable == null || drawable.IntrinsicWidth == 0 || drawable.IntrinsicHeight == 0)
            {
                SetMeasuredDimension(0, 0);
                return;
            }
            var drawableWidth  = drawable.IntrinsicWidth;
            var drawableHeight = drawable.IntrinsicHeight;
            var widthSize      = MeasureSpec.GetSize(widthMeasureSpec);
            var widthMode      = (int)MeasureSpec.GetMode(widthMeasureSpec);
            var heightSize     = MeasureSpec.GetSize(heightMeasureSpec);
            var heightMode     = (int)MeasureSpec.GetMode(heightMeasureSpec);

            ViewWidth  = SetViewSize(widthMode, widthSize, drawableWidth);
            ViewHeight = SetViewSize(heightMode, heightSize, drawableHeight);

            //
            // Set view dimensions
            //
            SetMeasuredDimension(ViewWidth, ViewHeight);

            //
            // Fit content within view
            //
            FitImageToView();
        }
Exemplo n.º 26
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

            // The children are given the same width and height as the workspace
            int count = ChildCount;

            for (int i = 0; i < count; i++)
            {
                if (mSeparatorDrawable != null && (i & 1) == 1)
                {
                    // separator
                    GetChildAt(i).Measure(mSeparatorDrawable.IntrinsicWidth, heightMeasureSpec);
                }
                else
                {
                    GetChildAt(i).Measure(widthMeasureSpec, heightMeasureSpec);
                }
            }

            if (mFirstLayout)
            {
                HorizontalScrollBarEnabled = false;
                int width = MeasureSpec.GetSize(widthMeasureSpec);
                if (mSeparatorDrawable != null)
                {
                    width += mSeparatorDrawable.IntrinsicWidth;
                }
                ScrollTo(mCurrentScreen * width, 0);
                HorizontalScrollBarEnabled = true;
                mFirstLayout = false;
            }
        }
Exemplo n.º 27
0
        /**
         * Determines the width of this view
         *
         * @param measureSpec
         *            A measureSpec packed into an int
         * @return The width of the view, honoring constraints from measureSpec
         */
        private int MeasureLong(int measureSpec)
        {
            int result   = 0;
            var specMode = MeasureSpec.GetMode(measureSpec);
            var specSize = MeasureSpec.GetSize(measureSpec);

            if ((specMode == MeasureSpecMode.Exactly) || (mViewPager == null) || (mViewPager.Adapter == null))
            {
                //We were told how big to be
                result = specSize;
            }
            else
            {
                //Calculate the width according the views count
                int count = mViewPager.Adapter.Count;
                result = (int)(PaddingLeft + PaddingRight
                               + (count * 2 * mRadius) + (count - 1) * mRadius + 1);
                //Respect AT_MOST value if that was what is called for by measureSpec
                if (specMode == MeasureSpecMode.AtMost)
                {
                    result = Java.Lang.Math.Min(result, specSize);
                }
            }
            return(result);
        }
Exemplo n.º 28
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            var widthMode      = MeasureSpec.GetMode(widthMeasureSpec);
            var lockedExpanded = widthMode == MeasureSpecMode.Exactly;

            FillViewport = lockedExpanded;

            var childCount = _tabLayout.ChildCount;

            if (childCount > 1 && (widthMode == MeasureSpecMode.Exactly || widthMode == MeasureSpecMode.AtMost))
            {
                if (childCount > 2)
                {
                    _maxTabWidth = (int)(MeasureSpec.GetSize(widthMeasureSpec) * 0.4f);
                }
                else
                {
                    _maxTabWidth = MeasureSpec.GetSize(widthMeasureSpec) / 2;
                }
            }
            else
            {
                _maxTabWidth = -1;
            }

            var oldWidth = MeasuredWidth;

            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
            var newWidth = MeasuredWidth;

            if (lockedExpanded && oldWidth != newWidth)
            {
                CurrentItem = _selectedTabIndex;
            }
        }
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

            mWidth  = MeasureSpec.GetSize(widthMeasureSpec) - PaddingLeft - PaddingRight;
            mHeight = MeasureSpec.GetSize(heightMeasureSpec) - PaddingTop - PaddingBottom;

            if (Drawable != null)
            {
                mDrawableHeight = Drawable.IntrinsicHeight;
                mDrawableWidth  = Drawable.IntrinsicWidth;

                if (mDrawableWidth * mHeight > mDrawableHeight * mWidth)
                {
                    mOrientation = ORIENTATION_HORIZONTAL;
                    float imgScale = (float)mHeight / (float)mDrawableHeight;
                    mMaxOffset = Math.Abs((mDrawableWidth * imgScale - mWidth) * 0.5f);
                }
                else if (mDrawableHeight * mWidth > mDrawableWidth * mHeight)
                {
                    mOrientation = ORIENTATION_VERTICAL;
                    float imgScale = (float)mWidth / (float)mDrawableWidth;
                    mMaxOffset = Math.Abs((mDrawableHeight * imgScale - mHeight) * 0.5f);
                }
            }
        }
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

            // can be called several times, logic only needs to be done once though
            if (this.mViewWidth == MeasureSpec.GetSize(widthMeasureSpec) && this.mViewHeight == MeasureSpec.GetSize(heightMeasureSpec))
            {
                return;
            }

            this.mViewWidth  = MeasureSpec.GetSize(widthMeasureSpec);
            this.mViewHeight = MeasureSpec.GetSize(heightMeasureSpec);

            var drawable = this.Drawable; // if no drawable

            if (drawable == null || drawable.IntrinsicWidth == 0 || drawable.IntrinsicHeight == 0)
            {
                return;
            }

            this.mImageHeight = drawable.IntrinsicHeight;
            this.mImageWidth  = drawable.IntrinsicWidth;

            this.InitialiseImage();
        }