├── .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 |
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 | 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 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | 1.8
84 |
85 |
86 |
87 |
88 |
89 |
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 |
5 |
6 |
7 |
8 |
9 |
10 |
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 |
12 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangyxgit/CalendarListEvolution/b6003d5ffd7657775e47d78f93ccdaec5ef7e08f/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/icon_calendar_delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangyxgit/CalendarListEvolution/b6003d5ffd7657775e47d78f93ccdaec5ef7e08f/app/src/main/res/mipmap-hdpi/icon_calendar_delete.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangyxgit/CalendarListEvolution/b6003d5ffd7657775e47d78f93ccdaec5ef7e08f/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangyxgit/CalendarListEvolution/b6003d5ffd7657775e47d78f93ccdaec5ef7e08f/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangyxgit/CalendarListEvolution/b6003d5ffd7657775e47d78f93ccdaec5ef7e08f/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangyxgit/CalendarListEvolution/b6003d5ffd7657775e47d78f93ccdaec5ef7e08f/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #48c4fe
7 | #FFFFFF
8 | #e0e8ee
9 | #000000
10 | #b2b2b2
11 | #f4f4f4
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CalendarListEvolution
3 | 出发\t%1$s
4 | 返回\t%1$s
5 | 日
6 | 一
7 | 二
8 | 三
9 | 四
10 | 五
11 | 六
12 | 请选择出发日期
13 | 请选择返回日期
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/tangyx/calendar/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.tangyx.calendar;
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.2.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 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/calendarlist/.gitignore:
--------------------------------------------------------------------------------
1 | #Android generated
2 | bin
3 | gen
4 |
5 | #Eclipse
6 | .project
7 | .classpath
8 | .settings
9 |
10 | #IntelliJ IDEA
11 | .idea
12 | *.iml
13 | *.ipr
14 | *.iws
15 | out
16 |
17 | #Gradle
18 | .gradle
19 | build
20 |
21 | #Maven
22 | target
23 | release.properties
24 | pom.xml.*
25 | project.properties
26 |
27 | #Ant
28 | build.xml
29 | local.properties
30 | gradle.properties
31 | proguard.cfg
32 |
33 | #OSX
34 | .DS_Store/
35 |
36 | # Crashlytics
37 | com_crashlytics_export_strings.xml
38 | crashlytics-build.properties
39 | crashlytics.properties
--------------------------------------------------------------------------------
/calendarlist/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Robin Chutaux
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/calendarlist/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion '23.0.3'
6 |
7 | defaultConfig {
8 | minSdkVersion 10
9 | targetSdkVersion 24
10 | versionCode 9
11 | versionName "1.2.3"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile 'com.android.support:appcompat-v7:24.2.1'
24 | compile 'com.android.support:recyclerview-v7:24.2.1'
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/calendarlist/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 C:/Users/robin.chutaux/Documents/adt/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 |
--------------------------------------------------------------------------------
/calendarlist/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/calendarlist/src/main/java/com/andexert/calendarlistview/library/CalendarUtils.java:
--------------------------------------------------------------------------------
1 | /***********************************************************************************
2 | * The MIT License (MIT)
3 |
4 | * Copyright (c) 2014 Robin Chutaux
5 |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 |
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | ***********************************************************************************/
24 | package com.andexert.calendarlistview.library;
25 |
26 | import java.util.Calendar;
27 |
28 |
29 | public class CalendarUtils
30 | {
31 | public static int getDaysInMonth(int month, int year) {
32 | switch (month) {
33 | case Calendar.JANUARY:
34 | case Calendar.MARCH:
35 | case Calendar.MAY:
36 | case Calendar.JULY:
37 | case Calendar.AUGUST:
38 | case Calendar.OCTOBER:
39 | case Calendar.DECEMBER:
40 | return 31;
41 | case Calendar.APRIL:
42 | case Calendar.JUNE:
43 | case Calendar.SEPTEMBER:
44 | case Calendar.NOVEMBER:
45 | return 30;
46 | case Calendar.FEBRUARY:
47 | return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? 29 : 28;
48 | default:
49 | throw new IllegalArgumentException("Invalid Month");
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/calendarlist/src/main/java/com/andexert/calendarlistview/library/DatePickerController.java:
--------------------------------------------------------------------------------
1 | /***********************************************************************************
2 | * The MIT License (MIT)
3 |
4 | * Copyright (c) 2014 Robin Chutaux
5 |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 |
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | ***********************************************************************************/
24 | package com.andexert.calendarlistview.library;
25 |
26 | public interface DatePickerController {
27 |
28 | int getMaxYear();
29 |
30 | void onDayOfMonthSelected(int year, int month, int day);
31 |
32 | void onDateRangeSelected(final SimpleMonthAdapter.SelectedDays selectedDays);
33 |
34 | }
--------------------------------------------------------------------------------
/calendarlist/src/main/java/com/andexert/calendarlistview/library/DayPickerView.java:
--------------------------------------------------------------------------------
1 | /***********************************************************************************
2 | * The MIT License (MIT)
3 |
4 | * Copyright (c) 2014 Robin Chutaux
5 |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 |
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | ***********************************************************************************/
24 | package com.andexert.calendarlistview.library;
25 |
26 | import android.content.Context;
27 | import android.content.res.TypedArray;
28 | import android.support.v7.widget.LinearLayoutManager;
29 | import android.support.v7.widget.RecyclerView;
30 | import android.util.AttributeSet;
31 |
32 | import java.util.Calendar;
33 |
34 | public class DayPickerView extends RecyclerView {
35 | protected Context mContext;
36 | protected SimpleMonthAdapter mAdapter;
37 | private DatePickerController mController;
38 | protected int mCurrentScrollState = 0;
39 | protected long mPreviousScrollPosition;
40 | protected int mPreviousScrollState = 0;
41 | private TypedArray typedArray;
42 | private OnScrollListener onScrollListener;
43 |
44 | public DayPickerView(Context context)
45 | {
46 | this(context, null);
47 | }
48 |
49 | public DayPickerView(Context context, AttributeSet attrs)
50 | {
51 | this(context, attrs, 0);
52 | }
53 |
54 | public DayPickerView(Context context, AttributeSet attrs, int defStyle) {
55 | super(context, attrs, defStyle);
56 | if (!isInEditMode()) {
57 | typedArray = context.obtainStyledAttributes(attrs, R.styleable.DayPickerView);
58 | setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
59 | init(context);
60 | }
61 | }
62 |
63 | public void setController(DatePickerController mController)
64 | {
65 | this.mController = mController;
66 | setUpAdapter();
67 | setAdapter(mAdapter);
68 | }
69 |
70 |
71 | public void init(Context paramContext) {
72 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(paramContext);
73 | setLayoutManager(linearLayoutManager);
74 | mContext = paramContext;
75 | setUpListView();
76 |
77 | onScrollListener = new OnScrollListener()
78 | {
79 | @Override
80 | public void onScrolled(RecyclerView recyclerView, int dx, int dy)
81 | {
82 | super.onScrolled(recyclerView, dx, dy);
83 | final SimpleMonthView child = (SimpleMonthView) recyclerView.getChildAt(0);
84 | if (child == null) {
85 | return;
86 | }
87 |
88 | mPreviousScrollPosition = dy;
89 | mPreviousScrollState = mCurrentScrollState;
90 | }
91 | };
92 | }
93 |
94 | public void setUpAdapter() {
95 | if (mAdapter == null) {
96 | mAdapter = new SimpleMonthAdapter(getContext(), mController, typedArray);
97 | }
98 | mAdapter.notifyDataSetChanged();
99 | }
100 |
101 | protected void setUpListView() {
102 | setVerticalScrollBarEnabled(false);
103 | setOnScrollListener(onScrollListener);
104 | setFadingEdgeLength(0);
105 | }
106 |
107 | public SimpleMonthAdapter.SelectedDays getSelectedDays()
108 | {
109 | return mAdapter.getSelectedDays();
110 | }
111 |
112 | protected DatePickerController getController()
113 | {
114 | return mController;
115 | }
116 |
117 | protected TypedArray getTypedArray()
118 | {
119 | return typedArray;
120 | }
121 |
122 | public void setMinDay(Calendar minDay){
123 | mAdapter.setMinDay(minDay);
124 | }
125 | public void setTrainDay(Calendar trainDay){
126 | mAdapter.setTrainDay(trainDay);
127 | }
128 | public void setSingle(boolean isSingle){
129 | mAdapter.setSingle(isSingle);
130 | }
131 | }
--------------------------------------------------------------------------------
/calendarlist/src/main/java/com/andexert/calendarlistview/library/SimpleMonthAdapter.java:
--------------------------------------------------------------------------------
1 | /***********************************************************************************
2 | * The MIT License (MIT)
3 |
4 | * Copyright (c) 2014 Robin Chutaux
5 |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 |
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | ***********************************************************************************/
24 | package com.andexert.calendarlistview.library;
25 |
26 | import android.content.Context;
27 | import android.content.res.TypedArray;
28 | import android.graphics.Bitmap;
29 | import android.graphics.BitmapFactory;
30 | import android.graphics.Matrix;
31 | import android.support.v7.widget.RecyclerView;
32 | import android.view.View;
33 | import android.view.ViewGroup;
34 | import android.view.ViewGroup.LayoutParams;
35 | import android.widget.AbsListView;
36 |
37 | import java.io.Serializable;
38 | import java.util.Calendar;
39 | import java.util.Date;
40 | import java.util.HashMap;
41 |
42 | public class SimpleMonthAdapter extends RecyclerView.Adapter implements SimpleMonthView.OnDayClickListener {
43 |
44 | protected static final int MONTHS_IN_YEAR = 12;
45 | private final TypedArray typedArray;
46 | private final Context mContext;
47 | private final DatePickerController mController;
48 | private final Calendar calendar;
49 | private final SelectedDays selectedDays;
50 | private final Integer firstMonth;
51 | private final Integer lastMonth;
52 | private boolean isSingle;
53 | private Calendar minDay;
54 | private Calendar trainDay;
55 | private Bitmap trainMap;
56 |
57 | public SimpleMonthAdapter(Context context, DatePickerController datePickerController, TypedArray typedArray) {
58 | this.typedArray = typedArray;
59 | calendar = Calendar.getInstance();
60 | firstMonth = typedArray.getInt(R.styleable.DayPickerView_firstMonth, calendar.get(Calendar.MONTH));
61 | lastMonth = typedArray.getInt(R.styleable.DayPickerView_lastMonth, (calendar.get(Calendar.MONTH)) % MONTHS_IN_YEAR);
62 | isSingle = typedArray.getBoolean(R.styleable.DayPickerView_selectSingle,false);
63 | selectedDays = new SelectedDays<>();
64 | mContext = context;
65 | mController = datePickerController;
66 | trainMap = BitmapFactory.decodeResource(context.getResources(), R.drawable.calendar_train_blue);
67 | trainMap = onScaleImage(trainMap, 0.5f);
68 | init();
69 | }
70 |
71 | private Bitmap onScaleImage(Bitmap bitmap, float scale){
72 | Matrix matrix = new Matrix();
73 | matrix.postScale(scale, scale);
74 | return Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
75 | }
76 |
77 | @Override
78 | public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
79 | final SimpleMonthView simpleMonthView = new SimpleMonthView(mContext, typedArray);
80 | simpleMonthView.setMinDay(minDay);
81 | simpleMonthView.setMaxYear(mController.getMaxYear());
82 | simpleMonthView.setLastMonth(lastMonth);
83 | return new ViewHolder(simpleMonthView, this);
84 | }
85 |
86 | public void setMinDay(Calendar minDay) {
87 | this.minDay = minDay;
88 | }
89 |
90 | public void setTrainDay(Calendar trainDay){
91 | this.trainDay = trainDay;
92 | }
93 |
94 | public void setSingle(boolean isSingle){
95 | this.isSingle = isSingle;
96 | if(isSingle){
97 | selectedDays.setLast(new CalendarDay(System.currentTimeMillis()));
98 | }else{
99 | selectedDays.setLast(null);
100 | }
101 | }
102 |
103 | @Override
104 | public void onBindViewHolder(ViewHolder viewHolder, int position)
105 | {
106 | final SimpleMonthView v = viewHolder.simpleMonthView;
107 | final HashMap drawingParams = new HashMap();
108 | int month;
109 | int year;
110 |
111 | month = (firstMonth + (position % MONTHS_IN_YEAR)) % MONTHS_IN_YEAR;
112 | year = position / MONTHS_IN_YEAR + calendar.get(Calendar.YEAR) + ((firstMonth + (position % MONTHS_IN_YEAR)) / MONTHS_IN_YEAR);
113 |
114 | int selectedFirstDay = -1;
115 | int selectedLastDay = -1;
116 | int selectedFirstMonth = -1;
117 | int selectedLastMonth = -1;
118 | int selectedFirstYear = -1;
119 | int selectedLastYear = -1;
120 |
121 | if (selectedDays.getFirst() != null)
122 | {
123 | selectedFirstDay = selectedDays.getFirst().day;
124 | selectedFirstMonth = selectedDays.getFirst().month;
125 | selectedFirstYear = selectedDays.getFirst().year;
126 | }
127 |
128 | if (selectedDays.getLast() != null && !isSingle)
129 | {
130 | selectedLastDay = selectedDays.getLast().day;
131 | selectedLastMonth = selectedDays.getLast().month;
132 | selectedLastYear = selectedDays.getLast().year;
133 | }
134 |
135 | v.reuse();
136 |
137 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_BEGIN_YEAR, selectedFirstYear);
138 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_LAST_YEAR, selectedLastYear);
139 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_BEGIN_MONTH, selectedFirstMonth);
140 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_LAST_MONTH, selectedLastMonth);
141 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_BEGIN_DAY, selectedFirstDay);
142 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_LAST_DAY, selectedLastDay);
143 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_YEAR, year);
144 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_MONTH, month);
145 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_WEEK_START, calendar.getFirstDayOfWeek());
146 | v.setMonthParams(drawingParams);
147 | v.invalidate();
148 | }
149 |
150 | public long getItemId(int position) {
151 | return position;
152 | }
153 |
154 | @Override
155 | public int getItemCount()
156 | {
157 | int itemCount = (((mController.getMaxYear() - calendar.get(Calendar.YEAR)) + 1) * MONTHS_IN_YEAR);
158 |
159 | if (firstMonth != -1)
160 | itemCount -= firstMonth;
161 |
162 | if (lastMonth != -1)
163 | itemCount -= (MONTHS_IN_YEAR - lastMonth) - 1;
164 |
165 | return itemCount;
166 | }
167 |
168 | static class ViewHolder extends RecyclerView.ViewHolder
169 | {
170 | final SimpleMonthView simpleMonthView;
171 |
172 | ViewHolder(View itemView, SimpleMonthView.OnDayClickListener onDayClickListener)
173 | {
174 | super(itemView);
175 | simpleMonthView = (SimpleMonthView) itemView;
176 | simpleMonthView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
177 | simpleMonthView.setClickable(true);
178 | simpleMonthView.setOnDayClickListener(onDayClickListener);
179 | }
180 | }
181 |
182 | protected void init() {
183 | if (typedArray.getBoolean(R.styleable.DayPickerView_currentDaySelected, false)){
184 | onDayTapped(new CalendarDay(System.currentTimeMillis()));
185 | }
186 | if(isSingle){
187 | selectedDays.setLast(new CalendarDay(System.currentTimeMillis()));
188 | }
189 | }
190 |
191 | public void onDayClick(SimpleMonthView simpleMonthView, CalendarDay calendarDay) {
192 | if (calendarDay != null) {
193 | onDayTapped(calendarDay);
194 | }
195 | }
196 |
197 | private void onDayTapped(CalendarDay calendarDay) {
198 | mController.onDayOfMonthSelected(calendarDay.year, calendarDay.month, calendarDay.day);
199 | setSelectedDay(calendarDay);
200 | }
201 |
202 | private void setSelectedDay(CalendarDay calendarDay) {
203 | if (selectedDays.getFirst() != null && selectedDays.getLast() == null) {
204 | selectedDays.setLast(calendarDay);
205 | if (selectedDays.getFirst().month < calendarDay.month) {
206 | for (int i = 0; i < selectedDays.getFirst().month - calendarDay.month - 1; ++i)
207 | mController.onDayOfMonthSelected(selectedDays.getFirst().year, selectedDays.getFirst().month + i, selectedDays.getFirst().day);
208 | }
209 | } else if (selectedDays.getLast() != null) {
210 | selectedDays.setFirst(calendarDay);
211 | if(!isSingle){
212 | selectedDays.setLast(null);
213 | }
214 | } else{
215 | selectedDays.setFirst(calendarDay);
216 | }
217 | mController.onDateRangeSelected(selectedDays);
218 | notifyDataSetChanged();
219 | }
220 |
221 | public static class CalendarDay implements Serializable {
222 | private static final long serialVersionUID = -5456695978688356202L;
223 | private Calendar calendar;
224 |
225 | public int day;
226 | public int month;
227 | public int year;
228 |
229 | public CalendarDay() {
230 | setTime(System.currentTimeMillis());
231 | }
232 |
233 | public CalendarDay(int year, int month, int day) {
234 | setDay(year, month, day);
235 | }
236 |
237 | public CalendarDay(long timeInMillis) {
238 | setTime(timeInMillis);
239 | }
240 |
241 | public CalendarDay(Calendar calendar) {
242 | year = calendar.get(Calendar.YEAR);
243 | month = calendar.get(Calendar.MONTH);
244 | day = calendar.get(Calendar.DAY_OF_MONTH);
245 | }
246 |
247 | private void setTime(long timeInMillis) {
248 | if (calendar == null) {
249 | calendar = Calendar.getInstance();
250 | }
251 | calendar.setTimeInMillis(timeInMillis);
252 | month = this.calendar.get(Calendar.MONTH);
253 | year = this.calendar.get(Calendar.YEAR);
254 | day = this.calendar.get(Calendar.DAY_OF_MONTH);
255 | }
256 |
257 | public void set(CalendarDay calendarDay) {
258 | year = calendarDay.year;
259 | month = calendarDay.month;
260 | day = calendarDay.day;
261 | }
262 |
263 | public void setDay(int year, int month, int day) {
264 | this.year = year;
265 | this.month = month;
266 | this.day = day;
267 | }
268 |
269 | public Date getDate()
270 | {
271 | if (calendar == null) {
272 | calendar = Calendar.getInstance();
273 | }
274 | calendar.set(year, month, day);
275 | return calendar.getTime();
276 | }
277 |
278 | @Override
279 | public String toString()
280 | {
281 | final StringBuilder stringBuilder = new StringBuilder();
282 | stringBuilder.append("{ year: ");
283 | stringBuilder.append(year);
284 | stringBuilder.append(", month: ");
285 | stringBuilder.append(month);
286 | stringBuilder.append(", day: ");
287 | stringBuilder.append(day);
288 | stringBuilder.append(" }");
289 |
290 | return stringBuilder.toString();
291 | }
292 | }
293 |
294 | public SelectedDays getSelectedDays()
295 | {
296 | return selectedDays;
297 | }
298 |
299 | public static class SelectedDays implements Serializable
300 | {
301 | private static final long serialVersionUID = 3942549765282708376L;
302 | private K first;
303 | private K last;
304 |
305 | public K getFirst()
306 | {
307 | return first;
308 | }
309 |
310 | public void setFirst(K first)
311 | {
312 | this.first = first;
313 | }
314 |
315 | public K getLast()
316 | {
317 | return last;
318 | }
319 |
320 | public void setLast(K last)
321 | {
322 | this.last = last;
323 | }
324 | }
325 | }
--------------------------------------------------------------------------------
/calendarlist/src/main/java/com/andexert/calendarlistview/library/SimpleMonthView.java:
--------------------------------------------------------------------------------
1 | /***********************************************************************************
2 | * The MIT License (MIT)
3 |
4 | * Copyright (c) 2014 Robin Chutaux
5 |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 |
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | ***********************************************************************************/
24 | package com.andexert.calendarlistview.library;
25 |
26 | import android.content.Context;
27 | import android.content.res.Resources;
28 | import android.content.res.TypedArray;
29 | import android.graphics.Bitmap;
30 | import android.graphics.Canvas;
31 | import android.graphics.Paint;
32 | import android.graphics.Paint.Align;
33 | import android.graphics.Paint.Style;
34 | import android.graphics.Rect;
35 | import android.graphics.RectF;
36 | import android.graphics.Typeface;
37 | import android.support.v4.content.ContextCompat;
38 | import android.text.format.DateUtils;
39 | import android.text.format.Time;
40 | import android.util.Log;
41 | import android.view.MotionEvent;
42 | import android.view.View;
43 |
44 | import java.security.InvalidParameterException;
45 | import java.text.DateFormatSymbols;
46 | import java.text.ParseException;
47 | import java.text.SimpleDateFormat;
48 | import java.util.Calendar;
49 | import java.util.HashMap;
50 | import java.util.Locale;
51 |
52 | public class SimpleMonthView extends View {
53 |
54 | public static final String VIEW_PARAMS_HEIGHT = "height";
55 | public static final String VIEW_PARAMS_MONTH = "month";
56 | public static final String VIEW_PARAMS_YEAR = "year";
57 | public static final String VIEW_PARAMS_SELECTED_BEGIN_DAY = "selected_begin_day";
58 | public static final String VIEW_PARAMS_SELECTED_LAST_DAY = "selected_last_day";
59 | public static final String VIEW_PARAMS_SELECTED_BEGIN_MONTH = "selected_begin_month";
60 | public static final String VIEW_PARAMS_SELECTED_LAST_MONTH = "selected_last_month";
61 | public static final String VIEW_PARAMS_SELECTED_BEGIN_YEAR = "selected_begin_year";
62 | public static final String VIEW_PARAMS_SELECTED_LAST_YEAR = "selected_last_year";
63 | public static final String VIEW_PARAMS_WEEK_START = "week_start";
64 |
65 | protected static int DEFAULT_HEIGHT = 32;
66 | protected static final int DEFAULT_NUM_ROWS = 6;
67 | protected static int DAY_SELECTED_CIRCLE_SIZE;
68 | protected static int DAY_SEPARATOR_WIDTH = 1;
69 | protected static int MINI_DAY_NUMBER_TEXT_SIZE;
70 | protected static int MIN_HEIGHT = 10;
71 | protected static int MONTH_DAY_LABEL_TEXT_SIZE;
72 | protected static int MONTH_HEADER_SIZE;
73 | protected static int MONTH_LABEL_TEXT_SIZE;
74 |
75 | protected int mPadding = 0;
76 |
77 | private String mDayOfWeekTypeface;
78 |
79 | protected Paint mMonthDayLabelPaint;
80 | protected Paint mMonthNumPaint;
81 | protected Paint mMonthNumLinePaint;
82 | protected Paint mMonthTitleBGPaint;
83 | protected Paint mMonthTitlePaint;
84 | protected Paint mSelectedCirclePaint;
85 | protected int mCurrentDayTextColor;
86 | protected int mMonthTextColor;
87 | protected int mDayTextColor;
88 | protected int mDayNumColor;
89 | protected int mMonthTitleBGColor;
90 | protected int mPreviousDayColor;
91 | protected int mSelectedDaysColor;
92 |
93 | private final StringBuilder mStringBuilder;
94 |
95 | protected boolean mHasToday = false;
96 | protected boolean mIsPrev = false;
97 | protected boolean mIsShowMonthDay=true;
98 | protected int mSelectedBeginDay = -1;
99 | protected int mSelectedLastDay = -1;
100 | protected int mSelectedBeginMonth = -1;
101 | protected int mSelectedLastMonth = -1;
102 | protected int mSelectedBeginYear = -1;
103 | protected int mSelectedLastYear = -1;
104 | protected int mToday = -1;
105 | protected int mWeekStart = 1;
106 | protected int mNumDays = 7;
107 | protected int mNumCells = mNumDays;
108 | private int mDayOfWeekStart = 0;
109 | protected int mMonth;
110 | protected Boolean mDrawRect;
111 | protected int mRowHeight = DEFAULT_HEIGHT;
112 | protected int mWidth;
113 | protected int mYear;
114 | protected final Time today;
115 | protected Calendar minDay;
116 | protected int maxYear;
117 | protected int lastMonth;
118 |
119 | private final Calendar mCalendar;
120 | private final Calendar mDayLabelCalendar;
121 | private final Boolean isPrevDayEnabled;
122 |
123 | private int mNumRows = DEFAULT_NUM_ROWS;
124 |
125 | private DateFormatSymbols mDateFormatSymbols = new DateFormatSymbols();
126 |
127 | private OnDayClickListener mOnDayClickListener;
128 |
129 | public SimpleMonthView(Context context, TypedArray typedArray) {
130 | super(context);
131 |
132 | Resources resources = context.getResources();
133 | mDayLabelCalendar = Calendar.getInstance();
134 | mCalendar = Calendar.getInstance();
135 | today = new Time(Time.getCurrentTimezone());
136 | today.setToNow();
137 | mDayOfWeekTypeface = resources.getString(R.string.sans_serif);
138 | mCurrentDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorCurrentDay, resources.getColor(R.color.to_day));
139 | mMonthTextColor = typedArray.getColor(R.styleable.DayPickerView_colorMonthName, resources.getColor(R.color.normal_day));
140 | mDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorDayName, resources.getColor(R.color.normal_day));
141 | mDayNumColor = typedArray.getColor(R.styleable.DayPickerView_colorNormalDay, resources.getColor(R.color.normal_day));
142 | mPreviousDayColor = typedArray.getColor(R.styleable.DayPickerView_colorPreviousDay, resources.getColor(R.color.normal_day));
143 | mSelectedDaysColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayBackground, resources.getColor(R.color.selected_day_background));
144 | mMonthTitleBGColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayText, resources.getColor(R.color.selected_day_text));
145 | mIsShowMonthDay = typedArray.getBoolean(R.styleable.DayPickerView_showMonthDay,true);
146 | mDrawRect = typedArray.getBoolean(R.styleable.DayPickerView_drawRoundRect, false);
147 |
148 | mStringBuilder = new StringBuilder(50);
149 |
150 | MINI_DAY_NUMBER_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDay, resources.getDimensionPixelSize(R.dimen.text_size_day));
151 | MONTH_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeMonth, resources.getDimensionPixelSize(R.dimen.text_size_month));
152 | MONTH_DAY_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDayName, resources.getDimensionPixelSize(R.dimen.text_size_day_name));
153 | MONTH_HEADER_SIZE = typedArray.getDimensionPixelOffset(R.styleable.DayPickerView_headerMonthHeight, resources.getDimensionPixelOffset(mIsShowMonthDay?R.dimen.header_month_height_showWeek:R.dimen.header_month_height));
154 | DAY_SELECTED_CIRCLE_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_selectedDayRadius, resources.getDimensionPixelOffset(R.dimen.selected_day_radius));
155 |
156 | mRowHeight = ((typedArray.getDimensionPixelSize(R.styleable.DayPickerView_calendarHeight, resources.getDimensionPixelOffset(R.dimen.calendar_height)) - MONTH_HEADER_SIZE) / 6);
157 |
158 | isPrevDayEnabled = typedArray.getBoolean(R.styleable.DayPickerView_enablePreviousDay, true);
159 |
160 | initView();
161 |
162 | }
163 |
164 | private int calculateNumRows() {
165 | int offset = findDayOffset();
166 | int dividend = (offset + mNumCells) / mNumDays;
167 | int remainder = (offset + mNumCells) % mNumDays;
168 | return (dividend + (remainder > 0 ? 1 : 0));
169 | }
170 |
171 | private void drawMonthDayLabels(Canvas canvas) {
172 | int y = MONTH_HEADER_SIZE - (MONTH_DAY_LABEL_TEXT_SIZE / 2);
173 | int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2);
174 |
175 | for (int i = 0; i < mNumDays; i++) {
176 | int calendarDay = (i + mWeekStart) % mNumDays;
177 | int x = (2 * i + 1) * dayWidthHalf + mPadding;
178 | mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay);
179 | String numberDay = mDateFormatSymbols.getShortWeekdays()[mDayLabelCalendar.get(Calendar.DAY_OF_WEEK)].toUpperCase(Locale.getDefault());
180 | if(numberDay.equals("星期日")){
181 | numberDay = "日";
182 | }else if(numberDay.equals("星期一")){
183 | numberDay = "一";
184 | }else if(numberDay.equals("星期二")){
185 | numberDay = "二";
186 | }else if(numberDay.equals("星期三")){
187 | numberDay = "三";
188 | }else if(numberDay.equals("星期四")){
189 | numberDay = "四";
190 | }else if(numberDay.equals("星期五")){
191 | numberDay = "五";
192 | }else if(numberDay.equals("星期六")){
193 | numberDay = "六";
194 | }
195 | canvas.drawText(numberDay, x, y, mMonthDayLabelPaint);
196 | }
197 | }
198 |
199 | /**
200 | * 绘制当月是哪一年的哪一月。
201 | * @param canvas
202 | */
203 | private void drawMonthTitle(Canvas canvas) {
204 | StringBuilder stringBuilder = new StringBuilder(getMonthAndYearString().toLowerCase());
205 | stringBuilder.setCharAt(0, Character.toUpperCase(stringBuilder.charAt(0)));
206 | String text = stringBuilder.toString();
207 | Rect rect = new Rect();
208 | mMonthTitlePaint.getTextBounds(text,0,text.length(),rect);
209 | // int x = (mWidth + 2 * mPadding) / 2;
210 | int leftPadding = getResources().getDimensionPixelSize(R.dimen.month_day_left_padding);
211 | int x = rect.width()/2+leftPadding;
212 | // int y = (MONTH_HEADER_SIZE - MONTH_DAY_LABEL_TEXT_SIZE) / 2 + (MONTH_LABEL_TEXT_SIZE / 3);
213 | int y = (MONTH_HEADER_SIZE - MONTH_DAY_LABEL_TEXT_SIZE) + (MONTH_LABEL_TEXT_SIZE/4);
214 | if(mIsShowMonthDay){
215 | y = MONTH_HEADER_SIZE - MONTH_DAY_LABEL_TEXT_SIZE - (MONTH_LABEL_TEXT_SIZE * 2);
216 | }
217 | canvas.drawText(text, x, y, mMonthTitlePaint);
218 | int linePadding = getResources().getDimensionPixelSize(R.dimen.month_day_line_padding);
219 | canvas.drawLine(leftPadding,y+linePadding,rect.width()+leftPadding,y+linePadding,mMonthNumLinePaint);
220 | }
221 |
222 | private int findDayOffset() {
223 | return (mDayOfWeekStart < mWeekStart ? (mDayOfWeekStart + mNumDays) : mDayOfWeekStart)
224 | - mWeekStart;
225 | }
226 |
227 | private String getMonthAndYearString() {
228 | int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY;
229 | mStringBuilder.setLength(0);
230 | long millis = mCalendar.getTimeInMillis();
231 | return DateUtils.formatDateRange(getContext(), millis, millis, flags);
232 | }
233 |
234 | private void onDayClick(SimpleMonthAdapter.CalendarDay calendarDay) {
235 | if(mOnDayClickListener==null){
236 | return;
237 | }
238 | int year = calendarDay.year;
239 | int month = calendarDay.month;
240 | int day = calendarDay.day;
241 | if(year > getMaxYear() || (year == getMaxYear() && month>getLastMonth()) || (year == getMaxYear() && month == getLastMonth() && day>today.monthDay)){
242 | return;
243 | }
244 | if(minDay!=null){
245 | Calendar calendar = Calendar.getInstance();
246 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd",Locale.getDefault());
247 | try {
248 | long time = simpleDateFormat.parse(year+"-"+(month+1)+"-"+day).getTime();
249 | calendar.setTimeInMillis(time);
250 | } catch (ParseException e) {
251 | e.printStackTrace();
252 | }
253 | if(calendar.getTimeInMillis()>=minDay.getTimeInMillis()){
254 | mOnDayClickListener.onDayClick(this, calendarDay);
255 | }
256 | return;
257 | }
258 | if (isPrevDayEnabled
259 | || !((month == today.month)
260 | && (year == today.year)
261 | && day < today.monthDay)) {
262 | mOnDayClickListener.onDayClick(this, calendarDay);
263 | }
264 | }
265 |
266 | private boolean sameDay(int monthDay, Time time) {
267 | return (mYear == time.year) && (mMonth == time.month) && (monthDay == time.monthDay);
268 | }
269 |
270 | /**
271 | * 今天之前的时间
272 | * @param monthDay
273 | * @param time
274 | * @return
275 | */
276 | private boolean prevDay(int monthDay, Time time) {
277 | if(minDay!=null){
278 | Calendar currentCalendar = Calendar.getInstance();
279 | currentCalendar.set(mYear,mMonth,monthDay);
280 | return currentCalendar.getTimeInMillis() getMaxYear())) || (mYear == getMaxYear() && mMonth > getLastMonth()) || (mYear == getMaxYear() && mMonth == getLastMonth() && monthDay > today.monthDay);
290 | }
291 |
292 | protected void drawMonthNums(Canvas canvas) {
293 | int y = (mRowHeight + MINI_DAY_NUMBER_TEXT_SIZE) / 2 - DAY_SEPARATOR_WIDTH + MONTH_HEADER_SIZE;
294 | int paddingDay = (mWidth - 2 * mPadding) / (2 * mNumDays);
295 | int dayOffset = findDayOffset();
296 | int day = 1;
297 | String toDayRes = getResources().getString(R.string.today);
298 | while (day <= mNumCells) {
299 | boolean isShowTrain=true;
300 | int x = paddingDay * (1 + dayOffset * 2) + mPadding;
301 | if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear) || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear)) {
302 | if (mDrawRect) {
303 | RectF rectF = new RectF(x - DAY_SELECTED_CIRCLE_SIZE, (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) - DAY_SELECTED_CIRCLE_SIZE, x + DAY_SELECTED_CIRCLE_SIZE, (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) + DAY_SELECTED_CIRCLE_SIZE);
304 | canvas.drawRoundRect(rectF, 10.0f, 10.0f,mSelectedCirclePaint);
305 | } else{
306 | canvas.drawCircle(x, y - MINI_DAY_NUMBER_TEXT_SIZE / 3, DAY_SELECTED_CIRCLE_SIZE, mSelectedCirclePaint);
307 | }
308 | isShowTrain = false;
309 | }
310 | if (mHasToday && (mToday == day)) {
311 | mMonthNumPaint.setColor(mCurrentDayTextColor);
312 | } else {
313 | mMonthNumPaint.setColor(mDayNumColor);
314 | mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
315 | }
316 |
317 | if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear) || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear))
318 | mMonthNumPaint.setColor(mMonthTitleBGColor);
319 |
320 | if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear &&
321 | mSelectedBeginMonth == mSelectedLastMonth &&
322 | mSelectedBeginDay == mSelectedLastDay &&
323 | day == mSelectedBeginDay &&
324 | mMonth == mSelectedBeginMonth &&
325 | mYear == mSelectedBeginYear)){
326 | mMonthNumPaint.setColor(mSelectedDaysColor);
327 | }
328 | //多日期选中区间样式
329 | if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mSelectedBeginYear == mYear) &&
330 | (((mMonth == mSelectedBeginMonth && mSelectedLastMonth == mSelectedBeginMonth) && ((mSelectedBeginDay < mSelectedLastDay && day > mSelectedBeginDay && day < mSelectedLastDay) || (mSelectedBeginDay > mSelectedLastDay && day < mSelectedBeginDay && day > mSelectedLastDay))) ||
331 | ((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth && day < mSelectedLastDay)) ||
332 | ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth && day < mSelectedBeginDay) || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth && day > mSelectedLastDay)))) {
333 | mMonthNumPaint.setColor(mSelectedDaysColor);
334 | }
335 |
336 | if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear && ((mSelectedBeginYear == mYear && mMonth == mSelectedBeginMonth) || (mSelectedLastYear == mYear && mMonth == mSelectedLastMonth)) &&
337 | (((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth && day < mSelectedBeginDay) || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth && day > mSelectedLastDay)) ||
338 | ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth && day < mSelectedLastDay)))))
339 | {
340 | mMonthNumPaint.setColor(mSelectedDaysColor);
341 | }
342 |
343 | if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mYear == mSelectedBeginYear) &&
344 | ((mMonth > mSelectedBeginMonth && mMonth < mSelectedLastMonth && mSelectedBeginMonth < mSelectedLastMonth) ||
345 | (mMonth < mSelectedBeginMonth && mMonth > mSelectedLastMonth && mSelectedBeginMonth > mSelectedLastMonth)))
346 | {
347 | mMonthNumPaint.setColor(mSelectedDaysColor);
348 | }
349 |
350 | if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear) &&
351 | ((mSelectedBeginYear < mSelectedLastYear && ((mMonth > mSelectedBeginMonth && mYear == mSelectedBeginYear) || (mMonth < mSelectedLastMonth && mYear == mSelectedLastYear))) ||
352 | (mSelectedBeginYear > mSelectedLastYear && ((mMonth < mSelectedBeginMonth && mYear == mSelectedBeginYear) || (mMonth > mSelectedLastMonth && mYear == mSelectedLastYear)))))
353 | {
354 | mMonthNumPaint.setColor(mSelectedDaysColor);
355 | }
356 |
357 | if ((!isPrevDayEnabled && prevDay(day, today)) || nextDay(day)) {
358 | mMonthNumPaint.setColor(mPreviousDayColor);
359 | }
360 | if (mHasToday && (mToday == day)) {
361 | canvas.drawText(toDayRes, x, y, mMonthNumPaint);
362 | }else{
363 | canvas.drawText(String.format("%d", day), x, y, mMonthNumPaint);
364 | }
365 | dayOffset++;
366 | if (dayOffset == mNumDays) {
367 | dayOffset = 0;
368 | y += mRowHeight;
369 | }
370 | day++;
371 | }
372 | }
373 |
374 | public SimpleMonthAdapter.CalendarDay getDayFromLocation(float x, float y) {
375 | int padding = mPadding;
376 | if ((x < padding) || (x > mWidth - mPadding)) {
377 | return null;
378 | }
379 |
380 | int yDay = (int) (y - MONTH_HEADER_SIZE) / mRowHeight;
381 | int day = 1 + ((int) ((x - padding) * mNumDays / (mWidth - padding - mPadding)) - findDayOffset()) + yDay * mNumDays;
382 |
383 | if (mMonth > 11 || mMonth < 0 || CalendarUtils.getDaysInMonth(mMonth, mYear) < day || day < 1)
384 | return null;
385 |
386 | return new SimpleMonthAdapter.CalendarDay(mYear, mMonth, day);
387 | }
388 |
389 | protected void initView() {
390 | mMonthTitlePaint = new Paint();
391 | // mMonthTitlePaint.setFakeBoldText(true);
392 | mMonthTitlePaint.setAntiAlias(true);
393 | mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
394 | // mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
395 | mMonthTitlePaint.setColor(mMonthTextColor);
396 | mMonthTitlePaint.setTextAlign(Align.CENTER);
397 | mMonthTitlePaint.setStyle(Style.FILL);
398 |
399 | mMonthTitleBGPaint = new Paint();
400 | mMonthTitleBGPaint.setFakeBoldText(true);
401 | mMonthTitleBGPaint.setAntiAlias(true);
402 | mMonthTitleBGPaint.setColor(mMonthTitleBGColor);
403 | mMonthTitleBGPaint.setTextAlign(Align.CENTER);
404 | mMonthTitleBGPaint.setStyle(Style.FILL);
405 |
406 | mSelectedCirclePaint = new Paint();
407 | mSelectedCirclePaint.setFakeBoldText(true);
408 | mSelectedCirclePaint.setAntiAlias(true);
409 | mSelectedCirclePaint.setColor(mSelectedDaysColor);
410 | mSelectedCirclePaint.setTextAlign(Align.CENTER);
411 | mSelectedCirclePaint.setStyle(Style.FILL);
412 | // mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);
413 |
414 | mMonthDayLabelPaint = new Paint();
415 | mMonthDayLabelPaint.setAntiAlias(true);
416 | mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
417 | mMonthDayLabelPaint.setColor(mDayTextColor);
418 | mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL));
419 | mMonthDayLabelPaint.setStyle(Style.FILL);
420 | mMonthDayLabelPaint.setTextAlign(Align.CENTER);
421 | mMonthDayLabelPaint.setFakeBoldText(true);
422 |
423 | mMonthNumPaint = new Paint();
424 | mMonthNumPaint.setAntiAlias(true);
425 | mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE);
426 | mMonthNumPaint.setStyle(Style.FILL);
427 | mMonthNumPaint.setTextAlign(Align.CENTER);
428 | // mMonthNumPaint.setFakeBoldText(false);
429 |
430 | mMonthNumLinePaint = new Paint();
431 | mMonthNumLinePaint.setAntiAlias(true);
432 | mMonthNumLinePaint.setStrokeWidth(getResources().getDimensionPixelSize(R.dimen.month_day_line_width));
433 | mMonthNumLinePaint.setColor(ContextCompat.getColor(getContext(),R.color.month_num_line));
434 | }
435 |
436 | protected void onDraw(Canvas canvas) {
437 | drawMonthTitle(canvas);
438 | if(mIsShowMonthDay){
439 | drawMonthDayLabels(canvas);
440 | }
441 | drawMonthNums(canvas);
442 | }
443 |
444 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
445 | setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), mRowHeight * mNumRows + MONTH_HEADER_SIZE);
446 | }
447 |
448 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
449 | mWidth = w;
450 | }
451 |
452 | public boolean onTouchEvent(MotionEvent event) {
453 | if (event.getAction() == MotionEvent.ACTION_UP) {
454 | SimpleMonthAdapter.CalendarDay calendarDay = getDayFromLocation(event.getX(), event.getY());
455 | if (calendarDay != null) {
456 | onDayClick(calendarDay);
457 | }
458 | }
459 | return true;
460 | }
461 |
462 | public void reuse() {
463 | mNumRows = DEFAULT_NUM_ROWS;
464 | requestLayout();
465 | }
466 |
467 | public void setMonthParams(HashMap params) {
468 | if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) {
469 | throw new InvalidParameterException("You must specify month and year for this view");
470 | }
471 | setTag(params);
472 |
473 | if (params.containsKey(VIEW_PARAMS_HEIGHT)) {
474 | mRowHeight = params.get(VIEW_PARAMS_HEIGHT);
475 | if (mRowHeight < MIN_HEIGHT) {
476 | mRowHeight = MIN_HEIGHT;
477 | }
478 | }
479 | if (params.containsKey(VIEW_PARAMS_SELECTED_BEGIN_DAY)) {
480 | mSelectedBeginDay = params.get(VIEW_PARAMS_SELECTED_BEGIN_DAY);
481 | }
482 | if (params.containsKey(VIEW_PARAMS_SELECTED_LAST_DAY)) {
483 | mSelectedLastDay = params.get(VIEW_PARAMS_SELECTED_LAST_DAY);
484 | }
485 | if (params.containsKey(VIEW_PARAMS_SELECTED_BEGIN_MONTH)) {
486 | mSelectedBeginMonth = params.get(VIEW_PARAMS_SELECTED_BEGIN_MONTH);
487 | }
488 | if (params.containsKey(VIEW_PARAMS_SELECTED_LAST_MONTH)) {
489 | mSelectedLastMonth = params.get(VIEW_PARAMS_SELECTED_LAST_MONTH);
490 | }
491 | if (params.containsKey(VIEW_PARAMS_SELECTED_BEGIN_YEAR)) {
492 | mSelectedBeginYear = params.get(VIEW_PARAMS_SELECTED_BEGIN_YEAR);
493 | }
494 | if (params.containsKey(VIEW_PARAMS_SELECTED_LAST_YEAR)) {
495 | mSelectedLastYear = params.get(VIEW_PARAMS_SELECTED_LAST_YEAR);
496 | }
497 |
498 | mMonth = params.get(VIEW_PARAMS_MONTH);
499 | mYear = params.get(VIEW_PARAMS_YEAR);
500 |
501 | mHasToday = false;
502 | mToday = -1;
503 |
504 | mCalendar.set(Calendar.MONTH, mMonth);
505 | mCalendar.set(Calendar.YEAR, mYear);
506 | mCalendar.set(Calendar.DAY_OF_MONTH, 1);
507 | mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);
508 |
509 | if (params.containsKey(VIEW_PARAMS_WEEK_START)) {
510 | mWeekStart = params.get(VIEW_PARAMS_WEEK_START);
511 | } else {
512 | mWeekStart = mCalendar.getFirstDayOfWeek();
513 | }
514 |
515 | mNumCells = CalendarUtils.getDaysInMonth(mMonth, mYear);
516 | for (int i = 0; i < mNumCells; i++) {
517 | final int day = i + 1;
518 | if (sameDay(day, today)) {
519 | mHasToday = true;
520 | mToday = day;
521 | }
522 |
523 | mIsPrev = prevDay(day, today);
524 | }
525 |
526 | mNumRows = calculateNumRows();
527 | }
528 |
529 | public void setMinDay(Calendar calendar){
530 | this.minDay = calendar;
531 | }
532 |
533 | public int getMaxYear() {
534 | return maxYear;
535 | }
536 |
537 | public void setMaxYear(int maxYear) {
538 | this.maxYear = maxYear;
539 | }
540 |
541 | public int getLastMonth() {
542 | return lastMonth;
543 | }
544 |
545 | public void setLastMonth(int lastMonth) {
546 | this.lastMonth = lastMonth;
547 | }
548 |
549 | public void setOnDayClickListener(OnDayClickListener onDayClickListener) {
550 | mOnDayClickListener = onDayClickListener;
551 | }
552 |
553 | public interface OnDayClickListener {
554 | void onDayClick(SimpleMonthView simpleMonthView, SimpleMonthAdapter.CalendarDay calendarDay);
555 | }
556 | }
--------------------------------------------------------------------------------
/calendarlist/src/main/res/drawable-hdpi/calendar_train_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangyxgit/CalendarListEvolution/b6003d5ffd7657775e47d78f93ccdaec5ef7e08f/calendarlist/src/main/res/drawable-hdpi/calendar_train_blue.png
--------------------------------------------------------------------------------
/calendarlist/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangyxgit/CalendarListEvolution/b6003d5ffd7657775e47d78f93ccdaec5ef7e08f/calendarlist/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/calendarlist/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangyxgit/CalendarListEvolution/b6003d5ffd7657775e47d78f93ccdaec5ef7e08f/calendarlist/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/calendarlist/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangyxgit/CalendarListEvolution/b6003d5ffd7657775e47d78f93ccdaec5ef7e08f/calendarlist/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/calendarlist/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tangyxgit/CalendarListEvolution/b6003d5ffd7657775e47d78f93ccdaec5ef7e08f/calendarlist/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/calendarlist/src/main/res/values/attrs.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 |
--------------------------------------------------------------------------------
/calendarlist/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #ff999999
5 | #E75F49
6 | #fff2f2f2
7 | #3ec599
8 | #f4f4f4
9 |
10 |
--------------------------------------------------------------------------------
/calendarlist/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16sp
4 | 16sp
5 | 10sp
6 | 50dip
7 | 80dip
8 | 16dip
9 | 25dip
10 | 10dip
11 | 3dip
12 | 300dip
13 |
--------------------------------------------------------------------------------
/calendarlist/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CalendarListview
3 |
4 |
5 | sans-serif
6 | 今天
7 |
8 |
--------------------------------------------------------------------------------
/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/tangyxgit/CalendarListEvolution/b6003d5ffd7657775e47d78f93ccdaec5ef7e08f/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-2.14.1-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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':calendarlist'
2 |
--------------------------------------------------------------------------------