├── CalendarList.iml ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── bao │ │ └── calendarlist │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── bao │ │ │ └── calendarlist │ │ │ ├── CalendarList.java │ │ │ ├── DateBean.java │ │ │ ├── MainActivity.java │ │ │ └── MyItemD.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ └── shape.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── item_calendar.xml │ │ ├── item_day.xml │ │ └── item_month.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── bao │ └── calendarlist │ └── ExampleUnitTest.java ├── build.gradle ├── build └── intermediates │ └── lint-cache │ ├── maven.google │ ├── com │ │ └── android │ │ │ └── support │ │ │ ├── constraint │ │ │ └── group-index.xml │ │ │ ├── group-index.xml │ │ │ └── test │ │ │ ├── espresso │ │ │ └── group-index.xml │ │ │ └── group-index.xml │ └── master-index.xml │ └── sdk-registry.xml │ └── sdk-registry.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties └── settings.gradle /CalendarList.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CalendarList 2 | Android自定义日期区间选择,日期范围选择的日历,实现类似美团携程选择酒店入住日期和离店日期的日历效果 3 | # 效果如下图: 4 | ![image](https://img-blog.csdnimg.cn/20181224145328435.gif) 5 | 6 | 博客介绍地址 https://blog.csdn.net/qifengdeqingchen/article/details/85233379 7 | 8 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.example.bao.calendarlist" 7 | minSdkVersion 15 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(include: ['*.jar'], dir: 'libs') 23 | implementation 'com.android.support:appcompat-v7:28.0.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 28 | implementation 'com.timehop.stickyheadersrecyclerview:library:0.4.3' 29 | 30 | implementation 'com.android.support:recyclerview-v7:28.0.0' 31 | } 32 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/bao/calendarlist/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.bao.calendarlist; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.bao.calendarlist", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/bao/calendarlist/CalendarList.java: -------------------------------------------------------------------------------- 1 | package com.example.bao.calendarlist; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.support.annotation.NonNull; 6 | import android.support.v7.widget.GridLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.text.TextUtils; 9 | import android.util.AttributeSet; 10 | import android.util.Log; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.FrameLayout; 15 | import android.widget.TextView; 16 | 17 | import java.text.SimpleDateFormat; 18 | import java.util.ArrayList; 19 | import java.util.Calendar; 20 | import java.util.Date; 21 | import java.util.List; 22 | 23 | public class CalendarList extends FrameLayout { 24 | private static final String TAG = MainActivity.class.getSimpleName() + "_LOG"; 25 | RecyclerView recyclerView; 26 | CalendarAdapter adapter; 27 | private DateBean startDate;//开始时间 28 | private DateBean endDate;//结束时间 29 | OnDateSelected onDateSelected;//选中监听 30 | SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd"); 31 | 32 | public CalendarList(Context context) { 33 | super(context); 34 | init(context); 35 | } 36 | 37 | public CalendarList(Context context,AttributeSet attrs) { 38 | super(context, attrs); 39 | init(context); 40 | } 41 | 42 | public CalendarList(Context context,AttributeSet attrs, int defStyleAttr) { 43 | super(context, attrs, defStyleAttr); 44 | init(context); 45 | } 46 | 47 | private void init(Context context) { 48 | addView(LayoutInflater.from(context).inflate(R.layout.item_calendar, this, false)); 49 | 50 | recyclerView = findViewById(R.id.recyclerView); 51 | adapter = new CalendarAdapter(); 52 | GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 7); 53 | gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { 54 | @Override 55 | public int getSpanSize(int i) { 56 | if (DateBean.item_type_month == adapter.data.get(i).getItemType()) { 57 | return 7; 58 | } else { 59 | return 1; 60 | } 61 | } 62 | }); 63 | recyclerView.setLayoutManager(gridLayoutManager); 64 | recyclerView.setAdapter(adapter); 65 | adapter.data.addAll(days("", "")); 66 | 67 | // DividerItemDecoration dividerItemDecoration=new DividerItemDecoration(this,DividerItemDecoration.VERTICAL); 68 | // dividerItemDecoration.setDrawable(ContextCompat.getDrawable(this,R.drawable.shape)); 69 | // recyclerView.addItemDecoration(dividerItemDecoration); 70 | 71 | MyItemD myItemD = new MyItemD(); 72 | recyclerView.addItemDecoration(myItemD); 73 | 74 | adapter.setOnRecyclerviewItemClick(new CalendarAdapter.OnRecyclerviewItemClick() { 75 | @Override 76 | public void onItemClick(View v, int position) { 77 | onClick(adapter.data.get(position)); 78 | } 79 | }); 80 | } 81 | 82 | private void onClick(DateBean dateBean) { 83 | 84 | if (dateBean.getItemType() == DateBean.item_type_month || TextUtils.isEmpty(dateBean.getDay())) { 85 | return; 86 | } 87 | 88 | //如果没有选中开始日期则此次操作选中开始日期 89 | if (startDate == null) { 90 | startDate = dateBean; 91 | dateBean.setItemState(DateBean.ITEM_STATE_BEGIN_DATE); 92 | } else if (endDate == null) { 93 | //如果选中了开始日期但没有选中结束日期,本次操作选中结束日期 94 | 95 | //如果当前点击的结束日期跟开始日期一致 则不做操作 96 | if (startDate == dateBean) { 97 | 98 | } else if (dateBean.getDate().getTime() < startDate.getDate().getTime()) { 99 | //当前点选的日期小于当前选中的开始日期 则本次操作重新选中开始日期 100 | startDate.setItemState(DateBean.ITEM_STATE_NORMAL); 101 | startDate = dateBean; 102 | startDate.setItemState(DateBean.ITEM_STATE_BEGIN_DATE); 103 | } else { 104 | //选中结束日期 105 | endDate = dateBean; 106 | endDate.setItemState(DateBean.ITEM_STATE_END_DATE); 107 | setState(); 108 | 109 | if(onDateSelected!=null){ 110 | onDateSelected.selected(simpleDateFormat.format(startDate.getDate()),simpleDateFormat.format(endDate.getDate())); 111 | } 112 | } 113 | 114 | } else if (startDate != null && endDate != null) { 115 | //结束日期和开始日期都已选中 116 | clearState(); 117 | 118 | //重新选择开始日期,结束日期清除 119 | startDate.setItemState(DateBean.ITEM_STATE_NORMAL); 120 | startDate = dateBean; 121 | startDate.setItemState(DateBean.ITEM_STATE_BEGIN_DATE); 122 | 123 | endDate.setItemState(DateBean.ITEM_STATE_NORMAL); 124 | endDate = null; 125 | } 126 | 127 | adapter.notifyDataSetChanged(); 128 | } 129 | 130 | //选中中间的日期 131 | private void setState() { 132 | if (endDate != null && startDate != null) { 133 | int start = adapter.data.indexOf(startDate); 134 | start += 1; 135 | int end = adapter.data.indexOf(endDate); 136 | for (; start < end; start++) { 137 | 138 | DateBean dateBean = adapter.data.get(start); 139 | if (!TextUtils.isEmpty(dateBean.getDay())) { 140 | dateBean.setItemState(DateBean.ITEM_STATE_SELECTED); 141 | } 142 | } 143 | } 144 | } 145 | 146 | //取消选中状态 147 | private void clearState() { 148 | if (endDate != null && startDate != null) { 149 | int start = adapter.data.indexOf(startDate); 150 | start += 1; 151 | int end = adapter.data.indexOf(endDate); 152 | for (; start < end; start++) { 153 | DateBean dateBean = adapter.data.get(start); 154 | dateBean.setItemState(DateBean.ITEM_STATE_NORMAL); 155 | } 156 | } 157 | } 158 | 159 | //日历adapter 160 | public static class CalendarAdapter extends RecyclerView.Adapter { 161 | ArrayList data = new ArrayList<>(); 162 | private CalendarAdapter.OnRecyclerviewItemClick onRecyclerviewItemClick; 163 | 164 | public CalendarAdapter.OnRecyclerviewItemClick getOnRecyclerviewItemClick() { 165 | return onRecyclerviewItemClick; 166 | } 167 | 168 | public void setOnRecyclerviewItemClick(CalendarAdapter.OnRecyclerviewItemClick onRecyclerviewItemClick) { 169 | this.onRecyclerviewItemClick = onRecyclerviewItemClick; 170 | } 171 | 172 | @Override 173 | public int getItemCount() { 174 | return data.size(); 175 | } 176 | 177 | @NonNull 178 | @Override 179 | public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { 180 | if (i == DateBean.item_type_day) { 181 | View rootView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_day, viewGroup, false); 182 | 183 | final CalendarAdapter.DayViewHolder dayViewHolder = new CalendarAdapter.DayViewHolder(rootView); 184 | dayViewHolder.itemView.setOnClickListener(new View.OnClickListener() { 185 | @Override 186 | public void onClick(View v) { 187 | if (onRecyclerviewItemClick != null) { 188 | onRecyclerviewItemClick.onItemClick(v, dayViewHolder.getLayoutPosition()); 189 | } 190 | } 191 | }); 192 | return dayViewHolder; 193 | } else if (i == DateBean.item_type_month) { 194 | View rootView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_month, viewGroup, false); 195 | final CalendarAdapter.MonthViewHolder monthViewHolder = new CalendarAdapter.MonthViewHolder(rootView); 196 | monthViewHolder.itemView.setOnClickListener(new View.OnClickListener() { 197 | @Override 198 | public void onClick(View v) { 199 | if (onRecyclerviewItemClick != null) { 200 | onRecyclerviewItemClick.onItemClick(v, monthViewHolder.getLayoutPosition()); 201 | } 202 | } 203 | }); 204 | return monthViewHolder; 205 | } 206 | return null; 207 | } 208 | 209 | @Override 210 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) { 211 | if (viewHolder instanceof CalendarAdapter.MonthViewHolder) { 212 | ((CalendarAdapter.MonthViewHolder) viewHolder).tv_month.setText(data.get(i).getMonthStr()); 213 | } else { 214 | CalendarAdapter.DayViewHolder vh = ((CalendarAdapter.DayViewHolder) viewHolder); 215 | vh.tv_day.setText(data.get(i).getDay()); 216 | vh.tv_check_in_check_out.setVisibility(View.GONE); 217 | DateBean dateBean = data.get(i); 218 | 219 | //设置item状态 220 | if (dateBean.getItemState() == DateBean.ITEM_STATE_BEGIN_DATE || dateBean.getItemState() == DateBean.ITEM_STATE_END_DATE) { 221 | //开始日期或结束日期 222 | vh.itemView.setBackgroundColor(Color.parseColor("#ff6600")); 223 | vh.tv_day.setTextColor(Color.WHITE); 224 | vh.tv_check_in_check_out.setVisibility(View.VISIBLE); 225 | if (dateBean.getItemState() == DateBean.ITEM_STATE_END_DATE) { 226 | vh.tv_check_in_check_out.setText("离店"); 227 | } else { 228 | vh.tv_check_in_check_out.setText("入住"); 229 | } 230 | 231 | } else if (dateBean.getItemState() == DateBean.ITEM_STATE_SELECTED) { 232 | //选中状态 233 | vh.itemView.setBackgroundColor(Color.parseColor("#ffa500")); 234 | vh.tv_day.setTextColor(Color.WHITE); 235 | } else { 236 | //正常状态 237 | vh.itemView.setBackgroundColor(Color.WHITE); 238 | vh.tv_day.setTextColor(Color.BLACK); 239 | } 240 | } 241 | } 242 | 243 | @Override 244 | public int getItemViewType(int position) { 245 | return data.get(position).getItemType(); 246 | } 247 | 248 | public class DayViewHolder extends RecyclerView.ViewHolder { 249 | public TextView tv_day; 250 | public TextView tv_check_in_check_out; 251 | 252 | public DayViewHolder(@NonNull View itemView) { 253 | super(itemView); 254 | tv_day = itemView.findViewById(R.id.tv_day); 255 | tv_check_in_check_out = itemView.findViewById(R.id.tv_check_in_check_out); 256 | } 257 | } 258 | 259 | public class MonthViewHolder extends RecyclerView.ViewHolder { 260 | public TextView tv_month; 261 | 262 | public MonthViewHolder(@NonNull View itemView) { 263 | super(itemView); 264 | tv_month = itemView.findViewById(R.id.tv_month); 265 | } 266 | } 267 | 268 | public interface OnRecyclerviewItemClick { 269 | void onItemClick(View v, int position); 270 | } 271 | } 272 | 273 | /** 274 | * 生成日历数据 275 | */ 276 | private List days(String sDate, String eDate) { 277 | List dateBeans = new ArrayList<>(); 278 | try { 279 | Calendar calendar = Calendar.getInstance(); 280 | //日期格式化 281 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); 282 | SimpleDateFormat formatYYYYMM = new SimpleDateFormat("yyyy-MM"); 283 | 284 | //起始日期 285 | Date startDate = new Date(); 286 | calendar.setTime(startDate); 287 | 288 | //结束日期 289 | calendar.add(Calendar.MONTH, 5); 290 | Date endDate = new Date(calendar.getTimeInMillis()); 291 | 292 | Log.d(TAG, "startDate:" + format.format(startDate) + "----------endDate:" + format.format(endDate)); 293 | 294 | //格式化开始日期和结束日期为 yyyy-mm-dd格式 295 | String endDateStr = format.format(endDate); 296 | endDate = format.parse(endDateStr); 297 | 298 | String startDateStr = format.format(startDate); 299 | startDate = format.parse(startDateStr); 300 | 301 | calendar.setTime(startDate); 302 | 303 | Log.d(TAG, "startDateStr:" + startDateStr + "---------endDate:" + format.format(endDate)); 304 | Log.d(TAG, "endDateStr:" + endDateStr + "---------endDate:" + format.format(endDate)); 305 | 306 | calendar.set(Calendar.DAY_OF_MONTH, 1); 307 | Calendar monthCalendar = Calendar.getInstance(); 308 | 309 | 310 | //按月生成日历 每行7个 最多6行 42个 311 | //每一行有七个日期 日 一 二 三 四 五 六 的顺序 312 | for (; calendar.getTimeInMillis() <= endDate.getTime(); ) { 313 | 314 | //月份item 315 | DateBean monthDateBean = new DateBean(); 316 | monthDateBean.setDate(calendar.getTime()); 317 | monthDateBean.setMonthStr(formatYYYYMM.format(monthDateBean.getDate())); 318 | monthDateBean.setItemType(DateBean.item_type_month); 319 | dateBeans.add(monthDateBean); 320 | 321 | //获取一个月结束的日期和开始日期 322 | monthCalendar.setTime(calendar.getTime()); 323 | monthCalendar.set(Calendar.DAY_OF_MONTH, 1); 324 | Date startMonthDay = calendar.getTime(); 325 | 326 | monthCalendar.add(Calendar.MONTH, 1); 327 | monthCalendar.add(Calendar.DAY_OF_MONTH, -1); 328 | Date endMonthDay = monthCalendar.getTime(); 329 | 330 | //重置为本月开始 331 | monthCalendar.set(Calendar.DAY_OF_MONTH, 1); 332 | 333 | Log.d(TAG, "月份的开始日期:" + format.format(startMonthDay) + "---------结束日期:" + format.format(endMonthDay)); 334 | for (; monthCalendar.getTimeInMillis() <= endMonthDay.getTime(); ) { 335 | //生成单个月的日历 336 | 337 | //处理一个月开始的第一天 338 | if (monthCalendar.get(Calendar.DAY_OF_MONTH) == 1) { 339 | //看某个月第一天是周几 340 | int weekDay = monthCalendar.get(Calendar.DAY_OF_WEEK); 341 | switch (weekDay) { 342 | case 1: 343 | //周日 344 | break; 345 | case 2: 346 | //周一 347 | addDatePlaceholder(dateBeans, 1, monthDateBean.getMonthStr()); 348 | break; 349 | case 3: 350 | //周二 351 | addDatePlaceholder(dateBeans, 2, monthDateBean.getMonthStr()); 352 | break; 353 | case 4: 354 | //周三 355 | addDatePlaceholder(dateBeans, 3, monthDateBean.getMonthStr()); 356 | break; 357 | case 5: 358 | //周四 359 | addDatePlaceholder(dateBeans, 4, monthDateBean.getMonthStr()); 360 | break; 361 | case 6: 362 | addDatePlaceholder(dateBeans, 5, monthDateBean.getMonthStr()); 363 | //周五 364 | break; 365 | case 7: 366 | addDatePlaceholder(dateBeans, 6, monthDateBean.getMonthStr()); 367 | //周六 368 | break; 369 | } 370 | } 371 | 372 | //生成某一天日期实体 日item 373 | DateBean dateBean = new DateBean(); 374 | dateBean.setDate(monthCalendar.getTime()); 375 | dateBean.setDay(monthCalendar.get(Calendar.DAY_OF_MONTH) + ""); 376 | dateBean.setMonthStr(monthDateBean.getMonthStr()); 377 | dateBeans.add(dateBean); 378 | 379 | //处理一个月的最后一天 380 | if (monthCalendar.getTimeInMillis() == endMonthDay.getTime()) { 381 | //看某个月第一天是周几 382 | int weekDay = monthCalendar.get(Calendar.DAY_OF_WEEK); 383 | switch (weekDay) { 384 | case 1: 385 | //周日 386 | addDatePlaceholder(dateBeans, 6, monthDateBean.getMonthStr()); 387 | break; 388 | case 2: 389 | //周一 390 | addDatePlaceholder(dateBeans, 5, monthDateBean.getMonthStr()); 391 | break; 392 | case 3: 393 | //周二 394 | addDatePlaceholder(dateBeans, 4, monthDateBean.getMonthStr()); 395 | break; 396 | case 4: 397 | //周三 398 | addDatePlaceholder(dateBeans, 3, monthDateBean.getMonthStr()); 399 | break; 400 | case 5: 401 | //周四 402 | addDatePlaceholder(dateBeans, 2, monthDateBean.getMonthStr()); 403 | break; 404 | case 6: 405 | addDatePlaceholder(dateBeans, 1, monthDateBean.getMonthStr()); 406 | //周5 407 | break; 408 | } 409 | } 410 | 411 | //天数加1 412 | monthCalendar.add(Calendar.DAY_OF_MONTH, 1); 413 | } 414 | 415 | Log.d(TAG, "日期" + format.format(calendar.getTime()) + "----周几" + getWeekStr(calendar.get(Calendar.DAY_OF_WEEK) + "")); 416 | //月份加1 417 | calendar.add(Calendar.MONTH, 1); 418 | } 419 | 420 | } catch (Exception ex) { 421 | 422 | } 423 | 424 | return dateBeans; 425 | } 426 | 427 | //添加空的日期占位 428 | private void addDatePlaceholder(List dateBeans, int count, String monthStr) { 429 | for (int i = 0; i < count; i++) { 430 | DateBean dateBean = new DateBean(); 431 | dateBean.setMonthStr(monthStr); 432 | dateBeans.add(dateBean); 433 | } 434 | } 435 | 436 | private String getWeekStr(String mWay) { 437 | if ("1".equals(mWay)) { 438 | mWay = "天"; 439 | } else if ("2".equals(mWay)) { 440 | mWay = "一"; 441 | } else if ("3".equals(mWay)) { 442 | mWay = "二"; 443 | } else if ("4".equals(mWay)) { 444 | mWay = "三"; 445 | } else if ("5".equals(mWay)) { 446 | mWay = "四"; 447 | } else if ("6".equals(mWay)) { 448 | mWay = "五"; 449 | } else if ("7".equals(mWay)) { 450 | mWay = "六"; 451 | } 452 | return mWay; 453 | } 454 | 455 | public interface OnDateSelected{ 456 | void selected(String startDate,String endDate); 457 | } 458 | 459 | public void setOnDateSelected(OnDateSelected onDateSelected) { 460 | this.onDateSelected = onDateSelected; 461 | } 462 | } 463 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/bao/calendarlist/DateBean.java: -------------------------------------------------------------------------------- 1 | package com.example.bao.calendarlist; 2 | 3 | import java.util.Date; 4 | 5 | public class DateBean { 6 | //item类型 7 | public static int item_type_day = 1;//日期item 8 | public static int item_type_month = 2;//月份item 9 | int itemType = 1;//默认是日期item 10 | 11 | //item状态 12 | public static int ITEM_STATE_BEGIN_DATE = 1;//开始日期 13 | public static int ITEM_STATE_END_DATE = 2;//结束日期 14 | public static int ITEM_STATE_SELECTED = 3;//选中状态 15 | public static int ITEM_STATE_NORMAL = 4;//正常状态 16 | public int itemState = ITEM_STATE_NORMAL; 17 | 18 | Date date;//具体日期 19 | String day;//一个月的某天 20 | String monthStr;//月份 21 | 22 | public int getItemState() { 23 | return itemState; 24 | } 25 | 26 | public void setItemState(int itemState) { 27 | this.itemState = itemState; 28 | } 29 | 30 | public int getItemType() { 31 | return itemType; 32 | } 33 | 34 | public void setItemType(int itemType) { 35 | this.itemType = itemType; 36 | } 37 | 38 | public String getMonthStr() { 39 | return monthStr; 40 | } 41 | 42 | public void setMonthStr(String monthStr) { 43 | this.monthStr = monthStr; 44 | } 45 | 46 | public static int getItem_type_month() { 47 | return item_type_month; 48 | } 49 | 50 | public static void setItem_type_month(int item_type_month) { 51 | DateBean.item_type_month = item_type_month; 52 | } 53 | 54 | public static int getItem_type_day() { 55 | return item_type_day; 56 | } 57 | 58 | public static void setItem_type_day(int item_type_day) { 59 | DateBean.item_type_day = item_type_day; 60 | } 61 | 62 | public String getDay() { 63 | return day; 64 | } 65 | 66 | public void setDay(String day) { 67 | this.day = day; 68 | } 69 | 70 | public Date getDate() { 71 | return date; 72 | } 73 | 74 | public void setDate(Date date) { 75 | this.date = date; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/bao/calendarlist/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.bao.calendarlist; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.Toast; 6 | 7 | /** 8 | * 思路 9 | * 1、生成日历数据 10 | * 生成每个月的每一天的数据 11 | */ 12 | 13 | public class MainActivity extends AppCompatActivity { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_main); 19 | 20 | CalendarList calendarList=findViewById(R.id.calendarList); 21 | calendarList.setOnDateSelected(new CalendarList.OnDateSelected() { 22 | @Override 23 | public void selected(String startDate, String endDate) { 24 | Toast.makeText(getApplicationContext(),"s:"+startDate+"e:"+endDate,Toast.LENGTH_LONG).show(); 25 | } 26 | }); 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/bao/calendarlist/MyItemD.java: -------------------------------------------------------------------------------- 1 | package com.example.bao.calendarlist; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.Color; 5 | import android.graphics.Paint; 6 | import android.support.annotation.NonNull; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.View; 9 | 10 | public class MyItemD extends RecyclerView.ItemDecoration { 11 | Paint paint=new Paint(); 12 | Paint colorPaint=new Paint(); 13 | Paint linePaint=new Paint(); 14 | 15 | public MyItemD(){ 16 | paint.setColor(Color.parseColor("#ffffff")); 17 | paint.setStyle(Paint.Style.FILL); 18 | colorPaint.setColor(Color.parseColor("#ff6600")); 19 | colorPaint.setAntiAlias(true); 20 | linePaint.setAntiAlias(true); 21 | linePaint.setColor(Color.parseColor("#dddddd")); 22 | } 23 | 24 | @Override 25 | public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { 26 | super.onDrawOver(c, parent, state); 27 | if(parent.getChildCount()<=0){ 28 | return; 29 | } 30 | 31 | //头部的高度 32 | int height=50; 33 | final float scale = parent.getContext().getResources().getDisplayMetrics().density; 34 | height= (int) (height*scale+0.5f); 35 | 36 | //获取第一个可见的view,通过此view获取其对应的月份 37 | CalendarList.CalendarAdapter a=(CalendarList.CalendarAdapter) parent.getAdapter(); 38 | View fistView=parent.getChildAt(0); 39 | String text=a.data.get(parent.getChildAdapterPosition(fistView)).getMonthStr(); 40 | 41 | String fistMonthStr=""; 42 | int fistViewTop=0; 43 | //查找当前可见的itemView中第一个月份类型的item 44 | for(int i=0;i 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_calendar.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | 26 | 27 | 34 | 35 | 42 | 43 | 50 | 51 | 58 | 59 | 65 | 66 | 73 | 74 | 75 | 76 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_day.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 21 | 22 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_month.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qifengdeqingchen/CalendarList/b59440eae187fdfb8ef054af6714d1ef78f2c8a8/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qifengdeqingchen/CalendarList/b59440eae187fdfb8ef054af6714d1ef78f2c8a8/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qifengdeqingchen/CalendarList/b59440eae187fdfb8ef054af6714d1ef78f2c8a8/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qifengdeqingchen/CalendarList/b59440eae187fdfb8ef054af6714d1ef78f2c8a8/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qifengdeqingchen/CalendarList/b59440eae187fdfb8ef054af6714d1ef78f2c8a8/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qifengdeqingchen/CalendarList/b59440eae187fdfb8ef054af6714d1ef78f2c8a8/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qifengdeqingchen/CalendarList/b59440eae187fdfb8ef054af6714d1ef78f2c8a8/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qifengdeqingchen/CalendarList/b59440eae187fdfb8ef054af6714d1ef78f2c8a8/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qifengdeqingchen/CalendarList/b59440eae187fdfb8ef054af6714d1ef78f2c8a8/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qifengdeqingchen/CalendarList/b59440eae187fdfb8ef054af6714d1ef78f2c8a8/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CalendarList 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/bao/calendarlist/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.bao.calendarlist; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.2.1' 11 | 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /build/intermediates/lint-cache/maven.google/com/android/support/constraint/group-index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /build/intermediates/lint-cache/maven.google/com/android/support/group-index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /build/intermediates/lint-cache/maven.google/com/android/support/test/espresso/group-index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /build/intermediates/lint-cache/maven.google/com/android/support/test/group-index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /build/intermediates/lint-cache/maven.google/master-index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /build/intermediates/lint-cache/sdk-registry.xml/sdk-registry.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | 16 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qifengdeqingchen/CalendarList/b59440eae187fdfb8ef054af6714d1ef78f2c8a8/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file is automatically generated by Android Studio. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file should *NOT* be checked into Version Control Systems, 5 | # as it contains information specific to your local configuration. 6 | # 7 | # Location of the SDK. This is only used by Gradle. 8 | # For customization when using a Version Control System, please read the 9 | # header note. 10 | sdk.dir=/Users/bao/Library/Android/sdk -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------