├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── dictionaries
│ └── Administrator.xml
├── encodings.xml
├── gradle.xml
├── inspectionProfiles
│ ├── Project_Default.xml
│ └── profiles_settings.xml
├── markdown-navigator.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
├── smartfox_info.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── muzi
│ │ └── calendarrangeselect
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── muzi
│ │ │ └── calendarrangeselect
│ │ │ └── Main2Activity.java
│ └── res
│ │ ├── layout
│ │ └── activity_main2.xml
│ │ ├── mipmap-hdpi
│ │ ├── bg_white_circle.png
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── muzi
│ └── calendarrangeselect
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── neisha
│ │ └── library
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── neisha
│ │ │ └── library
│ │ │ ├── adapter
│ │ │ ├── DayTimeAdapter.java
│ │ │ └── MonthTimeAdapter.java
│ │ │ ├── entity
│ │ │ ├── DayTimeEntity.java
│ │ │ ├── MonthTimeEntity.java
│ │ │ └── UpdataCalendar.java
│ │ │ ├── holder
│ │ │ ├── DayTimeViewHolder.java
│ │ │ └── MonthTimeViewHolder.java
│ │ │ └── widget
│ │ │ ├── CalendarView.java
│ │ │ ├── EmptyDrawable.java
│ │ │ ├── NsLinearLayoutManager.java
│ │ │ └── PagingScrollHelper.java
│ └── res
│ │ ├── drawable
│ │ ├── bg_time_start.xml
│ │ ├── bg_time_startstop.xml
│ │ └── bg_time_stop.xml
│ │ ├── layout
│ │ ├── item_day.xml
│ │ └── item_rmonth.xml
│ │ └── values
│ │ ├── colors.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── neisha
│ └── library
│ └── ExampleUnitTest.java
├── preview
├── app-debug.apk
└── img.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/dictionaries/Administrator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | Android
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/smartfox_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CalendarRangeSelect
2 | Android日历连续区间选择
3 |
4 | ## 效果预览
5 | 
6 |
7 | ## Gradle配置
8 |
9 | * Step 1. build.gradle(Project:***)添加
10 | ```
11 | allprojects {
12 | repositories {
13 | ...
14 | maven { url 'https://jitpack.io' }
15 | }
16 | }
17 |
18 | ```
19 |
20 | * Step 2. build.gradle(Module:app)
21 | ```
22 | dependencies {
23 | compile 'com.github.TurnTears:CalendarRangeSelect:1.1.1'
24 | }
25 |
26 | ```
27 |
28 | ## 基本使用
29 |
30 | * 1、布局文件
31 | ```
32 |
36 | ```
37 |
38 | * 2、Activity
39 | ```
40 | calendarView = (CalendarView) findViewById(R.id.calendarView);
41 |
42 | //必须在setOnCalendarSelect()之前
43 | calendarView.setMonthNum(12);
44 |
45 | //回调
46 | calendarView.setOnCalendarSelect(new CalendarView.onCalendarSelect() {
47 | @Override
48 | public void OnMonthSwhit(MonthTimeEntity entity) {
49 | textView.setText(entity.toString());
50 | }
51 |
52 | @Override
53 | public void OnDaySelect(DayTimeEntity startDay, DayTimeEntity endDay, int day) {
54 | Toast.makeText(Main2Activity.this, "开始时间:"
55 | + startDay.toString() + "\n结束时间:"
56 | + endDay.toString() + "\n共"
57 | + day + "天", Toast.LENGTH_SHORT).show();
58 |
59 | startTime.setText(startDay.getMonth() + "月" + startDay.getDay() + "日" + "\n");
60 | stopTime.setText(endDay.getMonth() + "月" + endDay.getDay() + "日");
61 | }
62 | });
63 |
64 | @Override
65 | protected void onDestroy() {
66 | super.onDestroy();
67 | calendarView.onDestory();
68 | }
69 | ```
70 |
71 | * 这样就完成了,可以开始点击了
72 |
73 |
74 |
75 | ## CalendarView基本功能介绍
76 | * 设置日历显示的月份数量默认为6个月
77 | ```
78 | calendarView.setMonthNum(12);
79 | ```
80 |
81 | * 设置不可点击的天数, 从今天以后开始计算,在途状态不可点击
82 | ```
83 | calendarView.setUnableSelectDay(2);
84 | ```
85 |
86 | * 设置连续选择
87 | ```
88 | calendarView.setMultipleChoice(6);
89 | ```
90 |
91 |
92 | ## 感谢
93 | * 一行代码让RecyclerView分页滚动 [HorizontalPage](https://github.com/zhuguohui/HorizontalPage)
94 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 |
6 | dependencies {
7 | classpath 'me.tatarka:gradle-retrolambda:3.2.5'
8 | }
9 | }
10 |
11 | apply plugin: 'com.android.application'
12 | apply plugin: 'me.tatarka.retrolambda'
13 |
14 | android {
15 | compileSdkVersion 25
16 | buildToolsVersion "26.0.0"
17 | defaultConfig {
18 | applicationId "com.muzi.calendarrangeselect"
19 | minSdkVersion 19
20 | targetSdkVersion 25
21 | versionCode 1
22 | versionName "1.0"
23 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
24 | }
25 | buildTypes {
26 | release {
27 | minifyEnabled false
28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
29 | }
30 | }
31 | compileOptions {
32 | targetCompatibility 1.8
33 | sourceCompatibility 1.8
34 | }
35 | }
36 |
37 | dependencies {
38 | compile fileTree(include: ['*.jar'], dir: 'libs')
39 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
40 | exclude group: 'com.android.support', module: 'support-annotations'
41 | })
42 | compile 'com.android.support:appcompat-v7:25.3.1'
43 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
44 | testCompile 'junit:junit:4.12'
45 | compile project(':library')
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/muzi/calendarrangeselect/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.muzi.calendarrangeselect;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.muzi.calendarrangeselect", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/muzi/calendarrangeselect/Main2Activity.java:
--------------------------------------------------------------------------------
1 | package com.muzi.calendarrangeselect;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.widget.Button;
6 | import android.widget.EditText;
7 | import android.widget.TextView;
8 | import android.widget.Toast;
9 |
10 | import com.neisha.library.entity.DayTimeEntity;
11 | import com.neisha.library.entity.MonthTimeEntity;
12 | import com.neisha.library.widget.CalendarView;
13 |
14 |
15 | public class Main2Activity extends AppCompatActivity {
16 |
17 | private TextView textView;
18 | private TextView startTime; //开始时间
19 | private TextView stopTime; //结束时间
20 | private Button btn1, btn2;
21 | private EditText edit1, edit2;
22 | private CalendarView calendarView;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_main2);
28 |
29 | textView = (TextView) findViewById(R.id.month);
30 |
31 | startTime = (TextView) findViewById(R.id.plan_time_txt_start);
32 | stopTime = (TextView) findViewById(R.id.plan_time_txt_stop);
33 |
34 | btn1 = (Button) findViewById(R.id.btn1);
35 | btn2 = (Button) findViewById(R.id.btn2);
36 | edit1 = (EditText) findViewById(R.id.edit1);
37 | edit2 = (EditText) findViewById(R.id.edit2);
38 |
39 | btn1.setOnClickListener(v ->
40 | calendarView.setUnableSelectDay(Integer.parseInt(edit1.getText().toString()))
41 | );
42 |
43 | btn2.setOnClickListener(v ->
44 | calendarView.setMultipleChoice(Integer.parseInt(edit2.getText().toString()))
45 | );
46 |
47 | initCalendar();
48 | }
49 |
50 | private void initCalendar() {
51 | calendarView = (CalendarView) findViewById(R.id.calendarView);
52 |
53 |
54 | calendarView.setMonthNum(12);
55 |
56 | calendarView.setOnCalendarSelect(new CalendarView.onCalendarSelect() {
57 | @Override
58 | public void OnMonthSwhit(MonthTimeEntity entity) {
59 | textView.setText(entity.toString());
60 | }
61 |
62 | @Override
63 | public void OnDaySelect(DayTimeEntity startDay, DayTimeEntity endDay, int day) {
64 | Toast.makeText(Main2Activity.this, "开始时间:"
65 | + startDay.toString() + "\n结束时间:"
66 | + endDay.toString() + "\n共"
67 | + day + "天", Toast.LENGTH_SHORT).show();
68 |
69 | startTime.setText(startDay.getMonth() + "月" + startDay.getDay() + "日" + "\n");
70 | stopTime.setText(endDay.getMonth() + "月" + endDay.getDay() + "日");
71 | }
72 | });
73 | }
74 |
75 | @Override
76 | protected void onDestroy() {
77 | super.onDestroy();
78 | calendarView.onDestory();
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main2.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
12 |
13 |
18 |
19 |
25 |
26 |
27 |
31 |
32 |
37 |
38 |
44 |
45 |
46 |
47 |
51 |
52 |
60 |
61 |
70 |
71 |
82 |
83 |
84 |
92 |
93 |
97 |
98 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/bg_white_circle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/app/src/main/res/mipmap-hdpi/bg_white_circle.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #ffffff
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CalendarRangeSelect
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/muzi/calendarrangeselect/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.muzi.calendarrangeselect;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | maven { url 'https://jitpack.io' }
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Aug 08 20:16:06 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile 'com.android.support:appcompat-v7:26.+'
30 | testCompile 'junit:junit:4.12'
31 | compile 'de.greenrobot:eventbus:3+'
32 | compile 'com.android.support:design:26+'
33 | }
34 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/neisha/library/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.neisha.library;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.neisha.library.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/library/src/main/java/com/neisha/library/adapter/DayTimeAdapter.java:
--------------------------------------------------------------------------------
1 | package com.neisha.library.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.neisha.library.R;
10 | import com.neisha.library.entity.DayTimeEntity;
11 | import com.neisha.library.entity.UpdataCalendar;
12 | import com.neisha.library.holder.DayTimeViewHolder;
13 |
14 | import java.util.ArrayList;
15 | import java.util.Calendar;
16 |
17 | import de.greenrobot.event.EventBus;
18 |
19 |
20 | import static com.neisha.library.entity.UpdataCalendar.inTransitDay;
21 | import static com.neisha.library.entity.UpdataCalendar.tenancyTerm;
22 |
23 | /**
24 | * Created by 木子 on 2017/08/08.
25 | */
26 | public class DayTimeAdapter extends RecyclerView.Adapter {
27 |
28 | private ArrayList days;
29 | private Context context;
30 |
31 | private Calendar calendarToday;//手机当前日期
32 | private Calendar calendarLimit;//当前日期+在途时间
33 | private Calendar calendarCurre;//item日期
34 | private Calendar calendarStart;//点击开始日期
35 | private Calendar calendarEnd;//结束日期
36 |
37 |
38 | public DayTimeAdapter(ArrayList days, Context context) {
39 | this.days = days;
40 | this.context = context;
41 | calendarToday = Calendar.getInstance();
42 | calendarLimit = Calendar.getInstance();
43 | calendarCurre = Calendar.getInstance();
44 | calendarStart = Calendar.getInstance();
45 | calendarEnd = Calendar.getInstance();
46 | calendarLimit.add(Calendar.DAY_OF_MONTH, inTransitDay);
47 | }
48 |
49 | @Override
50 | public DayTimeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
51 | DayTimeViewHolder ret = null;
52 | // 不需要检查是否复用,因为只要进入此方法,必然没有复用
53 | // 因为RecyclerView 通过Holder检查复用
54 | View v = LayoutInflater.from(context).inflate(R.layout.item_day, parent, false);
55 | ret = new DayTimeViewHolder(v);
56 |
57 | return ret;
58 | }
59 |
60 | @Override
61 | public void onBindViewHolder(final DayTimeViewHolder holder, final int position) {
62 | final DayTimeEntity dayTimeEntity = days.get(position);
63 | calendarCurre.set(dayTimeEntity.getYear(), dayTimeEntity.getMonth() - 1, dayTimeEntity.getDay());
64 | //显示日期
65 | if (dayTimeEntity.getDay() != 0) {
66 | holder.select_ly_day.setVisibility(View.VISIBLE);
67 | holder.select_txt_day.setText(String.valueOf(dayTimeEntity.getDay()));
68 | //当前日期+在途日期之前的禁止点击
69 | if (calendarCurre.after(calendarLimit)) {
70 | //当前日期在 在途日期之后
71 | holder.select_ly_day.setEnabled(true);
72 | } else {
73 | holder.select_ly_day.setEnabled(false);
74 | }
75 | } else {
76 | holder.select_ly_day.setEnabled(false);
77 | holder.select_ly_day.setVisibility(View.INVISIBLE);
78 | }
79 |
80 | holder.select_ly_day.setOnClickListener(new View.OnClickListener() {
81 | @Override
82 | public void onClick(View v) {
83 | if (UpdataCalendar.startDay.getYear() == 0) { // 第一次点击开始的位置,因为开始默认参数是 0,0,0,0
84 | setStartDay(dayTimeEntity, position);
85 | } else if (UpdataCalendar.startDay.getYear() > 0 && UpdataCalendar.stopDay.getYear() == -1) { //已经点击了开始 ,点击结束位置,(默认结束位置-1,-1,-1,-1 说明还没有点击结束位置)
86 | if (dayTimeEntity.getYear() > UpdataCalendar.startDay.getYear()) {
87 | //如果选中的年份大于开始的年份,说明结束日期肯定大于开始日期 ,合法的 ,将该item的天数的 信息 赋给 结束日期
88 | setStopDay(dayTimeEntity, position);
89 | } else if (dayTimeEntity.getYear() == UpdataCalendar.startDay.getYear()) {
90 | //如果选中的年份 等于 选中的年份
91 | if (dayTimeEntity.getMonth() > UpdataCalendar.startDay.getMonth()) {
92 | //如果改item的天数的月份大于开始日期的月份,说明结束日期肯定大于开始日期 ,合法的 ,将该item的天数的 信息 赋给 结束日期
93 | setStopDay(dayTimeEntity, position);
94 | } else if (dayTimeEntity.getMonth() == UpdataCalendar.startDay.getMonth()) {
95 | //年份月份 都相等
96 | if (dayTimeEntity.getDay() >= UpdataCalendar.startDay.getDay()) {
97 | //判断天数 ,如果 该item的天数的 日子大于等于 开始日期的 日子 ,说明结束日期合法的 ,将该item的天数的 信息 赋给 结束日期
98 | setStopDay(dayTimeEntity, position);
99 | } else {
100 | //天数小与初始 从新选择开始 ,结束日期重置,开始日期为当前的位置的天数的信息
101 | resetStopDay();
102 | setStartDay(dayTimeEntity, position);
103 | }
104 | } else {
105 | //选中的月份 比开始日期的月份还小,说明 结束位置不合法,结束日期重置,开始日期为当前的位置的天数的信息
106 | resetStopDay();
107 | setStartDay(dayTimeEntity, position);
108 | }
109 |
110 | } else {
111 | //选中的年份 比开始日期的年份还小,说明 结束位置不合法,结束日期重置,开始日期为当前的位置的天数的信息
112 | resetStopDay();
113 | setStartDay(dayTimeEntity, position);
114 | }
115 | } else if (UpdataCalendar.startDay.getYear() > 0 && UpdataCalendar.startDay.getYear() > 1) {
116 | //已经点击开始和结束 第三次点击 ,重新点击开始
117 | resetStopDay();
118 | setStartDay(dayTimeEntity, position);
119 | }
120 | EventBus.getDefault().post(new UpdataCalendar()); // 发消息刷新适配器,目的为了显示日历上各个日期的背景颜色
121 | }
122 | });
123 |
124 |
125 | if (UpdataCalendar.startDay.getYear() == dayTimeEntity.getYear() && UpdataCalendar.startDay.getMonth() == dayTimeEntity.getMonth() && UpdataCalendar.startDay.getDay() == dayTimeEntity.getDay()
126 | && UpdataCalendar.stopDay.getYear() == dayTimeEntity.getYear() && UpdataCalendar.stopDay.getMonth() == dayTimeEntity.getMonth() && UpdataCalendar.stopDay.getDay() == dayTimeEntity.getDay()) {
127 | //开始和结束同一天
128 | setStartAndrStopBackGround(holder);
129 | setTextState(holder, context.getResources().getString(R.string.text_calendar_one));
130 | setTextSelectColor(holder);
131 | } else if (UpdataCalendar.startDay.getYear() == dayTimeEntity.getYear() && UpdataCalendar.startDay.getMonth() == dayTimeEntity.getMonth() && UpdataCalendar.startDay.getDay() == dayTimeEntity.getDay()) {
132 | //该item是 开始日期
133 | setStartBackGround(holder);
134 | setTextState(holder, context.getResources().getString(R.string.text_calendar_start));
135 | setTextSelectColor(holder);
136 | } else if (UpdataCalendar.stopDay.getYear() == dayTimeEntity.getYear() && UpdataCalendar.stopDay.getMonth() == dayTimeEntity.getMonth() && UpdataCalendar.stopDay.getDay() == dayTimeEntity.getDay()) {
137 | //该item是 结束日期
138 | setStopBackGround(holder);
139 | setTextState(holder, context.getResources().getString(R.string.text_calendar_stop));
140 | setTextSelectColor(holder);
141 | } else if (dayTimeEntity.getMonthPosition() >= UpdataCalendar.startDay.getMonthPosition() && dayTimeEntity.getMonthPosition() <= UpdataCalendar.stopDay.getMonthPosition()) {
142 | //处于开始和结束之间的点
143 | setTextState(holder, null);
144 | if (dayTimeEntity.getMonthPosition() == UpdataCalendar.startDay.getMonthPosition() && dayTimeEntity.getMonthPosition() == UpdataCalendar.stopDay.getMonthPosition()) {
145 | //开始和结束是一个月份
146 | if (dayTimeEntity.getDay() > UpdataCalendar.startDay.getDay() && dayTimeEntity.getDay() < UpdataCalendar.stopDay.getDay()) {
147 | setBetweenBackGround(holder);
148 | setTextSelectColor(holder);
149 | } else {
150 | resetBackGround(holder);
151 | setTextUnSelectColor(holder);
152 | }
153 | } else if (UpdataCalendar.startDay.getMonthPosition() != UpdataCalendar.stopDay.getMonthPosition()) {
154 | // 日期和 开始 不是一个月份
155 | if (dayTimeEntity.getMonthPosition() == UpdataCalendar.startDay.getMonthPosition() && dayTimeEntity.getDay() > UpdataCalendar.startDay.getDay()) {
156 | //和初始相同月 天数往后
157 | setBetweenBackGround(holder);
158 | setTextSelectColor(holder);
159 | } else if (dayTimeEntity.getMonthPosition() == UpdataCalendar.stopDay.getMonthPosition() && dayTimeEntity.getDay() < UpdataCalendar.stopDay.getDay()) {
160 | //和结束相同月 天数往前
161 | setBetweenBackGround(holder);
162 | setTextSelectColor(holder);
163 | } else if (dayTimeEntity.getMonthPosition() != UpdataCalendar.startDay.getMonthPosition() && dayTimeEntity.getMonthPosition() != UpdataCalendar.stopDay.getMonthPosition()) {
164 | //和 开始结束都不是同一个月
165 | setBetweenBackGround(holder);
166 | setTextSelectColor(holder);
167 | } else {
168 | resetBackGround(holder);
169 | setTextUnSelectColor(holder);
170 |
171 | }
172 | }
173 | } else {
174 | resetBackGround(holder);
175 | setTextState(holder, null);
176 | setTextUnSelectColor(holder);
177 | }
178 |
179 |
180 | if (calendarCurre.before(calendarLimit) || calendarCurre.equals(calendarLimit)) {
181 | holder.select_txt_day.setTextColor(context.getResources().getColor(R.color.calendar_text_unable));
182 | holder.select_txt_day_state.setTextColor(context.getResources().getColor(R.color.calendar_text_unable));
183 | }
184 |
185 | //在途
186 | if (calendarCurre.after(calendarToday) && calendarCurre.before(calendarLimit) || calendarCurre.equals(calendarLimit)) {
187 | setTextState(holder, context.getResources().getString(R.string.text_calendar_transit));
188 | }
189 |
190 | //今日
191 | if (calendarCurre.equals(calendarToday)) {
192 | setTextState(holder, context.getResources().getString(R.string.text_calendar_today));
193 | }
194 |
195 | }
196 |
197 |
198 | /*
199 | packageDay-选中区间范围
200 | 给定选中区间范围和开始时间,计算结束时间范围
201 | */
202 | private void calculateStopDay(int position) {
203 | calendarStart.set(UpdataCalendar.startDay.getYear(), UpdataCalendar.startDay.getMonth() - 1, UpdataCalendar.startDay.getDay());
204 | calendarEnd.set(UpdataCalendar.startDay.getYear(), UpdataCalendar.startDay.getMonth() - 1, UpdataCalendar.startDay.getDay());
205 | calendarEnd.add(Calendar.DAY_OF_MONTH, tenancyTerm);
206 | for (DayTimeEntity day : MonthTimeAdapter.allDays) {
207 | if (day.getYear() == (int) calendarEnd.get(Calendar.YEAR) && day.getMonth() == (calendarEnd.get(Calendar.MONTH) + 1) && day.getDay() == (int) calendarEnd.get(Calendar.DAY_OF_MONTH)) {
208 | setStopDay(day, position);
209 | break;
210 | }
211 | }
212 | }
213 |
214 |
215 | /*
216 | calculateStopDay优化版
217 | packageDay-选中区间范围
218 | 给定选中区间范围和开始时间,计算结束时间范围
219 | */
220 | private void calculateStopDayUpdate(int position) {
221 | calendarStart.set(UpdataCalendar.startDay.getYear(), UpdataCalendar.startDay.getMonth() - 1, UpdataCalendar.startDay.getDay());
222 | calendarEnd.set(UpdataCalendar.startDay.getYear(), UpdataCalendar.startDay.getMonth() - 1, UpdataCalendar.startDay.getDay());
223 | calendarEnd.add(Calendar.DAY_OF_MONTH, tenancyTerm);
224 | if (calendarStart.get(Calendar.MONTH) == calendarEnd.get(Calendar.MONTH)) {
225 | //起租时间和归还时间在同一个月
226 | // 归还时间=起租时间+租期-1。
227 | int endPosition = UpdataCalendar.startDay.getDayPosition() + tenancyTerm;
228 | setStopDay(days.get(endPosition), endPosition);
229 | } else {
230 | //起租时间和归还时间不在同一个月
231 | // 归还时间在(起租时间+租期-1)之后,从这之后开始遍历。
232 | for (int i = UpdataCalendar.startDay.getDayPosition() + tenancyTerm; i < MonthTimeAdapter.allDays.size(); i++) {
233 | if (MonthTimeAdapter.allDays.get(i).getYear() == (int) calendarEnd.get(Calendar.YEAR) && MonthTimeAdapter.allDays.get(i).getMonth() == (calendarEnd.get(Calendar.MONTH) + 1) && MonthTimeAdapter.allDays.get(i).getDay() == (int) calendarEnd.get(Calendar.DAY_OF_MONTH)) {
234 | setStopDay(MonthTimeAdapter.allDays.get(i), position);
235 | break;
236 | }
237 | }
238 | }
239 | }
240 |
241 | /*
242 | 设置日历下文字内容
243 | */
244 | private void setTextState(DayTimeViewHolder holder, String text) {
245 | if (text == null) {
246 | holder.select_txt_day_state.setVisibility(View.GONE);
247 | } else {
248 | holder.select_txt_day_state.setVisibility(View.VISIBLE);
249 | }
250 | holder.select_txt_day_state.setText(text);
251 | }
252 |
253 | /*
254 | 设置归还时间
255 | */
256 | private void setStopDay(DayTimeEntity dayTimeEntity, int position) {
257 | UpdataCalendar.stopDay.setDay(dayTimeEntity.getDay());
258 | UpdataCalendar.stopDay.setMonth(dayTimeEntity.getMonth());
259 | UpdataCalendar.stopDay.setYear(dayTimeEntity.getYear());
260 | UpdataCalendar.stopDay.setMonthPosition(dayTimeEntity.getMonthPosition());
261 | UpdataCalendar.stopDay.setDayPosition(position);
262 | }
263 |
264 | /*
265 | 重置归还时间
266 | */
267 | private void resetStopDay() {
268 | UpdataCalendar.stopDay.setDay(-1);
269 | UpdataCalendar.stopDay.setMonth(-1);
270 | UpdataCalendar.stopDay.setYear(-1);
271 | UpdataCalendar.stopDay.setMonthPosition(-1);
272 | UpdataCalendar.stopDay.setDayPosition(-1);
273 | }
274 |
275 | /*
276 | 设置起租时间
277 | */
278 | private void setStartDay(DayTimeEntity dayTimeEntity, int position) {
279 | UpdataCalendar.startDay.setDay(dayTimeEntity.getDay()); // 该item 天数的 年月日等信息 赋给 开始日期
280 | UpdataCalendar.startDay.setMonth(dayTimeEntity.getMonth());
281 | UpdataCalendar.startDay.setYear(dayTimeEntity.getYear());
282 | UpdataCalendar.startDay.setMonthPosition(dayTimeEntity.getMonthPosition());
283 | UpdataCalendar.startDay.setDayPosition(position);
284 |
285 | //如果固定租期>0,就计算归还时间
286 | if (tenancyTerm > 0) {
287 | calculateStopDayUpdate(position);
288 | }
289 |
290 |
291 | }
292 |
293 | /*
294 | 设置起租选中背景
295 | */
296 | private void setStartBackGround(DayTimeViewHolder holder) {
297 | holder.select_ly_day.setBackgroundResource(R.drawable.bg_time_start);
298 | }
299 |
300 | /*
301 | 设置归还选中背景
302 | */
303 | private void setStopBackGround(DayTimeViewHolder holder) {
304 | holder.select_ly_day.setBackgroundResource(R.drawable.bg_time_stop);
305 | }
306 |
307 | /*
308 | 设置起租、归还之间的背景颜色
309 | */
310 | private void setBetweenBackGround(DayTimeViewHolder holder) {
311 | holder.select_ly_day.setBackgroundResource(R.color.calendar_back_between);
312 | }
313 |
314 | /*
315 | 设置未选中背景颜色
316 | */
317 | private void resetBackGround(DayTimeViewHolder holder) {
318 | holder.select_ly_day.setBackgroundResource(R.color.white);
319 | }
320 |
321 | /*
322 | 设置起租、归还重叠背景颜色
323 | */
324 | private void setStartAndrStopBackGround(DayTimeViewHolder holder) {
325 | holder.select_ly_day.setBackgroundResource(R.drawable.bg_time_startstop);
326 | }
327 |
328 |
329 | /*
330 | 设置字体选中颜色
331 | */
332 | private void setTextSelectColor(DayTimeViewHolder holder) {
333 | holder.select_txt_day.setTextColor(context.getResources().getColor(R.color.calendar_text_select));
334 | holder.select_txt_day_state.setTextColor(context.getResources().getColor(R.color.calendar_text_select));
335 | }
336 |
337 | /*
338 | 设置字体未选中颜色
339 | */
340 | private void setTextUnSelectColor(DayTimeViewHolder holder) {
341 | holder.select_txt_day.setTextColor(context.getResources().getColor(R.color.calendar_text_unselect));
342 | holder.select_txt_day_state.setTextColor(context.getResources().getColor(R.color.calendar_text_unselect));
343 | }
344 |
345 | @Override
346 | public int getItemCount() {
347 | int ret = 0;
348 | if (days != null) {
349 | ret = days.size();
350 | }
351 | return ret;
352 | }
353 |
354 | }
355 |
--------------------------------------------------------------------------------
/library/src/main/java/com/neisha/library/adapter/MonthTimeAdapter.java:
--------------------------------------------------------------------------------
1 | package com.neisha.library.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.neisha.library.R;
10 | import com.neisha.library.entity.DayTimeEntity;
11 | import com.neisha.library.entity.MonthTimeEntity;
12 | import com.neisha.library.holder.MonthTimeViewHolder;
13 |
14 | import java.util.ArrayList;
15 | import java.util.Calendar;
16 |
17 | /**
18 | * Created by 木子 on 2017/08/08.
19 | */
20 | public class MonthTimeAdapter extends RecyclerView.Adapter {
21 |
22 | private ArrayList datas;
23 | private Context context;
24 | public static ArrayList allDays = new ArrayList<>();
25 |
26 | public MonthTimeAdapter(ArrayList datas, Context context) {
27 | this.datas = datas;
28 | this.context = context;
29 | }
30 |
31 |
32 | @Override
33 | public MonthTimeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
34 | MonthTimeViewHolder ret = null;
35 | // 不需要检查是否复用,因为只要进入此方法,必然没有复用
36 | // 因为RecyclerView 通过Holder检查复用
37 | View v = LayoutInflater.from(context).inflate(R.layout.item_rmonth, parent, false);
38 | ret = new MonthTimeViewHolder(v, context);
39 | return ret;
40 | }
41 |
42 | @Override
43 | public void onBindViewHolder(MonthTimeViewHolder holder, int position) {
44 | MonthTimeEntity monthTimeEntity = datas.get(position);
45 | //得到该月份的第一天
46 | Calendar calendar = Calendar.getInstance();
47 | calendar.set(Calendar.YEAR, monthTimeEntity.getYear()); //指定年份
48 | calendar.set(Calendar.MONTH, monthTimeEntity.getMonth() - 1); //指定月份 Java月份从0开始算
49 | calendar.set(Calendar.DAY_OF_MONTH, 1); // 指定天数 ,这三行是为了得到 这一年这一月的第一天
50 |
51 | int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); //得到该月份第一天 是星期几
52 | ArrayList days = new ArrayList();
53 | for (int i = 0; i < dayOfWeek - 1; i++) { //
54 | days.add(new DayTimeEntity(0, monthTimeEntity.getMonth(), monthTimeEntity.getYear(), position));
55 | }
56 | calendar.add(Calendar.MONTH, 1);// 加一个月,变为下月的1号
57 | calendar.add(Calendar.DATE, -1);// 减去一天,变为当月最后一天
58 | for (int i = 1; i <= calendar.get(Calendar.DAY_OF_MONTH); i++) { //添加 该月份的天数 一号 到 该月的最后一天
59 | days.add(new DayTimeEntity(i, monthTimeEntity.getMonth(), monthTimeEntity.getYear(), position));
60 | }
61 |
62 | allDays.addAll(days);
63 | DayTimeAdapter adapter = new DayTimeAdapter(days, context);
64 | holder.plan_time_recycler_content.setAdapter(adapter);
65 |
66 | }
67 |
68 | @Override
69 | public int getItemCount() {
70 | int ret = 0;
71 | if (datas != null) {
72 | ret = datas.size();
73 | }
74 | return ret;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/library/src/main/java/com/neisha/library/entity/DayTimeEntity.java:
--------------------------------------------------------------------------------
1 | package com.neisha.library.entity;
2 |
3 | import java.text.DateFormat;
4 | import java.text.SimpleDateFormat;
5 |
6 | /**
7 | * Created by 木子 on 2017/08/08.
8 | * 日历中每一个月中的 每一个天数
9 | */
10 | public class DayTimeEntity {
11 | private int day; //日期,几号
12 | private int month; //属于的月份
13 | private int year; //属于的年份
14 |
15 | private int monthPosition; //属于的月份位置,注意是该日期属于的月份在外层列表中的position,不是月份
16 | private int dayPosition; //属于的日期位置,注意是该日期在每个月(内层列表)中的位置
17 |
18 | DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
19 |
20 | public DayTimeEntity(int day, int month, int year, int monthPosition) {
21 | this.day = day;
22 | this.month = month;
23 | this.year = year;
24 | this.monthPosition = monthPosition;
25 | }
26 |
27 |
28 | public int getDay() {
29 | return day;
30 | }
31 |
32 | public void setDay(int day) {
33 | this.day = day;
34 | }
35 |
36 | public int getMonth() {
37 | return month;
38 | }
39 |
40 | public void setMonth(int month) {
41 | this.month = month;
42 | }
43 |
44 | public int getYear() {
45 | return year;
46 | }
47 |
48 | public void setYear(int year) {
49 |
50 | this.year = year;
51 | }
52 |
53 | public int getMonthPosition() {
54 | return monthPosition;
55 | }
56 |
57 | public void setMonthPosition(int monthPosition) {
58 | this.monthPosition = monthPosition;
59 | }
60 |
61 | public int getDayPosition() {
62 | return dayPosition;
63 | }
64 |
65 | public void setDayPosition(int dayPosition) {
66 | this.dayPosition = dayPosition;
67 | }
68 |
69 |
70 | @Override
71 | public String toString() {
72 | return year + "-" + month + "-" + day;
73 | }
74 |
75 | public boolean equals(DayTimeEntity entity) {
76 | if (entity == this) {
77 | return true;
78 | }
79 |
80 | if (this.day == entity.getDay() && this.month == getMonth() && this.year == entity.getYear()) {
81 | return true;
82 | }
83 | return false;
84 | }
85 |
86 | public boolean isBetween(DayTimeEntity arg0, DayTimeEntity arg1) {
87 | if (arg0.getYear() < this.year) {
88 |
89 | }
90 | return false;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/library/src/main/java/com/neisha/library/entity/MonthTimeEntity.java:
--------------------------------------------------------------------------------
1 | package com.neisha.library.entity;
2 |
3 | /**
4 | * Created by 木子 on 2017/08/08.
5 | * 代表日历上的每一个月份
6 | */
7 | public class MonthTimeEntity {
8 |
9 | private int year; //该月份 属于哪一年
10 | private int month; // 该月 是哪一个月份
11 |
12 | public MonthTimeEntity(int year, int month) {
13 | this.year = year;
14 | this.month = month;
15 | }
16 |
17 | public int getYear() {
18 | return year;
19 | }
20 |
21 | public void setYear(int year) {
22 | this.year = year;
23 | }
24 |
25 | public int getMonth() {
26 | return month;
27 | }
28 |
29 | public void setMonth(int month) {
30 | this.month = month;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return year + "-" + month;
36 | }
37 | }
38 |
39 |
40 |
--------------------------------------------------------------------------------
/library/src/main/java/com/neisha/library/entity/UpdataCalendar.java:
--------------------------------------------------------------------------------
1 | package com.neisha.library.entity;
2 |
3 | import java.util.Calendar;
4 |
5 | /**
6 | * Created by 木子 on 2017/08/08.
7 | * 用于EventBus发送消息
8 | */
9 | public class UpdataCalendar {
10 | public static DayTimeEntity startDay;
11 | public static DayTimeEntity stopDay;
12 | public static int inTransitDay = 0;//在途天数
13 | public static int tenancyTerm = 0;//固定租期
14 |
15 | /**
16 | * 计算两个日期差
17 | */
18 | public static int estimatedDate() {
19 | Calendar startCalendar = Calendar.getInstance();
20 | Calendar stopCalendar = Calendar.getInstance();
21 | startCalendar.set(startDay.getYear(), startDay.getMonth() - 1, startDay.getDay());
22 | stopCalendar.set(stopDay.getYear(), stopDay.getMonth() - 1, stopDay.getDay());
23 | return (int) ((stopCalendar.getTime().getTime() - startCalendar.getTime().getTime()) / (1000 * 60 * 60 * 24) + 1);
24 | }
25 |
26 |
27 | /**
28 | * 设置固定租期
29 | */
30 | public static void setTenancyTerm(int day) {
31 | if (day < 1) {
32 | try {
33 | throw new Exception("固定租期不能小于1天");
34 | } catch (Exception e) {
35 | e.printStackTrace();
36 | }
37 | }
38 | tenancyTerm = day - 1;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/library/src/main/java/com/neisha/library/holder/DayTimeViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.neisha.library.holder;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 | import android.widget.LinearLayout;
6 | import android.widget.TextView;
7 |
8 | import com.neisha.library.R;
9 |
10 |
11 | /**
12 | * Created by 木子 on 2017/08/08.
13 | *
14 | */
15 | public class DayTimeViewHolder extends RecyclerView.ViewHolder{
16 |
17 | public TextView select_txt_day; //日期文本
18 | public LinearLayout select_ly_day; //父容器 , 用于点击日期
19 | public TextView select_txt_day_state;
20 |
21 | public DayTimeViewHolder(View itemView) {
22 | super(itemView);
23 | select_ly_day = (LinearLayout) itemView.findViewById(R.id.select_ly_day);
24 | select_txt_day = (TextView) itemView.findViewById(R.id.select_txt_day);
25 | select_txt_day_state= (TextView) itemView.findViewById(R.id.select_txt_state);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/library/src/main/java/com/neisha/library/holder/MonthTimeViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.neisha.library.holder;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.GridLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.View;
7 |
8 | import com.neisha.library.R;
9 |
10 |
11 | /**
12 | * Created by 木子 on 2017/08/08.
13 | */
14 | public class MonthTimeViewHolder extends RecyclerView.ViewHolder{
15 | public RecyclerView plan_time_recycler_content ; //月份里面详细日期的列表
16 | public Context context; //上下文
17 |
18 | public MonthTimeViewHolder(View itemView, Context context) {
19 | super(itemView);
20 | this.context = context;
21 | plan_time_recycler_content = (RecyclerView) itemView.findViewById(R.id.plan_time_recycler_content);
22 |
23 | RecyclerView.LayoutManager layoutManager =
24 | new GridLayoutManager(context,
25 | 7, // 每行显示item项数目
26 | GridLayoutManager.VERTICAL, //水平排列
27 | false
28 | );
29 |
30 | plan_time_recycler_content.setLayoutManager(layoutManager);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/library/src/main/java/com/neisha/library/widget/CalendarView.java:
--------------------------------------------------------------------------------
1 | package com.neisha.library.widget;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.widget.DividerItemDecoration;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.util.AttributeSet;
9 |
10 | import com.neisha.library.adapter.MonthTimeAdapter;
11 | import com.neisha.library.entity.DayTimeEntity;
12 | import com.neisha.library.entity.MonthTimeEntity;
13 | import com.neisha.library.entity.UpdataCalendar;
14 |
15 | import java.util.ArrayList;
16 | import java.util.Calendar;
17 |
18 | import de.greenrobot.event.EventBus;
19 | import de.greenrobot.event.Subscribe;
20 | import de.greenrobot.event.ThreadMode;
21 |
22 | /**
23 | * Created by muzi on 2017/10/11.
24 | * 727784430@qq.com
25 | */
26 |
27 | public class CalendarView extends RecyclerView {
28 |
29 | private Context context;
30 |
31 | private NsLinearLayoutManager nsLinearLayoutManager;
32 |
33 | private DividerItemDecoration hDividerItemDecoration;
34 |
35 | private MonthTimeAdapter monthAdapter;
36 |
37 | //RecycleView分页滚动的工具类
38 | private PagingScrollHelper scrollHelper;
39 |
40 | //日历数据集合
41 | private ArrayList dateList = new ArrayList<>();
42 |
43 | //默认显示6个月数据
44 | private int monthNum = 6;
45 |
46 |
47 | private onCalendarSelect onCalendarSelect;
48 |
49 |
50 | public CalendarView(Context context) {
51 | super(context);
52 | this.context = context;
53 | }
54 |
55 | public CalendarView(Context context, @Nullable AttributeSet attrs) {
56 | super(context, attrs);
57 | this.context = context;
58 | }
59 |
60 |
61 | /**
62 | * 显示的日历月份数,默认显示6个月
63 | * 在init();之前调用
64 | *
65 | * @param monthNum
66 | */
67 | public void setMonthNum(int monthNum) {
68 | this.monthNum = monthNum;
69 | }
70 |
71 |
72 | /**
73 | * 设置在途天数
74 | * 从今天以后开始计算
75 | * 在途状态不可点击
76 | *
77 | * @param unableSelectDay
78 | */
79 | public void setUnableSelectDay(int unableSelectDay) {
80 | UpdataCalendar.inTransitDay = unableSelectDay;
81 | if (monthAdapter != null) {
82 | resetState();
83 | }
84 | }
85 |
86 | /**
87 | * 设置连续选择
88 | *
89 | * @param day
90 | */
91 | public void setMultipleChoice(int day) {
92 | UpdataCalendar.setTenancyTerm(day);
93 | if (monthAdapter != null) {
94 | resetState();
95 | }
96 | }
97 |
98 | /**
99 | * 日历数据
100 | */
101 | private void getData() {
102 | Calendar calendar;
103 | for (int i = 0; i < monthNum; i++) {
104 | calendar = Calendar.getInstance();
105 | calendar.add(Calendar.MONTH, i);
106 | int year = calendar.get(Calendar.YEAR);
107 | int month = calendar.get(Calendar.MONTH) + 1;
108 | dateList.add(new MonthTimeEntity(year, month));
109 | }
110 |
111 | if (onCalendarSelect != null) {
112 | onCalendarSelect.OnMonthSwhit(dateList.get(0));
113 | }
114 | }
115 |
116 | public void setOnCalendarSelect(CalendarView.onCalendarSelect onCalendarSelect) {
117 | this.onCalendarSelect = onCalendarSelect;
118 | init();
119 | }
120 |
121 | /**
122 | * 初始化界面
123 | */
124 | private void init() {
125 | EventBus.getDefault().register(this);
126 | getData();
127 | initCalenderSwipe();
128 | monthAdapter = new MonthTimeAdapter(dateList, context);
129 | resetState();
130 | }
131 |
132 | /**
133 | * 还原状态
134 | */
135 | private void resetState() {
136 | UpdataCalendar.startDay = new DayTimeEntity(0, 0, 0, 0);
137 | UpdataCalendar.stopDay = new DayTimeEntity(-1, -1, -1, -1);
138 | setAdapter(monthAdapter);
139 | }
140 |
141 |
142 | /**
143 | * 初始化日历滑动
144 | */
145 | private void initCalenderSwipe() {
146 | //翻页效果
147 | nsLinearLayoutManager = new NsLinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
148 | hDividerItemDecoration = new DividerItemDecoration(context, LinearLayoutManager.HORIZONTAL);
149 | hDividerItemDecoration.setDrawable(new EmptyDrawable());
150 | setLayoutManager(nsLinearLayoutManager);
151 | addItemDecoration(hDividerItemDecoration);
152 |
153 | scrollHelper = new PagingScrollHelper();
154 | scrollHelper.setUpRecycleView(this);
155 |
156 | scrollHelper.setOnPageChangeListener(new PagingScrollHelper.onPageChangeListener() {
157 | @Override
158 | public void onPageChange(int index) {
159 | if (onCalendarSelect != null) {
160 | onCalendarSelect.OnMonthSwhit(dateList.get(index));
161 | }
162 | }
163 | });
164 | }
165 |
166 | @Subscribe(threadMode = ThreadMode.MainThread)
167 | public void onEventMainThread(UpdataCalendar event) {
168 | monthAdapter.notifyDataSetChanged();
169 | if (onCalendarSelect != null && UpdataCalendar.stopDay.getDay() != -1) {
170 | onCalendarSelect.OnDaySelect(UpdataCalendar.startDay, UpdataCalendar.stopDay, UpdataCalendar.estimatedDate());
171 | }
172 |
173 | }
174 |
175 | public interface onCalendarSelect {
176 | void OnMonthSwhit(MonthTimeEntity entity);
177 |
178 | void OnDaySelect(DayTimeEntity startDay, DayTimeEntity endDay, int day);
179 | }
180 |
181 | public void onDestory(){
182 | EventBus.getDefault().unregister(this);
183 | }
184 | }
185 |
--------------------------------------------------------------------------------
/library/src/main/java/com/neisha/library/widget/EmptyDrawable.java:
--------------------------------------------------------------------------------
1 | package com.neisha.library.widget;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.ColorFilter;
5 | import android.graphics.drawable.Drawable;
6 | import android.support.annotation.IntRange;
7 | import android.support.annotation.NonNull;
8 | import android.support.annotation.Nullable;
9 |
10 | /**
11 | * Created by muzi on 2017/10/11.
12 | * 727784430@qq.com
13 | */
14 |
15 | public class EmptyDrawable extends Drawable{
16 | @Override
17 | public void draw(@NonNull Canvas canvas) {
18 |
19 | }
20 |
21 | @Override
22 | public void setAlpha(@IntRange(from = 0, to = 255) int alpha) {
23 |
24 | }
25 |
26 | @Override
27 | public void setColorFilter(@Nullable ColorFilter colorFilter) {
28 |
29 | }
30 |
31 | @Override
32 | public int getOpacity() {
33 | return 0;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/library/src/main/java/com/neisha/library/widget/NsLinearLayoutManager.java:
--------------------------------------------------------------------------------
1 | package com.neisha.library.widget;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.AttributeSet;
7 |
8 | /**
9 | * Created by muzi on 2017/10/11.
10 | * 727784430@qq.com
11 | */
12 |
13 | public class NsLinearLayoutManager extends LinearLayoutManager {
14 | public NsLinearLayoutManager(Context context) {
15 | super(context);
16 | }
17 |
18 | public NsLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
19 | super(context, orientation, reverseLayout);
20 | }
21 |
22 | public NsLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
23 | super(context, attrs, defStyleAttr, defStyleRes);
24 | }
25 |
26 | @Override
27 | public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
28 | try {
29 | super.onLayoutChildren(recycler, state);
30 | } catch (IndexOutOfBoundsException e) {
31 | e.printStackTrace();
32 | }
33 | }
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/library/src/main/java/com/neisha/library/widget/PagingScrollHelper.java:
--------------------------------------------------------------------------------
1 | package com.neisha.library.widget;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ValueAnimator;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.MotionEvent;
8 | import android.view.View;
9 |
10 | /**
11 | * 实现RecycleView分页滚动的工具类
12 | * Created by zhuguohui on 2016/11/10.
13 | */
14 |
15 | public class PagingScrollHelper {
16 |
17 | RecyclerView mRecyclerView = null;
18 |
19 | private MyOnScrollListener mOnScrollListener = new MyOnScrollListener();
20 |
21 | private MyOnFlingListener mOnFlingListener = new MyOnFlingListener();
22 | private int offsetY = 0;
23 | private int offsetX = 0;
24 |
25 | int startY = 0;
26 | int startX = 0;
27 |
28 |
29 | enum ORIENTATION {
30 | HORIZONTAL, VERTICAL, NULL
31 | }
32 |
33 | ORIENTATION mOrientation = ORIENTATION.HORIZONTAL;
34 |
35 | public void setUpRecycleView(RecyclerView recycleView) {
36 | if (recycleView == null) {
37 | throw new IllegalArgumentException("recycleView must be not null");
38 | }
39 | mRecyclerView = recycleView;
40 | //处理滑动
41 | recycleView.setOnFlingListener(mOnFlingListener);
42 | //设置滚动监听,记录滚动的状态,和总的偏移量
43 | recycleView.setOnScrollListener(mOnScrollListener);
44 | //记录滚动开始的位置
45 | recycleView.setOnTouchListener(mOnTouchListener);
46 | //获取滚动的方向
47 | updateLayoutManger();
48 | }
49 |
50 | public void updateLayoutManger() {
51 | RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager();
52 | if (layoutManager != null) {
53 | if (layoutManager.canScrollVertically()) {
54 | mOrientation = ORIENTATION.VERTICAL;
55 | } else if (layoutManager.canScrollHorizontally()) {
56 | mOrientation = ORIENTATION.HORIZONTAL;
57 | } else {
58 | mOrientation = ORIENTATION.NULL;
59 | }
60 | if (mAnimator != null) {
61 | mAnimator.cancel();
62 | }
63 | startX = 0;
64 | startY = 0;
65 | offsetX = 0;
66 | offsetY = 0;
67 |
68 | }
69 |
70 | }
71 |
72 | ValueAnimator mAnimator = null;
73 |
74 | public class MyOnFlingListener extends RecyclerView.OnFlingListener {
75 |
76 | @Override
77 | public boolean onFling(int velocityX, int velocityY) {
78 | if (mOrientation == ORIENTATION.NULL) {
79 | return false;
80 | }
81 | //获取开始滚动时所在页面的index
82 | int p = getStartPageIndex();
83 |
84 | //记录滚动开始和结束的位置
85 | int endPoint = 0;
86 | int startPoint = 0;
87 |
88 | //如果是垂直方向
89 | if (mOrientation == ORIENTATION.VERTICAL) {
90 | startPoint = offsetY;
91 |
92 | if (velocityY < 0) {
93 | p--;
94 | } else if (velocityY > 0) {
95 | p++;
96 | }
97 | //更具不同的速度判断需要滚动的方向
98 | //注意,此处有一个技巧,就是当速度为0的时候就滚动会开始的页面,即实现页面复位
99 | endPoint = p * mRecyclerView.getHeight();
100 |
101 | } else {
102 | startPoint = offsetX;
103 | if (velocityX < 0) {
104 | p--;
105 | } else if (velocityX > 0) {
106 | p++;
107 | }
108 | endPoint = p * mRecyclerView.getWidth();
109 |
110 | }
111 | if (endPoint < 0) {
112 | endPoint = 0;
113 | }
114 |
115 | //使用动画处理滚动
116 | if (mAnimator == null) {
117 | mAnimator = new ValueAnimator().ofInt(startPoint, endPoint);
118 |
119 | mAnimator.setDuration(300);
120 | mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
121 | @Override
122 | public void onAnimationUpdate(ValueAnimator animation) {
123 | int nowPoint = (int) animation.getAnimatedValue();
124 |
125 | if (mOrientation == ORIENTATION.VERTICAL) {
126 | int dy = nowPoint - offsetY;
127 | //这里通过RecyclerView的scrollBy方法实现滚动。
128 | mRecyclerView.scrollBy(0, dy);
129 | } else {
130 | int dx = nowPoint - offsetX;
131 | mRecyclerView.scrollBy(dx, 0);
132 | }
133 | }
134 | });
135 |
136 | mAnimator.addListener(new AnimatorListenerAdapter() {
137 | @Override
138 | public void onAnimationEnd(Animator animation) {
139 | //回调监听
140 | if (null != mOnPageChangeListener) {
141 | mOnPageChangeListener.onPageChange(getPageIndex());
142 | }
143 | }
144 | });
145 | } else {
146 | mAnimator.cancel();
147 | mAnimator.setIntValues(startPoint, endPoint);
148 | }
149 |
150 | mAnimator.start();
151 |
152 | return true;
153 | }
154 | }
155 |
156 | public class MyOnScrollListener extends RecyclerView.OnScrollListener {
157 | @Override
158 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
159 | //newState==0表示滚动停止,此时需要处理回滚
160 | if (newState == 0 && mOrientation != ORIENTATION.NULL) {
161 | boolean move;
162 | int vX = 0, vY = 0;
163 | if (mOrientation == ORIENTATION.VERTICAL) {
164 | int absY = Math.abs(offsetY - startY);
165 | //如果滑动的距离超过屏幕的一半表示需要滑动到下一页
166 | move = absY > recyclerView.getHeight() / 2;
167 | vY = 0;
168 |
169 | if (move) {
170 | vY = offsetY - startY < 0 ? -1000 : 1000;
171 | }
172 |
173 | } else {
174 | int absX = Math.abs(offsetX - startX);
175 | move = absX > recyclerView.getWidth() / 2;
176 | if (move) {
177 | vX = offsetX - startX < 0 ? -1000 : 1000;
178 | }
179 |
180 | }
181 |
182 | mOnFlingListener.onFling(vX, vY);
183 |
184 | }
185 |
186 | }
187 |
188 | @Override
189 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
190 | //滚动结束记录滚动的偏移量
191 | offsetY += dy;
192 | offsetX += dx;
193 | }
194 | }
195 |
196 | private MyOnTouchListener mOnTouchListener = new MyOnTouchListener();
197 |
198 |
199 | public class MyOnTouchListener implements View.OnTouchListener {
200 |
201 | @Override
202 | public boolean onTouch(View v, MotionEvent event) {
203 | //手指按下的时候记录开始滚动的坐标
204 | if (event.getAction() == MotionEvent.ACTION_DOWN) {
205 | startY = offsetY;
206 | startX = offsetX;
207 | }
208 | return false;
209 | }
210 |
211 | }
212 |
213 | private int getPageIndex() {
214 | int p = 0;
215 | if (mOrientation == ORIENTATION.VERTICAL) {
216 | p = offsetY / mRecyclerView.getHeight();
217 | } else {
218 | p = offsetX / mRecyclerView.getWidth();
219 | }
220 | return p;
221 | }
222 |
223 | private int getStartPageIndex() {
224 | int p = 0;
225 | if (mOrientation == ORIENTATION.VERTICAL) {
226 | p = startY / mRecyclerView.getHeight();
227 | } else {
228 | p = startX / mRecyclerView.getWidth();
229 | }
230 | return p;
231 | }
232 |
233 | onPageChangeListener mOnPageChangeListener;
234 |
235 | public void setOnPageChangeListener(onPageChangeListener listener) {
236 | mOnPageChangeListener = listener;
237 | }
238 |
239 | public interface onPageChangeListener {
240 | void onPageChange(int index);
241 | }
242 |
243 | }
244 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/bg_time_start.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/bg_time_startstop.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/bg_time_stop.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/item_day.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
19 |
20 |
27 |
28 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/item_rmonth.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
13 |
14 |
20 |
21 |
27 |
28 |
34 |
35 |
41 |
42 |
48 |
49 |
55 |
56 |
62 |
63 |
64 |
68 |
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ffffff
4 | #038EDF
5 | #74C5F2
6 | #ffffff
7 | #515151
8 | #a4a4a4
9 |
10 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | library
3 | 起租
4 | 归还
5 | 一天
6 | 今天
7 | 在途
8 |
9 |
--------------------------------------------------------------------------------
/library/src/test/java/com/neisha/library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.neisha.library;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/preview/app-debug.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/preview/app-debug.apk
--------------------------------------------------------------------------------
/preview/img.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doutuifei/CalendarRangeSelect/faff7a03597d4a0560fd70c86b56e556c29371c1/preview/img.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------