From fca27540a298cd014cfd6de059965b27eeec2636 Mon Sep 17 00:00:00 2001 From: Gingod Date: Tue, 17 Apr 2018 14:50:15 +0800 Subject: [PATCH] =?UTF-8?q?1.BasisTimesUtils=20=E5=B7=A5=E5=85=B7=E7=B1=BB?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20DatePickerDialog=20=E5=92=8C=20TimePickerD?= =?UTF-8?q?ialog=20=E7=9A=84=E4=BD=BF=E7=94=A8;=202.=E5=B8=B8=E8=A7=84?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 1 + .../gingold/basisdependency/MainActivity.java | 4 + .../activity/AnimationActivity.java | 72 ++++++- .../activity/DateTimePickerActivity.java | 149 ++++++++++++++ .../activity/TestActivity.java | 11 +- .../basisdependency/bean/TestBean.java | 25 +++ .../basisdependency/data/MainData.java | 2 + .../main/res/layout/activity_animation.xml | 50 ++++- .../res/layout/activity_datetimepicker.xml | 67 +++++++ app/src/main/res/layout/activity_test.xml | 7 + .../basislibrary/Base/BasisHtml5Activity.java | 11 +- .../basislibrary/utils/BasisTimesUtils.java | 185 ++++++++++++++++++ gradle/wrapper/gradle-wrapper.properties | 12 +- 13 files changed, 575 insertions(+), 21 deletions(-) create mode 100644 app/src/main/java/com/gingold/basisdependency/activity/DateTimePickerActivity.java create mode 100644 app/src/main/java/com/gingold/basisdependency/bean/TestBean.java create mode 100644 app/src/main/res/layout/activity_datetimepicker.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8fd35b1..e2c0241 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,6 +38,7 @@ + diff --git a/app/src/main/java/com/gingold/basisdependency/MainActivity.java b/app/src/main/java/com/gingold/basisdependency/MainActivity.java index 36ccef2..ef0f38d 100644 --- a/app/src/main/java/com/gingold/basisdependency/MainActivity.java +++ b/app/src/main/java/com/gingold/basisdependency/MainActivity.java @@ -9,6 +9,7 @@ import com.gingold.basisdependency.activity.AnimationActivity; import com.gingold.basisdependency.activity.BugRecycler2To1Activity; import com.gingold.basisdependency.activity.DBActivity; +import com.gingold.basisdependency.activity.DateTimePickerActivity; import com.gingold.basisdependency.activity.DialogActivity; import com.gingold.basisdependency.activity.ExceptionInfoActivity; import com.gingold.basisdependency.activity.GlideActivity; @@ -58,6 +59,9 @@ public void onClick(View v) { int flag = Paint.DITHER_FLAG; toast(data.des); switch (data.des) { + case MainData.DATEPICKER: + startActivity(DateTimePickerActivity.class); + break; case MainData.ANIMATION: startActivity(AnimationActivity.class); break; diff --git a/app/src/main/java/com/gingold/basisdependency/activity/AnimationActivity.java b/app/src/main/java/com/gingold/basisdependency/activity/AnimationActivity.java index 541215b..65911e2 100644 --- a/app/src/main/java/com/gingold/basisdependency/activity/AnimationActivity.java +++ b/app/src/main/java/com/gingold/basisdependency/activity/AnimationActivity.java @@ -4,9 +4,11 @@ import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.AnimationSet; +import android.view.animation.LinearInterpolator; import android.view.animation.RotateAnimation; import android.view.animation.ScaleAnimation; import android.view.animation.TranslateAnimation; +import android.widget.ImageView; import com.gingold.basisdependency.Base.BaseActivity; import com.gingold.basisdependency.R; @@ -16,19 +18,22 @@ */ public class AnimationActivity extends BaseActivity { + private ImageView iv_animation; + @Override public void setupViewLayout() { setContentView(R.layout.activity_animation); + initTitle("动画", ""); } @Override public void initView() { - + iv_animation = getViewNoClickable(R.id.iv_animation); } @Override public void listener() { - + setOnClickListener(R.id.tv_animation_alpha, R.id.tv_animation_translate, R.id.tv_animation_scale, R.id.tv_animation_rotate, R.id.tv_animation_set, R.id.tv_animation_rotate_contitue); } @Override @@ -38,7 +43,26 @@ public void logicDispose() { @Override public void onClick(View v) { - + switch (v.getId()) { + case R.id.tv_animation_alpha: + alpha(iv_animation); + break; + case R.id.tv_animation_translate: + trans(iv_animation); + break; + case R.id.tv_animation_scale: + scale(iv_animation); + break; + case R.id.tv_animation_rotate: + rotate(iv_animation); + break; + case R.id.tv_animation_set: + set(iv_animation); + break; + case R.id.tv_animation_rotate_contitue: + rotateContinue(iv_animation); + break; + } } /** @@ -47,7 +71,7 @@ public void onClick(View v) { * @param view */ public void alpha(View view) { - AlphaAnimation aa = new AlphaAnimation(0.0f, 1.0f); + AlphaAnimation aa = new AlphaAnimation(1.0f, 0.0f); // 动画播放的时间长度 aa.setDuration(2000); // 设置重复播放的次数 @@ -65,8 +89,8 @@ public void alpha(View view) { */ public void trans(View view) { TranslateAnimation ta = new TranslateAnimation( - Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1f, - Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1f); + Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0.5f, + Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0.5f); // 动画播放的时间长度 ta.setDuration(2000); // 设置重复播放的次数 @@ -111,11 +135,38 @@ public void rotate(View view) { view.startAnimation(ra); } + /** + * 连续旋转 + */ + public void rotateContinue(View view) { + RotateAnimation ra = new RotateAnimation(0, 360, + Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, + 0.5f); + // 动画播放的时间长度 + ra.setDuration(252); + // 设置重复播放的次数 + ra.setRepeatCount(Animation.INFINITE); + // 设置重复播放的模式 + ra.setRepeatMode(Animation.RESTART); + ra.setInterpolator(new LinearInterpolator());//速度平均 + // 让iv播放aa动画 + view.startAnimation(ra); + } + /** * 动画合集 集合 */ public void set(View view) { AnimationSet set = new AnimationSet(false); + + AlphaAnimation aa = new AlphaAnimation(0.0f, 1.0f); + // 动画播放的时间长度 + aa.setDuration(2000); + // 设置重复播放的次数 + aa.setRepeatCount(Animation.INFINITE); + // 设置重复播放的模式 + aa.setRepeatMode(Animation.REVERSE); + RotateAnimation ra = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); @@ -125,6 +176,7 @@ public void set(View view) { ra.setRepeatCount(Animation.INFINITE); // 设置重复播放的模式 ra.setRepeatMode(Animation.REVERSE); + ScaleAnimation sa = new ScaleAnimation(0.2f, 2.0f, 0.2f, 2.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); @@ -134,16 +186,18 @@ public void set(View view) { sa.setRepeatCount(Animation.INFINITE); // 设置重复播放的模式 sa.setRepeatMode(Animation.REVERSE); - // 让iv播放aa动画 + TranslateAnimation ta = new TranslateAnimation( - Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1f, - Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1f); + Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0.15f, + Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0.15f); // 动画播放的时间长度 ta.setDuration(2000); // 设置重复播放的次数 ta.setRepeatCount(Animation.INFINITE); // 设置重复播放的模式 ta.setRepeatMode(Animation.REVERSE); + + set.addAnimation(aa); set.addAnimation(ta); set.addAnimation(sa); set.addAnimation(ra); diff --git a/app/src/main/java/com/gingold/basisdependency/activity/DateTimePickerActivity.java b/app/src/main/java/com/gingold/basisdependency/activity/DateTimePickerActivity.java new file mode 100644 index 0000000..9f15bcf --- /dev/null +++ b/app/src/main/java/com/gingold/basisdependency/activity/DateTimePickerActivity.java @@ -0,0 +1,149 @@ +package com.gingold.basisdependency.activity; + +import android.os.Build; +import android.support.annotation.RequiresApi; +import android.view.View; +import android.widget.DatePicker; +import android.widget.TimePicker; + +import com.gingold.basisdependency.Base.BaseActivity; +import com.gingold.basisdependency.R; +import com.gingold.basislibrary.utils.BasisLogUtils; +import com.gingold.basislibrary.utils.BasisTimesUtils; + +public class DateTimePickerActivity extends BaseActivity { + private DatePicker dp_datetimepicker_date; + private TimePicker tp_datetimepicker_time; + + @Override + public void setupViewLayout() { + setContentView(R.layout.activity_datetimepicker); + initTitle("日期时间选择", ""); + } + + @Override + public void initView() { + dp_datetimepicker_date = getViewNoClickable(R.id.dp_datetimepicker_date); + tp_datetimepicker_time = getViewNoClickable(R.id.tp_datetimepicker_time); + } + + @Override + public void listener() { + setOnClickListener(R.id.tv_datetimepicker_date, R.id.tv_datetimepicker_time, R.id.tv_datetimepicker_yearmonth, R.id.tv_datetimepicker_monthday); + } + + @RequiresApi(api = Build.VERSION_CODES.M) + @Override + public void logicDispose() { + //日期选择器初始化和变化监听 + dp_datetimepicker_date.init(2016, 1, 1, new DatePicker.OnDateChangedListener() { + @Override + public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { + BasisLogUtils.e("onDateChanged: " + year + "-" + monthOfYear + "-" + dayOfMonth); + } + }); + + //时间选择器初始化和变化监听 + tp_datetimepicker_time.setIs24HourView(true); + tp_datetimepicker_time.setHour(16); + tp_datetimepicker_time.setMinute(36); + tp_datetimepicker_time.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { + @Override + public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { + BasisLogUtils.e(hourOfDay + ":" + minute); + } + }); + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.tv_datetimepicker_date://年月日选择 + showYearMonthDayPicker(); + break; + case R.id.tv_datetimepicker_yearmonth://年月选择 + showYearMonthPicker(); + break; + case R.id.tv_datetimepicker_monthday://月日选择 + showMonthDayPicker(); + break; + case R.id.tv_datetimepicker_time://时间选择 + showTimerPicker(); + break; + + } + } + + /** + * 时间选择 + */ + private void showTimerPicker() { + BasisTimesUtils.showTimerPickerDialog(mActivity, true, "请选择时间", 21, 33, true, new BasisTimesUtils.OnTimerPickerListener() { + @Override + public void onConfirm(int hourOfDay, int minute) { + toast(hourOfDay + ":" + minute); + } + + @Override + public void onCancel() { + toast("cancle"); + } + }); + } + + /** + * 月日选择 + */ + private void showMonthDayPicker() { + BasisTimesUtils.showDatePickerDialog(context, false, "请选择月日", 2015, 8, 28, new BasisTimesUtils.OnDatePickerListener() { + + @Override + public void onConfirm(int year, int month, int dayOfMonth) { + toast(year + "-" + month + "-" + dayOfMonth); + } + + @Override + public void onCancel() { + toast("cancle"); + } + }).setYearGone(); + } + + /** + * 年月选择 + */ + private void showYearMonthPicker() { + BasisTimesUtils.showDatePickerDialog(context, true, "", 2015, 12, 22, + new BasisTimesUtils.OnDatePickerListener() { + + @Override + public void onConfirm(int year, int month, int dayOfMonth) { + toast(year + "-" + month + "-" + dayOfMonth); + } + + @Override + public void onCancel() { + toast("cancle"); + } + }).setDayGone(); + } + + /** + * 年月日选择 + */ + private void showYearMonthDayPicker() { + BasisTimesUtils.showDatePickerDialog(context, BasisTimesUtils.THEME_HOLO_DARK, "请选择年月日", 2015, 1, 1, new BasisTimesUtils.OnDatePickerListener() { + + @Override + public void onConfirm(int year, int month, int dayOfMonth) { + toast(year + "-" + month + "-" + dayOfMonth); + } + + @Override + public void onCancel() { + toast("cancle"); + } + }); + } + +} diff --git a/app/src/main/java/com/gingold/basisdependency/activity/TestActivity.java b/app/src/main/java/com/gingold/basisdependency/activity/TestActivity.java index 95ad532..8b30d47 100644 --- a/app/src/main/java/com/gingold/basisdependency/activity/TestActivity.java +++ b/app/src/main/java/com/gingold/basisdependency/activity/TestActivity.java @@ -15,6 +15,7 @@ import com.gingold.basisdependency.Base.BaseActivity; import com.gingold.basisdependency.MyApplication; import com.gingold.basisdependency.R; +import com.gingold.basisdependency.bean.TestBean; import com.gingold.basislibrary.utils.BasisCommonUtils; import com.gingold.basislibrary.utils.BasisDeviceUtils; import com.gingold.basislibrary.utils.BasisFileUtils; @@ -26,8 +27,10 @@ import com.gingold.basislibrary.utils.dialog.BasisDialogUtils; import com.gingold.basislibrary.utils.dialog.BasisPBLoadingUtils; import com.gingold.basislibrary.utils.dialog.BasisProgressDialogUtils; +import com.google.gson.reflect.TypeToken; import java.io.File; +import java.util.ArrayList; import butterknife.Bind; import butterknife.ButterKnife; @@ -69,7 +72,7 @@ public void initView() { @Override public void listener() { - setOnClickListener(R.id.tv_test_installapk); + setOnClickListener(R.id.tv_test_installapk, R.id.tv_test_gson); } @Override @@ -114,7 +117,11 @@ public void onProgress(long totalSize, long currentSize, long progress) { basisPBLoadingUtils.setMessage("正在复制 " + progress + "%"); } }); - + break; + case R.id.tv_test_gson: + String test = "[{\"distributioncode\": \"qlkd\",\"goodsname\": \"你\", \"goodsnum\": \"6\"}]"; + ArrayList list = gson.fromJson(test, new TypeToken>() { + }.getType()); break; } } diff --git a/app/src/main/java/com/gingold/basisdependency/bean/TestBean.java b/app/src/main/java/com/gingold/basisdependency/bean/TestBean.java new file mode 100644 index 0000000..84773c1 --- /dev/null +++ b/app/src/main/java/com/gingold/basisdependency/bean/TestBean.java @@ -0,0 +1,25 @@ +package com.gingold.basisdependency.bean; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * + */ +public class TestBean { + + /** + * distributioncode : qlkd + * goodsname : 你 + * goodsnum : 6 + */ + @Expose + @SerializedName("distributioncode") + public String distributioncode; + @Expose + @SerializedName("goodsname") + public String goodsname; + @Expose + @SerializedName("goodsnum") + public String goodsnum; +} diff --git a/app/src/main/java/com/gingold/basisdependency/data/MainData.java b/app/src/main/java/com/gingold/basisdependency/data/MainData.java index 1028b60..831d1cd 100644 --- a/app/src/main/java/com/gingold/basisdependency/data/MainData.java +++ b/app/src/main/java/com/gingold/basisdependency/data/MainData.java @@ -26,10 +26,12 @@ public class MainData { public final static String HTML5 = "HTML5"; public final static String IMMERSE = "IMMERSE"; public final static String ANIMATION = "ANIMATION"; + public final static String DATEPICKER = "DATEPICKER"; public static ArrayList mainList = new ArrayList<>(); static { + mainList.add(new MainBean(DATEPICKER, null)); mainList.add(new MainBean(ANIMATION, null)); mainList.add(new MainBean(IMMERSE, null)); mainList.add(new MainBean(HTML5, null)); diff --git a/app/src/main/res/layout/activity_animation.xml b/app/src/main/res/layout/activity_animation.xml index 266069a..c84da03 100644 --- a/app/src/main/res/layout/activity_animation.xml +++ b/app/src/main/res/layout/activity_animation.xml @@ -1,19 +1,63 @@ + android:layout_height="match_parent" + android:orientation="vertical"> + + + + + + + + + + + android:gravity="center" + android:text="连续旋转" + android:textColor="@color/black"/> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_datetimepicker.xml b/app/src/main/res/layout/activity_datetimepicker.xml new file mode 100644 index 0000000..6506ccd --- /dev/null +++ b/app/src/main/res/layout/activity_datetimepicker.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_test.xml b/app/src/main/res/layout/activity_test.xml index 7ef1e4c..cbea61b 100644 --- a/app/src/main/res/layout/activity_test.xml +++ b/app/src/main/res/layout/activity_test.xml @@ -56,4 +56,11 @@ android:gravity="center" android:text="安装软件"/> + + \ No newline at end of file diff --git a/basislibrary/src/main/java/com/gingold/basislibrary/Base/BasisHtml5Activity.java b/basislibrary/src/main/java/com/gingold/basislibrary/Base/BasisHtml5Activity.java index 2a3b740..1d7e3af 100644 --- a/basislibrary/src/main/java/com/gingold/basislibrary/Base/BasisHtml5Activity.java +++ b/basislibrary/src/main/java/com/gingold/basislibrary/Base/BasisHtml5Activity.java @@ -11,6 +11,8 @@ import android.view.ViewGroup; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; +import android.webkit.WebResourceError; +import android.webkit.WebResourceRequest; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; @@ -104,9 +106,16 @@ public void onScaleChanged(WebView view, float oldScale, float newScale) { doScaleChanged(view, oldScale, newScale); } - + @Override + public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { + super.onReceivedError(view, request, error); + doReceivedError(view, request, error); + } }; + public void doReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { + } + public void doScaleChanged(WebView view, float oldScale, float newScale) { } diff --git a/basislibrary/src/main/java/com/gingold/basislibrary/utils/BasisTimesUtils.java b/basislibrary/src/main/java/com/gingold/basislibrary/utils/BasisTimesUtils.java index f747829..4d64015 100644 --- a/basislibrary/src/main/java/com/gingold/basislibrary/utils/BasisTimesUtils.java +++ b/basislibrary/src/main/java/com/gingold/basislibrary/utils/BasisTimesUtils.java @@ -1,5 +1,17 @@ package com.gingold.basislibrary.utils; +import android.app.AlertDialog; +import android.app.DatePickerDialog; +import android.app.TimePickerDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.text.TextUtils; +import android.view.View; +import android.view.ViewGroup; +import android.widget.DatePicker; +import android.widget.NumberPicker; +import android.widget.TimePicker; + import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; @@ -9,6 +21,12 @@ */ public class BasisTimesUtils { + public static int THEME_DEVICE_DEFAULT_LIGHT = AlertDialog.THEME_DEVICE_DEFAULT_LIGHT; + public static int THEME_DEVICE_DEFAULT_DARK = AlertDialog.THEME_DEVICE_DEFAULT_DARK; + public static int THEME_TRADITIONAL = AlertDialog.THEME_TRADITIONAL; + public static int THEME_HOLO_LIGHT = AlertDialog.THEME_HOLO_LIGHT; + public static int THEME_HOLO_DARK = AlertDialog.THEME_HOLO_DARK; + private static DatePickerDialog mDatePickerDialog;//日期选择器 /** * 将字符串时间转为Long时间 @@ -190,4 +208,171 @@ public static int getLastDayOfMonth(int year, int month) { return lastDay; } + + /** + * 显示日期选择器 + * + * @param themeLight true 白色背景; false 黑色背景 + */ + public static BasisTimesUtils showDatePickerDialog(Context context, boolean themeLight, String title, int year, int month, int day, OnDatePickerListener onDateTimePickerListener) { + int themeId = AlertDialog.THEME_HOLO_LIGHT;//默认白色背景 + if (!themeLight) { + themeId = AlertDialog.THEME_HOLO_DARK;//黑色背景 + } + return showDatePickerDialog(context, themeId, title, year, month, day, onDateTimePickerListener); + } + + /** + * 显示日期选择器, 默认白色背景 + */ + public static BasisTimesUtils showDatePickerDialog(Context context, String title, int year, int month, int day, OnDatePickerListener onDateTimePickerListener) { + return showDatePickerDialog(context, AlertDialog.THEME_HOLO_LIGHT, title, year, month, day, onDateTimePickerListener); + } + + /** + * 显示日期选择器 + */ + public static BasisTimesUtils showDatePickerDialog(Context context, int themeId, String title, int year, int month, int day, + final OnDatePickerListener onDateTimePickerListener) { + mDatePickerDialog = new DatePickerDialog(context, themeId, new DatePickerDialog.OnDateSetListener() { + @Override + public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { + month = month + 1;//月份加一 + if (onDateTimePickerListener != null) { + onDateTimePickerListener.onConfirm(year, month, dayOfMonth); + } + } + + }, year, month - 1, day);//月份减一 + + mDatePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + if (onDateTimePickerListener != null) { + onDateTimePickerListener.onCancel(); + } + } + }); + + if (!TextUtils.isEmpty(title)) { + mDatePickerDialog.setTitle(title); + } + mDatePickerDialog.show(); + return new BasisTimesUtils(); + } + + /** + * 隐藏年, 只显示月和日 + */ + public void setYearGone() { + setSpecialDatePicker(1); + } + + /** + * 隐藏日, 只显示年和月 + */ + public void setDayGone() { + setSpecialDatePicker(2); + } + + private void setSpecialDatePicker(int state) { + try { + DatePicker dp = mDatePickerDialog.getDatePicker(); + + NumberPicker view0 = (NumberPicker) ((ViewGroup) ((ViewGroup) dp.getChildAt(0)).getChildAt(0)).getChildAt(0); //获取最前一位的宽度 + NumberPicker view1 = (NumberPicker) ((ViewGroup) ((ViewGroup) dp.getChildAt(0)).getChildAt(0)).getChildAt(1); //获取中间一位的宽度 + NumberPicker view2 = (NumberPicker) ((ViewGroup) ((ViewGroup) dp.getChildAt(0)).getChildAt(0)).getChildAt(2);//获取最后一位的宽度 + + //年的最大值为2100 + //月的最大值为11 + //日的最大值为28,29,30,31 + int value0 = view0.getMaxValue();//获取第一个View的最大值 + int value1 = view1.getMaxValue();//获取第二个View的最大值 + int value2 = view2.getMaxValue();//获取第三个View的最大值 + + if (state == 1) {//隐藏年, 只显示月和日 + if (value0 > 252) { + view0.setVisibility(View.GONE); + } else if (value1 > 252) { + view1.setVisibility(View.GONE); + } else if (value2 > 252) { + view2.setVisibility(View.GONE); + } + } else if (state == 2) {//隐藏日, 只显示年和月 + if (value0 > 25 && value0 < 252) { + view0.setVisibility(View.GONE); + } else if (value1 > 25 && value1 < 252) { + view1.setVisibility(View.GONE); + } else if (value2 > 25 && value2 < 252) { + view2.setVisibility(View.GONE); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 显示时间选择器 + */ + public static void showTimerPickerDialog(Context context, boolean themeLight, String title, int hourOfDay, int minute, boolean is24HourView, final OnTimerPickerListener onTimerPickerListener) { + int themeId = AlertDialog.THEME_HOLO_LIGHT;//默认白色背景 + if (!themeLight) { + themeId = AlertDialog.THEME_HOLO_DARK;//黑色背景 + } + showTimerPickerDialog(context, themeId, title, hourOfDay, minute, is24HourView, onTimerPickerListener); + } + + /** + * 显示时间选择器, 默认白色背景 + */ + public static void showTimerPickerDialog(Context context, String title, int hourOfDay, int minute, boolean is24HourView, final OnTimerPickerListener onTimerPickerListener) { + showTimerPickerDialog(context, AlertDialog.THEME_HOLO_LIGHT, title, hourOfDay, minute, is24HourView, onTimerPickerListener); + } + + /** + * 显示时间选择器 + */ + public static void showTimerPickerDialog(Context context, int themeId, String title, int hourOfDay, int minute, boolean is24HourView, final OnTimerPickerListener onTimerPickerListener) { + TimePickerDialog dialog = new TimePickerDialog(context, themeId, new TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(TimePicker view, int hourOfDay, int minute) { + if (onTimerPickerListener != null) { + onTimerPickerListener.onConfirm(hourOfDay, minute); + } + } + }, hourOfDay, minute, is24HourView); + + dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + if (onTimerPickerListener != null) { + onTimerPickerListener.onCancel(); + } + } + }); + + if (!TextUtils.isEmpty(title)) { + dialog.setTitle(title); + } + dialog.show(); + } + + /** + * 日期选择器监听 + */ + public interface OnDatePickerListener { + void onConfirm(int year, int month, int dayOfMonth); + + void onCancel(); + } + + /** + * 时间选择器监听 + */ + public interface OnTimerPickerListener { + void onConfirm(int hourOfDay, int minute); + + void onCancel(); + } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f34f9fe..d2675d2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Jul 24 16:19:28 CST 2017 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +#Thu Apr 12 11:07:51 CST 2018 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip