static int CalculateCenterItemIndex(int firstVisibleItemIndex, RecyclerView recyclerView, LinearLayoutManager linearLayoutManager)
        {
            // This can happen if a layout pass has not happened yet
            if (firstVisibleItemIndex == -1)
            {
                return(firstVisibleItemIndex);
            }

            AView centerView;

            if (linearLayoutManager.Orientation == LinearLayoutManager.Horizontal)
            {
                float centerX = recyclerView.Width / 2;
                centerView = recyclerView.FindChildViewUnder(centerX, recyclerView.Top);
            }
            else
            {
                float centerY = recyclerView.Height / 2;
                centerView = recyclerView.FindChildViewUnder(recyclerView.Left, centerY);
            }

            if (centerView != null)
            {
                return(recyclerView.GetChildAdapterPosition(centerView));
            }

            return(firstVisibleItemIndex);
        }
Example #2
0
        public static AView GetCenteredView(this RecyclerView recyclerView)
        {
            if (!(recyclerView.GetLayoutManager() is LinearLayoutManager linearLayoutManager))
            {
                return(null);
            }

            AView centeredView;

            if (linearLayoutManager.Orientation == LinearLayoutManager.Horizontal)
            {
                float centerX = linearLayoutManager.Width / 2;
                float centerY = linearLayoutManager.Height / 2;

                centeredView = recyclerView.FindChildViewUnder(centerX, centerY);
            }
            else
            {
                float centerY = linearLayoutManager.Height / 2;
                float centerX = linearLayoutManager.Width / 2;

                centeredView = recyclerView.FindChildViewUnder(centerX, centerY);
            }
            return(centeredView);
        }
Example #3
0
            public override bool OnSingleTapUp(MotionEvent e)
            {
                View childView = mRecyclerView.FindChildViewUnder(e.GetX(), e.GetY());

                if (childView != null && mListener != null)
                {
                    mListener.OnItemClick(childView, mRecyclerView.GetChildAdapterPosition(childView));
                }

                return(true);
            }
Example #4
0
        /// <summary>
        /// 单击事件
        /// </summary>
        /// <returns><c>true</c>, if single tap up was oned, <c>false</c> otherwise.</returns>
        /// <param name="e">E.</param>
        public override bool OnSingleTapUp(MotionEvent e)
        {
            View child = m_RecyclerView.FindChildViewUnder(e.GetX(), e.GetY());

            if (child != null)
            {
                RecyclerView.ViewHolder vh = m_RecyclerView.GetChildViewHolder(child);
                int position = vh.LayoutPosition;
                if (m_IRecyclerViewClickListerner != null)
                {
                    m_IRecyclerViewClickListerner.OnItemClick(child, position);
                }
            }
            return(true);
        }
        protected internal override bool ClickAction(RecyclerView view, MotionEvent e)
        {
            // Get interacted view from x,y coordinate.
            Android.Views.View childView = view.FindChildViewUnder(e.GetX(), e.GetY());
            if (childView != null)
            {
                // Find the view holder
                AbstractViewHolder holder = (AbstractViewHolder)mRecyclerView.GetChildViewHolder(childView);
                int column = holder.AdapterPosition;
                // Control to ignore selection color
                if (!mTableView.IsIgnoreSelectionColors())
                {
                    mSelectionHandler.SetSelectedColumnPosition(holder, column);
                }

                if (GetTableViewListener() != null)
                {
                    // Call ITableView listener for item click
                    GetTableViewListener().OnColumnHeaderClicked(holder, column);
                }

                return(true);
            }

            return(false);
        }
Example #6
0
        public bool OnInterceptTouchEvent(RecyclerView view, MotionEvent e)
        {
            var childView = view.FindChildViewUnder(e.GetX(), e.GetY());

            if (childView != null && gestureDetector.OnTouchEvent(e))
            {
                var intent = new Intent(mainActivity, typeof(ExhibitDetailsActivity));

                Exhibit exhibit = null;
                for (var i = 0; i < exhibitSet.ActiveSet.Count; ++i)
                {
                    exhibit = exhibitSet.ActiveSet [i];
                    if (exhibit.Id == childView.ContentDescription)
                    {
                        break;
                    }
                }

                if (exhibit != null)
                {
                    var pageList = exhibit.Pages;
                    if (pageList == null || !pageList.Any())
                    {
                        Toast.MakeText(mainActivity,
                                       mainActivity.GetString(Resource.String.currently_no_further_info),
                                       ToastLength.Short)
                        .Show();
                        return(false);
                    }
                    intent.PutExtra(ExhibitDetailsActivity.INTENT_EXTRA_EXHIBIT_ID, exhibit.Id);
                    ActivityCompat.StartActivity(mainActivity, intent, null);
                }
            }
            return(false);
        }
        public override void OnLongPress(MotionEvent e)
        {
            var child = _recyclerView.FindChildViewUnder(e.GetX(), e.GetY());

            if (child != null && _clickListener != null)
            {
                _clickListener.OnLongClick(child, _recyclerView.GetChildAdapterPosition(child));
            }
        }
 public bool OnInterceptTouchEvent(RecyclerView rv, MotionEvent e)
 {
     View child = rv.FindChildViewUnder(e.GetX(), e.GetY());
     if (child != null && clickListener != null && gestureDetector.OnTouchEvent(e))
     {
         clickListener.OnClick(child, rv.GetChildPosition(child));
     }
     return false;
 }
        public bool OnInterceptTouchEvent(RecyclerView rv, MotionEvent e)
        {
            View childView = rv.FindChildViewUnder(e.GetX(), e.GetY());
            if (childView != null && this.gestureDetector.OnTouchEvent(e)) 
            {
                this.OnClick(rv, childView, rv.GetChildAdapterPosition(childView));
            }

            return false;
        }
        public bool OnInterceptTouchEvent(RecyclerView rv, MotionEvent e)
        {
            View childView = rv.FindChildViewUnder(e.GetX(), e.GetY());

            if (childView != null && this.gestureDetector.OnTouchEvent(e))
            {
                this.OnClick(rv, childView, rv.GetChildAdapterPosition(childView));
            }

            return(false);
        }
Example #11
0
        public bool OnInterceptTouchEvent(RecyclerView view, MotionEvent e)
        {
            var childView = view.FindChildViewUnder(e.GetX(), e.GetY());

            if (childView == null || !_getstureDetector.OnTouchEvent(e))
            {
                return(false);
            }
            var handler = ItemClickEvent;

            handler?.Invoke(this, new ItemClickEvent(childView, view.GetChildPosition(childView)));
            return(false);
        }
Example #12
0
        public bool OnInterceptTouchEvent(RecyclerView rv, MotionEvent e)
        {
            var child = rv.FindChildViewUnder(e.GetX(), e.GetY());

            if (child != null && _clicklistener != null && _gestureDetector.OnTouchEvent(e))
            {
                _clicklistener.OnClick(child, rv.GetChildAdapterPosition(child));

                // https://medium.com/@anupdey99/multiple-click-problem-need-to-return-true-4a21b72f0953
                return(true);
            }

            return(false);
        }
        public bool OnInterceptTouchEvent(RecyclerView recyclerView, MotionEvent @event)
        {
            var child = recyclerView.FindChildViewUnder(@event.GetX(), @event.GetY());

            if (child != null && gestureDetector.OnTouchEvent(@event))
            {
                var fab      = FindViewById <FloatingActionButton>(Resource.Id.fab_add);
                var snackbar = Snackbar.Make(fab, Resource.String.Item_Clicked, Snackbar.LengthLong);
                snackbar.SetAction("Do Something", this);
                snackbar.Show();

                return(true);
            }
            return(false);
        }
 public RecyclerTouchListener(Context context, RecyclerView recyclerView, IOnClickListener clickListener)
 {
     this.clickListener = clickListener;
     var gestureListener = new GenericOnGestureListener();
     gestureListener.ActionOnLongPress = (e) =>
     {
         View child = recyclerView.FindChildViewUnder(e.GetX(), e.GetY());
         if (child != null && clickListener != null)
         {
             clickListener.OnLongClick(child, recyclerView.GetChildPosition(child));
         }
     };
     gestureListener.FuncOnSingleTapUp = (e) => true;
     gestureDetector = new GestureDetector(context, gestureListener);
 }
Example #15
0
        internal void ResolveItem(float x, float y)
        {
            _touchedView = _recyclerView.FindChildViewUnder(x, y);
            if (_touchedView == null)
            {
                //no child under
                _frontView = null;
                return;
            }

            // check if the view is being animated. in that case do not allow to move it
            if (RunningAnimationsOn.Contains(_touchedView))
            {
                _frontView = null;
                return;
            }

            InitViewForItem((SwipeViewHolder <M>)_recyclerView.GetChildViewHolder(_touchedView));
        }