企业互联网服务培训资料doc 60页完美优质版.docx

上传人:b****6 文档编号:8600919 上传时间:2023-02-01 格式:DOCX 页数:75 大小:33.74KB
下载 相关 举报
企业互联网服务培训资料doc 60页完美优质版.docx_第1页
第1页 / 共75页
企业互联网服务培训资料doc 60页完美优质版.docx_第2页
第2页 / 共75页
企业互联网服务培训资料doc 60页完美优质版.docx_第3页
第3页 / 共75页
企业互联网服务培训资料doc 60页完美优质版.docx_第4页
第4页 / 共75页
企业互联网服务培训资料doc 60页完美优质版.docx_第5页
第5页 / 共75页
点击查看更多>>
下载资源
资源描述

企业互联网服务培训资料doc 60页完美优质版.docx

《企业互联网服务培训资料doc 60页完美优质版.docx》由会员分享,可在线阅读,更多相关《企业互联网服务培训资料doc 60页完美优质版.docx(75页珍藏版)》请在冰豆网上搜索。

企业互联网服务培训资料doc 60页完美优质版.docx

企业互联网服务培训资料doc60页完美优质版

importandroid.content.Context;

importandroid.util.AttributeSet;

importandroid.view.MotionEvent;

importandroid.view.View;

importandroid.view.ViewTreeObserver.OnGlobalLayoutListener;

importandroid.view.animation.DecelerateInterpolator;

importandroid.widget.AbsListView;

importandroid.widget.AbsListView.OnScrollListener;

importandroid.widget.ListAdapter;

importandroid.widget.ListView;

importandroid.widget.RelativeLayout;

importandroid.widget.Scroller;

importandroid.widget.TextView;

importcom.insthub.ecmobile.R;

importandroid.os.Message;

importandroid.os.Handler;

publicclassXListViewextendsListViewimplementsOnScrollListener{

privatefloatmLastY=-1;//saveeventy

privateScrollermScroller;//usedforscrollback

privateOnScrollListenermScrollListener;//user'sscrolllistener

//theinterfacetotriggerrefreshandloadmore.

privateIXListViewListenermListViewListener;

//--headerview

privateXListViewHeadermHeaderView;

//headerviewcontent,useittocalculatetheHeader'sheight.Andhideit

//whendisablepullrefresh.

privateRelativeLayoutmHeaderViewContent;

privateTextViewmHeaderTimeView;

privateintmHeaderViewHeight;//headerview'sheight

privatebooleanmEnablePullRefresh=true;

privatebooleanmPullRefreshing=false;//isrefreashing.

//--footerview

privateXListViewFootermFooterView;

privatebooleanmEnablePullLoad;

privatebooleanmPullLoading;

privatebooleanmIsFooterReady=false;

//totallistitems,usedtodetectisatthebottomoflistview.

privateintmTotalItemCount;

//formScroller,scrollbackfromheaderorfooter.

privateintmScrollBack;

privatefinalstaticintSCROLLBACK_HEADER=0;

privatefinalstaticintSCROLLBACK_FOOTER=1;

privatefinalstaticintSCROLL_DURATION=400;//scrollbackduration

privatefinalstaticintPULL_LOAD_MORE_DELTA=50;//whenpullup>=50px

//atbottom,trigger

//loadmore.

privatefinalstaticfloatOFFSET_RADIO=1.8f;//supportiOSlikepull

//feature.

privateintid;

/**

*@paramcontext

*/

publicXListView(Contextcontext){

super(context);

initWithContext(context);

}

publicXListView(Contextcontext,AttributeSetattrs){

super(context,attrs);

initWithContext(context);

}

publicXListView(Contextcontext,AttributeSetattrs,intdefStyle){

super(context,attrs,defStyle);

initWithContext(context);

}

privatevoidinitWithContext(Contextcontext){

mScroller=newScroller(context,newDecelerateInterpolator());

//XListViewneedthescrollevent,anditwilldispatchtheeventto

//user'slistener(asaproxy).

super.setOnScrollListener(this);

//initheaderview

mHeaderView=newXListViewHeader(context);

mHeaderViewContent=(RelativeLayout)mHeaderView

.findViewById(R.id.xlistview_header_content);

mHeaderTimeView=(TextView)mHeaderView

.findViewById(R.id.xlistview_header_time);

addHeaderView(mHeaderView);

//initfooterview

mFooterView=newXListViewFooter(context);

//initheaderheight

mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(

newOnGlobalLayoutListener(){

@Override

publicvoidonGlobalLayout(){

mHeaderViewHeight=mHeaderViewContent.getHeight();

getViewTreeObserver()

.removeGlobalOnLayoutListener(this);

}

});

}

@Override

publicvoidsetAdapter(ListAdapteradapter){

//makesureXListViewFooteristhelastfooterview,andonlyaddonce.

if(mIsFooterReady==false){

mIsFooterReady=true;

addFooterView(mFooterView);

}

super.setAdapter(adapter);

}

/**

*enableordisablepulldownrefreshfeature.

*

*@paramenable

*/

publicvoidsetPullRefreshEnable(booleanenable){

mEnablePullRefresh=enable;

if(!

mEnablePullRefresh){//disable,hidethecontent

mHeaderViewContent.setVisibility(View.INVISIBLE);

}else{

mHeaderViewContent.setVisibility(View.VISIBLE);

}

}

/**

*enableordisablepulluploadmorefeature.

*

*@paramenable

*/

publicvoidsetPullLoadEnable(booleanenable){

mEnablePullLoad=enable;

if(!

mEnablePullLoad){

mFooterView.hide();

mFooterView.setOnClickListener(null);

}else{

mPullLoading=false;

mFooterView.show();

mFooterView.setState(XListViewFooter.STATE_NORMAL);

//both"pullup"and"click"willinvokeloadmore.

mFooterView.setOnClickListener(newOnClickListener(){

@Override

publicvoidonClick(Viewv){

startLoadMore();

}

});

}

}

/**

*stoprefresh,resetheaderview.

*/

publicvoidstopRefresh(){

if(mPullRefreshing==true){

mPullRefreshing=false;

resetHeaderHeight();

}

}

/**

*stoploadmore,resetfooterview.

*/

publicvoidstopLoadMore(){

if(mPullLoading==true){

mPullLoading=false;

mFooterView.setState(XListViewFooter.STATE_NORMAL);

}

mFooterView.setEnabled(true);

}

/**

*setlastrefreshtime

*

*@paramtime

*/

publicvoidsetRefreshTime(){

//mHeaderTimeView.setText(newDate().toLocaleString());

mHeaderTimeView.setText(date());

}

//获取系统时间

publicStringdate(){

SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-ddHH:

mm:

ss");

Datedate=newDate();

Stringt=sdf.format(date);

returnt;

}

privatevoidinvokeOnScrolling(){

if(mScrollListenerinstanceofOnXScrollListener){

OnXScrollListenerl=(OnXScrollListener)mScrollListener;

l.onXScrolling(this);

}

}

privatevoidupdateHeaderHeight(floatdelta){

mHeaderView.setVisiableHeight((int)delta

+mHeaderView.getVisiableHeight());

if(mEnablePullRefresh&&!

mPullRefreshing){//未处于刷新状态,更新箭头

if(mHeaderView.getVisiableHeight()>mHeaderViewHeight){

mHeaderView.setState(XListViewHeader.STATE_READY);

}else{

mHeaderView.setState(XListViewHeader.STATE_NORMAL);

}

}

setSelection(0);//scrolltotopeachtime

}

/**

*resetheaderview'sheight.

*/

privatevoidresetHeaderHeight(){

intheight=mHeaderView.getVisiableHeight();

if(height==0)//notvisible.

return;

//refreshingandheaderisn'tshownfully.donothing.

if(mPullRefreshing&&height<=mHeaderViewHeight){

return;

}

intfinalHeight=0;//default:

scrollbacktodismissheader.

//isrefreshing,justscrollbacktoshowalltheheader.

if(mPullRefreshing&&height>mHeaderViewHeight){

finalHeight=mHeaderViewHeight;

}

mScrollBack=SCROLLBACK_HEADER;

mScroller.startScroll(0,height,0,finalHeight-height,

SCROLL_DURATION);

//triggercomputeScroll

invalidate();

}

privatevoidupdateFooterHeight(floatdelta){

intheight=mFooterView.getBottomMargin()+(int)delta;

if(mEnablePullLoad&&!

mPullLoading){

if(height>PULL_LOAD_MORE_DELTA){//heightenoughtoinvokeload

//more.

mFooterView.setState(XListViewFooter.STATE_READY);

}else{

mFooterView.setState(XListViewFooter.STATE_NORMAL);

}

}

mFooterView.setBottomMargin(height);

//setSelection(mTotalItemCount-1);//scrolltobottom

}

privatevoidresetFooterHeight(){

intbottomMargin=mFooterView.getBottomMargin();

if(bottomMargin>0){

mScrollBack=SCROLLBACK_FOOTER;

mScroller.startScroll(0,bottomMargin,0,-bottomMargin,

SCROLL_DURATION);

invalidate();

}

}

publicvoidstartLoadMore(){

mPullLoading=true;

mFooterView.setState(XListViewFooter.STATE_LOADING);

if(mListViewListener!

=null){

mListViewListener.onLoadMore(id);

}

mFooterView.setEnabled(false);

HandlermHandler=newHandler(){

@Override

publicvoidhandleMessage(Messagemsg){

super.handleMessage(msg);

XListView.this.stopLoadMore();

}

};

mHandler.sendEmptyMessageDelayed(0,4000);

}

@Override

publicbooleanonTouchEvent(MotionEventev){

if(mLastY==-1){

mLastY=ev.getRawY();

}

switch(ev.getAction()){

caseMotionEvent.ACTION_DOWN:

mLastY=ev.getRawY();

break;

caseMotionEvent.ACTION_MOVE:

finalfloatdeltaY=ev.getRawY()-mLastY;

mLastY=ev.getRawY();

if(getFirstVisiblePosition()==0

&&(mHeaderView.getVisiableHeight()>0||deltaY>0)){

//thefirstitemisshowing,headerhasshownorpulldown.

updateHeaderHeight(deltaY/OFFSET_RADIO);

invokeOnScrolling();

}elseif(getLastVisiblePosition()==mTotalItemCount-1

&&(mFooterView.getBottomMargin()>0||deltaY<0)){

//lastitem,alreadypulleduporwanttopullup.

updateFooterHeight(-deltaY/OFFSET_RADIO);

}

break;

default:

mLastY=-1;//reset

if(getFirstVisiblePosition()==0){

//invokerefresh

if(mEnablePullRefresh

&&mHeaderView.getVisiableHeight()>mHeaderViewHeight){

mPullRefreshing=true;

mHeaderView.setState(XListViewHeader.STATE_REFRESHING);

if(mListViewListener!

=null){

mListViewListener.onRefresh(id);

HandlermHandler=newHandler(){

@Override

publicvoidhandleMessage(Messagemsg){

super.handleMessage(msg);

XListView.this.stopRefresh();

}

};

mHandler.sendEmptyMessageDelayed(0,4000);

}

}

resetHeaderHeight();

}elseif(getLastVisiblePosition()==mTotalItemCount-1){

//invokeloadmore.

if(mEnablePullLoad

&&mFooterView.getBottomMargin()>PULL_LOAD_MORE_DELTA){

if(mFooterView.isEnabled()){

startLoadMore();

}

}

resetFooterHeight();

}

break;

}

returnsuper.onTouchEvent(ev);

}

@Override

publicvoidcomputeScroll(){

if(mSputeScrollOffset()){

if(mScrollBack==SCROLLBACK_HEADER){

mHeaderView.setVisiableHeight(mScroller.getCurrY());

}else{

mFooterView.setBottomMargin(mScroller.getCurrY());

}

postInvalidate();

invokeOnScrolling();

}

puteScroll();

}

@Override

publicvoidsetOnScrollListener(OnScrollListenerl){

mScrollListener=l;

}

@Override

publicvoidonScrollStateChanged(AbsListViewview,intscrollState){

if(mScrollListener!

=null){

mScrollListener.onScrollStateChang

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1