using System;
using Android.Widget;
|
using Com.Scwang.Smartrefresh.Layout;
|
using Com.Scwang.Smartrefresh.Layout.Header;
|
using Com.Scwang.Smartrefresh.Layout.Listener;
|
using Com.Scwang.Smartrefresh.Layout.Api;
|
using Com.Scwang.Smartrefresh.Layout.Constant;
|
|
namespace Shared
{
|
|
//VerticalRefreshLayout 带下拉刷新
|
/// <summary>
/// 位置布局
/// </summary>
public class VerticalRefreshLayout : ViewGroup
{
public Action BeginHeaderRefreshingAction;
|
|
private ScrollView mAndroidRefreshScrolView;
|
private SmartRefreshLayout mSmartRefreshLayout;
|
|
|
/// <summary>
/// 构造函数
/// </summary>
public VerticalRefreshLayout()
{
|
|
|
mSmartRefreshLayout = new SmartRefreshLayout(Application.Activity);
|
ClassicsHeader mClassicsHeader = new ClassicsHeader(Application.Activity);
|
//隐藏最后刷新时间文字
|
mClassicsHeader.SetEnableLastTime(false);
|
|
mSmartRefreshLayout.SetRefreshHeader(mClassicsHeader);
|
|
mOnRefreshListener = new OnRefreshListener(this);
|
mSmartRefreshLayout.SetOnRefreshListener(mOnRefreshListener);
|
viewGroup = mSmartRefreshLayout;
|
|
|
mAndroidRefreshScrolView = new ScrollView(Application.Activity, null);
|
|
viewGroup.AddView(mAndroidRefreshScrolView);
|
|
realViewGroup = new AndroidLinearLayout(Application.Activity, this);
|
(realViewGroup as AndroidLinearLayout).Orientation = Orientation.Vertical;
|
mAndroidRefreshScrolView.AddView(realViewGroup);
|
|
_isCanHeaderRefresh = true;
|
|
}
|
|
|
OnRefreshListener mOnRefreshListener;
|
|
public class OnRefreshListener : Java.Lang.Object, IOnRefreshListener
|
{
|
|
VerticalRefreshLayout _VerticalRefreshLayout;
|
|
public OnRefreshListener(VerticalRefreshLayout view)
|
{
|
_VerticalRefreshLayout = view;
|
}
|
|
public void OnRefresh(IRefreshLayout p0)
|
{
|
_VerticalRefreshLayout.BeginHeaderRefreshingAction?.Invoke();
|
}
|
}
|
|
|
/// <summary>
/// 视图宽度
/// </summary>
/// <value>The width.</value>
public override int Width
{
get
{
return base.Width;
}
set
{
base.Width = value;
if (!IsCanRefresh)
{
return;
}
var layoutParameters = realViewGroup.LayoutParameters;
layoutParameters.Width = Width;
realViewGroup.LayoutParameters = layoutParameters;
}
}
/// <summary>
/// 视图高度
/// </summary>
/// <value>The height.</value>
public override int Height
{
get
{
return base.Height;
}
set
{
base.Height = value;
if (!IsCanRefresh)
{
return;
}
var layoutParameters = realViewGroup.LayoutParameters;
layoutParameters.Height = Height;
realViewGroup.LayoutParameters = layoutParameters;
}
}
|
|
|
|
|
|
|
///// <summary>
|
///// 是否允许滑动
|
///// </summary>
|
///// <value><c>true</c> if scroll enabled; otherwise, <c>false</c>.</value>
|
//public bool ScrollEnabled
|
//{
|
// get
|
// {
|
// return (mAndroidRefreshScrolView as AndroidScrolView).ScrollEnable;
|
// }
|
// set
|
// {
|
// (mAndroidRefreshScrolView as AndroidScrolView).ScrollEnable = value;
|
// }
|
//}
|
|
///// <summary>
|
///// 是否正在滑动
|
///// </summary>
|
///// <value><c>true</c> if decelerating; otherwise, <c>false</c>.</value>
|
//public bool Decelerating
|
//{
|
// get
|
// {
|
// return false;
|
// }
|
//}
|
|
|
|
|
|
//***************************下拉刷新***************************
|
/// <summary>
/// 是否支持下拉刷新
/// </summary>
|
bool _isCanHeaderRefresh;
|
private bool IsCanHeaderRefresh
|
{
|
get
{
return _isCanHeaderRefresh;
}
|
set
|
{
|
_isCanHeaderRefresh = value;
|
}
|
}
|
|
|
/// <summary>
/// 头开始刷新
/// </summary>
|
public void BeginHeaderRefreshing()
|
{
|
if (!IsCanHeaderRefresh) return;
|
|
if (mSmartRefreshLayout.State != RefreshState.Refreshing)
|
{
|
mSmartRefreshLayout.AutoRefresh();
|
//Shared.HDLUtils.WriteLine("AutoRefresh");
|
|
}
|
}
|
|
/// <summary>
/// 头结束刷新
/// </summary>
|
public void EndHeaderRefreshing()
|
{
|
if (!IsCanHeaderRefresh) return;
|
|
if (mSmartRefreshLayout.State == RefreshState.Refreshing)
|
{
|
mSmartRefreshLayout.FinishRefresh();
|
//Shared.HDLUtils.WriteLine("FinishRefresh");
|
|
}
|
}
|
|
/// <summary>
/// 是否显示滚动条
/// </summary>
|
//bool _IsShowScrollBar;
|
public bool VerticalScrollBarEnabled
|
{
|
get
{
return mAndroidRefreshScrolView.VerticalScrollBarEnabled;
}
|
set
|
{
|
mAndroidRefreshScrolView.VerticalScrollBarEnabled = value;
|
|
}
|
}
|
|
|
|
////***************************上拉加载***************************
|
///// <summary>
|
///// 是否正在上拉加载
|
///// </summary>
|
//bool _isFooterRefreshing;
|
//public bool IsFooterRefreshing
|
//{
|
// get
|
// {
|
// return _isFooterRefreshing;
|
// }
|
// set
|
// {
|
// _isFooterRefreshing = value;
|
// }
|
//}
|
|
|
///// <summary>
|
///// 底部 开始上拉加载
|
///// </summary>
|
//public void beginFooterRefreshing()
|
//{
|
// if (!IsCanFooterRefresh) return;
|
|
// if (!IsFooterRefreshing)
|
// {
|
|
// mFooterLoadingView.Start(mHeaderRefreshText);
|
// IsFooterRefreshing = true;
|
// beginFooterRefreshingAction?.Invoke();
|
// }
|
//}
|
|
///// <summary>
|
///// 底部 结束上拉加载
|
///// </summary>
|
//public void endFooterRefreshing()
|
//{
|
// if (!IsCanFooterRefresh) return;
|
|
// if (IsFooterRefreshing)
|
// {
|
// mFooterLoadingView.Hide();
|
// IsFooterRefreshing = false;
|
// }
|
//}
|
|
|
|
|
|
|
}
|
|
///// <summary>
|
///// 竖直方向滑动控件
|
///// </summary>
|
//class AndroidRefreshScrolView : Android.Widget.ScrollView
|
//{
|
// /// <summary>
|
// /// 是否允许滑动
|
// /// </summary>
|
// public bool ScrollEnable = true;
|
|
// public Action AlreadyToTopAction;
|
// public Action AlreadyToTopUpAction;
|
// public Action AlreadyToBottomAction;
|
|
|
|
|
// View _view;
|
// /// <summary>
|
// /// 构造函数
|
// /// </summary>
|
// /// <param name="context">Context.</param>
|
// /// <param name="view">View.</param>
|
// public AndroidRefreshScrolView(Context context, View view)
|
// : base(context)
|
// {
|
// _view = view;
|
// VerticalScrollBarEnabled = true;
|
// //mScroller = new Scroller(context, new DecelerateInterpolator());
|
// }
|
|
|
// bool bAlreadyToTop;
|
|
// public override bool DispatchTouchEvent(MotionEvent e)
|
// {
|
// //Shared.HDLUtils.WriteLine($"{GetType()} Height->{Height} Width->{Width} DispatchTouchEvent->{e.Action}");
|
// if (e.Action == MotionEventActions.Down)
|
// {
|
// //还原允许拦截事件
|
// RequestDisallowInterceptTouchEvent(false);
|
// }
|
// return base.DispatchTouchEvent(e);
|
// }
|
|
// float mLastX, mLastY ;
|
// public override bool OnInterceptTouchEvent(MotionEvent ev)
|
// {
|
// //Shared.HDLUtils.WriteLine($"{GetType()} Height->{Height} Width->{Width} OnInterceptTouchEvent->{ev.Action}");
|
|
// if (!ScrollEnable || disallowIntercept)
|
// {
|
// return false;
|
// }
|
|
// switch (ev.Action)
|
// {
|
// case MotionEventActions.Down:
|
// mLastX = ev.RawX;
|
// mLastY = ev.RawY;
|
// bAlreadyToTop = false;
|
// Shared.HDLUtils.WriteLine($"MotionEventActions.Down");
|
// Parent?.RequestDisallowInterceptTouchEvent(true);
|
// break;
|
// case MotionEventActions.Up:
|
|
// Parent?.RequestDisallowInterceptTouchEvent(true);
|
// Shared.HDLUtils.WriteLine($"MotionEventActions.Up");
|
// if (bAlreadyToTop)
|
// {
|
// AlreadyToTopUpAction?.Invoke();
|
// Shared.HDLUtils.WriteLine($"AlreadyToTopUpAction");
|
// }
|
// break;
|
// case MotionEventActions.Move:
|
// var x = ev.RawX;
|
// var y = ev.RawY;
|
// var deltaX = x - mLastX;
|
// var deltaY = y - mLastY;
|
// Shared.HDLUtils.WriteLine($"MotionEventActions.Move");
|
|
// if (Math.Abs(deltaX) < Math.Abs(deltaY))
|
// {
|
// //向下滑动,如果当前已经滑动到顶,就允许父控件的拦截事件
|
// if (deltaY > 0 && ScrollY == 0)
|
// {
|
// bAlreadyToTop = true;
|
// AlreadyToTopAction?.Invoke();
|
// Parent?.RequestDisallowInterceptTouchEvent(false);
|
|
|
|
// return false;
|
// }
|
// //向上滑动时,如果translateY等于高度时,即表明滑动到底部,可又顶层View控制滑动
|
// var mChildH = 0;
|
// if (0 < ChildCount)
|
// {
|
// mChildH = GetChildAt(ChildCount - 1).Bottom;
|
// }
|
// var translateY = mChildH - ScrollY;
|
// if (deltaY < 0 && translateY == Height)
|
// {
|
// AlreadyToBottomAction?.Invoke();
|
// Parent?.RequestDisallowInterceptTouchEvent(false);
|
|
// return false;
|
// }
|
// }
|
// else
|
// {
|
// //左右滑动时,允许父控件的拦截
|
// if (4 < Math.Abs(deltaX))
|
// {
|
// Parent?.RequestDisallowInterceptTouchEvent(false);
|
// }
|
// }
|
// break;
|
// }
|
|
// return base.OnInterceptTouchEvent(ev);
|
// }
|
// /// <summary>
|
// /// 重写点击事件
|
// /// </summary>
|
// /// <returns><c>true</c>, if touch event was oned, <c>false</c> otherwise.</returns>
|
// /// <param name="e">E.</param>
|
// public override bool OnTouchEvent(MotionEvent e)
|
// {
|
// //Shared.HDLUtils.WriteLine($"{GetType()} Height->{Height} Width->{Width} OnInterceptTouchEvent->{e.Action}");
|
// _view?.TouchEvent(e);
|
// base.OnTouchEvent(e);
|
// //如果返回真父控件就不需要处理了
|
// return true;
|
// }
|
// bool disallowIntercept;
|
// public override void RequestDisallowInterceptTouchEvent(bool disallowIntercept)
|
// {
|
// this.disallowIntercept = disallowIntercept;
|
// //Shared.HDLUtils.WriteLine($"{GetType()} Height->{Height} RequestDisallowInterceptTouchEvent->{disallowIntercept}");
|
// base.RequestDisallowInterceptTouchEvent(disallowIntercept);
|
// Parent?.RequestDisallowInterceptTouchEvent(disallowIntercept);
|
// }
|
//}
|
|
|
|
|
}
|