예제 #1
0
        // Search for the best size
        private int binarySearch(int start, int end, ISizeTester sizeTester, RectF availableSpace)
        {
            int lastBest = start, lo = start, hi = end - 1, mid;

            while (lo <= hi)
            {
                mid = lo + hi >> 1;
                int midValCmp = sizeTester.OnTestSize(mid, availableSpace);
                if (midValCmp < 0)
                {
                    lastBest = lo;
                    lo       = mid + 1;
                }
                else if (midValCmp > 0)
                {
                    hi       = mid - 1;
                    lastBest = hi;
                }
                else
                {
                    calculatedSize = mid;
                    return(mid);
                }
            }

            // make sure to return last best
            // this is what should always be returned
            calculatedSize = lastBest;

            // update the list of resized controls
            if (fieldValueType != FieldValueType.NotSet)
            {
                if (resizedControls.Where(p => p.Key.fieldValueType == fieldValueType).Count() == 0)
                {
                    resizedControls.TryAdd(this, lastBest);
                }
                else if (resizedControls.Where(p => p.Key == this).Count() == 1)
                {
                    resizedControls[this] = lastBest;
                }
            }

            return(lastBest);
        }
예제 #2
0
        // Initialize helper after the target control is set/updated
        private void InitHelper()
        {
            // Set the default Typeface: NotoSans
            targetControl.Typeface = Typeface.Create("NotoSans", TypefaceStyle.Normal);

            // Using the minimal recommended font size
            minTextSize = TypedValue.ApplyDimension(ComplexUnitType.Sp, 7, targetControl.Resources.DisplayMetrics);
            maxTextSize = TypedValue.ApplyDimension(ComplexUnitType.Sp, 99, targetControl.Resources.DisplayMetrics);

            paint      = new TextPaint(targetControl.Paint);
            sizeTester = this;

            if (maxLines == 0)
            {
                // No value was assigned during construction
                maxLines = NO_LINE_LIMIT;
            }

            initialized = true;
        }