├── .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 | 60 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 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 | 19 | 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 | 62 | 63 | 64 | 65 | 66 | 67 | 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 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/smartfox_info.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CalendarRangeSelect 2 | Android日历连续区间选择 3 | 4 | ## 效果预览 5 | ![image](https://github.com/TurnTears/CalendarRangeSelect/blob/2d9b3e081698d61c201ffafac581583982f3d750/preview/img.gif) 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 |