├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tangyx │ │ └── calendar │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── tangyx │ │ │ └── calendar │ │ │ ├── CalendarActivity.java │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable │ │ └── border_f4_bg_white.xml │ │ ├── layout │ │ ├── activity_calendar.xml │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── icon_calendar_delete.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── tangyx │ └── calendar │ └── ExampleUnitTest.java ├── build.gradle ├── calendarlist ├── .gitignore ├── LICENSE.txt ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── andexert │ │ └── calendarlistview │ │ └── library │ │ ├── CalendarUtils.java │ │ ├── DatePickerController.java │ │ ├── DayPickerView.java │ │ ├── SimpleMonthAdapter.java │ │ └── SimpleMonthView.java │ └── res │ ├── drawable-hdpi │ ├── calendar_train_blue.png │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ └── values │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ └── strings.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── 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/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 26 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | Android 46 | 47 | 48 | Android > Lint > Correctness 49 | 50 | 51 | Java 52 | 53 | 54 | Java language level migration aidsJava 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 76 | 77 | 79 | 80 | 81 | 82 | 83 | 1.8 84 | 85 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.2" 6 | defaultConfig { 7 | applicationId "com.tangyx.calendar" 8 | minSdkVersion 15 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:24.2.1' 28 | testCompile 'junit:junit:4.12' 29 | compile project(path: ':calendarlist') 30 | } 31 | -------------------------------------------------------------------------------- /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 /Users/tangyx/Library/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 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/tangyx/calendar/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.tangyx.calendar; 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.tangyx.calendar", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/tangyx/calendar/CalendarActivity.java: -------------------------------------------------------------------------------- 1 | package com.tangyx.calendar; 2 | 3 | import android.graphics.Color; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.content.ContextCompat; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.text.TextUtils; 9 | import android.util.Log; 10 | import android.view.View; 11 | import android.widget.ImageView; 12 | import android.widget.RelativeLayout; 13 | import android.widget.TextView; 14 | import android.widget.Toast; 15 | 16 | import com.andexert.calendarlistview.library.DatePickerController; 17 | import com.andexert.calendarlistview.library.DayPickerView; 18 | import com.andexert.calendarlistview.library.SimpleMonthAdapter; 19 | 20 | import java.text.ParseException; 21 | import java.text.SimpleDateFormat; 22 | import java.util.Calendar; 23 | import java.util.Date; 24 | import java.util.Locale; 25 | 26 | /** 27 | * Created by tangyx on 16/3/22. 28 | * 29 | */ 30 | public class CalendarActivity extends AppCompatActivity implements DatePickerController,View.OnClickListener{ 31 | private DayPickerView mDayPickerView; 32 | private RelativeLayout mGoLayout; 33 | private TextView mGo; 34 | private ImageView mGoDelete; 35 | private RelativeLayout mBackLayout; 36 | private TextView mBack; 37 | private ImageView mBackDelete; 38 | private boolean isSingle; 39 | 40 | @Override 41 | protected void onCreate(@Nullable Bundle savedInstanceState) { 42 | super.onCreate(savedInstanceState); 43 | setContentView(R.layout.activity_calendar); 44 | mGoLayout = (RelativeLayout) findViewById(R.id.go_layout); 45 | mGo = (TextView) findViewById(R.id.go); 46 | mGoDelete = (ImageView) findViewById(R.id.go_delete); 47 | mBackLayout = (RelativeLayout) findViewById(R.id.back_layout); 48 | mBack = (TextView) findViewById(R.id.back); 49 | mBackDelete = (ImageView) findViewById(R.id.back_delete); 50 | mDayPickerView = (DayPickerView) findViewById(R.id.day_picker); 51 | mDayPickerView.setController(this); 52 | mGoDelete.setOnClickListener(this); 53 | mBackDelete.setOnClickListener(this); 54 | isSingle = getIntent().getBooleanExtra("isSingle",true); 55 | mDayPickerView.setSingle(isSingle); 56 | if(isSingle){ 57 | findViewById(R.id.time_layout).setVisibility(View.GONE); 58 | } 59 | String date = getIntent().getStringExtra("minDay"); 60 | if(!TextUtils.isEmpty(date)){ 61 | Calendar calendar = Calendar.getInstance(); 62 | try { 63 | calendar.setTimeInMillis(new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).parse(date).getTime()); 64 | } catch (ParseException e) { 65 | e.printStackTrace(); 66 | } 67 | mDayPickerView.setMinDay(calendar); 68 | } 69 | } 70 | 71 | @Override 72 | public int getMaxYear() { 73 | return Calendar.getInstance().get(Calendar.YEAR)+1; 74 | } 75 | 76 | /** 77 | * 当日期发生改变每次都会调用的函数 78 | * @param year 79 | * @param month 80 | * @param day 81 | */ 82 | @Override 83 | public void onDayOfMonthSelected(int year, int month, int day) { 84 | if(isSingle){ 85 | Toast.makeText(this,"当前单选一个日期:"+year+"-"+(month+1)+"-"+day,Toast.LENGTH_LONG).show(); 86 | } 87 | } 88 | 89 | /** 90 | * 选中多个的时候触发,但是每次选中或者改变日期的时候都会触发 91 | * @param selectedDays 92 | */ 93 | @Override 94 | public void onDateRangeSelected(SimpleMonthAdapter.SelectedDays selectedDays) { 95 | if(!isSingle){ 96 | //获取第一个选择的日期 97 | SimpleMonthAdapter.CalendarDay firstDay = selectedDays.getFirst(); 98 | //获取第二个选择日期 99 | SimpleMonthAdapter.CalendarDay lastDay = selectedDays.getLast(); 100 | //根据需求做对应的逻辑处理, 101 | //我这里是做了一个往返日期逻辑,得到两个选中的日期后需要进行判断出小的日期肯定是出发日期。 102 | if(firstDay!=null){ 103 | Calendar firstCalendar = Calendar.getInstance(); 104 | firstCalendar.set(firstDay.year,firstDay.month,firstDay.day); 105 | mGoLayout.setBackgroundColor(ContextCompat.getColor(this,R.color.color_48c4fe)); 106 | mGoDelete.setVisibility(View.VISIBLE); 107 | mGo.setText(getString(R.string.select_calendar_go,getYYYY_MM_dd(new Date(firstCalendar.getTimeInMillis())).replace("-","/"))); 108 | mGo.setTag(firstCalendar); 109 | }else{ 110 | mGoLayout.setBackgroundColor(Color.WHITE); 111 | mGoDelete.setVisibility(View.INVISIBLE); 112 | mGo.setText(null); 113 | mGo.setTag(null); 114 | } 115 | if(lastDay!=null){ 116 | Calendar lastCalendar = Calendar.getInstance(); 117 | lastCalendar.set(lastDay.year,lastDay.month,lastDay.day); 118 | mBackLayout.setBackgroundColor(ContextCompat.getColor(this,R.color.color_48c4fe)); 119 | mBackDelete.setVisibility(View.VISIBLE); 120 | mBack.setText(getString(R.string.select_calendar_back,getYYYY_MM_dd(new Date(lastCalendar.getTimeInMillis())).replace("-","/"))); 121 | mBack.setTag(lastCalendar); 122 | }else{ 123 | mBackLayout.setBackgroundColor(Color.WHITE); 124 | mBackDelete.setVisibility(View.INVISIBLE); 125 | mBack.setText(null); 126 | mBack.setTag(null); 127 | } 128 | Calendar goCalendar = (Calendar) mGo.getTag(); 129 | Calendar backCalendar = (Calendar) mBack.getTag(); 130 | if(goCalendar!=null && backCalendar!=null 131 | && goCalendar.getTimeInMillis()>backCalendar.getTimeInMillis()){ 132 | mGo.setText(getString(R.string.select_calendar_go,getYYYY_MM_dd(new Date(backCalendar.getTimeInMillis())).replace("-","/"))); 133 | mGo.setTag(backCalendar); 134 | selectedDays.setFirst(lastDay); 135 | 136 | mBack.setText(getString(R.string.select_calendar_back,getYYYY_MM_dd(new Date(goCalendar.getTimeInMillis())).replace("-","/"))); 137 | mBack.setTag(goCalendar); 138 | selectedDays.setLast(firstDay); 139 | } 140 | } 141 | } 142 | 143 | public String getYYYY_MM_dd(Date date){ 144 | return new SimpleDateFormat("yyyy-MM-dd",Locale.getDefault()).format(date); 145 | } 146 | 147 | 148 | @Override 149 | public void onClick(View view) { 150 | switch (view.getId()){ 151 | case R.id.go_delete: 152 | mDayPickerView.getSelectedDays().setFirst(null); 153 | mDayPickerView.getSelectedDays().setLast(null); 154 | break; 155 | case R.id.back_delete: 156 | mDayPickerView.getSelectedDays().setLast(null); 157 | break; 158 | } 159 | //刷新日历 160 | mDayPickerView.setUpAdapter(); 161 | onDateRangeSelected(mDayPickerView.getSelectedDays()); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /app/src/main/java/com/tangyx/calendar/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.tangyx.calendar; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | import com.andexert.calendarlistview.library.DayPickerView; 9 | 10 | public class MainActivity extends AppCompatActivity implements View.OnClickListener{ 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_main); 16 | findViewById(R.id.single).setOnClickListener(this); 17 | findViewById(R.id.choice).setOnClickListener(this); 18 | } 19 | 20 | @Override 21 | public void onClick(View v) { 22 | Intent intent = new Intent(this,CalendarActivity.class); 23 | switch (v.getId()){ 24 | case R.id.single: 25 | intent.putExtra("isSingle",true); 26 | break; 27 | case R.id.choice: 28 | intent.putExtra("isSingle",false); 29 | break; 30 | } 31 | startActivity(intent); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/border_f4_bg_white.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_calendar.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 18 | 26 | 35 | 44 | 45 | 53 | 62 | 71 | 72 | 73 | 80 | 89 | 98 | 107 | 116 | 125 | 133 | 142 | 143 | 161 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 |