Esempio n. 1
0
        private void PrepareFold(FoldingLayoutOrientation orientation, float anchorFactor, int numberOfFolds)
        {
            _src = new float[NumOfPolyPoints];
            _dst = new float[NumOfPolyPoints];

            _dstRect = new Rect();

            _foldFactor         = 0;
            _previousFoldFactor = 0;

            _isFoldPrepared = false;

            _solidShadow    = new Paint();
            _gradientShadow = new Paint();

            Orientation   = orientation;
            _isHorizontal = Orientation == FoldingLayoutOrientation.Horizontal;

            if (_isHorizontal)
            {
                _shadowLinearGradient = new LinearGradient(0, 0, ShadingFactor, 0, Color.Black, Color.Transparent,
                                                           Shader.TileMode.Clamp);
            }
            else
            {
                _shadowLinearGradient = new LinearGradient(0, 0, 0, ShadingFactor, Color.Black, Color.Transparent,
                                                           Shader.TileMode.Clamp);
            }

            _gradientShadow.SetStyle(Paint.Style.Fill);
            _gradientShadow.SetShader(_shadowLinearGradient);
            _shadowGradientMatrix = new Matrix();

            _anchorFactor  = anchorFactor;
            _numberOfFolds = numberOfFolds;

            _originalWidth  = MeasuredWidth;
            _originalHeight = MeasuredHeight;

            _foldRectArray = new Rect[_numberOfFolds];
            _matrix        = new Matrix[_numberOfFolds];

            for (var x = 0; x < _numberOfFolds; x++)
            {
                _matrix[x] = new Matrix();
            }

            var h = _originalHeight;
            var w = _originalWidth;

            if (Build.VERSION.SdkInt == BuildVersionCodes.JellyBeanMr2 && h != 0 && w != 0)
            {
                _fullBitmap = Bitmap.CreateBitmap(w, h, Bitmap.Config.Argb8888);
                var canvas = new Canvas(_fullBitmap);
                GetChildAt(0).Draw(canvas);
            }

            var delta = (int)Math.Round(_isHorizontal
                ? ((float)w) / _numberOfFolds
                : ((float)h) / _numberOfFolds);

            for (var i = 0; i < _numberOfFolds; i++)
            {
                if (_isHorizontal)
                {
                    var deltap = (i + 1) * delta > w ? w - i * delta : delta;
                    _foldRectArray[i] = new Rect(i * delta, 0, i * delta + deltap, h);
                }
                else
                {
                    var deltap = (i + 1) * delta > h ? h - i * delta : delta;
                    _foldRectArray[i] = new Rect(0, i * delta, w, i * delta + deltap);
                }
            }

            if (_isHorizontal)
            {
                _foldMaxHeight = h;
                _foldMaxWidth  = delta;
            }
            else
            {
                _foldMaxHeight = delta;
                _foldMaxWidth  = w;
            }

            _isFoldPrepared = true;
        }
        private void PrepareFold(FoldingLayoutOrientation orientation, float anchorFactor, int numberOfFolds)
        {
            _src = new float[NumOfPolyPoints];
            _dst = new float[NumOfPolyPoints];

            _dstRect = new Rect();

            _foldFactor = 0;
            _previousFoldFactor = 0;

            _isFoldPrepared = false;

            _solidShadow = new Paint();
            _gradientShadow = new Paint();

            Orientation = orientation;
            _isHorizontal = Orientation == FoldingLayoutOrientation.Horizontal;

            if (_isHorizontal)
                _shadowLinearGradient = new LinearGradient(0, 0, ShadingFactor, 0, Color.Black, Color.Transparent,
                    Shader.TileMode.Clamp);
            else
                _shadowLinearGradient = new LinearGradient(0, 0, 0, ShadingFactor, Color.Black, Color.Transparent,
                    Shader.TileMode.Clamp);

            _gradientShadow.SetStyle(Paint.Style.Fill);
            _gradientShadow.SetShader(_shadowLinearGradient);
            _shadowGradientMatrix = new Matrix();

            _anchorFactor = anchorFactor;
            _numberOfFolds = numberOfFolds;

            _originalWidth = MeasuredWidth;
            _originalHeight = MeasuredHeight;

            _foldRectArray = new Rect[_numberOfFolds];
            _matrix = new Matrix[_numberOfFolds];

            for (var x = 0; x < _numberOfFolds; x++)
                _matrix[x] = new Matrix();

            var h = _originalHeight;
            var w = _originalWidth;

            if (Build.VERSION.SdkInt == BuildVersionCodes.JellyBeanMr2 && h != 0 && w != 0)
            {
                _fullBitmap = Bitmap.CreateBitmap(w, h, Bitmap.Config.Argb8888);
                var canvas = new Canvas(_fullBitmap);
                GetChildAt(0).Draw(canvas);
            }

            var delta = (int) Math.Round(_isHorizontal
                ? ((float) w) / _numberOfFolds
                : ((float) h) / _numberOfFolds);

            for (var i = 0; i < _numberOfFolds; i++)
            {
                if (_isHorizontal)
                {
                    var deltap = (i + 1) * delta > w ? w - i * delta : delta;
                    _foldRectArray[i] = new Rect(i * delta, 0, i * delta + deltap, h);
                }
                else
                {
                    var deltap = (i + 1) * delta > h ? h - i * delta : delta;
                    _foldRectArray[i] = new Rect(0, i * delta, w, i * delta + deltap);
                }
            }

            if (_isHorizontal)
            {
                _foldMaxHeight = h;
                _foldMaxWidth = delta;
            }
            else
            {
                _foldMaxHeight = delta;
                _foldMaxWidth = w;
            }

            _isFoldPrepared = true;
        }