├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── .travis.yml ├── LICENSE.txt ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tubb │ │ └── calendarselector │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── tubb │ │ └── calendarselector │ │ ├── MainActivity.java │ │ ├── TestApplication.java │ │ ├── custom │ │ ├── AnimCalendarSelectorActivity.java │ │ ├── AnimDayViewActivity.java │ │ ├── AnimDayViewInflater.java │ │ ├── AppleCalendarActivity.java │ │ ├── AppleCalendarDayViewInflater.java │ │ ├── CustomDayViewActivity.java │ │ ├── CustomDayViewInflater.java │ │ ├── CustomMainActivity.java │ │ ├── DecorDayViewActivity.java │ │ └── DecorDayViewInflater.java │ │ └── normal │ │ ├── CalendarSelectorActivity.java │ │ ├── NormalActivity.java │ │ ├── NormalMainActivity.java │ │ ├── Protocol.java │ │ ├── SingleMonthSelectorActivity.java │ │ ├── StateSavedActivity.java │ │ └── ViewPagerActivity.java │ └── res │ ├── drawable │ ├── drawable_custom_dayview_text_bg.xml │ ├── shape_custom_dayview_text_bg_normal.xml │ └── shape_custom_dayview_text_bg_selected.xml │ ├── layout │ ├── activity_apple_calendar.xml │ ├── activity_custom_decor.xml │ ├── activity_custom_main.xml │ ├── activity_main.xml │ ├── activity_normal.xml │ ├── activity_normal_main.xml │ ├── activity_scrolling.xml │ ├── activity_single_month_selector.xml │ ├── activity_vp.xml │ ├── item_apple_calendar.xml │ ├── item_calendar.xml │ ├── item_vp.xml │ ├── layout_dayview_custom.xml │ ├── layout_dayview_decor_custom.xml │ ├── layout_monday_start.xml │ ├── layout_saturday_start.xml │ ├── layout_sunday_start.xml │ ├── view_horizontal_decor.xml │ └── view_vertical_decor.xml │ ├── menu │ ├── menu_mode.xml │ └── menu_normal.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-zh │ └── strings.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── art ├── 1.png └── preview.gif ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── tubb │ │ └── calendarselector │ │ ├── custom │ │ ├── DayViewHolder.java │ │ └── DayViewInflater.java │ │ └── library │ │ ├── CalendarSelector.java │ │ ├── DefaultDayViewHolder.java │ │ ├── DefaultDayViewInflater.java │ │ ├── FullDay.java │ │ ├── IntervalSelectListener.java │ │ ├── MonthView.java │ │ ├── SCDateUtils.java │ │ ├── SCMonth.java │ │ ├── SegmentSelectListener.java │ │ └── SingleMonthSelector.java │ └── res │ ├── color │ └── color_dayview_text_selector.xml │ ├── drawable │ ├── drawable_dayview_text_bg.xml │ ├── shape_dayview_text_bg_normal.xml │ └── shape_dayview_text_bg_selected.xml │ ├── layout │ └── layout_dayview_default.xml │ └── values │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ └── strings.xml └── 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 | /projectFilesBackup 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 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | android: 3 | components: 4 | - tools 5 | - platform-tools 6 | - build-tools-23.0.2 7 | - android-23 8 | - extra-android-m2repository 9 | - sys-img-armeabi-v7a-android-18 10 | 11 | script: 12 | - ./gradlew build connectedCheck 13 | 14 | before_script: 15 | # Create and start an emulator for instrumentation tests. 16 | - echo no | android create avd --force -n test -t android-18 --abi armeabi-v7a 17 | - emulator -avd test -no-audio -no-window & 18 | - android-wait-for-emulator 19 | - adb shell input keyevent 82 20 | 21 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Calendar Selector 2 | ================= 3 | 4 | [中文文档][9] 5 | 6 | A `calendar selector` for select dates, support select a `continuous` period of time and some `discontinuous` dates. 7 | 8 | Supported functionality: 9 | 10 | * select `continuous` or `discontinuous` dates 11 | * single month or multi months selection 12 | * intercept select event 13 | * save state 14 | * UI custom 15 | * indicate the start day of a week (`SUNDAY`、`SATURDAY`、`MONDAY`) 16 | * editor mode support, a good feeling of develop 17 | * API 8+ 18 | 19 | Preview 20 | ======= 21 | 22 | ![Preview](https://github.com/TUBB/CalendarSelector/blob/master/art/preview.gif) 23 | 24 | Usage 25 | ----- 26 | 27 | Add to dependencies 28 | 29 | ```groovy 30 | compile 'com.tubb.calendarselector.library:calendar-selector:0.2.3' 31 | ``` 32 | 33 | Just use [MonthView][1], [MonthView][1] is a custom view for display month's days 34 | 35 | ```xml 36 | 43 | ``` 44 | 45 | ![Month](https://github.com/TUBB/CalendarSelector/blob/master/art/1.png) 46 | 47 | We provide two `calendar selector` to select dates, one ( [SingleMonthSelector][2] ) is used for single month, 48 | another ( [CalendarSelector][3] ) is used for multi months, and the two `calendar selector` support `save state`, [StateSavedActivity][6] shows how to use them 49 | 50 | [SingleMonthSelector][2] usage 51 | 52 | ```java 53 | singleMonthSelector.bind(monthView); 54 | ``` 55 | 56 | [CalendarSelector][3] usage ( support all `ViewGroup`'s subclasses, but except `ListView` ) 57 | 58 | ```java 59 | calendarSelector.bind(containerViewGroup, monthView, itemPosition); 60 | ``` 61 | 62 | We support intercept select event, so you can do something you like, such as define the limit select dates 63 | 64 | We include two select mode, one is for `continuous` dates (`SEGMENT` MODE), another is for `discontinuous` dates (`INTERVAL` MODE) 65 | 66 | SEGMENT mode 67 | 68 | ```java 69 | selector = new CalendarSelector(data, CalendarSelector.Mode.SEGMENT); 70 | selector.setSegmentSelectListener(new SegmentSelectListener() { 71 | @Override 72 | public void onSegmentSelect(FullDay startDay, FullDay endDay) { 73 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString()); 74 | } 75 | 76 | @Override 77 | public boolean onInterceptSelect(FullDay selectingDay) { // one day intercept 78 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){ 79 | Toast.makeText(CalendarSelectorActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show(); 80 | return true; 81 | } 82 | return super.onInterceptSelect(selectingDay); 83 | } 84 | 85 | @Override 86 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) { // segment days intercept 87 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(), 88 | endDay.getYear(), endDay.getMonth(), endDay.getDay()); 89 | Log.d(TAG, "differDays " + differDays); 90 | if(differDays > 10) { 91 | Toast.makeText(CalendarSelectorActivity.this, "Selected days can't more than 10", Toast.LENGTH_SHORT).show(); 92 | return true; 93 | } 94 | return super.onInterceptSelect(startDay, endDay); 95 | } 96 | 97 | @Override 98 | public void selectedSameDay(FullDay sameDay) { // selected the same day 99 | super.selectedSameDay(sameDay); 100 | } 101 | }); 102 | ``` 103 | 104 | INTERVAL mode 105 | 106 | ```java 107 | selector = new SingleMonthSelector(CalendarSelector.Mode.INTERVAL); 108 | selector.setIntervalSelectListener(new IntervalSelectListener() { 109 | @Override 110 | public void onIntervalSelect(List selectedDays) { 111 | Log.d(TAG, "interval selected days " + selectedDays.toString()); 112 | } 113 | 114 | @Override 115 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) { 116 | if(selectedDays.size() >= 5) { 117 | Toast.makeText(SingleMonthSelectorActivity.this, "Selected days can't more than 5", Toast.LENGTH_LONG).show(); 118 | return true; 119 | } 120 | return super.onInterceptSelect(selectedDays, selectingDay); 121 | } 122 | }); 123 | ``` 124 | 125 | More details please see [SingleMonthSelectorActivity][4] and [CalendarSelectorActivity][5] 126 | 127 | Custom 128 | ====== 129 | 130 | `CalendarSelector` easy to custom, we abstract out the month's day ui to custom, 131 | so you can control the ui of month's day, just like a view, layout in xml 132 | 133 | ```xml 134 | 135 | 139 | 140 | 151 | 152 | 153 | ``` 154 | 155 | then implement your `DayViewInflater`, used by MonthView (`MonthView.setSCMonth(scMonth, new CustomDayViewInflater(context))`) 156 | 157 | ```java 158 | public class CustomDayViewInflater extends DayViewInflater{ 159 | 160 | public CustomDayViewInflater(Context context) { 161 | super(context); 162 | } 163 | 164 | @Override 165 | public DayViewHolder inflateDayView(ViewGroup container) { 166 | View dayView = mLayoutInflater.inflate(R.layout.layout_dayview_custom, container, false); 167 | return new CustomDayViewHolder(dayView); 168 | } 169 | 170 | public static class CustomDayViewHolder extends DayViewHolder{ 171 | 172 | protected TextView tvDay; 173 | private int mPrevMonthDayTextColor; 174 | private int mNextMonthDayTextColor; 175 | 176 | public CustomDayViewHolder(View dayView) { 177 | super(dayView); 178 | tvDay = (TextView) dayView.findViewById(com.tubb.calendarselector.library.R.id.tvDay); 179 | mPrevMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999); 180 | mNextMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999); 181 | } 182 | 183 | @Override 184 | public void setCurrentMonthDayText(FullDay day, boolean isSelected) { 185 | tvDay.setText(String.valueOf(day.getDay())); 186 | tvDay.setSelected(isSelected); 187 | } 188 | 189 | @Override 190 | public void setPrevMonthDayText(FullDay day) { 191 | tvDay.setTextColor(mPrevMonthDayTextColor); 192 | tvDay.setText(String.valueOf(day.getDay())); 193 | } 194 | 195 | @Override 196 | public void setNextMonthDayText(FullDay day) { 197 | tvDay.setTextColor(mNextMonthDayTextColor); 198 | tvDay.setText(String.valueOf(day.getDay())); 199 | } 200 | 201 | } 202 | } 203 | ``` 204 | 205 | When day has selected, the DayViewHolder.setCurrentMonthDayText(FullDay day, boolean isSelected) method will be excute, 206 | at this moment, you can do something interesting (add animator for day view), please see [AnimDayViewInflater][8] 207 | 208 | ```java 209 | @Override 210 | public void setCurrentMonthDayText(FullDay day, boolean isSelected) { 211 | boolean oldSelected = tvDay.isSelected(); 212 | tvDay.setText(String.valueOf(day.getDay())); 213 | tvDay.setSelected(isSelected); 214 | // view selected animation 215 | if(!oldSelected && isSelected){ 216 | AnimatorSet animatorSet = new AnimatorSet(); 217 | animatorSet.setInterpolator(AnimationUtils.loadInterpolator(mContext, android.R.anim.bounce_interpolator)); 218 | animatorSet.play(ObjectAnimator.ofFloat(tvDay, "scaleX", 0.5f, 1.0f)) 219 | .with(ObjectAnimator.ofFloat(tvDay, "scaleY", 0.5f, 1.0f)); 220 | animatorSet.setDuration(500) 221 | .start(); 222 | } 223 | } 224 | ``` 225 | 226 | We also provide the ability for decorate day view, please see [DecorDayViewInflater][7] 227 | ```java 228 | @Override 229 | public Decor inflateHorizontalDecor(ViewGroup container, int row, int totalRow) { 230 | return new Decor(mLayoutInflater.inflate(R.layout.view_horizontal_decor, container, false), true); 231 | } 232 | 233 | @Override 234 | public Decor inflateVerticalDecor(ViewGroup container, int col, int totalCol) { 235 | return new Decor(mLayoutInflater.inflate(R.layout.view_vertical_decor, container, false), true); 236 | } 237 | ``` 238 | 239 | We include several attrs for [MonthView][1] 240 | 241 | ```xml 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | ``` 261 | 262 | Note 263 | ==== 264 | 265 | If you have any question, just commit some issues 266 | 267 | 268 | License 269 | ------- 270 | 271 | Copyright 2016 TUBB 272 | 273 | Licensed under the Apache License, Version 2.0 (the "License"); 274 | you may not use this file except in compliance with the License. 275 | You may obtain a copy of the License at 276 | 277 | http://www.apache.org/licenses/LICENSE-2.0 278 | 279 | Unless required by applicable law or agreed to in writing, software 280 | distributed under the License is distributed on an "AS IS" BASIS, 281 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 282 | See the License for the specific language governing permissions and 283 | limitations under the License. 284 | 285 | 286 | 287 | [1]: https://github.com/TUBB/CalendarSelector/blob/master/library/src/main/java/com/tubb/calendarselector/library/MonthView.java 288 | [2]: https://github.com/TUBB/CalendarSelector/blob/master/library/src/main/java/com/tubb/calendarselector/library/SingleMonthSelector.java 289 | [3]: https://github.com/TUBB/CalendarSelector/blob/master/library/src/main/java/com/tubb/calendarselector/library/CalendarSelector.java 290 | [4]: https://github.com/TUBB/CalendarSelector/blob/master/app/src/main/java/com/tubb/calendarselector/normal/SingleMonthSelectorActivity.java 291 | [5]: https://github.com/TUBB/CalendarSelector/blob/master/app/src/main/java/com/tubb/calendarselector/normal/CalendarSelectorActivity.java 292 | [6]: https://github.com/TUBB/CalendarSelector/blob/master/app/src/main/java/com/tubb/calendarselector/normal/StateSavedActivity.java 293 | [7]: https://github.com/TUBB/CalendarSelector/blob/master/app/src/main/java/com/tubb/calendarselector/custom/DecorDayViewInflater.java 294 | [8]: https://github.com/TUBB/CalendarSelector/blob/master/app/src/main/java/com/tubb/calendarselector/custom/AnimDayViewInflater.java 295 | [9]: http://tubb.github.io/2016/04/17/Android%E6%97%A5%E6%9C%9F%E6%98%BE%E7%A4%BA%E5%92%8C%E9%80%89%E6%8B%A9%E5%BA%93/ 296 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion rootProject.compileSdkVersion 5 | buildToolsVersion rootProject.buildToolsVersion 6 | 7 | defaultConfig { 8 | applicationId "com.tubb.calendarselector" 9 | minSdkVersion 11 10 | targetSdkVersion rootProject.targetSdkVersion 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | packagingOptions { 21 | exclude 'LICENSE.txt' 22 | } 23 | } 24 | 25 | dependencies { 26 | compile fileTree(dir: 'libs', include: ['*.jar']) 27 | compile project(':library') 28 | compile 'com.android.support:appcompat-v7:'+rootProject.appcompatVersion 29 | compile 'com.android.support:recyclerview-v7:'+rootProject.appcompatVersion 30 | compile 'com.android.support:design:23.1.1' 31 | compile 'com.github.moduth:blockcanary-ui:1.2.0' 32 | } 33 | -------------------------------------------------------------------------------- /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/tubingbing/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/tubb/calendarselector/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | import com.tubb.calendarselector.custom.CustomMainActivity; 9 | import com.tubb.calendarselector.normal.CalendarSelectorActivity; 10 | import com.tubb.calendarselector.normal.NormalActivity; 11 | import com.tubb.calendarselector.normal.NormalMainActivity; 12 | import com.tubb.calendarselector.normal.SingleMonthSelectorActivity; 13 | import com.tubb.calendarselector.normal.StateSavedActivity; 14 | import com.tubb.calendarselector.normal.ViewPagerActivity; 15 | 16 | public class MainActivity extends AppCompatActivity { 17 | 18 | private static final String TAG = "mv"; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_main); 24 | } 25 | 26 | public void viewClick(View view){ 27 | switch (view.getId()){ 28 | case R.id.bt_default: 29 | startActivity(new Intent(this, NormalMainActivity.class)); 30 | break; 31 | case R.id.bt_custom: 32 | startActivity(new Intent(this, CustomMainActivity.class)); 33 | break; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/TestApplication.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector; 2 | 3 | import android.app.Application; 4 | 5 | import com.github.moduth.blockcanary.BlockCanary; 6 | import com.github.moduth.blockcanary.BlockCanaryContext; 7 | 8 | /** 9 | * Created by tubingbing on 16/4/15. 10 | */ 11 | public class TestApplication extends Application{ 12 | 13 | @Override 14 | public void onCreate() { 15 | super.onCreate(); 16 | // Do it on main process 17 | BlockCanary.install(this, new AppBlockCanaryContext()).start(); 18 | } 19 | 20 | class AppBlockCanaryContext extends BlockCanaryContext { 21 | // override to provide context like app qualifier, uid, network type, block threshold, log save path 22 | 23 | // this is default block threshold, you can set it by phone's performance 24 | @Override 25 | public int getConfigBlockThreshold() { 26 | return 500; 27 | } 28 | 29 | // if set true, notification will be shown, else only write log file 30 | @Override 31 | public boolean isNeedDisplay() { 32 | return BuildConfig.DEBUG; 33 | } 34 | 35 | // path to save log file 36 | @Override 37 | public String getLogPath() { 38 | return "/blockcanary/performance"; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/custom/AnimCalendarSelectorActivity.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.custom; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.support.v7.widget.SimpleItemAnimator; 8 | import android.util.Log; 9 | import android.util.SparseArray; 10 | import android.view.LayoutInflater; 11 | import android.view.Menu; 12 | import android.view.MenuItem; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.TextView; 16 | import android.widget.Toast; 17 | 18 | import com.tubb.calendarselector.R; 19 | import com.tubb.calendarselector.library.CalendarSelector; 20 | import com.tubb.calendarselector.library.FullDay; 21 | import com.tubb.calendarselector.library.IntervalSelectListener; 22 | import com.tubb.calendarselector.library.MonthView; 23 | import com.tubb.calendarselector.library.SCDateUtils; 24 | import com.tubb.calendarselector.library.SCMonth; 25 | import com.tubb.calendarselector.library.SegmentSelectListener; 26 | 27 | import java.util.List; 28 | 29 | public class AnimCalendarSelectorActivity extends AppCompatActivity { 30 | 31 | private static final String TAG = "mv"; 32 | 33 | CalendarSelector selector; 34 | RecyclerView rvCalendar; 35 | List data; 36 | 37 | @Override 38 | protected void onCreate(Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | setContentView(R.layout.activity_scrolling); 41 | if(savedInstanceState != null) 42 | selector = savedInstanceState.getParcelable("selector"); 43 | rvCalendar = (RecyclerView) findViewById(R.id.rvCalendar); 44 | rvCalendar.setLayoutManager(new LinearLayoutManager(this)); 45 | ((SimpleItemAnimator) rvCalendar.getItemAnimator()).setSupportsChangeAnimations(false); 46 | data = getData(); 47 | segmentMode(); 48 | } 49 | 50 | /** 51 | * segment mode 52 | */ 53 | private void segmentMode(){ 54 | 55 | data = getData(); 56 | 57 | selector = new CalendarSelector(data, CalendarSelector.SEGMENT); 58 | selector.setSegmentSelectListener(new SegmentSelectListener() { 59 | @Override 60 | public void onSegmentSelect(FullDay startDay, FullDay endDay) { 61 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString()); 62 | } 63 | 64 | @Override 65 | public boolean onInterceptSelect(FullDay selectingDay) { // one day intercept 66 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){ 67 | Toast.makeText(AnimCalendarSelectorActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show(); 68 | return true; 69 | } 70 | return super.onInterceptSelect(selectingDay); 71 | } 72 | 73 | @Override 74 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) { // segment days intercept 75 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(), 76 | endDay.getYear(), endDay.getMonth(), endDay.getDay()); 77 | Log.d(TAG, "differDays " + differDays); 78 | if(differDays > 10) { 79 | Toast.makeText(AnimCalendarSelectorActivity.this, "Selected days can't more than 10", Toast.LENGTH_SHORT).show(); 80 | return true; 81 | } 82 | return super.onInterceptSelect(startDay, endDay); 83 | } 84 | 85 | @Override 86 | public void selectedSameDay(FullDay sameDay) { // selected the same day 87 | super.selectedSameDay(sameDay); 88 | } 89 | }); 90 | rvCalendar.setAdapter(new CalendarAdpater(data)); 91 | } 92 | 93 | /** 94 | * interval mode 95 | */ 96 | private void intervalMode(){ 97 | data = getData(); 98 | selector = new CalendarSelector(data, CalendarSelector.INTERVAL); 99 | selector.setIntervalSelectListener(new IntervalSelectListener() { 100 | @Override 101 | public void onIntervalSelect(List selectedDays) { 102 | Log.d(TAG, "interval selected days " + selectedDays.toString()); 103 | } 104 | 105 | @Override 106 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) { 107 | if(selectedDays.size() >= 5) { 108 | Toast.makeText(AnimCalendarSelectorActivity.this, "Selected days can't more than 5", Toast.LENGTH_LONG).show(); 109 | return true; 110 | } 111 | return super.onInterceptSelect(selectedDays, selectingDay); 112 | } 113 | }); 114 | rvCalendar.setAdapter(new CalendarAdpater(data)); 115 | } 116 | 117 | public List getData() { 118 | return SCDateUtils.generateMonths(2016, 2018, SCMonth.SUNDAY_OF_WEEK); 119 | } 120 | 121 | class CalendarAdpater extends RecyclerView.Adapter{ 122 | 123 | List months; 124 | DayViewInflater animDayViewInflater; 125 | 126 | public CalendarAdpater(List months){ 127 | this.months = months; 128 | animDayViewInflater = new AnimDayViewInflater(AnimCalendarSelectorActivity.this); 129 | } 130 | 131 | @Override 132 | public CalendarViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 133 | return new CalendarViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_calendar, parent, false)); 134 | } 135 | 136 | @Override 137 | public void onBindViewHolder(CalendarViewHolder holder, int position) { 138 | SCMonth scMonth = months.get(position); 139 | holder.tvMonthTitle.setText(String.format("%d-%d", scMonth.getYear(), scMonth.getMonth())); 140 | holder.monthView.setSCMonth(scMonth, animDayViewInflater); 141 | selector.bind(rvCalendar, holder.monthView, position); 142 | } 143 | 144 | @Override 145 | public int getItemCount() { 146 | return months.size(); 147 | } 148 | } 149 | 150 | class CalendarViewHolder extends RecyclerView.ViewHolder{ 151 | 152 | TextView tvMonthTitle; 153 | MonthView monthView; 154 | 155 | public CalendarViewHolder(View itemView) { 156 | super(itemView); 157 | tvMonthTitle = (TextView) itemView.findViewById(R.id.tvMonthTitle); 158 | monthView = (MonthView) itemView.findViewById(R.id.ssMv); 159 | } 160 | } 161 | 162 | @Override 163 | public boolean onCreateOptionsMenu(Menu menu) { 164 | getMenuInflater().inflate(R.menu.menu_mode, menu); 165 | return true; 166 | } 167 | 168 | @Override 169 | public boolean onOptionsItemSelected(MenuItem item) { 170 | int id = item.getItemId(); 171 | 172 | if (id == R.id.action_segment) { 173 | segmentMode(); 174 | return true; 175 | } 176 | else if (id == R.id.action_interval) { 177 | intervalMode(); 178 | return true; 179 | } 180 | 181 | return super.onOptionsItemSelected(item); 182 | } 183 | 184 | @Override 185 | protected void onSaveInstanceState(Bundle outState) { 186 | outState.putParcelable("selector", selector); 187 | super.onSaveInstanceState(outState); 188 | } 189 | 190 | } 191 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/custom/AnimDayViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.custom; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.Log; 6 | import android.view.Menu; 7 | import android.view.MenuItem; 8 | import android.widget.TextView; 9 | import android.widget.Toast; 10 | 11 | import com.tubb.calendarselector.R; 12 | import com.tubb.calendarselector.library.FullDay; 13 | import com.tubb.calendarselector.library.IntervalSelectListener; 14 | import com.tubb.calendarselector.library.MonthView; 15 | import com.tubb.calendarselector.library.SCDateUtils; 16 | import com.tubb.calendarselector.library.SCMonth; 17 | import com.tubb.calendarselector.library.SegmentSelectListener; 18 | import com.tubb.calendarselector.library.SingleMonthSelector; 19 | 20 | import java.util.List; 21 | 22 | public class AnimDayViewActivity extends AppCompatActivity { 23 | 24 | private static final String TAG = "mv"; 25 | SCMonth scMonth; 26 | private SingleMonthSelector selector; 27 | private MonthView monthView; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_single_month_selector); 33 | monthView = (MonthView) findViewById(R.id.ssMv); 34 | TextView tvMonthTitle = (TextView) findViewById(R.id.tvMonthTitle); 35 | if(savedInstanceState != null){ 36 | scMonth = savedInstanceState.getParcelable("month"); 37 | } 38 | if(scMonth == null) 39 | scMonth = new SCMonth(2016, 5, SCMonth.SUNDAY_OF_WEEK); 40 | tvMonthTitle.setText(scMonth.toString()); 41 | segmentMode(); 42 | } 43 | 44 | private void segmentMode(){ 45 | scMonth = new SCMonth(2016, 5, SCMonth.SUNDAY_OF_WEEK); 46 | monthView.setSCMonth(scMonth, new AnimDayViewInflater(this)); 47 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.SEGMENT); 48 | selector.setSegmentSelectListener(new SegmentSelectListener() { 49 | @Override 50 | public void onSegmentSelect(FullDay startDay, FullDay endDay) { 51 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString()); 52 | } 53 | 54 | @Override 55 | public boolean onInterceptSelect(FullDay selectingDay) { 56 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){ 57 | Toast.makeText(AnimDayViewActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show(); 58 | return true; 59 | } 60 | return super.onInterceptSelect(selectingDay); 61 | } 62 | 63 | @Override 64 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) { 65 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(), 66 | endDay.getYear(), endDay.getMonth(), endDay.getDay()); 67 | Log.d(TAG, "differDays " + differDays); 68 | if(differDays > 5) { 69 | Toast.makeText(AnimDayViewActivity.this, "Selected days can't more than 5", Toast.LENGTH_SHORT).show(); 70 | return true; 71 | } 72 | return super.onInterceptSelect(startDay, endDay); 73 | } 74 | 75 | }); 76 | selector.bind(monthView); 77 | } 78 | 79 | private void intervalMode(){ 80 | scMonth = new SCMonth(2016, 5, SCMonth.SUNDAY_OF_WEEK); 81 | monthView.setSCMonth(scMonth, new AnimDayViewInflater(this)); 82 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.INTERVAL); 83 | selector.setIntervalSelectListener(new IntervalSelectListener() { 84 | @Override 85 | public void onIntervalSelect(List selectedDays) { 86 | Log.d(TAG, "interval selected days " + selectedDays.toString()); 87 | } 88 | 89 | @Override 90 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) { 91 | if(selectedDays.size() >= 5) { 92 | Toast.makeText(AnimDayViewActivity.this, "Selected days can't more than 5", Toast.LENGTH_LONG).show(); 93 | return true; 94 | } 95 | return super.onInterceptSelect(selectedDays, selectingDay); 96 | } 97 | }); 98 | selector.bind(monthView); 99 | } 100 | 101 | @Override 102 | public boolean onCreateOptionsMenu(Menu menu) { 103 | getMenuInflater().inflate(R.menu.menu_mode, menu); 104 | return true; 105 | } 106 | 107 | @Override 108 | public boolean onOptionsItemSelected(MenuItem item) { 109 | int id = item.getItemId(); 110 | 111 | if (id == R.id.action_segment) { 112 | segmentMode(); 113 | return true; 114 | } 115 | else if (id == R.id.action_interval) { 116 | intervalMode(); 117 | return true; 118 | } 119 | 120 | return super.onOptionsItemSelected(item); 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/custom/AnimDayViewInflater.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.custom; 2 | 3 | import android.animation.AnimatorSet; 4 | import android.animation.ObjectAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.support.v4.content.ContextCompat; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.view.animation.AnimationSet; 12 | import android.view.animation.AnimationUtils; 13 | import android.view.animation.BounceInterpolator; 14 | import android.widget.TextView; 15 | 16 | import com.tubb.calendarselector.R; 17 | import com.tubb.calendarselector.library.FullDay; 18 | 19 | /** 20 | * Created by tubingbing on 16/4/14. 21 | */ 22 | public class AnimDayViewInflater extends DayViewInflater{ 23 | 24 | public AnimDayViewInflater(Context context) { 25 | super(context); 26 | } 27 | 28 | @Override 29 | public DayViewHolder inflateDayView(ViewGroup container) { 30 | View dayView = mLayoutInflater.inflate(R.layout.layout_dayview_custom, container, false); 31 | return new CustomDayViewHolder(dayView); 32 | } 33 | 34 | public static class CustomDayViewHolder extends DayViewHolder{ 35 | 36 | protected TextView tvDay; 37 | private int mPrevMonthDayTextColor; 38 | private int mNextMonthDayTextColor; 39 | 40 | public CustomDayViewHolder(View dayView) { 41 | super(dayView); 42 | tvDay = (TextView) dayView.findViewById(com.tubb.calendarselector.library.R.id.tvDay); 43 | mPrevMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999); 44 | mNextMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_dddddd); 45 | } 46 | 47 | @Override 48 | public void setCurrentMonthDayText(FullDay day, boolean isSelected) { 49 | boolean oldSelected = tvDay.isSelected(); 50 | tvDay.setText(String.valueOf(day.getDay())); 51 | tvDay.setSelected(isSelected); 52 | // selected animation 53 | if(!oldSelected && isSelected){ 54 | AnimatorSet animatorSet = new AnimatorSet(); 55 | animatorSet.setInterpolator(AnimationUtils.loadInterpolator(mContext, android.R.anim.bounce_interpolator)); 56 | animatorSet.play(ObjectAnimator.ofFloat(tvDay, "scaleX", 0.5f, 1.0f)) 57 | .with(ObjectAnimator.ofFloat(tvDay, "scaleY", 0.5f, 1.0f)); 58 | animatorSet.setDuration(500) 59 | .start(); 60 | } 61 | } 62 | 63 | @Override 64 | public void setPrevMonthDayText(FullDay day) { 65 | tvDay.setTextColor(mPrevMonthDayTextColor); 66 | tvDay.setText(String.valueOf(day.getDay())); 67 | } 68 | 69 | @Override 70 | public void setNextMonthDayText(FullDay day) { 71 | tvDay.setTextColor(mNextMonthDayTextColor); 72 | tvDay.setText(String.valueOf(day.getDay())); 73 | } 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/custom/AppleCalendarActivity.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.custom; 2 | 3 | import android.animation.AnimatorSet; 4 | import android.animation.ObjectAnimator; 5 | import android.animation.ValueAnimator; 6 | import android.os.Bundle; 7 | import android.support.annotation.Nullable; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.support.v7.widget.SimpleItemAnimator; 12 | import android.util.Log; 13 | import android.view.LayoutInflater; 14 | import android.view.View; 15 | import android.view.ViewGroup; 16 | import android.view.animation.AccelerateDecelerateInterpolator; 17 | import android.view.animation.AccelerateInterpolator; 18 | import android.view.animation.AnimationSet; 19 | import android.widget.LinearLayout; 20 | import android.widget.TextView; 21 | import android.widget.Toast; 22 | 23 | import com.tubb.calendarselector.R; 24 | import com.tubb.calendarselector.library.CalendarSelector; 25 | import com.tubb.calendarselector.library.FullDay; 26 | import com.tubb.calendarselector.library.MonthView; 27 | import com.tubb.calendarselector.library.SCDateUtils; 28 | import com.tubb.calendarselector.library.SCMonth; 29 | import com.tubb.calendarselector.library.SegmentSelectListener; 30 | import com.tubb.calendarselector.library.SingleMonthSelector; 31 | 32 | import java.util.HashSet; 33 | import java.util.List; 34 | import java.util.Locale; 35 | import java.util.Set; 36 | 37 | /** 38 | * Created by tubingbing on 16/4/25. 39 | */ 40 | public class AppleCalendarActivity extends AppCompatActivity{ 41 | 42 | private RecyclerView rvCalendar; 43 | private CalendarSelector selector; 44 | 45 | @Override 46 | protected void onCreate(@Nullable Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | setContentView(R.layout.activity_apple_calendar); 49 | setTitle("2016"); 50 | rvCalendar = (RecyclerView) findViewById(R.id.rvCalendar); 51 | rvCalendar.setLayoutManager(new LinearLayoutManager(this)); 52 | ((SimpleItemAnimator) rvCalendar.getItemAnimator()).setSupportsChangeAnimations(false); 53 | List months = SCDateUtils.generateMonths(2016, 2016); 54 | rvCalendar.setAdapter(new CalendarAdpater(months)); 55 | selector = new CalendarSelector(months, SingleMonthSelector.SEGMENT); 56 | selector.setSegmentSelectListener(new SegmentSelectListener() { 57 | @Override 58 | public void onSegmentSelect(FullDay startDay, FullDay endDay) { 59 | // TODO 60 | } 61 | }); 62 | } 63 | 64 | class CalendarAdpater extends RecyclerView.Adapter{ 65 | 66 | List months; 67 | DayViewInflater appleCalendarDayViewInflater; 68 | Set animPositionSet = new HashSet<>(); 69 | 70 | public CalendarAdpater(List months){ 71 | this.months = months; 72 | appleCalendarDayViewInflater = new AppleCalendarDayViewInflater(AppleCalendarActivity.this); 73 | } 74 | 75 | @Override 76 | public CalendarViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 77 | return new CalendarViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_apple_calendar, parent, false)); 78 | } 79 | 80 | public void onBindViewHolder(final CalendarViewHolder holder, final int position) { 81 | final SCMonth scMonth = months.get(position); 82 | holder.tvMonthTitle.setText(String.format(Locale.getDefault(), "%d月", scMonth.getMonth())); 83 | holder.monthView.setSCMonth(scMonth, appleCalendarDayViewInflater); 84 | 85 | // wait for MonthView measure finish 86 | holder.monthView.post(new Runnable() { 87 | @Override 88 | public void run() { 89 | 90 | final int firstdayOfWeekPosInMonth = scMonth.getFirstdayOfWeekPosInMonth(); 91 | final int lineScrollX = -(firstdayOfWeekPosInMonth - 1) * holder.monthView.getDayWidth(); 92 | final int monthScrollX = -(firstdayOfWeekPosInMonth - 1) * holder.monthView.getDayWidth() 93 | - (holder.monthView.getDayWidth() / 2 - holder.tvMonthTitle.getWidth() / 2); 94 | 95 | // avoid anim every time 96 | if(!animPositionSet.contains(position)){ 97 | animPositionSet.add(position); 98 | ValueAnimator lineAnimator = ValueAnimator.ofInt(0, lineScrollX); 99 | lineAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 100 | @Override 101 | public void onAnimationUpdate(ValueAnimator animation) { 102 | int scrollX = (int) animation.getAnimatedValue(); 103 | holder.flScrollLine.scrollTo(scrollX , 0); 104 | } 105 | }); 106 | 107 | ValueAnimator monthAnimator = ValueAnimator.ofInt(0, monthScrollX); 108 | monthAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 109 | @Override 110 | public void onAnimationUpdate(ValueAnimator animation) { 111 | int scrollX = (int) animation.getAnimatedValue(); 112 | holder.flScrollMonth.scrollTo(scrollX , 0); 113 | } 114 | }); 115 | AnimatorSet animationSet = new AnimatorSet(); 116 | animationSet.play(monthAnimator).with(lineAnimator); 117 | animationSet.setInterpolator(new AccelerateDecelerateInterpolator()); 118 | animationSet.setDuration(500); 119 | animationSet.start(); 120 | }else{ 121 | holder.flScrollLine.scrollTo(lineScrollX , 0); 122 | holder.flScrollMonth.scrollTo(monthScrollX , 0); 123 | } 124 | 125 | int dayCount = holder.monthView.getCurrentMonthLastRowDayCount(); 126 | View decorView = holder.monthView.getLastHorizontalDecor(); 127 | if(decorView != null) 128 | decorView.scrollTo((7 - dayCount)*holder.monthView.getDayWidth(), 0); 129 | } 130 | }); 131 | 132 | selector.bind(rvCalendar, holder.monthView, position); 133 | } 134 | 135 | @Override 136 | public int getItemCount() { 137 | return months.size(); 138 | } 139 | } 140 | 141 | class CalendarViewHolder extends RecyclerView.ViewHolder{ 142 | 143 | View flScrollMonth; 144 | View flScrollLine; 145 | TextView tvMonthTitle; 146 | MonthView monthView; 147 | 148 | public CalendarViewHolder(View itemView) { 149 | super(itemView); 150 | tvMonthTitle = (TextView) itemView.findViewById(R.id.tvMonthTitle); 151 | monthView = (MonthView) itemView.findViewById(R.id.ssMv); 152 | flScrollMonth = itemView.findViewById(R.id.flScrollMonth); 153 | flScrollLine = itemView.findViewById(R.id.flScrollLine); 154 | } 155 | } 156 | 157 | } 158 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/custom/AppleCalendarDayViewInflater.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.custom; 2 | 3 | import android.animation.AnimatorSet; 4 | import android.animation.ObjectAnimator; 5 | import android.content.Context; 6 | import android.support.v4.content.ContextCompat; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | import com.tubb.calendarselector.R; 12 | import com.tubb.calendarselector.library.FullDay; 13 | 14 | /** 15 | * Created by tubingbing on 16/4/14. 16 | */ 17 | public class AppleCalendarDayViewInflater extends DayViewInflater{ 18 | 19 | public AppleCalendarDayViewInflater(Context context) { 20 | super(context); 21 | } 22 | 23 | @Override 24 | public DayViewHolder inflateDayView(ViewGroup container) { 25 | View dayView = mLayoutInflater.inflate(R.layout.layout_dayview_default, container, false); 26 | return new CustomDayViewHolder(dayView); 27 | } 28 | 29 | @Override 30 | public Decor inflateHorizontalDecor(ViewGroup container, int row, int totalRow) { 31 | return new Decor(mLayoutInflater.inflate(R.layout.view_horizontal_decor, container, false)); 32 | } 33 | 34 | @Override 35 | public boolean isShowHorizontalDecor(int row, int realRowCount) { 36 | if(row == 0 || row == realRowCount) return false; 37 | return super.isShowHorizontalDecor(row, realRowCount); 38 | } 39 | 40 | public static class CustomDayViewHolder extends DayViewHolder{ 41 | 42 | protected TextView tvDay; 43 | private int mPrevMonthDayTextColor; 44 | private int mNextMonthDayTextColor; 45 | 46 | public CustomDayViewHolder(View dayView) { 47 | super(dayView); 48 | tvDay = (TextView) dayView.findViewById(com.tubb.calendarselector.library.R.id.tvDay); 49 | mPrevMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999); 50 | mNextMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_dddddd); 51 | } 52 | 53 | @Override 54 | public void setCurrentMonthDayText(FullDay day, boolean isSelected) { 55 | if(day.getWeekOf() == FullDay.WEEK_1 || day.getWeekOf() == FullDay.WEEK_7) 56 | tvDay.setTextColor(mPrevMonthDayTextColor); 57 | boolean oldSelected = tvDay.isSelected(); 58 | tvDay.setText(String.valueOf(day.getDay())); 59 | tvDay.setSelected(isSelected); 60 | if(!oldSelected && isSelected){ 61 | AnimatorSet animatorSet = new AnimatorSet(); 62 | animatorSet.play(ObjectAnimator.ofFloat(tvDay, "rotationX", 0.0f, 360f)) 63 | .with(ObjectAnimator.ofFloat(tvDay, "rotationY", 0.0f, 360f)); 64 | animatorSet.setDuration(500) 65 | .start(); 66 | } 67 | } 68 | 69 | @Override 70 | public void setPrevMonthDayText(FullDay day) { 71 | tvDay.setTextColor(mPrevMonthDayTextColor); 72 | tvDay.setText(String.valueOf(day.getDay())); 73 | } 74 | 75 | @Override 76 | public void setNextMonthDayText(FullDay day) { 77 | tvDay.setTextColor(mNextMonthDayTextColor); 78 | tvDay.setText(String.valueOf(day.getDay())); 79 | } 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/custom/CustomDayViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.custom; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.Log; 6 | import android.view.Menu; 7 | import android.view.MenuItem; 8 | import android.widget.TextView; 9 | import android.widget.Toast; 10 | 11 | import com.tubb.calendarselector.R; 12 | import com.tubb.calendarselector.library.FullDay; 13 | import com.tubb.calendarselector.library.IntervalSelectListener; 14 | import com.tubb.calendarselector.library.MonthView; 15 | import com.tubb.calendarselector.library.SCDateUtils; 16 | import com.tubb.calendarselector.library.SCMonth; 17 | import com.tubb.calendarselector.library.SegmentSelectListener; 18 | import com.tubb.calendarselector.library.SingleMonthSelector; 19 | 20 | import java.util.List; 21 | 22 | public class CustomDayViewActivity extends AppCompatActivity { 23 | 24 | private static final String TAG = "mv"; 25 | SCMonth scMonth; 26 | private SingleMonthSelector selector; 27 | private MonthView monthView; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_single_month_selector); 33 | monthView = (MonthView) findViewById(R.id.ssMv); 34 | TextView tvMonthTitle = (TextView) findViewById(R.id.tvMonthTitle); 35 | if(savedInstanceState != null){ 36 | scMonth = savedInstanceState.getParcelable("month"); 37 | } 38 | if(scMonth == null) 39 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK); 40 | tvMonthTitle.setText(scMonth.toString()); 41 | segmentMode(); 42 | } 43 | 44 | private void segmentMode(){ 45 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.SEGMENT); 46 | monthView.setSCMonth(scMonth, new CustomDayViewInflater(this)); 47 | selector.setSegmentSelectListener(new SegmentSelectListener() { 48 | @Override 49 | public void onSegmentSelect(FullDay startDay, FullDay endDay) { 50 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString()); 51 | } 52 | 53 | @Override 54 | public boolean onInterceptSelect(FullDay selectingDay) { 55 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){ 56 | Toast.makeText(CustomDayViewActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show(); 57 | return true; 58 | } 59 | return super.onInterceptSelect(selectingDay); 60 | } 61 | 62 | @Override 63 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) { 64 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(), 65 | endDay.getYear(), endDay.getMonth(), endDay.getDay()); 66 | Log.d(TAG, "differDays " + differDays); 67 | if(differDays > 5) { 68 | Toast.makeText(CustomDayViewActivity.this, "Selected days can't more than 5", Toast.LENGTH_SHORT).show(); 69 | return true; 70 | } 71 | return super.onInterceptSelect(startDay, endDay); 72 | } 73 | 74 | }); 75 | selector.bind(monthView); 76 | } 77 | 78 | private void intervalMode(){ 79 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK); 80 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.INTERVAL); 81 | monthView.setSCMonth(scMonth, new CustomDayViewInflater(this)); 82 | selector.setIntervalSelectListener(new IntervalSelectListener() { 83 | @Override 84 | public void onIntervalSelect(List selectedDays) { 85 | Log.d(TAG, "interval selected days " + selectedDays.toString()); 86 | } 87 | 88 | @Override 89 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) { 90 | if(selectedDays.size() >= 5) { 91 | Toast.makeText(CustomDayViewActivity.this, "Selected days can't more than 5", Toast.LENGTH_LONG).show(); 92 | return true; 93 | } 94 | return super.onInterceptSelect(selectedDays, selectingDay); 95 | } 96 | }); 97 | selector.bind(monthView); 98 | } 99 | 100 | @Override 101 | public boolean onCreateOptionsMenu(Menu menu) { 102 | getMenuInflater().inflate(R.menu.menu_mode, menu); 103 | return true; 104 | } 105 | 106 | @Override 107 | public boolean onOptionsItemSelected(MenuItem item) { 108 | int id = item.getItemId(); 109 | 110 | if (id == R.id.action_segment) { 111 | segmentMode(); 112 | return true; 113 | } 114 | else if (id == R.id.action_interval) { 115 | intervalMode(); 116 | return true; 117 | } 118 | 119 | return super.onOptionsItemSelected(item); 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/custom/CustomDayViewInflater.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.custom; 2 | 3 | import android.content.Context; 4 | import android.support.v4.content.ContextCompat; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import com.tubb.calendarselector.R; 10 | import com.tubb.calendarselector.library.FullDay; 11 | 12 | /** 13 | * Created by tubingbing on 16/4/14. 14 | */ 15 | public class CustomDayViewInflater extends DayViewInflater{ 16 | 17 | public CustomDayViewInflater(Context context) { 18 | super(context); 19 | } 20 | 21 | @Override 22 | public DayViewHolder inflateDayView(ViewGroup container) { 23 | View dayView = mLayoutInflater.inflate(R.layout.layout_dayview_custom, container, false); 24 | return new CustomDayViewHolder(dayView); 25 | } 26 | 27 | public static class CustomDayViewHolder extends DayViewHolder{ 28 | 29 | protected TextView tvDay; 30 | private int mPrevMonthDayTextColor; 31 | private int mNextMonthDayTextColor; 32 | 33 | public CustomDayViewHolder(View dayView) { 34 | super(dayView); 35 | tvDay = (TextView) dayView.findViewById(com.tubb.calendarselector.library.R.id.tvDay); 36 | mPrevMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999); 37 | mNextMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999); 38 | } 39 | 40 | @Override 41 | public void setCurrentMonthDayText(FullDay day, boolean isSelected) { 42 | tvDay.setText(String.valueOf(day.getDay())); 43 | tvDay.setSelected(isSelected); 44 | } 45 | 46 | @Override 47 | public void setPrevMonthDayText(FullDay day) { 48 | tvDay.setTextColor(mPrevMonthDayTextColor); 49 | tvDay.setText(String.valueOf(day.getDay())); 50 | } 51 | 52 | @Override 53 | public void setNextMonthDayText(FullDay day) { 54 | tvDay.setTextColor(mNextMonthDayTextColor); 55 | tvDay.setText(String.valueOf(day.getDay())); 56 | } 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/custom/CustomMainActivity.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.custom; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | import com.tubb.calendarselector.R; 9 | import com.tubb.calendarselector.normal.CalendarSelectorActivity; 10 | import com.tubb.calendarselector.normal.NormalActivity; 11 | import com.tubb.calendarselector.normal.SingleMonthSelectorActivity; 12 | import com.tubb.calendarselector.normal.StateSavedActivity; 13 | import com.tubb.calendarselector.normal.ViewPagerActivity; 14 | 15 | public class CustomMainActivity extends AppCompatActivity { 16 | 17 | private static final String TAG = "mv"; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_custom_main); 23 | } 24 | 25 | public void viewClick(View view){ 26 | switch (view.getId()){ 27 | case R.id.bt_normal: 28 | startActivity(new Intent(this, CustomDayViewActivity.class)); 29 | break; 30 | case R.id.bt_anim: 31 | startActivity(new Intent(this, AnimDayViewActivity.class)); 32 | break; 33 | case R.id.bt_anim_calendar: 34 | startActivity(new Intent(this, AnimCalendarSelectorActivity.class)); 35 | break; 36 | case R.id.bt_decor: 37 | startActivity(new Intent(this, DecorDayViewActivity.class)); 38 | break; 39 | case R.id.bt_apple_calendar: 40 | startActivity(new Intent(this, AppleCalendarActivity.class)); 41 | break; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/custom/DecorDayViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.custom; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.Log; 6 | import android.view.Menu; 7 | import android.view.MenuItem; 8 | import android.widget.TextView; 9 | import android.widget.Toast; 10 | 11 | import com.tubb.calendarselector.R; 12 | import com.tubb.calendarselector.library.FullDay; 13 | import com.tubb.calendarselector.library.IntervalSelectListener; 14 | import com.tubb.calendarselector.library.MonthView; 15 | import com.tubb.calendarselector.library.SCDateUtils; 16 | import com.tubb.calendarselector.library.SCMonth; 17 | import com.tubb.calendarselector.library.SegmentSelectListener; 18 | import com.tubb.calendarselector.library.SingleMonthSelector; 19 | 20 | import java.util.List; 21 | 22 | public class DecorDayViewActivity extends AppCompatActivity { 23 | 24 | private static final String TAG = "mv"; 25 | SCMonth scMonth; 26 | private SingleMonthSelector selector; 27 | private MonthView monthView; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_custom_decor); 33 | monthView = (MonthView) findViewById(R.id.ssMv); 34 | TextView tvMonthTitle = (TextView) findViewById(R.id.tvMonthTitle); 35 | if(savedInstanceState != null){ 36 | scMonth = savedInstanceState.getParcelable("month"); 37 | } 38 | if(scMonth == null) 39 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK); 40 | tvMonthTitle.setText(scMonth.toString()); 41 | segmentMode(); 42 | } 43 | 44 | private void segmentMode(){ 45 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.SEGMENT); 46 | monthView.setSCMonth(scMonth, new DecorDayViewInflater(this)); 47 | selector.setSegmentSelectListener(new SegmentSelectListener() { 48 | @Override 49 | public void onSegmentSelect(FullDay startDay, FullDay endDay) { 50 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString()); 51 | } 52 | 53 | @Override 54 | public boolean onInterceptSelect(FullDay selectingDay) { 55 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){ 56 | Toast.makeText(DecorDayViewActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show(); 57 | return true; 58 | } 59 | return super.onInterceptSelect(selectingDay); 60 | } 61 | 62 | @Override 63 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) { 64 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(), 65 | endDay.getYear(), endDay.getMonth(), endDay.getDay()); 66 | Log.d(TAG, "differDays " + differDays); 67 | if(differDays > 15) { 68 | Toast.makeText(DecorDayViewActivity.this, "Selected days can't more than 15", Toast.LENGTH_SHORT).show(); 69 | return true; 70 | } 71 | return super.onInterceptSelect(startDay, endDay); 72 | } 73 | 74 | }); 75 | selector.bind(monthView); 76 | } 77 | 78 | private void intervalMode(){ 79 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK); 80 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.INTERVAL); 81 | monthView.setSCMonth(scMonth, new DecorDayViewInflater(this)); 82 | selector.setIntervalSelectListener(new IntervalSelectListener() { 83 | @Override 84 | public void onIntervalSelect(List selectedDays) { 85 | Log.d(TAG, "interval selected days " + selectedDays.toString()); 86 | } 87 | 88 | @Override 89 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) { 90 | if(selectedDays.size() >= 15) { 91 | Toast.makeText(DecorDayViewActivity.this, "Selected days can't more than 15", Toast.LENGTH_LONG).show(); 92 | return true; 93 | } 94 | return super.onInterceptSelect(selectedDays, selectingDay); 95 | } 96 | }); 97 | selector.bind(monthView); 98 | } 99 | 100 | @Override 101 | public boolean onCreateOptionsMenu(Menu menu) { 102 | getMenuInflater().inflate(R.menu.menu_mode, menu); 103 | return true; 104 | } 105 | 106 | @Override 107 | public boolean onOptionsItemSelected(MenuItem item) { 108 | int id = item.getItemId(); 109 | 110 | if (id == R.id.action_segment) { 111 | segmentMode(); 112 | return true; 113 | } 114 | else if (id == R.id.action_interval) { 115 | intervalMode(); 116 | return true; 117 | } 118 | 119 | return super.onOptionsItemSelected(item); 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/custom/DecorDayViewInflater.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.custom; 2 | 3 | import android.animation.AnimatorSet; 4 | import android.animation.ObjectAnimator; 5 | import android.content.Context; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import android.support.v4.content.ContextCompat; 9 | import android.support.v4.view.ViewCompat; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.view.animation.AnimationUtils; 13 | import android.widget.TextView; 14 | 15 | import com.tubb.calendarselector.R; 16 | import com.tubb.calendarselector.library.FullDay; 17 | 18 | /** 19 | * Created by tubingbing on 16/4/14. 20 | */ 21 | public class DecorDayViewInflater extends DayViewInflater{ 22 | 23 | public DecorDayViewInflater(Context context) { 24 | super(context); 25 | } 26 | 27 | @Override 28 | public DayViewHolder inflateDayView(ViewGroup container) { 29 | View dayView = mLayoutInflater.inflate(R.layout.layout_dayview_decor_custom, container, false); 30 | return new CustomDayViewHolder(dayView); 31 | } 32 | 33 | @Override 34 | public Decor inflateHorizontalDecor(ViewGroup container, int row, int totalRow) { 35 | return new Decor(mLayoutInflater.inflate(R.layout.view_horizontal_decor, container, false)); 36 | } 37 | 38 | @Override 39 | public Decor inflateVerticalDecor(ViewGroup container, int col, int totalCol) { 40 | return new Decor(mLayoutInflater.inflate(R.layout.view_vertical_decor, container, false)); 41 | } 42 | 43 | public static class CustomDayViewHolder extends DayViewHolder{ 44 | 45 | protected TextView tvDay; 46 | private int mPrevMonthDayTextColor; 47 | private int mNextMonthDayTextColor; 48 | 49 | public CustomDayViewHolder(View dayView) { 50 | super(dayView); 51 | tvDay = (TextView) dayView.findViewById(com.tubb.calendarselector.library.R.id.tvDay); 52 | mPrevMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999); 53 | mNextMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_dddddd); 54 | } 55 | 56 | @Override 57 | public void setCurrentMonthDayText(FullDay day, boolean isSelected) { 58 | boolean oldSelected = tvDay.isSelected(); 59 | tvDay.setText(String.valueOf(day.getDay())); 60 | tvDay.setSelected(isSelected); 61 | if(!oldSelected && isSelected){ 62 | AnimatorSet animatorSet = new AnimatorSet(); 63 | animatorSet.play(ObjectAnimator.ofFloat(tvDay, "rotationX", 0.0f, 360f)) 64 | .with(ObjectAnimator.ofFloat(tvDay, "rotationY", 0.0f, 360f)); 65 | animatorSet.setDuration(500) 66 | .start(); 67 | } 68 | } 69 | 70 | @Override 71 | public void setPrevMonthDayText(FullDay day) { 72 | tvDay.setTextColor(mPrevMonthDayTextColor); 73 | tvDay.setText(String.valueOf(day.getDay())); 74 | } 75 | 76 | @Override 77 | public void setNextMonthDayText(FullDay day) { 78 | tvDay.setTextColor(mNextMonthDayTextColor); 79 | tvDay.setText(String.valueOf(day.getDay())); 80 | } 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/normal/CalendarSelectorActivity.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.normal; 2 | 3 | import android.graphics.Bitmap; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.support.v7.widget.SimpleItemAnimator; 9 | import android.util.Log; 10 | import android.view.LayoutInflater; 11 | import android.view.Menu; 12 | import android.view.MenuItem; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.TextView; 16 | import android.widget.Toast; 17 | 18 | import com.tubb.calendarselector.R; 19 | import com.tubb.calendarselector.library.SCDateUtils; 20 | import com.tubb.calendarselector.library.FullDay; 21 | import com.tubb.calendarselector.library.IntervalSelectListener; 22 | import com.tubb.calendarselector.library.SCMonth; 23 | import com.tubb.calendarselector.library.CalendarSelector; 24 | import com.tubb.calendarselector.library.MonthView; 25 | import com.tubb.calendarselector.library.SegmentSelectListener; 26 | 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | public class CalendarSelectorActivity extends AppCompatActivity { 31 | 32 | private static final String TAG = "mv"; 33 | 34 | CalendarSelector selector; 35 | RecyclerView rvCalendar; 36 | List data; 37 | 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | setContentView(R.layout.activity_scrolling); 42 | if(savedInstanceState != null) 43 | selector = savedInstanceState.getParcelable("selector"); 44 | rvCalendar = (RecyclerView) findViewById(R.id.rvCalendar); 45 | rvCalendar.setLayoutManager(new LinearLayoutManager(this)); 46 | ((SimpleItemAnimator) rvCalendar.getItemAnimator()).setSupportsChangeAnimations(false); 47 | data = getData(); 48 | segmentMode(); 49 | // intervalMode(); 50 | } 51 | 52 | /** 53 | * segment mode 54 | */ 55 | private void segmentMode(){ 56 | 57 | data = getData(); 58 | 59 | selector = new CalendarSelector(data, CalendarSelector.SEGMENT); 60 | selector.addSelectedSegment(new FullDay(2016, 3, 10), new FullDay(2016, 4, 1)); 61 | selector.setSegmentSelectListener(new SegmentSelectListener() { 62 | @Override 63 | public void onSegmentSelect(FullDay startDay, FullDay endDay) { 64 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString()); 65 | } 66 | 67 | @Override 68 | public boolean onInterceptSelect(FullDay selectingDay) { // one day intercept 69 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){ 70 | Toast.makeText(CalendarSelectorActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show(); 71 | return true; 72 | } 73 | return super.onInterceptSelect(selectingDay); 74 | } 75 | 76 | @Override 77 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) { // segment days intercept 78 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(), 79 | endDay.getYear(), endDay.getMonth(), endDay.getDay()); 80 | Log.d(TAG, "differDays " + differDays); 81 | if(differDays > 10) { 82 | Toast.makeText(CalendarSelectorActivity.this, "Selected days can't more than 10", Toast.LENGTH_SHORT).show(); 83 | return true; 84 | } 85 | return super.onInterceptSelect(startDay, endDay); 86 | } 87 | 88 | @Override 89 | public void selectedSameDay(FullDay sameDay) { // selected the same day 90 | super.selectedSameDay(sameDay); 91 | } 92 | }); 93 | rvCalendar.setAdapter(new CalendarAdpater(data)); 94 | } 95 | 96 | /** 97 | * interval mode 98 | */ 99 | private void intervalMode(){ 100 | data = getData(); 101 | selector = new CalendarSelector(data, CalendarSelector.INTERVAL); 102 | selector.addSelectedInterval(new ArrayList(){ 103 | { 104 | add(new FullDay(2016, 2, 4)); 105 | add(new FullDay(2016, 3, 4)); 106 | add(new FullDay(2016, 3, 5)); 107 | add(new FullDay(2016, 4, 4)); 108 | } 109 | }); 110 | selector.setIntervalSelectListener(new IntervalSelectListener() { 111 | @Override 112 | public void onIntervalSelect(List selectedDays) { 113 | Log.d(TAG, "interval selected days " + selectedDays.toString()); 114 | } 115 | 116 | @Override 117 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) { 118 | if(selectedDays.size() >= 5) { 119 | Toast.makeText(CalendarSelectorActivity.this, "Selected days can't more than 5", Toast.LENGTH_LONG).show(); 120 | return true; 121 | } 122 | return super.onInterceptSelect(selectedDays, selectingDay); 123 | } 124 | }); 125 | rvCalendar.setAdapter(new CalendarAdpater(data)); 126 | } 127 | 128 | public List getData() { 129 | return SCDateUtils.generateMonths(2016, 2018, SCMonth.SUNDAY_OF_WEEK); 130 | } 131 | 132 | class CalendarAdpater extends RecyclerView.Adapter{ 133 | 134 | List months; 135 | 136 | public CalendarAdpater(List months){ 137 | this.months = months; 138 | } 139 | 140 | @Override 141 | public CalendarViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 142 | return new CalendarViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_calendar, parent, false)); 143 | } 144 | 145 | @Override 146 | public void onBindViewHolder(CalendarViewHolder holder, int position) { 147 | SCMonth scMonth = months.get(position); 148 | holder.tvMonthTitle.setText(String.format("%d-%d", scMonth.getYear(), scMonth.getMonth())); 149 | holder.monthView.setSCMonth(scMonth); 150 | selector.bind(rvCalendar, holder.monthView, position); 151 | } 152 | 153 | @Override 154 | public int getItemCount() { 155 | return months.size(); 156 | } 157 | } 158 | 159 | class CalendarViewHolder extends RecyclerView.ViewHolder{ 160 | 161 | TextView tvMonthTitle; 162 | MonthView monthView; 163 | 164 | public CalendarViewHolder(View itemView) { 165 | super(itemView); 166 | tvMonthTitle = (TextView) itemView.findViewById(R.id.tvMonthTitle); 167 | monthView = (MonthView) itemView.findViewById(R.id.ssMv); 168 | } 169 | } 170 | 171 | @Override 172 | public boolean onCreateOptionsMenu(Menu menu) { 173 | getMenuInflater().inflate(R.menu.menu_mode, menu); 174 | return true; 175 | } 176 | 177 | @Override 178 | public boolean onOptionsItemSelected(MenuItem item) { 179 | int id = item.getItemId(); 180 | 181 | if (id == R.id.action_segment) { 182 | segmentMode(); 183 | return true; 184 | } 185 | else if (id == R.id.action_interval) { 186 | intervalMode(); 187 | return true; 188 | } 189 | 190 | return super.onOptionsItemSelected(item); 191 | } 192 | 193 | 194 | @Override 195 | protected void onSaveInstanceState(Bundle outState) { 196 | outState.putParcelable("selector", selector); 197 | super.onSaveInstanceState(outState); 198 | } 199 | 200 | } 201 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/normal/NormalActivity.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.normal; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.TextView; 6 | 7 | import com.tubb.calendarselector.R; 8 | import com.tubb.calendarselector.library.FullDay; 9 | import com.tubb.calendarselector.library.SCMonth; 10 | import com.tubb.calendarselector.library.MonthView; 11 | 12 | public class NormalActivity extends AppCompatActivity { 13 | 14 | private static final String TAG = "mv"; 15 | SCMonth scMonth; 16 | private MonthView monthView; 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_normal); 22 | monthView = (MonthView) findViewById(R.id.ssMv); 23 | 24 | TextView tvMonthTitle = (TextView) findViewById(R.id.tvMonthTitle); 25 | if(savedInstanceState != null){ 26 | scMonth = savedInstanceState.getParcelable("month"); 27 | } 28 | if(scMonth == null) 29 | scMonth = new SCMonth(2016, 5, SCMonth.SUNDAY_OF_WEEK); 30 | tvMonthTitle.setText(scMonth.toString()); 31 | monthView.setSCMonth(scMonth); 32 | monthView.setMonthDayClickListener(new MonthView.OnMonthDayClickListener() { 33 | @Override 34 | public void onMonthDayClick(FullDay day) { 35 | monthView.clearSelectedDays(); 36 | monthView.addSelectedDay(day); 37 | } 38 | }); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/normal/NormalMainActivity.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.normal; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | import com.tubb.calendarselector.R; 9 | 10 | public class NormalMainActivity extends AppCompatActivity { 11 | 12 | private static final String TAG = "mv"; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_normal_main); 18 | } 19 | 20 | public void viewClick(View view){ 21 | switch (view.getId()){ 22 | case R.id.bt_normal: 23 | startActivity(new Intent(this, NormalActivity.class)); 24 | break; 25 | case R.id.bt_single: 26 | startActivity(new Intent(this, SingleMonthSelectorActivity.class)); 27 | break; 28 | case R.id.bt_calendar: 29 | startActivity(new Intent(this, CalendarSelectorActivity.class)); 30 | break; 31 | case R.id.bt_savedstate: 32 | startActivity(new Intent(this, StateSavedActivity.class)); 33 | break; 34 | case R.id.bt_vp: 35 | startActivity(new Intent(this, ViewPagerActivity.class)); 36 | break; 37 | case R.id.bt_state: 38 | startActivity(new Intent(this, StateSavedActivity.class)); 39 | break; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/normal/Protocol.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.normal; 2 | 3 | import com.tubb.calendarselector.library.SCMonth; 4 | 5 | /** 6 | * Created by tubingbing on 16/3/9. 7 | */ 8 | public interface Protocol { 9 | void clickNextMonthDay(SCMonth currentMonth); 10 | void clickPrevMonthDay(SCMonth currentMonth); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/normal/SingleMonthSelectorActivity.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.normal; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.Log; 6 | import android.view.Menu; 7 | import android.view.MenuItem; 8 | import android.widget.TextView; 9 | import android.widget.Toast; 10 | 11 | import com.tubb.calendarselector.R; 12 | import com.tubb.calendarselector.library.MonthView; 13 | import com.tubb.calendarselector.library.SCDateUtils; 14 | import com.tubb.calendarselector.library.FullDay; 15 | import com.tubb.calendarselector.library.IntervalSelectListener; 16 | import com.tubb.calendarselector.library.SCMonth; 17 | import com.tubb.calendarselector.library.SegmentSelectListener; 18 | import com.tubb.calendarselector.library.SingleMonthSelector; 19 | 20 | import java.util.List; 21 | 22 | public class SingleMonthSelectorActivity extends AppCompatActivity { 23 | 24 | private static final String TAG = "mv"; 25 | SCMonth scMonth; 26 | private SingleMonthSelector selector; 27 | private MonthView monthView; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_single_month_selector); 33 | monthView = (MonthView) findViewById(R.id.ssMv); 34 | TextView tvMonthTitle = (TextView) findViewById(R.id.tvMonthTitle); 35 | if(savedInstanceState != null){ 36 | scMonth = savedInstanceState.getParcelable("month"); 37 | } 38 | if(scMonth == null) 39 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK); 40 | tvMonthTitle.setText(scMonth.toString()); 41 | segmentMode(); 42 | } 43 | 44 | private void segmentMode(){ 45 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK); 46 | 47 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.SEGMENT); 48 | selector.addSelectedSegment(new FullDay(2016, 2, 4), new FullDay(2016, 2, 7)); 49 | monthView.setSCMonth(scMonth); 50 | selector.setSegmentSelectListener(new SegmentSelectListener() { 51 | @Override 52 | public void onSegmentSelect(FullDay startDay, FullDay endDay) { 53 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString()); 54 | } 55 | 56 | @Override 57 | public boolean onInterceptSelect(FullDay selectingDay) { 58 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){ 59 | Toast.makeText(SingleMonthSelectorActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show(); 60 | return true; 61 | } 62 | return super.onInterceptSelect(selectingDay); 63 | } 64 | 65 | @Override 66 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) { 67 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(), 68 | endDay.getYear(), endDay.getMonth(), endDay.getDay()); 69 | Log.d(TAG, "differDays " + differDays); 70 | if(differDays > 5) { 71 | Toast.makeText(SingleMonthSelectorActivity.this, "Selected days can't more than 5", Toast.LENGTH_SHORT).show(); 72 | return true; 73 | } 74 | return super.onInterceptSelect(startDay, endDay); 75 | } 76 | 77 | }); 78 | selector.bind(monthView); 79 | } 80 | 81 | private void intervalMode(){ 82 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK); 83 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.INTERVAL); 84 | selector.addSelectedInterval(new FullDay(2016, 2, 4)); 85 | selector.addSelectedInterval(new FullDay(2016, 2, 5)); 86 | selector.addSelectedInterval(new FullDay(2016, 2, 7)); 87 | monthView.setSCMonth(scMonth); 88 | selector.setIntervalSelectListener(new IntervalSelectListener() { 89 | @Override 90 | public void onIntervalSelect(List selectedDays) { 91 | Log.d(TAG, "interval selected days " + selectedDays.toString()); 92 | } 93 | 94 | @Override 95 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) { 96 | if(selectedDays.size() >= 5) { 97 | Toast.makeText(SingleMonthSelectorActivity.this, "Selected days can't more than 5", Toast.LENGTH_LONG).show(); 98 | return true; 99 | } 100 | return super.onInterceptSelect(selectedDays, selectingDay); 101 | } 102 | }); 103 | selector.bind(monthView); 104 | } 105 | 106 | @Override 107 | public boolean onCreateOptionsMenu(Menu menu) { 108 | getMenuInflater().inflate(R.menu.menu_mode, menu); 109 | return true; 110 | } 111 | 112 | @Override 113 | public boolean onOptionsItemSelected(MenuItem item) { 114 | int id = item.getItemId(); 115 | 116 | if (id == R.id.action_segment) { 117 | segmentMode(); 118 | return true; 119 | } 120 | else if (id == R.id.action_interval) { 121 | intervalMode(); 122 | return true; 123 | } 124 | 125 | return super.onOptionsItemSelected(item); 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/normal/StateSavedActivity.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.normal; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.util.Log; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.TextView; 12 | import android.widget.Toast; 13 | 14 | import com.tubb.calendarselector.R; 15 | import com.tubb.calendarselector.library.CalendarSelector; 16 | import com.tubb.calendarselector.library.SCDateUtils; 17 | import com.tubb.calendarselector.library.FullDay; 18 | import com.tubb.calendarselector.library.SCMonth; 19 | import com.tubb.calendarselector.library.MonthView; 20 | import com.tubb.calendarselector.library.SegmentSelectListener; 21 | 22 | import java.util.List; 23 | 24 | public class StateSavedActivity extends AppCompatActivity { 25 | 26 | private static final String TAG = "mv"; 27 | 28 | CalendarSelector processor; 29 | RecyclerView rvCalendar; 30 | List data; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_scrolling); 36 | if(savedInstanceState != null){ 37 | processor = savedInstanceState.getParcelable("selector"); 38 | } 39 | if(processor != null){ // restore data 40 | data = processor.getDataList(); 41 | }else{ // generate data 42 | data = getData(); 43 | processor = new CalendarSelector(data, CalendarSelector.SEGMENT); 44 | } 45 | 46 | rvCalendar = (RecyclerView) findViewById(R.id.rvCalendar); 47 | rvCalendar.setLayoutManager(new LinearLayoutManager(this)); 48 | 49 | processor.setSegmentSelectListener(new SegmentSelectListener() { 50 | @Override 51 | public void onSegmentSelect(FullDay startDay, FullDay endDay) { 52 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString()); 53 | } 54 | 55 | @Override 56 | public boolean onInterceptSelect(FullDay selectingDay) { 57 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){ 58 | Toast.makeText(StateSavedActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show(); 59 | return true; 60 | } 61 | return super.onInterceptSelect(selectingDay); 62 | } 63 | 64 | @Override 65 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) { 66 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(), 67 | endDay.getYear(), endDay.getMonth(), endDay.getDay()); 68 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString()); 69 | Log.d(TAG, "differDays " + differDays); 70 | if(differDays > 5) { 71 | Toast.makeText(StateSavedActivity.this, "Selected days can't more than 5", Toast.LENGTH_SHORT).show(); 72 | return true; 73 | } 74 | return super.onInterceptSelect(startDay, endDay); 75 | } 76 | }); 77 | rvCalendar.setAdapter(new CalendarAdpater(data)); 78 | } 79 | 80 | public List getData() { 81 | return SCDateUtils.generateMonths(2016, 2017, SCMonth.SUNDAY_OF_WEEK); 82 | } 83 | 84 | class CalendarAdpater extends RecyclerView.Adapter{ 85 | 86 | List months; 87 | 88 | public CalendarAdpater(List months){ 89 | this.months = months; 90 | } 91 | 92 | @Override 93 | public CalendarViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 94 | return new CalendarViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_calendar, parent, false)); 95 | } 96 | 97 | @Override 98 | public void onBindViewHolder(CalendarViewHolder holder, int position) { 99 | SCMonth SCMonth = months.get(position); 100 | holder.tvMonthTitle.setText(String.format("%d-%d", SCMonth.getYear(), SCMonth.getMonth())); 101 | holder.monthView.setSCMonth(SCMonth); 102 | processor.bind(rvCalendar, holder.monthView, position); 103 | } 104 | 105 | @Override 106 | public int getItemCount() { 107 | return months.size(); 108 | } 109 | } 110 | 111 | class CalendarViewHolder extends RecyclerView.ViewHolder{ 112 | 113 | TextView tvMonthTitle; 114 | MonthView monthView; 115 | 116 | public CalendarViewHolder(View itemView) { 117 | super(itemView); 118 | tvMonthTitle = (TextView) itemView.findViewById(R.id.tvMonthTitle); 119 | monthView = (MonthView) itemView.findViewById(R.id.ssMv); 120 | } 121 | } 122 | 123 | @Override 124 | protected void onSaveInstanceState(Bundle outState) { 125 | outState.putParcelable("selector", processor); 126 | super.onSaveInstanceState(outState); 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /app/src/main/java/com/tubb/calendarselector/normal/ViewPagerActivity.java: -------------------------------------------------------------------------------- 1 | package com.tubb.calendarselector.normal; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v4.app.FragmentManager; 8 | import android.support.v4.app.FragmentPagerAdapter; 9 | import android.support.v4.view.ViewPager; 10 | import android.support.v7.app.AppCompatActivity; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | import com.tubb.calendarselector.R; 18 | import com.tubb.calendarselector.library.FullDay; 19 | import com.tubb.calendarselector.library.MonthView; 20 | import com.tubb.calendarselector.library.SCDateUtils; 21 | import com.tubb.calendarselector.library.SCMonth; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | public class ViewPagerActivity extends AppCompatActivity implements Protocol { 27 | 28 | private static final String TAG = "mv"; 29 | 30 | TextView tvMonthTitle; 31 | ViewPager vpMonth; 32 | private List months; 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_vp); 38 | 39 | tvMonthTitle = (TextView) findViewById(R.id.tvMonthTitle); 40 | vpMonth = (ViewPager) findViewById(R.id.vpMonth); 41 | 42 | months = SCDateUtils.generateMonths(2016, 3, 2016, 12, SCMonth.SUNDAY_OF_WEEK); 43 | tvMonthTitle.setText(months.get(0).toString()); 44 | 45 | List fragments = new ArrayList<>(months.size()); 46 | for (SCMonth month:months){ 47 | fragments.add(MonthFragment.newInstance(month)); 48 | } 49 | vpMonth.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){ 50 | @Override 51 | public void onPageSelected(int position) { 52 | SCMonth month = months.get(position); 53 | tvMonthTitle.setText(month.toString()); 54 | } 55 | }); 56 | vpMonth.setAdapter(new MonthFragmentAdapter(getSupportFragmentManager(), fragments)); 57 | } 58 | 59 | @Override 60 | public void clickNextMonthDay(SCMonth currentMonth) { 61 | int currentIndex = months.indexOf(currentMonth); 62 | if(currentIndex+1 < months.size()) 63 | vpMonth.setCurrentItem(currentIndex+1, true); 64 | else Toast.makeText(this, "the end month", Toast.LENGTH_SHORT).show(); 65 | } 66 | 67 | @Override 68 | public void clickPrevMonthDay(SCMonth currentMonth) { 69 | int currentIndex = months.indexOf(currentMonth); 70 | if(currentIndex-1 >= 0) 71 | vpMonth.setCurrentItem(currentIndex-1, true); 72 | else Toast.makeText(this, "the start month", Toast.LENGTH_SHORT).show(); 73 | } 74 | 75 | class MonthFragmentAdapter extends FragmentPagerAdapter{ 76 | 77 | List fragments; 78 | 79 | public MonthFragmentAdapter(FragmentManager fm, List fragments) { 80 | super(fm); 81 | this.fragments = fragments; 82 | } 83 | 84 | @Override 85 | public Fragment getItem(int position) { 86 | return fragments.get(position); 87 | } 88 | 89 | @Override 90 | public int getCount() { 91 | return fragments.size(); 92 | } 93 | } 94 | 95 | public static final class MonthFragment extends Fragment{ 96 | 97 | public static Fragment newInstance(SCMonth month){ 98 | Fragment fragment = new MonthFragment(); 99 | Bundle bundle = new Bundle(); 100 | bundle.putParcelable("month", month); 101 | fragment.setArguments(bundle); 102 | return fragment; 103 | } 104 | 105 | @Nullable 106 | @Override 107 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 108 | return inflater.inflate(R.layout.item_vp, container, false); 109 | } 110 | 111 | @Override 112 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 113 | super.onViewCreated(view, savedInstanceState); 114 | final MonthView monthView = (MonthView) view.findViewById(R.id.scMv); 115 | final SCMonth month = getArguments().getParcelable("month"); 116 | monthView.setSCMonth(month); 117 | monthView.setMonthDayClickListener(new MonthView.OnMonthDayClickListener() { 118 | @Override 119 | public void onMonthDayClick(FullDay day) { 120 | if(SCDateUtils.isPrevMonthDay(monthView.getYear(), monthView.getMonth(), 121 | day.getYear(), day.getMonth())){ 122 | clickPrevMonthDay(month); 123 | }else if(SCDateUtils.isNextMonthDay(monthView.getYear(), monthView.getMonth(), 124 | day.getYear(), day.getMonth())){ 125 | clickNextMonthDay(month); 126 | }else{ 127 | monthView.clearSelectedDays(); 128 | monthView.addSelectedDay(day); 129 | } 130 | } 131 | }); 132 | } 133 | 134 | private void clickNextMonthDay(SCMonth month) { 135 | Activity activity = getActivity(); 136 | if(activity instanceof Protocol){ 137 | Protocol protocol = (Protocol)activity; 138 | protocol.clickNextMonthDay(month); 139 | } 140 | } 141 | 142 | private void clickPrevMonthDay(SCMonth month) { 143 | Activity activity = getActivity(); 144 | if(activity instanceof Protocol){ 145 | Protocol protocol = (Protocol)activity; 146 | protocol.clickPrevMonthDay(month); 147 | } 148 | } 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/drawable_custom_dayview_text_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_custom_dayview_text_bg_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_custom_dayview_text_bg_selected.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_apple_calendar.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 17 | 18 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_custom_decor.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 20 | 21 | 22 | 23 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_custom_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 |