public void ForceChildLayout(View child, LayoutParams layoutParams)
        {
            int childHeightSpec = ViewGroup.GetChildMeasureSpec(_heightMeasureSpec, PaddingTop + PaddingBottom, layoutParams.Height);
            int childWidthSpec  = ViewGroup.GetChildMeasureSpec(_widthMeasureSpec, PaddingLeft + PaddingRight, layoutParams.Width);

            child.Measure(childWidthSpec, childHeightSpec);
        }
Example #2
0
            void MeasureView(View view)
            {
                int widthMeasureSpec = ViewGroup.GetChildMeasureSpec(
                    View.MeasureSpec.MakeMeasureSpec(mRenderPageWidth,
                                                     MeasureSpecMode.Exactly), 0, view.LayoutParameters.Width);

                int heightMeasureSpec = ViewGroup.GetChildMeasureSpec(
                    View.MeasureSpec.MakeMeasureSpec(mRenderPageHeight,
                                                     MeasureSpecMode.Exactly), 0, view.LayoutParameters.Height);

                view.Measure(widthMeasureSpec, heightMeasureSpec);
            }
Example #3
0
        public override void Layout()
        {
            var parentWidthMeasureSpec  = AndroidView.MeasureSpec.MakeMeasureSpec((int)Math.Round(Bounds.Width), MeasureSpecMode.AtMost);
            var parentHeightMeasureSpec = AndroidView.MeasureSpec.MakeMeasureSpec((int)Math.Round(Bounds.Height), MeasureSpecMode.AtMost);
            int childWidthMeasureSpec   = ViewGroup.GetChildMeasureSpec(parentWidthMeasureSpec,
                                                                        0, (int)Math.Round(LayoutWidth));
            int childHeightMeasureSpec = ViewGroup.GetChildMeasureSpec(parentHeightMeasureSpec,
                                                                       0, (int)Math.Round(LayoutHeight));

            _view.PlatformView.Measure(childWidthMeasureSpec, childHeightMeasureSpec);
            _view.PlatformView.Layout((int)Math.Round(LayoutLeft),
                                      (int)Math.Round(LayoutTop),
                                      (int)Math.Round(LayoutRight),
                                      (int)Math.Round(LayoutBottom));
        }
Example #4
0
        private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
                                       int heightSpec, int[] measuredDimension)
        {
            View view = recycler.GetViewForPosition(position);

            if (view != null)
            {
                RecyclerView.LayoutParams p = (RecyclerView.LayoutParams)view.LayoutParameters;
                int childWidthSpec          = ViewGroup.GetChildMeasureSpec(widthSpec,
                                                                            PaddingLeft + PaddingRight, p.Width);
                int childHeightSpec = ViewGroup.GetChildMeasureSpec(heightSpec,
                                                                    PaddingTop + PaddingBottom, p.Height);
                view.Measure(childWidthSpec, childHeightSpec);
                measuredDimension[0] = view.MeasuredWidth + p.LeftMargin + p.RightMargin;
                measuredDimension[1] = view.MeasuredHeight + p.BottomMargin + p.TopMargin;
                recycler.RecycleView(view);
            }
        }
        private void FixLayoutSize(ViewGroup parent, View view)
        {
            if (view != null)
            {
                //specs for parent (recycler view)
                var widthSpec  = View.MeasureSpec.MakeMeasureSpec(parent.Width, MeasureSpecMode.Exactly);
                var heightSpec = View.MeasureSpec.MakeMeasureSpec(parent.Height, MeasureSpecMode.Unspecified);

                //specs for children (headers)
                var childWidthSpec  = ViewGroup.GetChildMeasureSpec(widthSpec, parent.PaddingLeft + parent.PaddingRight, view.LayoutParameters?.Width ?? 0);
                var childHeightSpec = ViewGroup.GetChildMeasureSpec(heightSpec, parent.PaddingTop + parent.PaddingBottom, view.LayoutParameters?.Height ?? 0);

                view.Measure(childWidthSpec, childHeightSpec);

                _stickyHeaderHeight = view.MeasuredHeight;
                view.Layout(0, 0, view.MeasuredWidth, _stickyHeaderHeight);
            }
        }
Example #6
0
        private void MeasureView(View child)
        {
            ViewGroup.LayoutParams p = child.LayoutParameters;
            if (p == null)
            {
                p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent);
            }

            int childWidthSpec = ViewGroup.GetChildMeasureSpec(0, 0 + 0, p.Width);
            int lpHeight       = p.Height;
            int childHeightSpec;

            if (lpHeight > 0)
            {
                childHeightSpec = MeasureSpec.MakeMeasureSpec(lpHeight, MeasureSpecMode.Exactly);
            }
            else
            {
                childHeightSpec = MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified);
            }
            child.Measure(childWidthSpec, childHeightSpec);
        }
Example #7
0
        public override void OnDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)
        {
            base.OnDrawOver(c, parent, state);

            if (adapter.IsSliding)
            {
                parent.SetPadding(0, 0, 0, 0);
                return;
            }

            if (MusicPlayer.CurrentID() < 0) //If there is no current item, do not draw the header
            {
                return;
            }

            if (parent.ChildCount > 1 && parent.Width > 0)
            {
                int firstPos   = parent.GetChildAdapterPosition(parent.GetChildAt(0));
                int lastPos    = parent.GetChildAdapterPosition(parent.GetChildAt(parent.ChildCount - 1));
                int currentPos = MusicPlayer.CurrentID() + 1;


                if (lastPos < firstPos) //It happen when the user just removed a song from the queue
                {
                    //We do this to continue the drawing of the current header when a song is being removed from the queue. It prevent a quick flash of the header.
                    switch (lastFrameTop)
                    {
                    case true:
                        System.Console.WriteLine("&DRAWING TOP - currentPos: " + currentPos + " firstPos: " + firstPos + " lastPos: " + lastPos);
                        firstPos = currentPos;
                        break;

                    case false:
                        System.Console.WriteLine("&DRAWING BOTTOM - currentPos: " + currentPos + " firstPos: " + firstPos + " lastPos: " + lastPos);
                        lastPos = currentPos;
                        break;

                    default:
                        return;
                    }
                }

                if (currentPos <= firstPos)
                {
                    View header       = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.QueueCurrent, parent, false);
                    int  parentWidth  = View.MeasureSpec.MakeMeasureSpec(parent.Width, MeasureSpecMode.Exactly);
                    int  parentHeight = View.MeasureSpec.MakeMeasureSpec(parent.Height, MeasureSpecMode.Unspecified);
                    int  headerWidth  = ViewGroup.GetChildMeasureSpec(parentWidth, 0, header.LayoutParameters.Width);
                    int  headerHeight = ViewGroup.GetChildMeasureSpec(parentHeight, 0, header.LayoutParameters.Height);

                    header.Measure(headerWidth, headerHeight);
                    header.Layout(0, 0, header.MeasuredWidth, header.MeasuredHeight);

                    header.FindViewById(Resource.Id.topDivider).Visibility = ViewStates.Gone;
                    BindHolder(new SongHolder(header, null, null));
                    Queue.instance.HeaderHeight = header.MeasuredHeight;

                    c.Save();
                    c.Translate(0, 0);
                    header.Draw(c);
                    c.Restore();
                    parent.SetPadding(0, header.MeasuredHeight, 0, 0);
                    lastFrameTop = true;
                }
                else if (currentPos >= lastPos)
                {
                    View header       = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.QueueCurrent, parent, false);
                    int  parentWidth  = View.MeasureSpec.MakeMeasureSpec(parent.Width, MeasureSpecMode.Exactly);
                    int  parentHeight = View.MeasureSpec.MakeMeasureSpec(parent.Height, MeasureSpecMode.Unspecified);
                    int  headerWidth  = ViewGroup.GetChildMeasureSpec(parentWidth, 0, header.LayoutParameters.Width);
                    int  headerHeight = ViewGroup.GetChildMeasureSpec(parentHeight, 0, header.LayoutParameters.Height);

                    header.Measure(headerWidth, headerHeight);
                    header.Layout(0, 0, header.MeasuredWidth, header.MeasuredHeight);

                    header.FindViewById(Resource.Id.bottomDivider).Visibility = ViewStates.Gone;
                    BindHolder(new SongHolder(header, null, null));
                    Queue.instance.HeaderHeight = -header.MeasuredHeight;

                    c.Save();
                    c.Translate(0, parentHeight - header.MeasuredHeight);
                    header.Draw(c);
                    c.Restore();
                    parent.SetPadding(0, 0, 0, header.MeasuredHeight);
                    lastFrameTop = false;
                }
                else
                {
                    Queue.instance.HeaderHeight = 0;
                    parent.SetPadding(0, 0, 0, 0);
                    lastFrameTop = null;
                }
            }

            void BindHolder(SongHolder holder)
            {
                Song current = MusicPlayer.queue[MusicPlayer.CurrentID()];

                holder.more.SetColorFilter(Color.White);
                holder.youtubeIcon.SetColorFilter(Color.White);
                holder.status.SetTextColor(MusicPlayer.isRunning ? Color.Argb(255, 244, 81, 30) : Color.Argb(255, 66, 165, 245));
                string          status     = MusicPlayer.isRunning ? Queue.instance.GetString(Resource.String.playing) : Queue.instance.GetString(Resource.String.paused);
                SpannableString statusText = new SpannableString(status);

                statusText.SetSpan(new BackgroundColorSpan(Color.ParseColor("#8C000000")), 0, status.Length, SpanTypes.InclusiveInclusive);
                holder.status.TextFormatted = statusText;

                SpannableString titleText = new SpannableString(current.Title);

                titleText.SetSpan(new BackgroundColorSpan(Color.ParseColor("#8C000000")), 0, current.Title.Length, SpanTypes.InclusiveInclusive);
                holder.Title.TextFormatted = titleText;

                if (current.AlbumArt == -1 || current.IsYt)
                {
                    var songAlbumArtUri = Android.Net.Uri.Parse(current.Album);
                    Picasso.With(Application.Context).Load(songAlbumArtUri).Placeholder(Resource.Color.background_material_dark).Transform(new RemoveBlackBorder(true)).Into(holder.AlbumArt);
                }
                else
                {
                    var songCover       = Android.Net.Uri.Parse("content://media/external/audio/albumart");
                    var songAlbumArtUri = ContentUris.WithAppendedId(songCover, current.AlbumArt);

                    Picasso.With(Application.Context).Load(songAlbumArtUri).Placeholder(Resource.Color.background_material_dark).Resize(400, 400).CenterCrop().Into(holder.AlbumArt);
                }

                if (current.IsLiveStream)
                {
                    holder.Live.Visibility = ViewStates.Visible;
                }
                else
                {
                    holder.Live.Visibility = ViewStates.Gone;
                }

                if (current.IsParsed != true && current.IsYt)
                {
                    holder.youtubeIcon.SetImageResource(Resource.Drawable.needProcessing);
                    holder.youtubeIcon.Visibility = ViewStates.Visible;
                }
                else if (current.IsParsed == true && current.IsYt)
                {
                    holder.youtubeIcon.SetImageResource(Resource.Drawable.PublicIcon);
                    holder.youtubeIcon.Visibility = ViewStates.Visible;
                }
                else
                {
                    holder.youtubeIcon.Visibility  = ViewStates.Gone;
                    holder.RightButtons.Background = null;
                    holder.more.SetBackgroundResource(Resource.Drawable.darkLinear);
                }
            }
        }