├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── wzh │ │ └── calendar │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── wzh │ │ │ └── calendar │ │ │ ├── MainActivity.java │ │ │ ├── adapter │ │ │ ├── BaseAdapter.java │ │ │ ├── DateAdapter.java │ │ │ └── DateMonthAdapter.java │ │ │ ├── bean │ │ │ └── DateEntity.java │ │ │ ├── utils │ │ │ ├── DataUtils.java │ │ │ └── Lunar.java │ │ │ └── view │ │ │ ├── DataView.java │ │ │ ├── DatePopupWindow.java │ │ │ └── SquareLayout.java │ └── res │ │ ├── anim │ │ ├── pophide.xml │ │ └── popshow.xml │ │ ├── drawable-hdpi │ │ ├── four_screen_bg.png │ │ ├── frv.png │ │ ├── frw.png │ │ ├── fullscreen_redenve_back.png │ │ ├── ic_clear.png │ │ ├── ic_mobile_flag.png │ │ ├── ic_password_flag.png │ │ ├── icon_date_right.png │ │ ├── icon_left.png │ │ ├── icon_right.png │ │ ├── pass_gone.png │ │ ├── pass_visuable.png │ │ └── skin_about_brand.png │ │ ├── drawable │ │ ├── bg_btn_login_selected.xml │ │ ├── ok_bg.xml │ │ ├── select_bg.xml │ │ └── select_green_bg.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── item_data.xml │ │ ├── item_month_data.xml │ │ ├── view_data.xml │ │ └── view_poup.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 │ └── wzh │ └── calendar │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android-CalendarView-master 2 | Android开发实现自定义日历、日期选择控件 3 | 最近项目需要日历效果,考虑用第三方的反而不太适合设计需求,修改复杂,与其这样不入自己重新写一个干净的控件。虽不是什么牛逼控件,但是也需要我们能按照设计自己写出来。在此记录一下实现思路。 4 | 5 | 效果图: 6 | 7 | ![切换周](http://upload-images.jianshu.io/upload_images/2018489-4717cf33106e3544.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 8 | 9 | ![切换月份](http://upload-images.jianshu.io/upload_images/2018489-eba2c986665394ac.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 10 | 11 | #### 实现思路 12 | * 头部是一个自定义组合控件; 13 | * 显示一周的日期部分用GridView 更加方便更新; 14 | * 切换月的部分是一个自定义PopupWindow; 15 | * GridView选中效果; 16 | * GridView根据手势GestureDetector监听左右滑动; 17 | * 核心其实还是Calendar类,根据这个类我们可以获取制定日期一周的日期集合、可以获取制定日期一月的日期集合等等; 18 | * 根据阳历日期获取阴历日期 19 | 20 | #### 使用 21 | ``` 22 | // xml布局引用 23 | 28 | 29 | 30 | // 代码中,自定义回调监听选中的日期 31 | dataView = (DataView) findViewById(R.id.week); 32 | dataView.setOnSelectListener(new DataView.OnSelectListener() { 33 | @Override 34 | public void onSelected(DateEntity date) { 35 | info.setText("日期:"+ date.date+"\n"+ 36 | "周几:"+ date.weekName+"\n"+ 37 | "今日:"+ date.isToday+"\n"+ 38 | "时间戳:"+ date.million+"\n"); 39 | Log.e("wenzhiao--------------",date.toString()); 40 | } 41 | }); 42 | //需要传递此种格式的日期,不传默认是获取今日的日期 43 | dataView.getData("2017-04-19"); 44 | ``` 45 | [博客详解地址](http://www.jianshu.com/p/a2f102c728ce) 46 | 47 | 邮箱:821027320@qq.com 48 | 49 | QQ:821027320 -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.wzh.calendar" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.3.1' 28 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 29 | testCompile 'junit:junit:4.12' 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/wzh/calendar/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.wzh.calendar; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.wzh.calendar", 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/wzh/calendar/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.wzh.calendar; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.FragmentActivity; 6 | import android.util.Log; 7 | import android.widget.TextView; 8 | 9 | import com.wzh.calendar.bean.DateEntity; 10 | import com.wzh.calendar.view.DataView; 11 | 12 | /** 13 | * author:Administrator on 2017/4/10 16:03 14 | * description:文件说明 15 | * version:版本 16 | */ 17 | public class MainActivity extends FragmentActivity { 18 | private DataView dataView ; 19 | private TextView info ; 20 | @Override 21 | protected void onCreate(@Nullable Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_main); 24 | info = (TextView) findViewById(R.id.info); 25 | dataView = (DataView) findViewById(R.id.week); 26 | dataView.setOnSelectListener(new DataView.OnSelectListener() { 27 | @Override 28 | public void onSelected(DateEntity date) { 29 | info.setText("日期:"+ date.date+"\n"+ 30 | "周几:"+ date.weekName+"\n"+ 31 | "今日:"+ date.isToday+"\n"+ 32 | "时间戳:"+ date.million+"\n"); 33 | Log.e("wenzhiao--------------",date.toString()); 34 | } 35 | }); 36 | dataView.getData("2017-04-19"); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/wzh/calendar/adapter/BaseAdapter.java: -------------------------------------------------------------------------------- 1 | package com.wzh.calendar.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | 7 | import java.util.ArrayList; 8 | 9 | public abstract class BaseAdapter extends android.widget.BaseAdapter { 10 | protected Context mContext; 11 | public ArrayList mBeanList; 12 | 13 | public BaseAdapter(Context c) { 14 | mContext = c; 15 | } 16 | 17 | public BaseAdapter(Context c, ArrayList beanList) { 18 | mContext = c; 19 | mBeanList = beanList; 20 | } 21 | 22 | public void setData(ArrayList beanList) { 23 | if (mBeanList == null) 24 | mBeanList = new ArrayList(); 25 | else 26 | mBeanList.clear(); 27 | if (beanList == null) { 28 | mBeanList.clear(); 29 | notifyDataSetChanged(); 30 | return; 31 | } 32 | mBeanList.addAll(beanList); 33 | notifyDataSetChanged(); 34 | } 35 | 36 | 37 | 38 | public void removeData(int position) { 39 | mBeanList.remove(position); 40 | notifyDataSetChanged(); 41 | } 42 | 43 | public void removeData(T data) { 44 | mBeanList.remove(data); 45 | notifyDataSetChanged(); 46 | } 47 | 48 | public void addListData(ArrayList beanList) { 49 | if (mBeanList == null) { 50 | mBeanList = new ArrayList(); 51 | } 52 | if (beanList == null) { 53 | return; 54 | } 55 | mBeanList.addAll(beanList); 56 | 57 | notifyDataSetChanged(); 58 | } 59 | 60 | public void addData(T bean) { 61 | if (mBeanList == null) 62 | mBeanList = new ArrayList(); 63 | if (bean == null) 64 | return; 65 | mBeanList.add(bean); 66 | 67 | notifyDataSetChanged(); 68 | } 69 | 70 | public void addData(int index,T bean) { 71 | if (mBeanList == null) 72 | mBeanList = new ArrayList(); 73 | if (bean == null) 74 | return; 75 | mBeanList.add(index,bean); 76 | 77 | notifyDataSetChanged(); 78 | } 79 | 80 | public ArrayList getData() { 81 | if (mBeanList == null) 82 | mBeanList = new ArrayList(); 83 | return mBeanList; 84 | } 85 | 86 | @Override 87 | public int getCount() { 88 | return mBeanList.size(); 89 | } 90 | 91 | public ArrayList getBeanList() { 92 | if (mBeanList == null) 93 | mBeanList = new ArrayList<>(); 94 | return mBeanList; 95 | } 96 | 97 | @Override 98 | public T getItem(int position) { 99 | return mBeanList.get(position); 100 | } 101 | 102 | @Override 103 | public long getItemId(int position) { 104 | return position; 105 | } 106 | 107 | @Override 108 | public abstract View getView(int position, View convertView, ViewGroup parent); 109 | } -------------------------------------------------------------------------------- /app/src/main/java/com/wzh/calendar/adapter/DateAdapter.java: -------------------------------------------------------------------------------- 1 | package com.wzh.calendar.adapter; 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.BaseAdapter; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.wzh.calendar.bean.DateEntity; 12 | import com.wzh.calendar.R; 13 | 14 | import java.util.ArrayList; 15 | 16 | /** 17 | * author:Administrator on 2017/4/10 16:11 18 | * description:文件说明 19 | * version:版本 20 | */ 21 | public class DateAdapter extends BaseAdapter { 22 | private Context mContext ; 23 | private ArrayList datas ; 24 | private String[] weekTitle = {"日","一", "二", "三", "四", "五", "六"}; 25 | public DateAdapter(Context mContext, ArrayList datas) { 26 | this.mContext = mContext; 27 | this.datas = datas; 28 | } 29 | 30 | @Override 31 | public int getCount() { 32 | return datas.size(); 33 | } 34 | 35 | @Override 36 | public DateEntity getItem(int position) { 37 | return datas.get(position); 38 | } 39 | 40 | @Override 41 | public long getItemId(int position) { 42 | return position; 43 | } 44 | 45 | private int selectedPosition = -1;// 选中的位置 46 | 47 | public void setSelectedPosition(int position) { 48 | selectedPosition = position; 49 | notifyDataSetChanged(); 50 | } 51 | 52 | @Override 53 | public View getView(int position, View convertView, ViewGroup parent) { 54 | ViewHolder holder; 55 | DateEntity info = datas.get(position); 56 | if (convertView == null) { 57 | holder = new ViewHolder(); 58 | convertView = View.inflate(mContext, R.layout.item_data, null); 59 | holder.image = (ImageView) convertView.findViewById(R.id.image); 60 | holder.week_num = (TextView) convertView.findViewById(R.id.week_num); 61 | holder.item_data = (TextView) convertView.findViewById(R.id.item_data); 62 | holder.layout_week = convertView.findViewById(R.id.layout_week); 63 | convertView.setTag(holder); 64 | } else { 65 | holder = (ViewHolder) convertView.getTag(); 66 | } 67 | holder.week_num.setText(weekTitle[position]); 68 | holder.item_data.setText(info.day); 69 | if (selectedPosition == position) { 70 | holder.week_num.setTextColor(ContextCompat.getColor(mContext,R.color.color_ffffff)); 71 | holder.item_data.setTextColor(ContextCompat.getColor(mContext,R.color.color_ffffff)); 72 | if (info.isToday){ 73 | holder.layout_week.setBackgroundResource(R.drawable.select_green_bg); 74 | }else { 75 | holder.layout_week.setBackgroundResource(R.drawable.select_bg); 76 | } 77 | 78 | } else { 79 | if (info.isToday){ 80 | holder.week_num.setTextColor(ContextCompat.getColor(mContext,R.color.color_ffffff)); 81 | holder.layout_week.setBackgroundResource(R.drawable.select_green_bg); 82 | holder.item_data.setTextColor(ContextCompat.getColor(mContext,R.color.color_ffffff)); 83 | }else { 84 | holder.week_num.setTextColor(ContextCompat.getColor(mContext,R.color.color_999999)); 85 | holder.item_data.setTextColor(ContextCompat.getColor(mContext,R.color.color_333333)); 86 | holder.layout_week.setBackgroundColor(ContextCompat.getColor(mContext,R.color.color_ffffff)); 87 | } 88 | 89 | } 90 | return convertView; 91 | } 92 | public class ViewHolder { 93 | TextView week_num; 94 | TextView item_data; 95 | ImageView image; 96 | View layout_week; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /app/src/main/java/com/wzh/calendar/adapter/DateMonthAdapter.java: -------------------------------------------------------------------------------- 1 | package com.wzh.calendar.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v4.content.ContextCompat; 5 | import android.text.TextUtils; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | import com.wzh.calendar.bean.DateEntity; 11 | import com.wzh.calendar.R; 12 | import com.wzh.calendar.utils.Lunar; 13 | 14 | import java.text.ParseException; 15 | import java.util.ArrayList; 16 | import java.util.Calendar; 17 | 18 | /** 19 | * author:Administrator on 2017/4/10 16:11 20 | * description:文件说明 21 | * version:版本 22 | */ 23 | public class DateMonthAdapter extends BaseAdapter { 24 | private String dateString; 25 | 26 | public DateMonthAdapter(Context c) { 27 | super(c); 28 | } 29 | 30 | public void setDateString(String dateString) { 31 | this.dateString = dateString; 32 | } 33 | 34 | @Override 35 | public void setData(ArrayList beanList) { 36 | super.setData(beanList); 37 | } 38 | 39 | private int selectedPosition = -1;// 选中的位置 40 | 41 | public void setSelectedPosition(int position) { 42 | selectedPosition = position; 43 | notifyDataSetChanged(); 44 | } 45 | 46 | @Override 47 | public View getView(int position, View convertView, ViewGroup parent) { 48 | ViewHolder holder; 49 | DateEntity info = getData().get(position); 50 | if (convertView == null) { 51 | holder = new ViewHolder(); 52 | convertView = View.inflate(mContext, R.layout.item_month_data, null); 53 | holder.data = (TextView) convertView.findViewById(R.id.data); 54 | holder.luna = (TextView) convertView.findViewById(R.id.luna); 55 | holder.bg = convertView.findViewById(R.id.bg); 56 | convertView.setTag(holder); 57 | } else { 58 | holder = (ViewHolder) convertView.getTag(); 59 | } 60 | if (TextUtils.isEmpty(info.date)) { 61 | holder.data.setText(""); 62 | holder.luna.setText(""); 63 | holder.bg.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); 64 | } else { 65 | 66 | holder.luna.setText(info.luna); 67 | holder.data.setText(info.day); 68 | if (dateString.equals(info.date)) { 69 | if (info.isToday) { 70 | holder.bg.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); 71 | holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_28d19d)); 72 | holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_28d19d)); 73 | } else { 74 | holder.bg.setBackgroundResource(R.drawable.select_bg); 75 | holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); 76 | holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); 77 | } 78 | 79 | } else { 80 | if (info.isToday) { 81 | holder.bg.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); 82 | holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_28d19d)); 83 | holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_28d19d)); 84 | } else { 85 | holder.bg.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); 86 | holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_666666)); 87 | holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_999999)); 88 | } 89 | } 90 | } 91 | if (selectedPosition == position) { 92 | if (!TextUtils.isEmpty(info.date)) { 93 | if (info.isToday) { 94 | holder.bg.setBackgroundResource(R.drawable.select_green_bg); 95 | holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); 96 | holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); 97 | } else { 98 | holder.bg.setBackgroundResource(R.drawable.select_bg); 99 | holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); 100 | holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); 101 | } 102 | } 103 | } else { 104 | if (info.isToday) { 105 | holder.bg.setBackgroundResource(R.drawable.select_green_bg); 106 | holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); 107 | holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); 108 | } else { 109 | holder.bg.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); 110 | holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_666666)); 111 | holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_999999)); 112 | } 113 | 114 | } 115 | return convertView; 116 | } 117 | 118 | public class ViewHolder { 119 | TextView data; 120 | TextView luna ; 121 | View bg ; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /app/src/main/java/com/wzh/calendar/bean/DateEntity.java: -------------------------------------------------------------------------------- 1 | package com.wzh.calendar.bean; 2 | 3 | public class DateEntity { 4 | public long million ; //时间戳 5 | public String weekName ; //周几 6 | public int weekNum ; //一周中第几天,非中式 7 | public String date ; //日期 8 | public boolean isToday ; //是否今天 9 | public String day ; //天 10 | public String luna ; //阴历 11 | 12 | @Override 13 | public String toString() { 14 | return "DateEntity{" + 15 | "million=" + million + 16 | ", weekName='" + weekName + '\'' + 17 | ", weekNum=" + weekNum + 18 | ", date='" + date + '\'' + 19 | ", isToday=" + isToday + 20 | ", day='" + day + '\'' + 21 | ", luna='" + luna + '\'' + 22 | '}'; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/wzh/calendar/utils/DataUtils.java: -------------------------------------------------------------------------------- 1 | package com.wzh.calendar.utils; 2 | 3 | import com.wzh.calendar.bean.DateEntity; 4 | 5 | import java.text.ParseException; 6 | import java.text.SimpleDateFormat; 7 | import java.util.ArrayList; 8 | import java.util.Calendar; 9 | import java.util.Date; 10 | 11 | public class DataUtils { 12 | public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 13 | public static int selectPosition =-1; 14 | 15 | public static int getSelectPosition() { 16 | return selectPosition; 17 | } 18 | 19 | 20 | /** 21 | * 22 | * 获取当前日期一周的日期 23 | * @param date 24 | * @return 25 | */ 26 | public static ArrayList getWeek(String date){ 27 | ArrayList result = new ArrayList<>(); 28 | Calendar cal =Calendar.getInstance(); 29 | try { 30 | cal.setTime(dateFormat.parse(date)); 31 | } catch (ParseException e) { 32 | // TODO Auto-generated catch block 33 | e.printStackTrace(); 34 | } 35 | cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); //获取本周一的日期 36 | for (int i = 0; i < 7; i++) { 37 | DateEntity entity = new DateEntity(); 38 | entity.date = getValue(cal.get(cal.YEAR))+"-"+getValue(cal.get(cal.MONTH)+1)+"-"+getValue(cal.get(cal.DATE)); 39 | entity.million = cal.getTimeInMillis() ; 40 | entity.day = getValue(cal.get(cal.DATE)); 41 | entity.weekNum = cal.get(Calendar.DAY_OF_WEEK); 42 | entity.weekName = getWeekName(entity.weekNum); 43 | entity.isToday = isToday(entity.date); 44 | cal.add(Calendar.DATE, 1); 45 | result.add(entity); 46 | } 47 | 48 | return result ; 49 | 50 | } 51 | /** 52 | * 获取当前日期一月的日期 53 | * @param date 54 | * @return 55 | */ 56 | public static ArrayList getMonth(String date){ 57 | ArrayList result = new ArrayList<>(); 58 | Calendar cal =Calendar.getInstance(); 59 | try { 60 | cal.setTime( new SimpleDateFormat("yyyy-MM").parse(date)); 61 | } catch (ParseException e) { 62 | // TODO Auto-generated catch block 63 | e.printStackTrace(); 64 | } 65 | int max = cal.getActualMaximum(Calendar.DAY_OF_MONTH); 66 | for (int i = 1; i <=max; i++) { 67 | DateEntity entity = new DateEntity(); 68 | entity.date = getValue(cal.get(cal.YEAR))+"-"+getValue(cal.get(cal.MONTH)+1)+"-"+getValue(cal.get(cal.DATE)); 69 | entity.million = cal.getTimeInMillis() ; 70 | entity.weekNum = cal.get(Calendar.DAY_OF_WEEK); 71 | entity.day = getValue(cal.get(cal.DATE)); 72 | entity.weekName = getWeekName(entity.weekNum); 73 | entity.isToday = isToday(entity.date); 74 | entity.luna = getLuna(entity.date); 75 | cal.add(Calendar.DATE, 1); 76 | result.add(entity); 77 | } 78 | //为了用空的值填补第一个之前的日期 79 | //先获取在本周内是周几 80 | int weekNum = result.get(0).weekNum -1 ; 81 | for (int j = 0 ;j9?num:("0"+num)); 158 | } 159 | 160 | 161 | private final static ThreadLocal dateFormater = new ThreadLocal() { 162 | @Override 163 | protected SimpleDateFormat initialValue() { 164 | return new SimpleDateFormat("yyyy-MM-dd"); 165 | } 166 | }; 167 | 168 | /** 169 | * 获取系统当前日期 170 | */ 171 | public static String getCurrDate(String format) { 172 | SimpleDateFormat formatter = new SimpleDateFormat(format); 173 | Date curDate = new Date(System.currentTimeMillis());//获取当前时间 174 | String str = formatter.format(curDate); 175 | return str; 176 | } 177 | /** 178 | * 格式化日期 179 | */ 180 | public static String formatDate(String date ,String format) { 181 | SimpleDateFormat formatter = new SimpleDateFormat(format); 182 | Date curDate = null;//获取当前时间 183 | try { 184 | curDate = formatter.parse(date); 185 | } catch (ParseException e) { 186 | e.printStackTrace(); 187 | } 188 | String str = formatter.format(curDate); 189 | return str; 190 | } 191 | 192 | /** 193 | * 切换周的时候用 194 | * 获取前/后 几天的一个日期 195 | * @param currentData 196 | * @param dayNum 197 | * @return 198 | */ 199 | public static String getSomeDays(String currentData,int dayNum){ 200 | Calendar c = Calendar.getInstance(); 201 | //过去七天 202 | try { 203 | c.setTime(DataUtils.dateFormat.parse(currentData)); 204 | } catch (ParseException e) { 205 | e.printStackTrace(); 206 | } 207 | c.add(Calendar.DATE, dayNum); 208 | Date d = c.getTime(); 209 | String day = DataUtils.dateFormat.format(d); 210 | return day ; 211 | } 212 | /** 213 | * 获取前/后 几个月的一个日期 切换月的时候用 214 | * @param currentData 215 | * @param monthNum 216 | * @return 217 | */ 218 | public static String getSomeMonthDay(String currentData,int monthNum){ 219 | Calendar c = Calendar.getInstance(); 220 | try { 221 | c.setTime(new SimpleDateFormat("yyyy-MM").parse(currentData)); 222 | } catch (ParseException e) { 223 | e.printStackTrace(); 224 | } 225 | c.set(Calendar.MONTH, c.get(Calendar.MONTH) +monthNum); 226 | Date day = c.getTime(); 227 | return new SimpleDateFormat("yyyy-MM-dd").format(day); 228 | } 229 | 230 | /** 231 | * 获取阴历 232 | * @param date 233 | * @return 234 | */ 235 | public static String getLuna(String date){ 236 | Calendar today = Calendar.getInstance(); 237 | try { 238 | today.setTime(Lunar.chineseDateFormat.parse(date)); 239 | } catch (ParseException e) { 240 | e.printStackTrace(); 241 | } 242 | return new Lunar(today).toString() ; 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /app/src/main/java/com/wzh/calendar/utils/Lunar.java: -------------------------------------------------------------------------------- 1 | package com.wzh.calendar.utils; 2 | 3 | import android.text.TextUtils; 4 | 5 | import java.text.ParseException; 6 | import java.text.SimpleDateFormat; 7 | import java.util.Calendar; 8 | import java.util.Date; 9 | import java.util.GregorianCalendar; 10 | import java.util.TimeZone; 11 | 12 | @SuppressWarnings({"unused", "SynchronizeOnNonFinalField"}) 13 | public class Lunar { 14 | private int year; 15 | private int month; 16 | private int day; 17 | private boolean leap; 18 | final static String chineseNumber[] = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"}; 19 | public static SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy-MM-dd"); 20 | final static long[] lunarInfo = new long[] 21 | {0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, 22 | 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, 23 | 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 24 | 0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, 25 | 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 26 | 0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0, 27 | 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, 28 | 0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6, 29 | 0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, 30 | 0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, 31 | 0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, 32 | 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, 33 | 0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, 34 | 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 35 | 0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0}; 36 | 37 | //====== 传回农历 y年的总天数 38 | final private static int yearDays(int y) { 39 | int i, sum = 348; 40 | for (i = 0x8000; i > 0x8; i >>= 1) { 41 | if ((lunarInfo[y - 1900] & i) != 0) sum += 1; 42 | } 43 | return (sum + leapDays(y)); 44 | } 45 | 46 | //====== 传回农历 y年闰月的天数 47 | final private static int leapDays(int y) { 48 | if (leapMonth(y) != 0) { 49 | if ((lunarInfo[y - 1900] & 0x10000) != 0) 50 | return 30; 51 | else 52 | return 29; 53 | } else 54 | return 0; 55 | } 56 | 57 | //====== 传回农历 y年闰哪个月 1-12 , 没闰传回 0 58 | final private static int leapMonth(int y) { 59 | return (int) (lunarInfo[y - 1900] & 0xf); 60 | } 61 | 62 | //====== 传回农历 y年m月的总天数 63 | final private static int monthDays(int y, int m) { 64 | if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0) 65 | return 29; 66 | else 67 | return 30; 68 | } 69 | 70 | //====== 传回农历 y年的生肖 71 | final public String animalsYear() { 72 | final String[] Animals = new String[]{"鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"}; 73 | return Animals[(year - 4) % 12]; 74 | } 75 | 76 | //====== 传入 月日的offset 传回干支, 0=甲子 77 | final private static String cyclicalm(int num) { 78 | final String[] Gan = new String[]{"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}; 79 | final String[] Zhi = new String[]{"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}; 80 | return (Gan[num % 10] + Zhi[num % 12]); 81 | } 82 | 83 | //====== 传入 offset 传回干支, 0=甲子 84 | final public String cyclical() { 85 | int num = year - 1900 + 36; 86 | return (cyclicalm(num)); 87 | } 88 | 89 | /** *//** 90 | * 传出y年m月d日对应的农历. 91 | * yearCyl3:农历年与1864的相差数 ? 92 | * monCyl4:从1900年1月31日以来,闰月数 93 | * dayCyl5:与1900年1月31日相差的天数,再加40 ? 94 | * @param cal 95 | * @return 96 | */ 97 | public Lunar(Calendar cal) { 98 | @SuppressWarnings("unused") int yearCyl, monCyl, dayCyl; 99 | int leapMonth = 0; 100 | Date baseDate = null; 101 | try { 102 | baseDate = chineseDateFormat.parse("1900-01-31"); 103 | } catch (ParseException e) { 104 | e.printStackTrace(); //To change body of catch statement use Options | File Templates. 105 | } 106 | 107 | //求出和1900年1月31日相差的天数 108 | int offset = (int) ((cal.getTime().getTime() - baseDate.getTime()) / 86400000L); 109 | dayCyl = offset + 40; 110 | monCyl = 14; 111 | 112 | //用offset减去每农历年的天数 113 | // 计算当天是农历第几天 114 | //i最终结果是农历的年份 115 | //offset是当年的第几天 116 | int iYear, daysOfYear = 0; 117 | for (iYear = 1900; iYear < 2050 && offset > 0; iYear++) { 118 | daysOfYear = yearDays(iYear); 119 | offset -= daysOfYear; 120 | monCyl += 12; 121 | } 122 | if (offset < 0) { 123 | offset += daysOfYear; 124 | iYear--; 125 | monCyl -= 12; 126 | } 127 | //农历年份 128 | year = iYear; 129 | 130 | yearCyl = iYear - 1864; 131 | leapMonth = leapMonth(iYear); //闰哪个月,1-12 132 | leap = false; 133 | 134 | //用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天 135 | int iMonth, daysOfMonth = 0; 136 | for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) { 137 | //闰月 138 | if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap) { 139 | --iMonth; 140 | leap = true; 141 | daysOfMonth = leapDays(year); 142 | } else 143 | daysOfMonth = monthDays(year, iMonth); 144 | 145 | offset -= daysOfMonth; 146 | //解除闰月 147 | if (leap && iMonth == (leapMonth + 1)) leap = false; 148 | if (!leap) monCyl++; 149 | } 150 | //offset为0时,并且刚才计算的月份是闰月,要校正 151 | if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) { 152 | if (leap) { 153 | leap = false; 154 | } else { 155 | leap = true; 156 | --iMonth; 157 | --monCyl; 158 | } 159 | } 160 | //offset小于0时,也要校正 161 | if (offset < 0) { 162 | offset += daysOfMonth; 163 | --iMonth; 164 | --monCyl; 165 | } 166 | month = iMonth; 167 | day = offset + 1; 168 | } 169 | 170 | public static String getChinaDayString(int day) { 171 | String chineseTen[] = {"初", "十", "廿", "卅"}; 172 | int n = day % 10 == 0 ? 9 : day % 10 - 1; 173 | if (day > 30) 174 | return ""; 175 | if (day == 10) 176 | return "初十"; 177 | else 178 | return chineseTen[day / 10] + chineseNumber[n]; 179 | } 180 | public String toString() { 181 | return getChinaDayString(day); 182 | } 183 | } -------------------------------------------------------------------------------- /app/src/main/java/com/wzh/calendar/view/DataView.java: -------------------------------------------------------------------------------- 1 | package com.wzh.calendar.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.graphics.drawable.BitmapDrawable; 6 | import android.graphics.drawable.ColorDrawable; 7 | import android.support.annotation.Nullable; 8 | import android.text.TextUtils; 9 | import android.util.AttributeSet; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.widget.AdapterView; 13 | import android.widget.GridView; 14 | import android.widget.LinearLayout; 15 | import android.widget.TextView; 16 | 17 | import com.wzh.calendar.bean.DateEntity; 18 | import com.wzh.calendar.R; 19 | import com.wzh.calendar.adapter.DateAdapter; 20 | import com.wzh.calendar.utils.DataUtils; 21 | 22 | import java.util.ArrayList; 23 | 24 | /** 25 | * author:Administrator on 2017/4/10 16:04 26 | * description:文件说明 27 | * version:版本 28 | */ 29 | public class DataView extends LinearLayout implements View.OnClickListener, AdapterView.OnItemClickListener { 30 | private ArrayList millisList ; 31 | private TextView frontWeekTv ; 32 | private TextView nextWeekTv ; 33 | private TextView currentDateTv ; 34 | private GridView list ; 35 | private DateAdapter mAdapter ; 36 | private ArrayList datas ; 37 | private String dataFormate = "yyyy-MM-dd" ; 38 | private String currentData ; 39 | private DatePopupWindow popupWindow ; 40 | 41 | public DataView(Context context) { 42 | this(context,null); 43 | } 44 | 45 | public DataView(Context context, @Nullable AttributeSet attrs) { 46 | this(context, attrs,0); 47 | } 48 | 49 | public DataView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 50 | super(context, attrs, defStyleAttr); 51 | init(); 52 | } 53 | 54 | private void init() { 55 | datas = new ArrayList<>(); 56 | millisList = new ArrayList<>(); 57 | View view = LayoutInflater.from(getContext()).inflate(R.layout.view_data,null,false); 58 | frontWeekTv = (TextView)view.findViewById(R.id.front_week); 59 | frontWeekTv.setOnClickListener(this); 60 | nextWeekTv = (TextView)view.findViewById(R.id.next_week); 61 | nextWeekTv.setOnClickListener(this); 62 | currentDateTv = (TextView)view.findViewById(R.id.now_day); 63 | currentDateTv.setOnClickListener(this); 64 | list = (GridView) view.findViewById(R.id.list); 65 | list.setSelector(new ColorDrawable(Color.TRANSPARENT)); 66 | mAdapter = new DateAdapter(getContext(),datas); 67 | list.setAdapter(mAdapter); 68 | list.setOnItemClickListener(this); 69 | addView(view); 70 | } 71 | 72 | public void getData(String dateNumber){ 73 | datas.clear(); 74 | millisList.clear(); 75 | currentDateTv.setText(dateNumber); 76 | if (TextUtils.isEmpty(dateNumber)){ 77 | dateNumber = DataUtils.getCurrDate(dataFormate); 78 | } 79 | millisList = DataUtils.getWeek(dateNumber); 80 | if (millisList==null || millisList.size()<=0){ 81 | return; 82 | } 83 | datas.addAll(millisList); 84 | for (int i=0;i parent, View view, int position, long id) { 119 | DateEntity entity = datas.get(position); 120 | currentData = entity.date ; 121 | currentDateTv.setText(currentData); 122 | mAdapter.setSelectedPosition(position); 123 | if (onSelectListener!=null){ 124 | onSelectListener.onSelected(millisList.get(position)); 125 | } 126 | } 127 | 128 | private void showPopupWindow(View v) { 129 | popupWindow = new DatePopupWindow(getContext(),currentData); 130 | popupWindow.setFocusable(true); 131 | popupWindow.setOutsideTouchable(true); 132 | popupWindow.setBackgroundDrawable(new BitmapDrawable()); 133 | popupWindow.showAsDropDown(v); 134 | popupWindow.setOnItemClick(new DatePopupWindow.OnItemClick() { 135 | @Override 136 | public void onItemClick(String date) { 137 | getData(date); 138 | } 139 | }); 140 | } 141 | 142 | /** 143 | * 选中日期之后的回调 144 | */ 145 | private OnSelectListener onSelectListener ; 146 | public void setOnSelectListener(OnSelectListener onSelectListener) { 147 | this.onSelectListener = onSelectListener; 148 | } 149 | public interface OnSelectListener{ 150 | void onSelected(DateEntity date); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /app/src/main/java/com/wzh/calendar/view/DatePopupWindow.java: -------------------------------------------------------------------------------- 1 | package com.wzh.calendar.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.ColorDrawable; 5 | import android.text.TextUtils; 6 | import android.util.Log; 7 | import android.view.GestureDetector; 8 | import android.view.LayoutInflater; 9 | import android.view.MotionEvent; 10 | import android.view.View; 11 | import android.widget.AdapterView; 12 | import android.widget.GridView; 13 | import android.widget.LinearLayout; 14 | import android.widget.PopupWindow; 15 | import android.widget.TextView; 16 | 17 | import com.wzh.calendar.R; 18 | import com.wzh.calendar.adapter.DateMonthAdapter; 19 | import com.wzh.calendar.utils.DataUtils; 20 | 21 | /** 22 | * author:Administrator on 2017/4/11 15:43 23 | * description:文件说明 24 | * version:版本 25 | */ 26 | public class DatePopupWindow extends PopupWindow implements View.OnClickListener{ 27 | private View conentView; 28 | private GridView gridView ; 29 | private TextView frontMonthTv ; 30 | private TextView nextMonthTv ; 31 | private TextView currentDateTv ; 32 | private DateMonthAdapter adapter ; 33 | private TextView ok ; 34 | public String date ; 35 | private int currentPosition =-1 ; 36 | final int RIGHT = 0; 37 | final int LEFT = 1; 38 | private GestureDetector gestureDetector; 39 | public DatePopupWindow(final Context context,String dateString) { 40 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 41 | conentView = inflater.inflate(R.layout.view_poup, null); 42 | int h = context.getResources().getDisplayMetrics().heightPixels; 43 | int w = context.getResources().getDisplayMetrics().widthPixels; 44 | // 设置SelectPicPopupWindow的View 45 | this.setContentView(conentView); 46 | // 设置SelectPicPopupWindow弹出窗体的宽 47 | this.setWidth(w); 48 | // 设置SelectPicPopupWindow弹出窗体的高 49 | this.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); 50 | // 设置SelectPicPopupWindow弹出窗体可点击 51 | this.setFocusable(true); 52 | this.setOutsideTouchable(true); 53 | // 刷新状态 54 | this.update(); 55 | // 实例化一个ColorDrawable颜色为半透明 56 | ColorDrawable dw = new ColorDrawable(0000000000); 57 | // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作 58 | this.setBackgroundDrawable(dw); 59 | // this.setAnimationStyle(android.R.style.Animation_Dialog); 60 | // 设置SelectPicPopupWindow弹出窗体动画效果 61 | // this.setAnimationStyle(R.style.Animation_Pop_style); 62 | gridView = (GridView) conentView.findViewById(R.id.list); 63 | frontMonthTv = (TextView)conentView.findViewById(R.id.front_month); 64 | frontMonthTv.setOnClickListener(this); 65 | nextMonthTv = (TextView)conentView.findViewById(R.id.next_month); 66 | nextMonthTv.setOnClickListener(this); 67 | ok = (TextView)conentView.findViewById(R.id.ok); 68 | ok.setOnClickListener(this); 69 | gestureDetector = new GestureDetector(context,onGestureListener); 70 | currentDateTv = (TextView)conentView.findViewById(R.id.now_month); 71 | this.date = dateString ; 72 | if (TextUtils.isEmpty(date)){ 73 | this.date = DataUtils.getCurrDate("yyyy-MM-dd"); 74 | } 75 | currentDateTv.setText("当前月份:"+DataUtils.formatDate(date,"yyyy-MM")); 76 | adapter = new DateMonthAdapter(context); 77 | adapter.setData(DataUtils.getMonth(date)); 78 | gridView.setAdapter(adapter); 79 | adapter.setDateString(date); 80 | adapter.setSelectedPosition(DataUtils.getSelectPosition()); 81 | gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 82 | @Override 83 | public void onItemClick(AdapterView parent, View view, int position, long id) { 84 | if (onItemClick!=null && !TextUtils.isEmpty(adapter.getItem(position).date)){ 85 | adapter.setSelectedPosition(position); 86 | currentDateTv.setText("当前月份:"+DataUtils.formatDate(adapter.getItem(position).date,"yyyy-MM")); 87 | date = adapter.getItem(position).date ; 88 | } 89 | } 90 | }); 91 | gridView.setOnTouchListener(new View.OnTouchListener() { 92 | @Override 93 | public boolean onTouch(View view, MotionEvent event) { 94 | return gestureDetector.onTouchEvent(event); 95 | } 96 | }); 97 | 98 | } 99 | 100 | /** 101 | * 手势监听是否是左右滑动 102 | */ 103 | private GestureDetector.OnGestureListener onGestureListener = 104 | new GestureDetector.SimpleOnGestureListener() { 105 | @Override 106 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, 107 | float velocityY) { 108 | float x = e2.getX() - e1.getX(); 109 | float y = e2.getY() - e1.getY(); 110 | 111 | if (x > 100) { 112 | doResult(RIGHT); 113 | } else if (x < -100) { 114 | doResult(LEFT); 115 | } 116 | return true; 117 | } 118 | }; 119 | public void doResult(int action) { 120 | 121 | switch (action) { 122 | case RIGHT: 123 | date = DataUtils.getSomeMonthDay(date,-1); 124 | adapter.setData(DataUtils.getMonth(date)); 125 | adapter.setDateString(date); 126 | adapter.setSelectedPosition(DataUtils.getSelectPosition()); 127 | currentDateTv.setText("当前月份:"+DataUtils.formatDate(date,"yyyy-MM")); 128 | Log.e("wenzihao","go right"); 129 | break; 130 | case LEFT: 131 | date = DataUtils.getSomeMonthDay(date,+1); 132 | adapter.setData(DataUtils.getMonth(date)); 133 | adapter.setDateString(date); 134 | adapter.setSelectedPosition(DataUtils.getSelectPosition()); 135 | currentDateTv.setText("当前月份:"+DataUtils.formatDate(date,"yyyy-MM")); 136 | Log.e("wenzihao","go left"); 137 | break; 138 | 139 | } 140 | } 141 | public OnItemClick onItemClick ; 142 | 143 | public void setOnItemClick(OnItemClick onItemClick) { 144 | this.onItemClick = onItemClick; 145 | } 146 | 147 | @Override 148 | public void onClick(View view) { 149 | int id = view.getId(); 150 | if (id==frontMonthTv.getId()){ 151 | date = DataUtils.getSomeMonthDay(date,-1); 152 | adapter.setData(DataUtils.getMonth(date)); 153 | adapter.setDateString(date); 154 | adapter.setSelectedPosition(DataUtils.getSelectPosition()); 155 | currentDateTv.setText("当前月份:"+DataUtils.formatDate(date,"yyyy-MM")); 156 | }else if (id==nextMonthTv.getId()){ 157 | date = DataUtils.getSomeMonthDay(date,+1); 158 | adapter.setData(DataUtils.getMonth(date)); 159 | adapter.setDateString(date); 160 | adapter.setSelectedPosition(DataUtils.getSelectPosition()); 161 | currentDateTv.setText("当前月份:"+DataUtils.formatDate(date,"yyyy-MM")); 162 | }else if (id==ok.getId()){ 163 | if (onItemClick!=null){ 164 | onItemClick.onItemClick(date); 165 | } 166 | dismiss(); 167 | } 168 | } 169 | 170 | /** 171 | * 点击回调接口 172 | */ 173 | public interface OnItemClick{ 174 | void onItemClick(String date); 175 | } 176 | 177 | @Override 178 | public void dismiss() { 179 | super.dismiss(); 180 | 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /app/src/main/java/com/wzh/calendar/view/SquareLayout.java: -------------------------------------------------------------------------------- 1 | package com.wzh.calendar.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.widget.LinearLayout; 6 | 7 | public class SquareLayout extends LinearLayout { 8 | public SquareLayout(Context context, AttributeSet attrs, int defStyle) { 9 | super(context, attrs, defStyle); 10 | } 11 | 12 | public SquareLayout(Context context, AttributeSet attrs) { 13 | super(context, attrs); 14 | } 15 | 16 | public SquareLayout(Context context) { 17 | super(context); 18 | } 19 | 20 | @SuppressWarnings("unused") 21 | @Override 22 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 23 | // For simple implementation, or internal size is always 0. 24 | // We depend on the container to specify the layout size of 25 | // our view. We can't really know what it is since we will be 26 | // adding and removing different arbitrary views and do not 27 | // want the layout to change as this happens. 28 | setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec)); 29 | 30 | // Children are just made to fill our space. 31 | int childWidthSize = getMeasuredWidth(); 32 | int childHeightSize = getMeasuredHeight(); 33 | //高度和宽度一样 34 | heightMeasureSpec = widthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY); 35 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 36 | } 37 | } -------------------------------------------------------------------------------- /app/src/main/res/anim/pophide.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/anim/popshow.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/four_screen_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/drawable-hdpi/four_screen_bg.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/frv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/drawable-hdpi/frv.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/frw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/drawable-hdpi/frw.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/fullscreen_redenve_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/drawable-hdpi/fullscreen_redenve_back.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_clear.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/drawable-hdpi/ic_clear.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_mobile_flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/drawable-hdpi/ic_mobile_flag.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_password_flag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/drawable-hdpi/ic_password_flag.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/icon_date_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/drawable-hdpi/icon_date_right.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/icon_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/drawable-hdpi/icon_left.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/icon_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/drawable-hdpi/icon_right.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/pass_gone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/drawable-hdpi/pass_gone.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/pass_visuable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/drawable-hdpi/pass_visuable.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/skin_about_brand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/drawable-hdpi/skin_about_brand.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_btn_login_selected.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ok_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 8 | 11 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/select_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 8 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/select_green_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 8 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 16 | 21 | 22 | 33 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_data.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 21 | 32 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_month_data.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 20 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/layout/view_data.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 25 | 26 | 39 | 40 | 51 | 52 | 53 | 57 | 67 | 68 | -------------------------------------------------------------------------------- /app/src/main/res/layout/view_poup.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 20 | 27 | 28 | 36 | 37 | 41 | 48 | 49 | 57 | 58 | 62 | 69 | 70 | 78 | 79 | 83 | 90 | 91 | 99 | 100 | 104 | 111 | 112 | 120 | 121 | 125 | 132 | 133 | 141 | 142 | 146 | 153 | 154 | 162 | 163 | 167 | 168 | 172 | 180 | 181 | 196 | 197 | 198 | 199 | 200 | 208 | 209 | 220 | 221 | 232 | 233 | 244 | 254 | 255 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #999999 7 | #666666 8 | #eeeeee 9 | #333333 10 | #ffffff 11 | #c61a04 12 | #cccccc 13 | #d81e06 14 | #b0b8b2 15 | #28d19d 16 | #000000 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Calendar 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/test/java/com/wzh/calendar/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.wzh.calendar; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.3.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wenzhihao123/Android-CalendarView-master/df6acde30e926cfe5c4fa28109449ae214454079/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Apr 14 16:24:43 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------