Skip to content

Commit

Permalink
增加代码设置日期区间
Browse files Browse the repository at this point in the history
  • Loading branch information
yanbinbin committed Oct 30, 2017
1 parent 3a7d6cd commit 53462d3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.necer.ncalendar.calendar.NCalendar;
import com.necer.ncalendar.listener.OnCalendarChangedListener;
import com.necer.ncalendar.utils.MyLog;

import org.joda.time.DateTime;

Expand Down Expand Up @@ -52,7 +53,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
tv_date = (TextView) findViewById(R.id.tv_date);


// ncalendar.setDateInterval("2017-04-02","2018-01-01");
ncalendar.setDateInterval("2017-04-02","2018-01-01");



Expand Down Expand Up @@ -84,6 +85,8 @@ public void run() {
public void onCalendarChanged(DateTime dateTime) {
tv_month.setText(dateTime.getMonthOfYear() + "月");
tv_date.setText(dateTime.getYear() + "年" + dateTime.getMonthOfYear() + "月" + dateTime.getDayOfMonth() + "日");

MyLog.d("dateTime::" + dateTime);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ public CalendarPager(Context context, AttributeSet attrs) {
endDateTime = new DateTime(endString == null ? "2099-12-31" : endString);

setDateInterval(null, null);

getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
initCurrentCalendarView(mCurrPage);
getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});

setBackgroundColor(Attrs.backgroundColor);
}

public void setDateInterval(String startString,String endString) {
Expand Down Expand Up @@ -133,15 +143,6 @@ public void onPageScrollStateChanged(int state) {

addOnPageChangeListener(onPageChangeListener);

getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
initCurrentCalendarView(mCurrPage);
getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});

setBackgroundColor(Attrs.backgroundColor);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ public void onAnimationRepeat(Animator animation) {
});
}

public void setDateInterval(String startString,String endString) {
monthCalendar.setDateInterval(startString,endString);
weekCalendar.setDateInterval(startString,endString);
}



@Override
Expand Down Expand Up @@ -567,4 +564,14 @@ public void toLastPager() {
weekCalendar.toLastPager();
}
}

/**
* 设置日期区间
* @param startString
* @param endString
*/
public void setDateInterval(String startString,String endString) {
monthCalendar.setDateInterval(startString,endString);
weekCalendar.setDateInterval(startString,endString);
}
}

0 comments on commit 53462d3

Please sign in to comment.