一)编写ini文件,用button实现加载界面
cl_animationWin={ type="window" x=0 y=0 w=1024 h=600 style="cl_normalwin" flags={ window_splash } ... cl_picLoadingButton={ type="button" x=425 y=180 w=174 h=174 style="comWaitBtn" flags={ no_focus button_no_offset no_event } } ... }
二)代码中实现此功能
static void initCarLifeAnimation() { TWidget *loading,*aniLogo; loading = TObjectGetFromName("cl_picLoadingButton"); aniLogo = TObjectGetFromName("cl_picLoadingLogo"); TTable *tableLoading = TTableCreate(); TTable *tableLogo = TTableCreate(); int i = 0; char picPath[ANI_PICPATH_CHARMAX]= {0}; for(i=0; i<ANI_LOADING_PIC_MAX; i++) { sprintf(picPath,"../style/carlife/car_ic_loading_%02d.png",i+1); CL_D("----add %d%s ",i,picPath); TTableAddString(tableLoading,(Tint)NULL,picPath,-1); memset(picPath,0,ANI_PICPATH_CHARMAX); } for(i = 0; i<ANI_LOGO_PIC_MAX; i++) { sprintf(picPath,"../style/carlife/car_ic_loading_logo%02d.png",i+1); CL_D("----add %d %s ",i,picPath); TTableAddString(tableLogo,(Tint)NULL,picPath,-1); memset(picPath,0,ANI_PICPATH_CHARMAX); } if(clViewInfo&&clViewInfo->animationInfo) { if(clViewInfo->animationInfo->btnAniLogo==NULL) { clViewInfo->animationInfo->btnAniLogo = createBtnAnimation(aniLogo,tableLogo,ANI_TIME_INT,1); registerAniBtnFinishCBK(clViewInfo->animationInfo->btnAniLogo,animationLogoFinished,animationShowLogo); } else { CL_E("[error] last logo animtion hasn't destory.plz check. "); } if(clViewInfo->animationInfo->btnAni==NULL) { clViewInfo->animationInfo->btnAni = createBtnAnimation(loading,tableLoading,ANI_TIME_INT,-1); registerAniBtnFinishCBK(clViewInfo->animationInfo->btnAni,animationLogoFinished,NULL); startBtnAnimation(clViewInfo->animationInfo->btnAni); } else { CL_E("[error] last loading animtion hasn't destory.plz check. "); } } TTableDestroy(tableLoading); TTableDestroy(tableLogo); }
三)开始加载界面 startBtnAnimation
四)暂停加载界面 stopBtnAnimation
五)实现回调函数
animationShowLogo
static void animationShowLogo(TWidget *widget) { TWidget *btn = TObjectGetFromName("cl_picBaiduLabel"); TwShow(btn); }
animationLogoFinished
static void animationLogoFinished(TWidget *widget) { CHECK_POINTER(clViewInfo); TWidget *loading = TObjectGetFromName("cl_picLoadingButton"); CL_D("%s %d widget %x:laoding %x ",__FUNCTION__,__LINE__,(Tuint32)widget,(Tuint32)loading); if(loading == widget) { CL_I(); TWidget *btn = TObjectGetFromName("cl_picLoadLogo"); TwHide(btn); btn = TObjectGetFromName("cl_picLoadingButton"); TwHide(btn); btn = TObjectGetFromName("cl_picLoadingLabel"); TwHide(btn); btn = TObjectGetFromName("cl_picLoadingLogo"); TwShow(btn); if(clViewInfo->animationInfo->btnAniLogo) { startBtnAnimation(clViewInfo->animationInfo->btnAniLogo); } } else { if(clViewInfo->isProjected == TRUE) { clViewInfo->isProjected = FALSE; changeView(CL_PROJECTED); } else { changeView(CL_Failed); } } }