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 f8d8ac5 commit e3c1856
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 25 deletions.
15 changes: 1 addition & 14 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.NCalendarActivity"
android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".activity.MonthNotSelectActivity"
android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity android:name=".activity.MonthSelectActivity"
android:configChanges="orientation|screenSize|keyboardHidden"/>
<activity
android:name=".activity.NCalendarActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />
<activity
android:name=".activity.MonthNotSelectActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />
<activity
android:name=".activity.MonthSelectActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />
<activity
android:name=".activity.WeekActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />


</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ public void defaultSelect(View v) {
public void notDefaultSelect(View v) {
startActivity(new Intent(this, MonthNotSelectActivity.class));
}
public void week(View v) {
startActivity(new Intent(this, WeekActivity.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
tv_date = (TextView) findViewById(R.id.tv_date);


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



recyclerView.setLayoutManager(new LinearLayoutManager(this));
AAAdapter aaAdapter = new AAAdapter(this);
recyclerView.setAdapter(aaAdapter);
Expand Down
46 changes: 46 additions & 0 deletions app/src/main/java/necer/ncalendardemo/activity/WeekActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package necer.ncalendardemo.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.necer.ncalendar.calendar.WeekCalendar;

import necer.ncalendardemo.R;

/**
* Created by 闫彬彬 on 2017/10/30.
* QQ:619008099
*/

public class WeekActivity extends Activity {


private WeekCalendar weekCalendar;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_week);

weekCalendar = (WeekCalendar) findViewById(R.id.weekCalendar);

weekCalendar.setDateInterval("2017-10-10","2017-11-20");
/* weekCalendar.post(new Runnable() {
@Override
public void run() {
weekCalendar.setOnWeekCalendarChangedListener(new OnWeekCalendarChangedListener() {
@Override
public void onWeekCalendarChanged(DateTime dateTime) {
MyLog.d("dateTime::" + dateTime);
}
});
weekCalendar.setDate("2017-11-5");
}
});*/



}
}
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
android:text="默认选中的月日历"
android:onClick="defaultSelect"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="周日历"
android:onClick="week"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout/activity_week.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">



<com.necer.ncalendar.calendar.WeekCalendar
android:id="@+id/weekCalendar"
android:layout_width="match_parent"
android:layout_height="50dp"></com.necer.ncalendar.calendar.WeekCalendar>

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public abstract class CalendarPager extends ViewPager {
protected DateTime lastSelectDateTime;//上次选中的datetime
protected boolean isDefaultSelect = true;//是否默认选中


private OnPageChangeListener onPageChangeListener;

public CalendarPager(Context context) {
this(context, null);
}
Expand Down Expand Up @@ -68,6 +71,7 @@ public CalendarPager(Context context, AttributeSet attrs) {
Attrs.holidayColor = ta.getColor(R.styleable.NCalendar_holidayColor, getResources().getColor(R.color.holidayColor));
Attrs.workdayColor = ta.getColor(R.styleable.NCalendar_workdayColor, getResources().getColor(R.color.workdayColor));

Attrs.backgroundColor = ta.getColor(R.styleable.NCalendar_backgroundColor, getResources().getColor(R.color.white));

String firstDayOfWeek = ta.getString(R.styleable.NCalendar_firstDayOfWeek);
String defaultCalendar = ta.getString(R.styleable.NCalendar_defaultCalendar);
Expand All @@ -85,6 +89,17 @@ public CalendarPager(Context context, AttributeSet attrs) {
startDateTime = new DateTime(startString == null ? "1901-01-01" : startString);
endDateTime = new DateTime(endString == null ? "2099-12-31" : endString);

setDateInterval(null, null);
}

public void setDateInterval(String startString,String endString) {
if (startString != null && !"".equals(startString)) {
startDateTime = new DateTime(startString);
}
if (endString != null && !"".equals(endString)) {
endDateTime = new DateTime(endString);
}


if (mInitialDateTime.getMillis() < startDateTime.getMillis() || mInitialDateTime.getMillis() > endDateTime.getMillis()) {
throw new RuntimeException(getResources().getString(R.string.range_date));
Expand All @@ -94,9 +109,15 @@ public CalendarPager(Context context, AttributeSet attrs) {
setAdapter(calendarAdapter);
setCurrentItem(mCurrPage);

addOnPageChangeListener(new OnPageChangeListener() {

if (onPageChangeListener != null) {
removeOnPageChangeListener(onPageChangeListener);
}

onPageChangeListener = new OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override
Expand All @@ -106,10 +127,11 @@ public void onPageSelected(int position) {

@Override
public void onPageScrollStateChanged(int state) {
}
});

}
};

addOnPageChangeListener(onPageChangeListener);

getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
Expand All @@ -119,10 +141,12 @@ public void onGlobalLayout() {
}
});

setBackgroundColor(Color.WHITE);
setBackgroundColor(Attrs.backgroundColor);
}




protected abstract CalendarAdapter getCalendarAdapter();

protected abstract void initCurrentCalendarView(int position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public void onAnimationRepeat(Animator animation) {
});
}

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


@Override
public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) {
Expand Down
2 changes: 2 additions & 0 deletions ncalendar/src/main/java/com/necer/ncalendar/utils/Attrs.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public class Attrs {
public static int holidayColor;
public static int workdayColor;

public static int backgroundColor;

}
1 change: 1 addition & 0 deletions ncalendar/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<attr name="isShowHoliday" format="boolean" />
<attr name="holidayColor" format="color" />
<attr name="workdayColor" format="color" />
<attr name="backgroundColor" format="color" />

</declare-styleable>
</resources>
1 change: 1 addition & 0 deletions ncalendar/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<color name="holidayColor">#39AF81</color>
<color name="workdayColor">#EC7230</color>
<color name="pointColor">#B2B2B2</color>
<color name="white">#ffffff</color>


</resources>

0 comments on commit e3c1856

Please sign in to comment.