这几天公司出了签到的需求,让我来做签到这一块,刚开始以为非常好做,不就是调用系统的日历吗。系统的日历与签到标签基于足够完成了。我首先用Android5.0以上的机器调用了日历控件,发现还不错,但是用了一台4.2的机器调用日历。我靠!这丑不拉几,看着都要吐了还能用?没有办法,我只能尝试自定义日历控件了。

下面是设计给的我第一张图:

刚开始我想的是可以画为6行7列的网格,GridView可以实现,正准备做,可是下午设计又给了我一张图:

大白圈是今天的日期,小白点是这个月已签过到的日期,黑色字体是已经过去的日期,灰色是还没有到来的日期。这变化有点大啊,这要的话用GridView就得区分好几种不同的Type了,如果以后还有其他加的不是会更麻烦,然后只能自己画View这样,自己对这个View很熟悉,以后要添加什么功能可以很清楚的加上代码。

于是我就在网上搜Android自定义日历控件,当我在CSDN上看到zou128865写的Android UI-自定义日历控件正好能满足我目前的需求,于是我就把他的代码下载下来,仔细的研究。在他的代码上修改变成我自己的日历控件。好啦废话不多说了,开始我们的日历控件之旅吧。


当我要做完这个控件的时候,设计发来了最终稿的动态图:不能上传完整的动态不然老板搞死我,见谅哈。

不会上传动态图呀 !!!!!!

来开始代码:

1.CalendarView:


packageoct.mama.view;importandroid.content.Context;importandroid.graphics.Canvas;importandroid.graphics.Color;importandroid.graphics.Paint;importandroid.view.MotionEvent;importandroid.view.View;importandroid.view.ViewConfiguration;importjava.util.List;importoct.mama.R;importoct.mama.model.CustomDateModel;importoct.mama.utils.CheckInUtils;importoct.mama.utils.CountDownTimerUtils;/***日历展示控件*CreatedbyAdministratoron2015/10/29.*/publicclassCalendarViewextendsView{privatestaticfinalintTOTAL_COL=7;//7列privatestaticfinalintTOTAL_ROW=6;//6行privatePaintmCirclePaint;//绘制圆形的画笔privatePaintmTextPaint;//绘制文本的画笔privateintmViewWidth;//视图的宽度privateintmViewHeight;//视图的高度privateintmCellSpace;//单元格列间距privateintmCellRowSpace;//单元行间距privatePaintmRowTextPaint;privateRowrows[]=newRow[TOTAL_ROW];//行数组,每个元素代表一行privatestaticCustomDateModelmShowDate;//自定义的日期,包括year,month,dayprivateOnCellClickListenermCellClickListener;//单元格点击回调事件privateinttouchSlop;//事件触发最小距离privateCellmClickCell;privatefloatmDownX;privatefloatmDownY;privateintcircleRadius;privatefloatcurrentDayX;privatefloatcurrentDayY;privateintcurrentMonthDays;//当前月天数privateList<Long>checkInDays;//服务器传来已签过的daysprivateintcheckIndex=0;//遍历checkInDays角标,每次onDarw时要将脚表归0,不然有时候会出现闪烁问题privatelongserverTime;//服务器传来时间privateCheckInUtilsmCheckInUtils;/***单元格点击的回调接口**@authorwuwenjie**/publicinterfaceOnCellClickListener{voidchangeDate(CustomDateModeldate);//回调滑动ViewPager改变的日期}publicCalendarView(Contextcontext,OnCellClickListenerlistener,longserverTime){super(context);this.mCellClickListener=listener;this.serverTime=serverTime;this.mCheckInUtils=CheckInUtils.getInstance();init(context);}privatevoidinit(Contextcontext){if(mCheckInUtils!=null){mCheckInUtils.setServerTime(serverTime);}mTextPaint=newPaint(Paint.ANTI_ALIAS_FLAG);mRowTextPaint=newPaint(Paint.ANTI_ALIAS_FLAG);mCirclePaint=newPaint(Paint.ANTI_ALIAS_FLAG);mCirclePaint.setStyle(Paint.Style.FILL);mCirclePaint.setColor(getResources().getColor(R.color.log_today_white_circle));//白色圆圈touchSlop=ViewConfiguration.get(context).getScaledTouchSlop();this.setBackgroundResource(R.color.log_today_calendar_bg);//控件背景initDate();}privatevoidinitDate(){mShowDate=newCustomDateModel(serverTime);//系统时间可能被更改,所以从服务器获取时间,(防刷)fillDate();//}/***填充数据*/privatevoidfillDate(){intmonthDay=mCheckInUtils.getCurrentMonthDay();//今天intlastMonthDays=mCheckInUtils.getMonthDays(mShowDate.year,mShowDate.month-1);//上个月的天数currentMonthDays=mCheckInUtils.getMonthDays(mShowDate.year,mShowDate.month);//当前月的天数intfirstDayWeek=mCheckInUtils.getWeekDayFromDate(mShowDate.year,mShowDate.month);booleanisCurrentMonth=false;if(mCheckInUtils.isCurrentMonth(mShowDate)){isCurrentMonth=true;}intday=0;/**判断当月位置,并对其设置对应的状态、数字。*/for(intj=0;j<TOTAL_ROW;j++){//6行rows[j]=newRow(j);for(inti=0;i<TOTAL_COL;i++){//7列intposition=i+j*TOTAL_COL;//单元格位置//这个月的if(position>=firstDayWeek&&position<firstDayWeek+currentMonthDays){day++;rows[j].cells[i]=newCell(CustomDateModel.modifiDayForObject(mShowDate,day),State.CURRENT_MONTH_DAY,i,j);//还没到时间的字体颜色都比较淡if(mShowDate.getYear()>mCheckInUtils.getYear()||(mShowDate.getYear()==mCheckInUtils.getYear()&&mShowDate.getMonth()>mCheckInUtils.getMonth())){rows[j].cells[i]=newCell(CustomDateModel.modifiDayForObject(mShowDate,day),State.UNREACH_DAY,i,j);}//今天if(isCurrentMonth&&day==monthDay){CustomDateModeldate=CustomDateModel.modifiDayForObject(mShowDate,day);rows[j].cells[i]=newCell(date,State.TODAY,i,j);}if(isCurrentMonth&&day>monthDay){//如果比这个月的今天要大,表示还没到rows[j].cells[i]=newCell(CustomDateModel.modifiDayForObject(mShowDate,day),State.UNREACH_DAY,i,j);}//过去一个月}elseif(position<firstDayWeek){rows[j].cells[i]=newCell(newCustomDateModel(mShowDate.year,mShowDate.month-1,lastMonthDays-(firstDayWeek-position-1)),State.PAST_MONTH_DAY,i,j);//下个月}elseif(position>=firstDayWeek+currentMonthDays){rows[j].cells[i]=newCell((newCustomDateModel(mShowDate.year,mShowDate.month+1,position-firstDayWeek-currentMonthDays+1)),State.NEXT_MONTH_DAY,i,j);}}}}@OverrideprotectedvoidonSizeChanged(intw,inth,intoldw,intoldh){super.onSizeChanged(w,h,oldw,oldh);mViewWidth=w;mViewHeight=h;mCellSpace=mViewWidth/TOTAL_COL;//每个框格宽度mCellRowSpace=mViewHeight/TOTAL_ROW;//每个框格高度circleRadius=mCellSpace/3;mTextPaint.setTextSize(mCellSpace/4);mRowTextPaint.setTextSize(mCellRowSpace/4);}@OverrideprotectedvoidonDraw(Canvascanvas){super.onDraw(canvas);checkIndex=0;for(inti=0;i<TOTAL_ROW;i++){if(rows[i]!=null){rows[i].drawCells(canvas);}}}/***目前还没用到为以后补签做准备**/@OverridepublicbooleanonTouchEvent(MotionEventevent){switch(event.getAction()){caseMotionEvent.ACTION_DOWN:mDownX=event.getX();mDownY=event.getY();break;caseMotionEvent.ACTION_UP:floatdisX=event.getX()-mDownX;floatdisY=event.getY()-mDownY;if(Math.abs(disX)<touchSlop&&Math.abs(disY)<touchSlop){intcol=(int)(mDownX/mCellSpace);introw=(int)(mDownY/mCellRowSpace);measureClickCell(col,row);}break;default:break;}returntrue;}/***计算点击的单元格*@paramcol*@paramrow*/privatevoidmeasureClickCell(intcol,introw){if(col>=TOTAL_COL||row>=TOTAL_ROW)return;if(mClickCell!=null){rows[mClickCell.j].cells[mClickCell.i]=mClickCell;}if(rows[row]!=null){mClickCell=newCell(rows[row].cells[col].date,rows[row].cells[col].state,rows[row].cells[col].i,rows[row].cells[col].j);CustomDateModeldate=rows[row].cells[col].date;date.week=col;//刷新界面update();}}/***组元素**/classRow{publicintj;Row(intj){this.j=j;}publicCell[]cells=newCell[TOTAL_COL];//绘制单元格publicvoiddrawCells(Canvascanvas){for(inti=0;i<cells.length;i++){if(cells[i]!=null){cells[i].drawSelf(canvas);}}}}/***单元格元素**@authorwuwenjie**/classCell{publicCustomDateModeldate;publicStatestate;publicinti;publicintj;publicCell(CustomDateModeldate,Statestate,inti,intj){super();this.date=date;this.state=state;this.i=i;this.j=j;}publicvoiddrawSelf(Canvascanvas){Stringcontent=String.valueOf(date.day);switch(state){caseTODAY://今天mTextPaint.setColor(getResources().getColor(R.color.log_today_current_text));currentDayX=(float)(mCellSpace*(i+0.55));currentDayY=(float)((j+0.48)*mCellRowSpace);canvas.drawCircle(currentDayX,currentDayY,circleRadius-10,mCirclePaint);break;caseCURRENT_MONTH_DAY://当前月日期mTextPaint.setColor(getResources().getColor(R.color.log_today_current_text));if(checkInDays!=null){if(checkIndex<checkInDays.size()){if((checkInDays.get(checkIndex)%100==date.day)){canvas.drawCircle((float)(mCellSpace*(i+0.55)),(float)(j+0.9)*mCellRowSpace,4,mCirclePaint);checkIndex++;}}}break;casePAST_MONTH_DAY://过去一个月caseNEXT_MONTH_DAY://下一个月mTextPaint.setColor(getResources().getColor(R.color.log_today_calendar_bg));break;caseUNREACH_DAY://还未到的天mTextPaint.setColor(Color.GRAY);break;default:break;}//绘制文字canvas.drawText(content,(float)((i+0.55)*mCellSpace-mTextPaint.measureText(content)/2),(float)((j+0.7)*mCellRowSpace-mRowTextPaint.measureText(content,0,1)/2),mTextPaint);}}/****@authorwuwenjie单元格的状态当前月日期,过去的月的日期,下个月的日期*/enumState{TODAY,CURRENT_MONTH_DAY,PAST_MONTH_DAY,NEXT_MONTH_DAY,UNREACH_DAY;}//从左往右划,上一个月publicvoidleftSlide(){checkInDays=null;if(mShowDate.month==1){mShowDate.month=12;mShowDate.year-=1;}else{mShowDate.month-=1;}if(mCellClickListener!=null){mCellClickListener.changeDate(mShowDate);}update();}//从右往左划,下一个月publicvoidrightSlide(){checkInDays=null;if(mShowDate.month==12){mShowDate.month=1;mShowDate.year+=1;}else{mShowDate.month+=1;}if(mCellClickListener!=null){mCellClickListener.changeDate(mShowDate);}update();}publicvoidupdate(){checkIndex=0;fillDate();invalidate();}publicvoidcurrentUpdate(){initDate();if(mCellClickListener!=null){mCellClickListener.changeDate(mShowDate);}invalidate();}/***当月已签days(正确时间)*/publicvoidsetCurrentCheckInDays(List<Long>currentLogs){this.checkInDays=currentLogs;initDate();if(mCellClickListener!=null){mCellClickListener.changeDate(mShowDate);}invalidate();}/***本月已签*@paramlogs*/publicvoidsetCheckInDays(List<Long>logs){this.checkInDays=logs;update();}/***签到刷新方法,并返回当前日期坐标(放大)*@return*/publicvoidSignIn(){newCountDownTimerUtils(350,25){@OverridepublicvoidonTick(longmillisUntilFinished){fillDate();circleRadius=circleRadius+1;invalidate();}@OverridepublicvoidonFinish(){cancel();SignInt();}}.start();}/***(缩小)*/privatevoidSignInt(){newCountDownTimerUtils(350,25){@OverridepublicvoidonTick(longmillisUntilFinished){fillDate();circleRadius=circleRadius-1;invalidate();}@OverridepublicvoidonFinish(){cancel();}}.start();}}


2.CheckInUtils

工具类,主要是从Calendar中获取日期,注意不要因为mCalender = Calender.getInstance就以为Calender是单例,我这这地方吃过亏。

packageoct.mama.utils;importandroid.annotation.SuppressLint;importandroid.content.Context;importjava.text.ParseException;importjava.text.SimpleDateFormat;importjava.util.Calendar;importjava.util.Date;importoct.mama.model.CustomDateModel;/***签到日期工具,调用除设置或获取参数外得先调用setServerTime函数;*CreatedbyAdministratoron2015/10/29.*/publicclassCheckInUtils{privatestaticCheckInUtilscheckInUtils=newCheckInUtils();publicstaticfinalStringCHECK_IN_KEY="check_in_time";//签到keypublicCalendarmCalender;privateCheckInUtils(){}publicstaticCheckInUtilsgetInstance(){returncheckInUtils;}publicvoidsetServerTime(longtime){mCalender=Calendar.getInstance();mCalender.setTimeInMillis(time*1000);}publicintgetMonthDays(intyear,intmonth){if(month>12){month=1;year+=1;}elseif(month<1){month=12;year-=1;}//月份对应的天数int[]arr={31,28,31,30,31,30,31,31,30,31,30,31};intdays=0;if((year%4==0&&year%100!=0)||year%400==0){arr[1]=29;//闰年2月29天}try{days=arr[month-1];}catch(Exceptione){e.getStackTrace();}returndays;}publicintgetYear(){returnmCalender.get(Calendar.YEAR);}publicStringgetCurrentTime(){returnmCalender.get(Calendar.YEAR)+"-"+checkInUtils.getMonth();}publicintgetMonth(){returnmCalender.get(Calendar.MONTH)+1;}publicintgetCurrentMonthDay(){returnmCalender.get(Calendar.DAY_OF_MONTH);}/***当月1号是第一个星期的第几天*@paramyear*@parammonth*@return*/publicintgetWeekDayFromDate(intyear,intmonth){Calendarcal=Calendar.getInstance();cal.setTime(getDateFromString(year,month));intweek_index=cal.get(Calendar.DAY_OF_WEEK)-1;if(week_index<0){week_index=0;}returnweek_index;}@SuppressLint("SimpleDateFormat")publicDategetDateFromString(intyear,intmonth){StringdateString=year+"-"+(month>9?month:("0"+month))+"-01";Datedate=null;try{SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd");date=sdf.parse(dateString);}catch(ParseExceptione){System.out.println(e.getMessage());}returndate;}publicbooleanisCurrentMonth(CustomDateModeldate){return(date.year==checkInUtils.getYear()&&date.month==checkInUtils.getMonth());}/***本地保存签到记录*/publicstaticvoidsavePreference(Contextcontext){SharedPreferencesUtils.setPreferenceLong(context,CHECK_IN_KEY,System.currentTimeMillis()/1000/60/60/24);}publicstaticlonggetPreference(Contextcontext){returnSharedPreferencesUtils.getPreferenceLong(context,CHECK_IN_KEY,0);}}


3.CustomDateModel

packageoct.mama.model;importoct.mama.utils.CheckInUtils;/***签到日期实体类*CreatedbyAdministratoron2015/10/29.*/publicclassCustomDateModel{publicintyear;publicintmonth;publicintday;publicintweek;publicCustomDateModel(intyear,intmonth,intday){if(month>12){month=1;year++;}elseif(month<1){month=12;year--;}this.year=year;this.month=month;this.day=day;}publicCustomDateModel(longserverTime){CheckInUtilsmCheckInUtils=CheckInUtils.getInstance();mCheckInUtils.setServerTime(serverTime);this.year=mCheckInUtils.getYear();this.month=mCheckInUtils.getMonth();this.day=mCheckInUtils.getCurrentMonthDay();}publicstaticCustomDateModelmodifiDayForObject(CustomDateModeldate,intday){CustomDateModelmodifiDate=newCustomDateModel(date.year,date.month,day);returnmodifiDate;}@OverridepublicStringtoString(){returnyear+"-"+month+"-"+day;}publicStringgetTime(){returnyear+"-"+month;}publicintgetYear(){returnyear;}publicvoidsetYear(intyear){this.year=year;}publicintgetMonth(){returnmonth;}publicvoidsetMonth(intmonth){this.month=month;}publicintgetDay(){returnday;}publicvoidsetDay(intday){this.day=day;}publicintgetWeek(){returnweek;}publicvoidsetWeek(intweek){this.week=week;}}


4.Activity:

注意在我请求数据的那些地方大家要填充自己的值。删除了许多跟公司相关的东西。

packageoct.mama.activity;importandroid.content.Intent;importandroid.os.Bundle;importandroid.support.v4.view.ViewPager;importandroid.text.SpannableStringBuilder;importandroid.text.Spanned;importandroid.text.style.ForegroundColorSpan;importandroid.view.Menu;importandroid.view.MenuItem;importandroid.view.View;importandroid.view.animation.AlphaAnimation;importandroid.view.animation.Animation;importandroid.view.animation.AnimationSet;importandroid.view.animation.TranslateAnimation;importandroid.widget.ImageView;importandroid.widget.TextView;importcom.loopj.android.http.RequestParams;importjava.text.MessageFormat;importjava.util.List;importoct.mama.R;importoct.mama.adapter.CalendarViewAdapter;importoct.mama.alert.CheckInRuleDialog;importoct.mama.alert.ConfirmDialog;importoct.mama.api.ApiInvoker;importoct.mama.apiInterface.IMemberApi;importoct.mama.apiResult.GenericResult;importoct.mama.connect.GenericResultResponseHandler;importoct.mama.model.CheckInResult;importoct.mama.model.CouponInfoModel;importoct.mama.model.CustomDateModel;importoct.mama.model.MonthSignLogModel;importoct.mama.model.ShowCheckInResult;importoct.mama.utils.CheckInUtils;importoct.mama.view.CalendarView;/***签到页面*/publicclassCheckInActivityextendsBaseTitleActivityimplementsCalendarView.OnCellClickListener,View.OnClickListener{privateViewPagermViewPager;publicList<Long>currentLogs;privateTextViewcouponRmb;privateTextViewcouponArea;privateImageViewlogTodayBgImageView;privateTextViewmonthText;privateImageViewsignInImageView;privateTextViewanimText;privateintmCurrentIndex=498;privateCalendarView[]mShowViews;privateCalendarViewAdapter<CalendarView>adapter;privateSildeDirectionmDirection=SildeDirection.NO_SILDE;privateCheckInRuleDialogcheckInRuleDialog;privateIMemberApimIMemberApi;privateintcontinuousDays;privateCheckInUtilsmCheckInUtils;privateStringrules;privateStringcurrentAmount;privateStringcurrentArea;enumSildeDirection{RIGHT,LEFT,NO_SILDE;}@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_log_today);setTitleText(R.string.log_have_gift);init();mCheckInUtils=CheckInUtils.getInstance();CheckInUtils.savePreference(this);//本地保存签到记录getCheckInData();}privatevoidinit(){ImageViewpreImgBtn=(ImageView)findViewById(R.id.last_month);ImageViewnextImgBtn=(ImageView)findViewById(R.id.next_month);monthText=(TextView)findViewById(R.id.log_today_time);signInImageView=(ImageView)findViewById(R.id.log_today_check);mViewPager=(ViewPager)this.findViewById(R.id.vp_calendar);animText=(TextView)findViewById(R.id.check_in_anim);preImgBtn.setOnClickListener(this);nextImgBtn.setOnClickListener(this);signInImageView.setOnClickListener(this);}/***获取是否已签到数据,以及当前时间,已签过日期*/publicvoidgetCheckInData(){//这里是请求数据库的值,没个公司,每个人要的数据是不一样的,到时候大家修改,大家编译的时候要对Activity好好修改,我是懒得改了//请求成功@OverridepublicvoidonSuccess(ShowCheckInResultgenericResult){super.onSuccess(genericResult);if(genericResult.getCode()==GenericResult.SUCCESS){if(genericResult.getRulesText()!=null){rules=genericResult.getRulesText();}invalidateOptionsMenu();signInImageView.setVisibility(View.VISIBLE);mCheckInUtils.setServerTime(genericResult.getServerTime());viewpager(genericResult.getServerTime());//当前月已签过dayscurrentLogs=genericResult.getLogs();//今天已签过到if(genericResult.isHasCheckIn()){signInImageView.setEnabled(false);signInImageView.setImageResource(R.drawable.icon_checked_logtoday);logTodayBgImageView.setImageResource(R.drawable.bg_logtoday_flower_open);}else{signInImageView.setEnabled(true);}}else{super.onFailure(genericResult);}}};}/***设置ViewPager数*@paramserverTime*/privatevoidviewpager(longserverTime){CalendarView[]views=newCalendarView[3];for(inti=0;i<3;i++){views[i]=newCalendarView(this,this,serverTime);}adapter=newCalendarViewAdapter<>(views);mShowViews=adapter.getAllItems();setViewPager();//(解决请求玩数据第一页不显示问题:没有对当前CalenderView执行onDraw方法,是因为CalenderView没有在UI线程)mViewPager.post(newRunnable(){@Overridepublicvoidrun(){mShowViews[0].setCurrentCheckInDays(currentLogs);}});}/***设置ViewPager其他特性*/privatevoidsetViewPager(){mViewPager.setAdapter(adapter);mViewPager.setCurrentItem(498);mViewPager.setOnPageChangeListener(newViewPager.OnPageChangeListener(){@OverridepublicvoidonPageSelected(intposition){measureDirection(position);updateCalendarView(position);}@OverridepublicvoidonPageScrolled(intarg0,floatarg1,intarg2){}@OverridepublicvoidonPageScrollStateChanged(intarg0){}});}/***计算方向**@paramarg0*/privatevoidmeasureDirection(intarg0){if(arg0>mCurrentIndex){mDirection=SildeDirection.RIGHT;}elseif(arg0<mCurrentIndex){mDirection=SildeDirection.LEFT;}mCurrentIndex=arg0;}//更新日历视图privatevoidupdateCalendarView(intarg0){if(mDirection==SildeDirection.RIGHT){mShowViews[arg0%mShowViews.length].rightSlide();}elseif(mDirection==SildeDirection.LEFT){mShowViews[arg0%mShowViews.length].leftSlide();}mDirection=SildeDirection.NO_SILDE;}/***月份切换*@paramdate*/@OverridepublicvoidchangeDate(CustomDateModeldate){monthText.setText(date.getYear()+"-"+date.getMonth());getMonthLogs(date);}/***当前页面签到日期查询*@paramdate*@return*/privatevoidgetMonthLogs(CustomDateModeldate){//请求成功publicvoidonSuccess(MonthSignLogModelgenericResult){super.onSuccess(genericResult);if(genericResult.getCode()==GenericResult.SUCCESS){if(genericResult.getLogs()!=null){mShowViews[mViewPager.getCurrentItem()%mShowViews.length].setCheckInDays(genericResult.getLogs());}}else{super.onFailure(genericResult);}}});}@OverridepublicvoidonClick(Viewv){switch(v.getId()){caseR.id.last_month:mViewPager.setCurrentItem(mViewPager.getCurrentItem()-1);break;caseR.id.next_month:mViewPager.setCurrentItem(mViewPager.getCurrentItem()+1);break;caseR.id.log_today_check:if(mViewPager.getCurrentItem()!=498){if(currentLogs!=null){mShowViews[mViewPager.getCurrentItem()%mShowViews.length].setCurrentCheckInDays(currentLogs);}else{mShowViews[mViewPager.getCurrentItem()%mShowViews.length].currentUpdate();}mShowViews[mViewPager.getCurrentItem()%mShowViews.length].SignIn();}else{mShowViews[0].SignIn();}//请求成功@OverridepublicvoidonSuccess(CheckInResultgenericResult){super.onSuccess(genericResult);if(genericResult.getCode()==GenericResult.SUCCESS){//签到成功setClickDate(genericResult);}else{confirmDialog.setConfirmContent(genericResult.getMessage());}confirmDialog.show();confirmDialog.setRightButtonClickListener(newView.OnClickListener(){@OverridepublicvoidonClick(Viewv){confirmDialog.dismiss();startActivity(newIntent(CheckInActivity.this,MyCoupon.class));}});}else{super.onFailure(genericResult);}}});break;}}/***设置点击数据*@paramgenericResult*/privatevoidsetClickDate(CheckInResultgenericResult){if(genericResult.getCouponInfoModel()!=null){CouponInfoModelmodel=genericResult.getCouponInfoModel();couponRmb.setText("¥"+model.getAmount());couponArea.setText(model.getScopInfo());}if(mCheckInUtils.getCurrentTime().equals(monthText.getText())&&genericResult.getJingYan()>0){anim(genericResult.getJingYan());}signInImageView.setEnabled(false);signInImageView.setImageResource(R.drawable.icon_checked_logtoday);logTodayBgImageView.setImageResource(R.drawable.bg_logtoday_flower_open);}/***经验值增加动画*/privatevoidanim(intjinYan){animText.setText(getResources().getString(R.string.log_today_experience)+jinYan);animText.setVisibility(View.VISIBLE);AnimationSetset=newAnimationSet(false);TranslateAnimationtranslateAnimation=newTranslateAnimation(0.1f,0.1f,0.1f,-200f);translateAnimation.setDuration(2500);translateAnimation.setFillAfter(true);AlphaAnimationalphaAnimation=newAlphaAnimation(1,0);alphaAnimation.setDuration(1000);alphaAnimation.setFillAfter(true);set.addAnimation(alphaAnimation);set.addAnimation(translateAnimation);animText.setAnimation(set);set.setAnimationListener(newAnimation.AnimationListener(){@OverridepublicvoidonAnimationStart(Animationanimation){}@OverridepublicvoidonAnimationEnd(Animationanimation){animText.setVisibility(View.GONE);}@OverridepublicvoidonAnimationRepeat(Animationanimation){}});}@OverridepublicbooleanonCreateOptionsMenu(Menumenu){if(rules!=null){getMenuInflater().inflate(R.menu.menu_log_today,menu);}returnsuper.onCreateOptionsMenu(menu);}@OverridepublicbooleanonOptionsItemSelected(MenuItemitem){switch(item.getItemId()){caseR.id.log_gift:if(checkInRuleDialog==null){checkInRuleDialog=newCheckInRuleDialog(this);if(rules!=null){checkInRuleDialog.setRulesText(rules);}}checkInRuleDialog.show();break;default:break;}returnsuper.onOptionsItemSelected(item);}}


5.XML :删除了很多跟公司资源相关的东西

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context="oct.mama.activity.CheckInActivity"><RelativeLayoutandroid:id="@+id/log_today_day"android:layout_below="@+id/log_today_istrue"android:layout_width="match_parent"android:layout_height="32dp"android:background="@color/log_today_calendar_bg"android:layout_marginRight="5dp"android:layout_marginLeft="5dp"><ImageViewandroid:id="@+id/last_month"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:paddingTop="10dp"android:paddingBottom="5dp"android:paddingLeft="10dp"android:paddingRight="20dp"android:src="@drawable/icon_last_month"/><ImageViewandroid:id="@+id/next_month"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_alignBottom="@+id/last_month"android:src="@drawable/icon_next_month"android:paddingTop="10dp"android:paddingBottom="5dp"android:paddingLeft="10dp"android:paddingRight="20dp"/><TextViewandroid:id="@+id/log_today_time"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="@color/common_white"android:layout_centerHorizontal="true"android:layout_marginTop="15dp"/></RelativeLayout><TableLayoutandroid:id="@+id/log_today_week"android:layout_below="@+id/log_today_day"android:layout_width="match_parent"android:layout_height="25dip"android:layout_marginLeft="5dp"android:layout_marginRight="5dp"android:paddingBottom="5dp"android:background="@color/log_today_calendar_bg"><TableRow><TextViewandroid:layout_width="0dp"android:layout_height="fill_parent"android:layout_weight="1"android:gravity="center"android:textSize="15sp"android:text="@string/sunday"android:textColor="@color/common_white"/><TextViewandroid:layout_width="0dp"android:layout_height="fill_parent"android:layout_weight="1"android:gravity="center"android:textSize="15sp"android:text="@string/monday"android:textColor="@color/common_white"/><TextViewandroid:layout_width="0dp"android:layout_height="fill_parent"android:layout_weight="1"android:gravity="center"android:textSize="15sp"android:text="@string/thesday"android:textColor="@color/common_white"/><TextViewandroid:layout_width="0dp"android:layout_height="fill_parent"android:layout_weight="1"android:gravity="center"android:textSize="15sp"android:text="@string/wednesday"android:textColor="@color/common_white"/><TextViewandroid:layout_width="0dp"android:layout_height="fill_parent"android:layout_weight="1"android:gravity="center"android:textSize="15sp"android:text="@string/thursday"android:textColor="@color/common_white"/><TextViewandroid:layout_width="0dp"android:layout_height="fill_parent"android:layout_weight="1"android:gravity="center"android:textSize="15sp"android:text="@string/friday"android:textColor="@color/common_white"/><TextViewandroid:layout_width="0dp"android:layout_height="fill_parent"android:layout_weight="1"android:gravity="center"android:textSize="15sp"android:text="@string/saturday"android:textColor="@color/common_white"/></TableRow></TableLayout><RelativeLayoutandroid:id="@+id/vp_relative"android:layout_below="@+id/log_today_week"android:layout_width="match_parent"android:layout_height="wrap_content"><android.support.v4.view.ViewPagerandroid:id="@+id/vp_calendar"android:layout_width="match_parent"android:layout_height="225dp"android:paddingTop="15dp"android:layout_marginLeft="5dp"android:layout_marginRight="5dp"android:background="@color/log_today_calendar_bg"android:layout_gravity="center"></android.support.v4.view.ViewPager><Viewandroid:layout_width="match_parent"android:layout_height="0.5dp"android:layout_marginRight="5dp"android:layout_marginLeft="5dp"android:background="@color/log_today_green_line"/><TextViewandroid:id="@+id/check_in_anim"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:textSize="16sp"android:visibility="gone"android:textColor="@color/log_today_experience_text"/></RelativeLayout><ImageViewandroid:id="@+id/log_today_check"android:layout_below="@+id/vp_relative"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:src="@drawable/btn_log_today_selector"android:layout_marginTop="20dp"android:layout_marginBottom="20dp"android:visibility="gone"/></RelativeLayout></LinearLayout>


在此,感谢zou128865,没有看他的博客我不可能很快就做出自己的东西,上面代码是编译通不过的缺少了一下资源文件,我也没有办法贴出来,大家拿到代码认真的分析分析加上自己的资源就能跑了。