Example #1
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            Logr.D("Grid.OnMeasure w={0} h={1}", MeasureSpec.ToString(widthMeasureSpec),
                   MeasureSpec.ToString(heightMeasureSpec));

            int widthMeasureSize  = MeasureSpec.GetSize(widthMeasureSpec);
            int heightMeasureSize = MeasureSpec.GetSize(heightMeasureSpec);

            if (_oldWidthMeasureSize == widthMeasureSize && _oldHeightMeasureSize == heightMeasureSize)
            {
                Logr.D("SKIP Grid.OnMeasure");
                SetMeasuredDimension(MeasuredWidth, MeasuredHeight);
                return;
            }

            var stopwatch = Stopwatch.StartNew();

            _oldWidthMeasureSize  = widthMeasureSize;
            _oldHeightMeasureSize = heightMeasureSize;
            int visibleChildCount = 0;

            for (int c = 0; c < ChildCount; c++)
            {
                var child = GetChildAt(c);
                if (child.Visibility == ViewStates.Visible)
                {
                    visibleChildCount++;
                }
            }
            int cellSize = Math.Min((widthMeasureSize - sidePadding * 2) / 7, heightMeasureSize / visibleChildCount);

            //int cellSize =  widthMeasureSize / 7;
            //Remove any extra pixels since /7 us unlikey to give whole nums.
            widthMeasureSize = cellSize * 7 + sidePadding * 2;
            int totalHeight   = 0;
            int rowWidthSpec  = MeasureSpec.MakeMeasureSpec(widthMeasureSize - 2 * sidePadding, MeasureSpecMode.Exactly);
            int rowHeightSpec = MeasureSpec.MakeMeasureSpec(cellSize, MeasureSpecMode.Exactly);

            for (int c = 0; c < ChildCount; c++)
            {
                var child = GetChildAt(c);
                if (child.Visibility == ViewStates.Visible)
                {
                    MeasureChild(child, rowWidthSpec,
                                 c == 0 ? MeasureSpec.MakeMeasureSpec(cellSize, MeasureSpecMode.AtMost) : rowHeightSpec);
                    totalHeight += child.MeasuredHeight;
                }
            }
            int measuredWidth  = widthMeasureSize; // Fudge factor to make the borders show up right.
            int measuredHeight = heightMeasureSize + 2;

            SetMeasuredDimension(measuredWidth, totalHeight);

            stopwatch.Stop();
            Logr.D("Grid.OnMeasure {0} ms", stopwatch.ElapsedMilliseconds);
        }
Example #2
0
 protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
 {
     if (Months.Count == 0)
     {
         throw new InvalidOperationException(
                   "Must have at least one month to display. Did you forget to call Init()?");
     }
     Logr.D("PickerView.OnMeasure w={0} h={1}", MeasureSpec.ToString(widthMeasureSpec),
            MeasureSpec.ToString(heightMeasureSpec));
     base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
 }
Example #3
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            Logr.D("Grid.OnMeasure w={0} h={1}", MeasureSpec.ToString(widthMeasureSpec),
                   MeasureSpec.ToString(heightMeasureSpec));

            int widthMeasureSize = MeasureSpec.GetSize(widthMeasureSpec);

            if (_oldWidthMeasureSize == widthMeasureSize)
            {
                Logr.D("SKIP Grid.OnMeasure");
                SetMeasuredDimension(MeasuredWidth, MeasuredHeight);
                return;
            }

            var stopwatch = Stopwatch.StartNew();

            _oldWidthMeasureSize = widthMeasureSize;
            int cellSize = widthMeasureSize / 7;

            //Remove any extra pixels since /7 us unlikey to give whole nums.
            widthMeasureSize = cellSize * 7;
            int heightSize    = (int)Math.Round(40 * (Context.Resources.DisplayMetrics.Ydpi / (int)DisplayMetricsDensity.Default));
            int totalHeight   = 0;
            int rowWidthSpec  = MeasureSpec.MakeMeasureSpec(widthMeasureSize, MeasureSpecMode.Exactly);
            int rowHeightSpec = MeasureSpec.MakeMeasureSpec(heightSize, MeasureSpecMode.Exactly);

            for (int c = 0; c < ChildCount; c++)
            {
                var child = GetChildAt(c);
                if (child.Visibility == ViewStates.Visible)
                {
                    MeasureChild(child, rowWidthSpec,
                                 c == 0 ? MeasureSpec.MakeMeasureSpec(heightSize, MeasureSpecMode.AtMost) : rowHeightSpec);
                    totalHeight += child.MeasuredHeight;
                }
            }
            int measuredWidth = widthMeasureSize + 2; // Fudge factor to make the borders show up right.

            SetMeasuredDimension(measuredWidth, totalHeight);

            stopwatch.Stop();
            Logr.D("Grid.OnMeasure {0} ms", stopwatch.ElapsedMilliseconds);
        }
Example #4
0
 /// <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)
 {
     Logr.D("Month.OnMeasure w={0} h={1}", MeasureSpec.ToString(widthMeasureSpec),
            MeasureSpec.ToString(heightMeasureSpec));
     base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
 }