├── .classpath ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── AndroidManifest.xml ├── README.md ├── ic_launcher-web.png ├── image ├── 0.jpg └── 1.jpg ├── libs └── android-support-v4.jar ├── proguard-project.txt ├── project.properties ├── res ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ ├── date_picker_button_select.9.png │ ├── date_picker_button_selected.9.png │ ├── date_picker_title_background.9.png │ ├── datepicker_bg.9.png │ └── ic_launcher.png ├── drawable-xxhdpi │ └── ic_launcher.png ├── drawable │ └── date_picker_button_background.xml ├── layout │ ├── activity_main.xml │ ├── date_picker_dialog.xml │ └── view_date_picker_dialog.xml ├── menu │ └── main.xml ├── values-sw600dp │ └── dimens.xml ├── values-sw720dp-land │ └── dimens.xml ├── values-v11 │ └── styles.xml ├── values-v14 │ └── styles.xml ├── values-w820dp │ └── dimens.xml └── values │ ├── arrays.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── src └── com └── example ├── android_datepickerdialog ├── DialogFactory.java ├── MainActivity.java └── MyDatePickerDialog.java └── util ├── Constants.java └── DateUtils.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Android_datepickerdialog 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # datepickerdialog 2 | Custom Date Picker Dialog(带有全日历图表and滚轮选择日期的dialog) 3 | 效果图: 4 | ![Alt text](https://github.com/xuningjack/datepickerdialog/raw/master/image/0.jpg) 5 | 6 | 选完操作: 7 | ![Alt text](https://github.com/xuningjack/datepickerdialog/raw/master/image/1.jpg) 8 | 9 | -------------------------------------------------------------------------------- /ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuningjack/datepickerdialog/86ee335fcc6423d816a144e4f1e69a6e6d4a57bd/ic_launcher-web.png -------------------------------------------------------------------------------- /image/0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuningjack/datepickerdialog/86ee335fcc6423d816a144e4f1e69a6e6d4a57bd/image/0.jpg -------------------------------------------------------------------------------- /image/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuningjack/datepickerdialog/86ee335fcc6423d816a144e4f1e69a6e6d4a57bd/image/1.jpg -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuningjack/datepickerdialog/86ee335fcc6423d816a144e4f1e69a6e6d4a57bd/libs/android-support-v4.jar -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-14 15 | -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuningjack/datepickerdialog/86ee335fcc6423d816a144e4f1e69a6e6d4a57bd/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuningjack/datepickerdialog/86ee335fcc6423d816a144e4f1e69a6e6d4a57bd/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/date_picker_button_select.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuningjack/datepickerdialog/86ee335fcc6423d816a144e4f1e69a6e6d4a57bd/res/drawable-xhdpi/date_picker_button_select.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/date_picker_button_selected.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuningjack/datepickerdialog/86ee335fcc6423d816a144e4f1e69a6e6d4a57bd/res/drawable-xhdpi/date_picker_button_selected.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/date_picker_title_background.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuningjack/datepickerdialog/86ee335fcc6423d816a144e4f1e69a6e6d4a57bd/res/drawable-xhdpi/date_picker_title_background.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/datepicker_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuningjack/datepickerdialog/86ee335fcc6423d816a144e4f1e69a6e6d4a57bd/res/drawable-xhdpi/datepicker_bg.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuningjack/datepickerdialog/86ee335fcc6423d816a144e4f1e69a6e6d4a57bd/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuningjack/datepickerdialog/86ee335fcc6423d816a144e4f1e69a6e6d4a57bd/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable/date_picker_button_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 16 | 17 | 18 | 19 | 28 | 29 | 37 | 38 | -------------------------------------------------------------------------------- /res/layout/date_picker_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 25 | 26 | 33 | 34 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /res/layout/view_date_picker_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | -------------------------------------------------------------------------------- /res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 64dp 9 | 10 | 11 | -------------------------------------------------------------------------------- /res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 摩羯座 5 | 水瓶座 6 | 双鱼座 7 | 白羊座 8 | 金牛座 9 | 双子座 10 | 巨蟹座 11 | 狮子座 12 | 处女座 13 | 天秤座 14 | 天蝎座 15 | 射手座 16 | 摩羯座 17 | 18 | 19 | -------------------------------------------------------------------------------- /res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Android_datepickerdialog 5 | Hello world! 6 | Settings 7 | 确      定 8 | 年龄限制,不得小于16岁 9 | 请选择生日: 10 | 11 | -------------------------------------------------------------------------------- /res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | 15 | 16 | -------------------------------------------------------------------------------- /src/com/example/android_datepickerdialog/DialogFactory.java: -------------------------------------------------------------------------------- 1 | package com.example.android_datepickerdialog; 2 | 3 | import android.app.DatePickerDialog.OnDateSetListener; 4 | import android.content.Context; 5 | import android.widget.TextView; 6 | 7 | 8 | /** 9 | * 自定义的dialog工厂类 10 | * @author Jack 11 | * @version 创建时间:2013-10-28 下午3:41:27 12 | */ 13 | public class DialogFactory { 14 | 15 | 16 | /** 17 | * 日期选择对话框 18 | * @param context 19 | * @param listener 20 | * @param year 21 | * @param month 22 | * @param day 23 | * @return 24 | */ 25 | public static MyDatePickerDialog createPickerDialog(Context context, TextView input,OnDateSetListener listener, int year, int month, int day) { 26 | 27 | return new MyDatePickerDialog(context, input, listener, year, month, day); 28 | } 29 | } -------------------------------------------------------------------------------- /src/com/example/android_datepickerdialog/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.android_datepickerdialog; 2 | 3 | import java.util.Calendar; 4 | import android.app.Activity; 5 | import android.app.DatePickerDialog; 6 | import android.os.Bundle; 7 | import android.text.TextUtils; 8 | import android.view.View; 9 | import android.widget.DatePicker; 10 | import android.widget.TextView; 11 | import android.widget.Toast; 12 | import com.example.util.Constants; 13 | import com.example.util.DateUtils; 14 | 15 | 16 | /** 17 | * 单击日期textview弹出选择日期dialog 18 | * @author Jack 19 | * @version 创建时间:2014年5月29日 上午11:27:44 20 | */ 21 | public class MainActivity extends Activity { 22 | 23 | private TextView mBirthday, mConstellation; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_main); 30 | 31 | mBirthday = (TextView)findViewById(R.id.birthday); 32 | mConstellation = (TextView)findViewById(R.id.constellation); 33 | mBirthday.setOnClickListener(new View.OnClickListener() { 34 | 35 | @Override 36 | public void onClick(View v) { 37 | 38 | int year = Calendar.getInstance().get(Calendar.YEAR); 39 | int month = Calendar.getInstance().get(Calendar.MONTH) - 1; 40 | int day = Calendar.getInstance().get(Calendar.DATE); 41 | String content = mBirthday.getText().toString().trim(); 42 | if (!TextUtils.isEmpty(content)) { 43 | String[] array = content.split("-"); 44 | year = Integer.valueOf(array[0]); 45 | month = Integer.valueOf(array[1]) - 1; 46 | day = Integer.valueOf(array[2]); 47 | } 48 | final StringBuffer sBuffer = new StringBuffer(); 49 | 50 | MyDatePickerDialog datePickerDialog = DialogFactory.createPickerDialog(MainActivity.this, mBirthday, new DatePickerDialog.OnDateSetListener() { 51 | 52 | @Override 53 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 54 | 55 | if (DateUtils.getMissSecondFromData(year + Constants.MIN_YEAR, monthOfYear, dayOfMonth) - System.currentTimeMillis() > 0) { //年龄不得小于16岁 56 | 57 | Toast.makeText(MainActivity.this, getString(R.string.nianling_xianzhi), Toast.LENGTH_SHORT).show(); 58 | return; 59 | } 60 | sBuffer.setLength(0); // 清除缓存 61 | sBuffer.append(year).append("-").append(monthOfYear + 1).append("-").append(dayOfMonth); 62 | String constellation = DateUtils.getConstellation(MainActivity.this, sBuffer.toString()); 63 | mBirthday.setText(DateUtils.addZero(sBuffer.toString())); 64 | mConstellation.setText(constellation); 65 | } 66 | }, year, month, day); 67 | datePickerDialog.show(); 68 | } 69 | }); 70 | } 71 | } -------------------------------------------------------------------------------- /src/com/example/android_datepickerdialog/MyDatePickerDialog.java: -------------------------------------------------------------------------------- 1 | package com.example.android_datepickerdialog; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.Calendar; 5 | 6 | import android.app.DatePickerDialog; 7 | import android.content.Context; 8 | import android.util.Log; 9 | import android.view.View; 10 | import android.widget.DatePicker; 11 | import android.widget.TextView; 12 | 13 | 14 | 15 | /** 16 | * 自定义选择日期dialog 17 | * @author Jack 18 | * @version 创建时间:2014年5月29日 上午11:45:36 19 | */ 20 | public class MyDatePickerDialog extends DatePickerDialog { 21 | 22 | private final String TAG = "MyDatePickerDialog"; 23 | 24 | public MyDatePickerDialog(Context context, TextView input, 25 | OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth) { 26 | 27 | super(context, callBack, year, monthOfYear, dayOfMonth); 28 | this.setTitle(context.getString(R.string.choose_birthday)); 29 | Calendar calendar = Calendar.getInstance(); 30 | getDatePicker().setMaxDate(calendar.getTimeInMillis()); // 年龄选择范围不能超过今天 31 | calendar.set(1949, 9, 1); 32 | getDatePicker().setMinDate(calendar.getTimeInMillis()); // 年龄范围不能早于建国前 33 | changeStyle(getDatePicker()); 34 | updateDate(year, monthOfYear, dayOfMonth); //注意:更新设置当前日期 35 | } 36 | 37 | /** 38 | * 改变DatePicker的样式 39 | * @param datePicker 40 | */ 41 | public void changeStyle(DatePicker datePicker){ 42 | 43 | View v_month2 = null; 44 | 45 | Field[] fields = DatePicker.class.getDeclaredFields(); 46 | //获取DatePicker中的属性 47 | for(Field field : fields) { 48 | field.setAccessible(true); 49 | if(field.getType().getSimpleName().equals("NumberPicker")) { 50 | try { 51 | v_month2 = (View)field.get(datePicker); 52 | } catch (Exception e) { 53 | Log.e(TAG, e.getMessage()); 54 | } 55 | } 56 | } 57 | 58 | //改变Month的宽度 59 | if(v_month2 != null) { 60 | v_month2.measure(0, 0); 61 | v_month2.getLayoutParams().width = (int) (v_month2.getMeasuredWidth() * 2f); //月份价宽了 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /src/com/example/util/Constants.java: -------------------------------------------------------------------------------- 1 | package com.example.util; 2 | 3 | public class Constants { 4 | 5 | /**日期可选范围最少距离当今的时间差*/ 6 | public static final int MIN_YEAR = 16; 7 | } 8 | -------------------------------------------------------------------------------- /src/com/example/util/DateUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.util; 2 | 3 | import java.util.Date; 4 | 5 | import android.content.Context; 6 | 7 | import com.example.android_datepickerdialog.R; 8 | 9 | 10 | /** 11 | * 日期操作工具类 12 | * @author Jack 13 | * @version 创建时间:2013-9-2 下午4:32:03 14 | */ 15 | public class DateUtils { 16 | 17 | /** 18 | * 根据生日得到星座信息 19 | * 20 | * @param birthday 格式如1994-3-13 21 | * @return 22 | */ 23 | public static String getConstellation(Context context, String birthday) { 24 | 25 | int month = 0; 26 | int day = 0; 27 | String[] temp = birthday.split("-"); 28 | String result = ""; 29 | 30 | if(temp != null && temp.length == 3) { 31 | 32 | month = removeZero(temp[1]); //得到月份 33 | day = removeZero(temp[2]); //得到日 34 | int[] dayArr = new int[] { 20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22 }; 35 | String[] constellationArr = context.getResources().getStringArray(R.array.list_constellation); 36 | result = day < dayArr[month - 1] ? constellationArr[month - 1] : constellationArr[month]; 37 | } 38 | return result; 39 | } 40 | 41 | /** 42 | * 去除截取日、月字符串前面的0 43 | * @param str 44 | * @return 45 | */ 46 | public static int removeZero(String str){ 47 | 48 | int result = 1; 49 | if(str.startsWith("0")){ //以0开头的月份去掉0 50 | 51 | result = Integer.parseInt(str.substring(1)); 52 | }else{ 53 | 54 | result = Integer.parseInt(str); 55 | } 56 | return result; 57 | } 58 | 59 | /** 60 | * 在月、日前面加0 61 | * @param str 62 | * @return 63 | */ 64 | public static String addZero(String str){ 65 | 66 | StringBuilder builder = new StringBuilder(); 67 | int month = 0; 68 | int day = 0; 69 | String[] temp = str.split("-"); 70 | 71 | if(temp != null && temp.length == 3) { 72 | 73 | builder.append(temp[0]); 74 | month = removeZero(temp[1]); //得到月份 75 | day = removeZero(temp[2]); //得到日 76 | if(month > 0 && month < 10){ 77 | 78 | builder.append("-0" + month); 79 | }else{ 80 | 81 | builder.append("-" + month); 82 | } 83 | if(day > 0 && day < 10){ 84 | 85 | builder.append("-0" + day); 86 | }else{ 87 | 88 | builder.append("-" + day); 89 | } 90 | 91 | } 92 | return builder.toString(); 93 | } 94 | 95 | /** 96 | * 获取指定日期的毫秒数 97 | */ 98 | public static long getMissSecondFromData(int year, int month, int day) { 99 | 100 | Date date = new Date(year - 1900, month, day); 101 | return date.getTime(); 102 | } 103 | } --------------------------------------------------------------------------------