From 8abb24dcbbe708debd89a32cff0d4058e5a86ae5 Mon Sep 17 00:00:00 2001 From: liyujiang <1032694760@qq.com> Date: Thu, 16 Sep 2021 22:05:30 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E6=A0=B7=E5=BC=8F=EF=BC=8C=E5=86=85=E7=BD=AE?= =?UTF-8?q?=E5=9B=9B=E7=A7=8D=E5=BC=B9=E7=AA=97=E6=A8=A1=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E6=95=88=E6=9E=9C=E8=AF=B7=E8=BF=90=E8=A1=8CDemo=EF=BC=9B=20-?= =?UTF-8?q?=20=E6=97=A5=E5=8E=86=E6=97=A5=E6=9C=9F=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E5=99=A8=E9=BB=98=E8=AE=A4=E9=80=89=E4=B8=AD=E9=A1=B9=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E5=88=B0=E5=BD=93=E5=89=8D=E5=8F=AF=E8=A7=81=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8CDemo=E6=97=A5=E5=8E=86=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=99=A8=E8=87=AA=E5=AE=9A=E4=B9=89=E9=85=8D?= =?UTF-8?q?=E8=89=B2=E7=A4=BA=E4=BE=8B=EF=BC=9B=20-=20=E6=BB=9A=E8=BD=AE?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=99=A8=E6=BB=9A=E5=8A=A8=E5=8F=98=E5=8C=96?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E5=99=A8=E4=BC=98=E5=8C=96=EF=BC=8CDemo?= =?UTF-8?q?=E6=BB=9A=E8=BD=AE=E9=80=89=E6=8B=A9=E5=99=A8=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E5=8F=98=E5=8C=96=E7=9B=91=E5=90=AC=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=EF=BC=9B=20-=20=E6=96=87=E4=BB=B6=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=99=A8=E7=95=8C=E9=9D=A2=E8=B0=83=E6=95=B4?= =?UTF-8?q?=EF=BC=9B=20-=20=E9=A2=9C=E8=89=B2=E9=80=89=E6=8B=A9=E5=99=A8?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E8=B0=83=E6=95=B4=EF=BC=9B=20-=20=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E5=B7=B2=E7=9F=A5=E7=9A=84=E5=B0=8F=E7=BC=BA=E9=99=B7?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=8A=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wheelpicker/AddressPicker.java | 1 + .../utility/AddressJsonParser.java | 4 +- CalendarPicker/README.md | 1 - .../calendarpicker/CalendarPicker.java | 55 ++-- .../calendar/adapter/CalendarAdapter.java | 72 +++-- ...r.java => OnCalendarDayClickListener.java} | 4 +- .../calendar/utils/DateUtils.java | 2 +- .../calendar/view/CalendarView.java | 2 +- .../calendar/view/MonthView.java | 8 +- .../src/main/res/layout/calendar_body.xml | 5 +- .../src/main/res/layout/calendar_picker.xml | 21 +- CalendarPicker/src/main/res/values/colors.xml | 11 +- ChangeLog.md | 9 + .../gzuliyujiang/colorpicker/ColorPicker.java | 61 ++--- .../gzuliyujiang/colorpicker/Utils.java | 6 +- .../main/res/layout/color_picker_content.xml | 56 +--- Common/src/main/AndroidManifest.xml | 2 +- .../basepicker/ConfirmPicker.java | 187 ------------- .../BaseDialog.java} | 151 +++-------- .../gzuliyujiang/dialog/BottomDialog.java | 127 +++++++++ .../gzuliyujiang/dialog/DialogConfig.java | 36 +++ .../PickerLog.java => dialog/DialogLog.java} | 6 +- .../gzuliyujiang/dialog/DialogStyle.java | 28 +- .../gzuliyujiang/dialog/ModalDialog.java | 254 ++++++++++++++++++ ...sheet_enter.xml => dialog_sheet_enter.xml} | 0 ...r_sheet_exit.xml => dialog_sheet_exit.xml} | 0 .../dialog_corner_round_all_white.xml} | 13 +- ....xml => dialog_corner_round_top_white.xml} | 0 .../dialog_ellipse_blue.xml} | 13 +- .../drawable/dialog_ellipse_light_gray.xml | 18 ++ .../main/res/layout/dialog_footer_style_1.xml | 55 ++++ .../main/res/layout/dialog_footer_style_2.xml | 35 +++ .../main/res/layout/dialog_footer_style_3.xml | 49 ++++ .../main/res/layout/dialog_header_style_1.xml | 28 ++ .../main/res/layout/dialog_header_style_2.xml | 44 +++ .../main/res/layout/dialog_header_style_3.xml | 28 ++ ...er.xml => dialog_header_style_default.xml} | 31 ++- .../res/mipmap-xxhdpi/dialog_close_icon.png | Bin 0 -> 1874 bytes Common/src/main/res/values/dialog_anims.xml | 26 ++ Common/src/main/res/values/dialog_themes.xml | 28 ++ FilePicker/README.md | 2 +- .../gzuliyujiang/filepicker/FileExplorer.java | 19 +- .../gzuliyujiang/filepicker/FilePicker.java | 19 +- .../filepicker/adapter/FileAdapter.java | 8 +- .../main/res/layout/file_picker_content.xml | 35 +-- ImagePicker/README.md | 2 +- README.md | 109 +++++++- .../wheelpicker/BirthdayPicker.java | 1 + .../wheelpicker/CarNumberPicker.java | 8 +- .../wheelpicker/ConstellationPicker.java | 6 + .../gzuliyujiang/wheelpicker/DatePicker.java | 13 +- .../wheelpicker/DatimePicker.java | 18 +- .../wheelpicker/EthnicPicker.java | 10 +- .../wheelpicker/LinkagePicker.java | 12 +- .../wheelpicker/NumberPicker.java | 12 +- .../wheelpicker/OptionPicker.java | 7 +- .../wheelpicker/PhoneCodePicker.java | 6 + .../gzuliyujiang/wheelpicker/SexPicker.java | 6 + .../gzuliyujiang/wheelpicker/TimePicker.java | 13 +- .../wheelpicker/widget/NumberWheelLayout.java | 6 +- .../main/res/layout/wheel_picker_linkage.xml | 3 +- .../wheelview/widget/NumberWheelView.java | 3 + .../wheelview/widget/WheelView.java | 8 +- app/build.gradle | 1 - .../github/gzuliyujiang/fallback/DemoApp.java | 7 +- .../activity/AddressPickerActivity.java | 51 +++- .../activity/CalendarPickerActivity.java | 2 - .../activity/ColorPickerActivity.java | 1 - .../activity/DateTimePickerActivity.java | 17 +- .../fallback/activity/FilePickerActivity.java | 2 - .../activity/ImagePickerActivity.java | 90 +++---- .../activity/LinkagePickerActivity.java | 1 - .../fallback/activity/MainActivity.java | 30 +++ .../activity/SinglePickerActivity.java | 13 +- .../fallback/custom/AntFortuneLikePicker.java | 38 ++- .../fallback/custom/CustomAddressPicker.java | 39 +-- .../main/res/layout/activity_picker_image.xml | 7 - .../main/res/layout/activity_picker_main.xml | 7 + app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/styles.xml | 32 +++ gradle/dependency.gradle | 1 - 81 files changed, 1341 insertions(+), 802 deletions(-) rename CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/protocol/{OnMonthClickListener.java => OnCalendarDayClickListener.java} (89%) delete mode 100644 Common/src/main/java/com/github/gzuliyujiang/basepicker/ConfirmPicker.java rename Common/src/main/java/com/github/gzuliyujiang/{basepicker/BottomDialog.java => dialog/BaseDialog.java} (59%) create mode 100644 Common/src/main/java/com/github/gzuliyujiang/dialog/BottomDialog.java create mode 100644 Common/src/main/java/com/github/gzuliyujiang/dialog/DialogConfig.java rename Common/src/main/java/com/github/gzuliyujiang/{basepicker/PickerLog.java => dialog/DialogLog.java} (92%) rename CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/protocol/OnCalendarSelectListener.java => Common/src/main/java/com/github/gzuliyujiang/dialog/DialogStyle.java (61%) create mode 100644 Common/src/main/java/com/github/gzuliyujiang/dialog/ModalDialog.java rename Common/src/main/res/anim/{picker_sheet_enter.xml => dialog_sheet_enter.xml} (100%) rename Common/src/main/res/anim/{picker_sheet_exit.xml => dialog_sheet_exit.xml} (100%) rename Common/src/main/res/{values/anims.xml => drawable/dialog_corner_round_all_white.xml} (71%) rename Common/src/main/res/drawable/{picker_corner_bg.xml => dialog_corner_round_top_white.xml} (100%) rename Common/src/main/res/{values/themes.xml => drawable/dialog_ellipse_blue.xml} (70%) create mode 100644 Common/src/main/res/drawable/dialog_ellipse_light_gray.xml create mode 100644 Common/src/main/res/layout/dialog_footer_style_1.xml create mode 100644 Common/src/main/res/layout/dialog_footer_style_2.xml create mode 100644 Common/src/main/res/layout/dialog_footer_style_3.xml create mode 100644 Common/src/main/res/layout/dialog_header_style_1.xml create mode 100644 Common/src/main/res/layout/dialog_header_style_2.xml create mode 100644 Common/src/main/res/layout/dialog_header_style_3.xml rename Common/src/main/res/layout/{picker_confirm_header.xml => dialog_header_style_default.xml} (75%) create mode 100644 Common/src/main/res/mipmap-xxhdpi/dialog_close_icon.png create mode 100644 Common/src/main/res/values/dialog_anims.xml create mode 100644 Common/src/main/res/values/dialog_themes.xml create mode 100644 app/src/main/res/values/styles.xml diff --git a/AddressPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/AddressPicker.java b/AddressPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/AddressPicker.java index 70a7304c..c0390d15 100644 --- a/AddressPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/AddressPicker.java +++ b/AddressPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/AddressPicker.java @@ -67,6 +67,7 @@ public AddressPicker(@NonNull Activity activity, @StyleRes int themeResId) { @Override protected void initData() { super.initData(); + titleView.setText("地址选择"); if (addressLoader == null || addressParser == null) { return; } diff --git a/AddressPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/utility/AddressJsonParser.java b/AddressPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/utility/AddressJsonParser.java index 4aff559b..b0b25a67 100644 --- a/AddressPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/utility/AddressJsonParser.java +++ b/AddressPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/utility/AddressJsonParser.java @@ -17,7 +17,7 @@ import androidx.annotation.NonNull; -import com.github.gzuliyujiang.basepicker.PickerLog; +import com.github.gzuliyujiang.dialog.DialogLog; import com.github.gzuliyujiang.wheelpicker.contract.AddressParser; import com.github.gzuliyujiang.wheelpicker.entity.CityEntity; import com.github.gzuliyujiang.wheelpicker.entity.CountyEntity; @@ -54,7 +54,7 @@ public List parseData(@NonNull String text) { JSONArray provinceArray = new JSONArray(text); return parseProvince(provinceArray); } catch (JSONException e) { - PickerLog.print(e); + DialogLog.print(e); } return new ArrayList<>(); } diff --git a/CalendarPicker/README.md b/CalendarPicker/README.md index f27b6e01..7bd9d2aa 100644 --- a/CalendarPicker/README.md +++ b/CalendarPicker/README.md @@ -6,7 +6,6 @@ ```groovy CalendarPicker picker = new CalendarPicker(this); - picker.enableRoundCorner(); picker.setRangeDateOnFuture(3); if (singleTimeInMillis == 0) { singleTimeInMillis = System.currentTimeMillis(); diff --git a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/CalendarPicker.java b/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/CalendarPicker.java index 19dae407..d39278ed 100644 --- a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/CalendarPicker.java +++ b/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/CalendarPicker.java @@ -16,17 +16,17 @@ import android.app.Activity; import android.text.TextUtils; import android.view.View; -import android.widget.FrameLayout; import androidx.annotation.NonNull; import androidx.annotation.StyleRes; -import com.github.gzuliyujiang.basepicker.ConfirmPicker; import com.github.gzuliyujiang.calendarpicker.calendar.adapter.CalendarAdapter; -import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnCalendarSelectListener; import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnCalendarSelectedListener; import com.github.gzuliyujiang.calendarpicker.calendar.utils.DateUtils; import com.github.gzuliyujiang.calendarpicker.calendar.view.CalendarView; +import com.github.gzuliyujiang.dialog.DialogConfig; +import com.github.gzuliyujiang.dialog.DialogStyle; +import com.github.gzuliyujiang.dialog.ModalDialog; import java.util.Calendar; import java.util.Date; @@ -39,9 +39,8 @@ * @since 2019/4/30 13:36 */ @SuppressWarnings({"unused", "deprecation"}) -public class CalendarPicker extends ConfirmPicker implements OnCalendarSelectedListener, OnCalendarSelectListener { +public class CalendarPicker extends ModalDialog implements OnCalendarSelectedListener { private CalendarView calendarView; - private FrameLayout bottomView; private CalendarAdapter calendarAdapter; private boolean singleMode = false; private Date minDate, maxDate; @@ -61,18 +60,27 @@ public CalendarPicker(@NonNull Activity activity, @StyleRes int themeResId) { @NonNull @Override - protected View createBodyView(@NonNull Activity activity) { - View view = View.inflate(activity, R.layout.calendar_picker, null); - calendarView = view.findViewById(R.id.calendar_picker_body); - bottomView = view.findViewById(R.id.calendar_picker_bottom); - return view; + protected View createBodyView() { + return View.inflate(activity, R.layout.calendar_picker, null); + } + + @Override + protected void initView(@NonNull View contentView) { + super.initView(contentView); + if (DialogConfig.getDialogStyle() == DialogStyle.Two) { + headerView.setVisibility(View.VISIBLE); + titleView.setText("日期选择"); + } else { + headerView.setVisibility(View.GONE); + } + calendarView = contentView.findViewById(R.id.calendar_picker_body); } @Override protected void initData() { super.initData(); initialized = true; - setHeight((int) (calendarView.getResources().getDisplayMetrics().heightPixels * 0.6)); + setHeight((int) (activity.getResources().getDisplayMetrics().heightPixels * 0.6f)); calendarAdapter = calendarView.getAdapter(); calendarAdapter.setOnCalendarSelectedListener(this); refreshData(); @@ -112,17 +120,6 @@ public void onRangeSelected(@NonNull Date start, @NonNull Date end) { endDate = end; } - @Override - public void onSingleSelect(@NonNull Date date) { - selectDate = date; - } - - @Override - public void onDoubleSelect(@NonNull Date before, @NonNull Date after) { - startDate = before; - endDate = after; - } - /** * 设置日期范围选择回调 */ @@ -242,16 +239,10 @@ private void scrollToSelectedPosition() { calendarView.post(new Runnable() { @Override public void run() { - final Calendar selectedCalendar = DateUtils.calendar(startDate.getTime() + (endDate.getTime() - startDate.getTime()) / 2); - int position = calendarAdapter.getDatePosition(selectedCalendar.getTime()); + int position = calendarAdapter.getDatePosition(startDate); position = Math.max(position, 0); position = Math.min(position, calendarAdapter.getItemCount() - 1); - if (position == 0) { - calendarView.getBodyView().scrollToPosition(0); - return; - } - int offset = (int) (-60 * calendarView.getResources().getDisplayMetrics().density); - calendarView.getLayoutManager().scrollToPositionWithOffset(position, offset); + calendarView.getLayoutManager().scrollToPositionWithOffset(position, 0); } }); } @@ -260,8 +251,4 @@ public final CalendarView getCalendarView() { return calendarView; } - public final FrameLayout getBottomView() { - return bottomView; - } - } diff --git a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/adapter/CalendarAdapter.java b/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/adapter/CalendarAdapter.java index 012bcab9..485dd951 100644 --- a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/adapter/CalendarAdapter.java +++ b/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/adapter/CalendarAdapter.java @@ -21,13 +21,13 @@ import com.github.gzuliyujiang.calendarpicker.calendar.protocol.Interval; import com.github.gzuliyujiang.calendarpicker.calendar.protocol.MonthEntity; -import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnCalendarSelectListener; +import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnCalendarDayClickListener; import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnCalendarSelectedListener; -import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnMonthClickListener; import com.github.gzuliyujiang.calendarpicker.calendar.utils.DateUtils; import com.github.gzuliyujiang.calendarpicker.calendar.view.MonthView; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.List; @@ -36,7 +36,7 @@ * Created by peng on 2017/8/3. */ @SuppressWarnings("UnusedReturnValue") -public class CalendarAdapter extends RecyclerView.Adapter implements OnMonthClickListener { +public class CalendarAdapter extends RecyclerView.Adapter implements OnCalendarDayClickListener { private boolean notify = true; private final List dates = new ArrayList<>(); private final Interval valid = new Interval<>(); @@ -44,8 +44,6 @@ public class CalendarAdapter extends RecyclerView.Adapter im private final Interval selectNote = new Interval<>(); private boolean singleMode = false; private Date lastClickDate = null; - @SuppressWarnings("deprecation") - private OnCalendarSelectListener calendarSelectListener; private OnCalendarSelectedListener onCalendarSelectedListener; public CalendarAdapter notify(boolean notify) { @@ -121,7 +119,7 @@ public CalendarAdapter range(Date startDate, Date endDate) { } public CalendarAdapter range(Date startDate, Date endDate, boolean clear) { - List dates = DateUtils.fillMonths(startDate, endDate); + List dates = DateUtils.fillDates(startDate, endDate); return range(dates, clear); } @@ -143,7 +141,7 @@ public CalendarAdapter range(List list, boolean clear) { */ @Deprecated public CalendarAdapter setRange(Date startDate, Date endDate, boolean clear, boolean notify) { - List dates = DateUtils.fillMonths(startDate, endDate); + List dates = DateUtils.fillDates(startDate, endDate); this.notify = notify; return range(dates, clear); } @@ -166,15 +164,6 @@ public void setOnCalendarSelectedListener(OnCalendarSelectedListener onCalendarS this.onCalendarSelectedListener = onCalendarSelectedListener; } - /** - * @deprecated 使用 {@link #setOnCalendarSelectedListener(OnCalendarSelectedListener)} 代替 - */ - @Deprecated - @SuppressWarnings("deprecation") - public void setOnCalendarSelectListener(OnCalendarSelectListener listener) { - calendarSelectListener = listener; - } - @NonNull @Override public CalendarViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -202,22 +191,34 @@ public int getItemCount() { } public final int getDatePosition(Date date) { - int position = -1; - if (dates.size() > 1) { - if (date.getTime() <= dates.get(0).getTime()) { - position = 0; - } else if (date.getTime() >= dates.get(dates.size() - 1).getTime()) { - position = dates.size() - 1; - } else { - for (int i = 0; i < dates.size() - 1; i++) { - if (date.getTime() >= dates.get(i).getTime() && date.getTime() <= dates.get(i + 1).getTime()) { - position = i; - break; - } - } + int size = dates.size(); + if (size <= 1) { + return 0; + } + long time = date.getTime(); + if (time <= dates.get(0).getTime()) { + return 0; + } + int lastPosition = size - 1; + if (time >= dates.get(lastPosition).getTime()) { + return lastPosition; + } + for (int i = 0; i < lastPosition; i++) { + Calendar minDate = DateUtils.calendar(dates.get(i).getTime()); + minDate.set(Calendar.DAY_OF_MONTH, 1); + minDate.set(Calendar.HOUR_OF_DAY, 0); + minDate.set(Calendar.MINUTE, 0); + minDate.set(Calendar.SECOND, 0); + Calendar maxDate = DateUtils.calendar(dates.get(i).getTime()); + maxDate.set(Calendar.DAY_OF_MONTH, DateUtils.maxDaysOfMonth(maxDate.getTime())); + maxDate.set(Calendar.HOUR_OF_DAY, 23); + maxDate.set(Calendar.MINUTE, 59); + maxDate.set(Calendar.SECOND, 59); + if (time >= minDate.getTime().getTime() && time <= maxDate.getTime().getTime()) { + return i; } } - return position; + return -1; } public Date value(int position) { @@ -228,16 +229,13 @@ public Date value(int position) { } @Override - public void onMonthClick(Date date) { + public void onCalendarDayClick(Date date) { if (null == date) { return; } if (null == lastClickDate || singleMode) { lastClickDate = date; select(date, date).refresh(); - if (null != calendarSelectListener) { - calendarSelectListener.onSingleSelect(date); - } if (null != onCalendarSelectedListener) { onCalendarSelectedListener.onSingleSelected(date); } @@ -246,17 +244,11 @@ public void onMonthClick(Date date) { if (lastClickDate.getTime() >= date.getTime()) { lastClickDate = date; select(date, date).refresh(); - if (null != calendarSelectListener) { - calendarSelectListener.onSingleSelect(date); - } if (null != onCalendarSelectedListener) { onCalendarSelectedListener.onSingleSelected(date); } } else { select(lastClickDate, date).refresh(); - if (null != calendarSelectListener) { - calendarSelectListener.onDoubleSelect(lastClickDate, date); - } if (null != onCalendarSelectedListener) { onCalendarSelectedListener.onRangeSelected(lastClickDate, date); } diff --git a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/protocol/OnMonthClickListener.java b/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/protocol/OnCalendarDayClickListener.java similarity index 89% rename from CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/protocol/OnMonthClickListener.java rename to CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/protocol/OnCalendarDayClickListener.java index 364bb25a..674e1bd4 100644 --- a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/protocol/OnMonthClickListener.java +++ b/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/protocol/OnCalendarDayClickListener.java @@ -19,8 +19,8 @@ * 月份中日期点击回调 * Created by peng on 2017/8/4. */ -public interface OnMonthClickListener { +public interface OnCalendarDayClickListener { - void onMonthClick(Date date); + void onCalendarDayClick(Date date); } diff --git a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/utils/DateUtils.java b/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/utils/DateUtils.java index 926b3ffc..596b48a0 100644 --- a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/utils/DateUtils.java +++ b/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/utils/DateUtils.java @@ -119,7 +119,7 @@ public static Date min(Date sDate, Date eDate) { * @param eDate 结束日期 * @return 区间内各月的Date */ - public static List fillMonths(Date sDate, Date eDate) { + public static List fillDates(Date sDate, Date eDate) { List dates = new ArrayList<>(); if (null == sDate || null == eDate) { dates.add(new Date()); diff --git a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/view/CalendarView.java b/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/view/CalendarView.java index e7246854..06fc3790 100644 --- a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/view/CalendarView.java +++ b/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/view/CalendarView.java @@ -124,7 +124,7 @@ public String getGroupName(int position) { .setDivideColor(ContextCompat.getColor(getContext(), R.color.calendar_month_divide_line_color)) //分割线颜色 .setDivideHeight((int) getResources().getDimension(R.dimen.calendar_decoration_divide_line_height)) //分割线高度 (默认没有分割线) - .setGroupTextColor(ContextCompat.getColor(getContext(), R.color.calendar_text_decoration_color)) + .setGroupTextColor(ContextCompat.getColor(getContext(), R.color.calendar_decoration_text_color)) //字体颜色 .setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)) //加粗 .setGroupTextSize((int) getResources().getDimension(R.dimen.calendar_decoration_text_size)) //字体大小 diff --git a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/view/MonthView.java b/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/view/MonthView.java index c86219e2..b15a4b1d 100644 --- a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/view/MonthView.java +++ b/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/view/MonthView.java @@ -26,7 +26,7 @@ import com.github.gzuliyujiang.calendarpicker.calendar.protocol.DayEntity; import com.github.gzuliyujiang.calendarpicker.calendar.protocol.MonthEntity; import com.github.gzuliyujiang.calendarpicker.calendar.protocol.NInterval; -import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnMonthClickListener; +import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnCalendarDayClickListener; import com.github.gzuliyujiang.calendarpicker.calendar.utils.DateUtils; import java.util.Date; @@ -213,9 +213,9 @@ public MonthEntity value() { return monthEntity; } - private OnMonthClickListener onDayInMonthClickListener; + private OnCalendarDayClickListener onDayInMonthClickListener; - public void setOnDayInMonthClickListener(OnMonthClickListener listener) { + public void setOnDayInMonthClickListener(OnCalendarDayClickListener listener) { onDayInMonthClickListener = listener; } @@ -233,7 +233,7 @@ public void onClick(View v) { DayEntity entity = dayView.value(); Date month = new Date(monthEntity.date().getTime()); Date dayDate = DateUtils.specialDayInMonth(month, entity.intValue()); - onDayInMonthClickListener.onMonthClick(dayDate); + onDayInMonthClickListener.onCalendarDayClick(dayDate); } catch (Exception e) { e.printStackTrace(); } diff --git a/CalendarPicker/src/main/res/layout/calendar_body.xml b/CalendarPicker/src/main/res/layout/calendar_body.xml index 0970da9a..6e9dc576 100644 --- a/CalendarPicker/src/main/res/layout/calendar_body.xml +++ b/CalendarPicker/src/main/res/layout/calendar_body.xml @@ -15,7 +15,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/calendar_background_color" - android:orientation="vertical"> + android:orientation="vertical" + android:padding="10dp"> diff --git a/CalendarPicker/src/main/res/layout/calendar_picker.xml b/CalendarPicker/src/main/res/layout/calendar_picker.xml index d14f0b7d..9291e7aa 100644 --- a/CalendarPicker/src/main/res/layout/calendar_picker.xml +++ b/CalendarPicker/src/main/res/layout/calendar_picker.xml @@ -11,22 +11,7 @@ ~ See the Mulan PSL v2 for more details. --> - - - - - - - + android:layout_height="match_parent" /> diff --git a/CalendarPicker/src/main/res/values/colors.xml b/CalendarPicker/src/main/res/values/colors.xml index da7ea7b7..dacc3b4c 100644 --- a/CalendarPicker/src/main/res/values/colors.xml +++ b/CalendarPicker/src/main/res/values/colors.xml @@ -14,16 +14,17 @@ - #FFFFFF - #FFFFFF + + @android:color/transparent + @android:color/transparent #FFFFFF - #333333 - + #333333 + #FFFFFF #FFFFFF - + #343434 #CCCCCC #FFFFFF diff --git a/ChangeLog.md b/ChangeLog.md index af7f94d9..53cce363 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,14 @@ # 更新日志 +## 4.x - 2021.09.16 + +- 支持设置弹窗样式,内置四种弹窗模式,效果请运行Demo; +- 日历日期选择器默认选中项展示到当前可见位置,Demo日历日期选择器自定义配色示例; +- 滚轮选择器滚动变化监听器优化,Demo滚轮选择器实时滚动变化监听示例; +- 文件目录选择器界面调整; +- 颜色选择器界面调整; +- 其他已知的小缺陷修复及代码优化; + ## 3.1.2 - 2021.09.13 - 选择器弹窗效果优化,支持启用顶部圆角背景; diff --git a/ColorPicker/src/main/java/com/github/gzuliyujiang/colorpicker/ColorPicker.java b/ColorPicker/src/main/java/com/github/gzuliyujiang/colorpicker/ColorPicker.java index fca301d5..cf87d9c1 100644 --- a/ColorPicker/src/main/java/com/github/gzuliyujiang/colorpicker/ColorPicker.java +++ b/ColorPicker/src/main/java/com/github/gzuliyujiang/colorpicker/ColorPicker.java @@ -23,8 +23,8 @@ import androidx.annotation.NonNull; import androidx.annotation.StyleRes; -import com.github.gzuliyujiang.basepicker.BottomDialog; -import com.github.gzuliyujiang.basepicker.PickerLog; +import com.github.gzuliyujiang.dialog.DialogLog; +import com.github.gzuliyujiang.dialog.ModalDialog; import java.util.Locale; @@ -33,10 +33,7 @@ * @since 2021/6/10 10:54 */ @SuppressWarnings("unused") -public class ColorPicker extends BottomDialog implements View.OnClickListener, OnColorChangedListener { - protected TextView cancelView; - protected TextView hexView; - protected TextView okView; +public class ColorPicker extends ModalDialog implements OnColorChangedListener { protected ColorGradientView colorGradientView; protected BrightnessGradientView brightnessGradientView; private boolean initialized = false; @@ -53,7 +50,7 @@ public ColorPicker(@NonNull Activity activity, @StyleRes int themeResId) { @NonNull @Override - protected View createContentView(@NonNull Activity activity) { + protected View createBodyView() { return View.inflate(activity, R.layout.color_picker_content, null); } @@ -61,9 +58,6 @@ protected View createContentView(@NonNull Activity activity) { @Override protected void initView(@NonNull View contentView) { super.initView(contentView); - cancelView = contentView.findViewById(R.id.color_picker_cancel); - hexView = contentView.findViewById(R.id.color_picker_hex); - okView = contentView.findViewById(R.id.color_picker_ok); colorGradientView = contentView.findViewById(R.id.color_picker_panel); brightnessGradientView = contentView.findViewById(R.id.color_picker_bright); } @@ -79,7 +73,6 @@ protected void initData() { if (okView != null) { okView.setOnClickListener(this); } - hexView.getPaint().setStrokeWidth(hexView.getResources().getDisplayMetrics().density * 3); colorGradientView.setOnColorChangedListener(this); brightnessGradientView.setOnColorChangedListener(this); colorGradientView.setBrightnessGradientView(brightnessGradientView); @@ -87,41 +80,27 @@ protected void initData() { colorGradientView.setColor(initColor); } - @CallSuper - @Override - public void onClick(View v) { - int id = v.getId(); - if (id == R.id.color_picker_cancel) { - PickerLog.print("cancel clicked"); - onCancel(); - dismiss(); - } else if (id == R.id.color_picker_ok) { - PickerLog.print("ok clicked"); - onOk(); - dismiss(); - } - } - @Override - public void onColorChanged(@ColorInt int color) { - updateCurrentColor(color); - } - protected void onCancel() { } + @Override protected void onOk() { if (onColorPickedListener != null) { onColorPickedListener.onColorPicked(getCurrentColor()); } } + @Override + public void onColorChanged(@ColorInt int color) { + updateCurrentColor(color); + } + private void updateCurrentColor(@ColorInt int color) { - String hexString = Utils.toHexString(color, false).toUpperCase(Locale.PRC); - hexView.setText(hexString); - hexView.setTextColor(Utils.reverseColor(color)); - hexView.setBackgroundColor(color); + titleView.setText(Utils.toHexString(color, false).toUpperCase(Locale.PRC)); + titleView.setTextColor(color); + titleView.setShadowLayer(10, 5, 5, Utils.reverseColor(color)); } /** @@ -143,23 +122,15 @@ public void setOnColorPickListener(OnColorPickedListener onColorPickedListener) @ColorInt public final int getCurrentColor() { try { - return Color.parseColor("#" + hexView.getText()); + return Color.parseColor("#" + titleView.getText()); } catch (Exception e) { - PickerLog.print(e); + DialogLog.print(e); return initColor; } } - public final TextView getOkView() { - return okView; - } - public final TextView getHexView() { - return hexView; - } - - public final TextView getCancelView() { - return cancelView; + return getTitleView(); } public final ColorGradientView getColorGradientView() { diff --git a/ColorPicker/src/main/java/com/github/gzuliyujiang/colorpicker/Utils.java b/ColorPicker/src/main/java/com/github/gzuliyujiang/colorpicker/Utils.java index 6ebde6a4..19b59355 100644 --- a/ColorPicker/src/main/java/com/github/gzuliyujiang/colorpicker/Utils.java +++ b/ColorPicker/src/main/java/com/github/gzuliyujiang/colorpicker/Utils.java @@ -18,7 +18,7 @@ import androidx.annotation.ColorInt; import androidx.annotation.NonNull; -import com.github.gzuliyujiang.basepicker.PickerLog; +import com.github.gzuliyujiang.dialog.DialogLog; /** * @author 贵州山野羡民(1032694760@qq.com) @@ -59,10 +59,10 @@ public static String toHexString(@ColorInt int color, boolean includeAlpha) { String colorString; if (includeAlpha) { colorString = alpha + red + green + blue; - PickerLog.print(String.format("%s to color string is %s", color, colorString)); + DialogLog.print(String.format("%s to color string is %s", color, colorString)); } else { colorString = red + green + blue; - PickerLog.print(String.format("%s to color string is %s%s%s%s, exclude alpha is %s", color, alpha, red, green, blue, colorString)); + DialogLog.print(String.format("%s to color string is %s%s%s%s, exclude alpha is %s", color, alpha, red, green, blue, colorString)); } return colorString; } diff --git a/ColorPicker/src/main/res/layout/color_picker_content.xml b/ColorPicker/src/main/res/layout/color_picker_content.xml index f1de1618..0ab634bc 100644 --- a/ColorPicker/src/main/res/layout/color_picker_content.xml +++ b/ColorPicker/src/main/res/layout/color_picker_content.xml @@ -15,66 +15,16 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" - android:background="@android:color/white" android:orientation="vertical"> - - - - - - - - - + android:layout_height="20dp" /> - - \ No newline at end of file diff --git a/Common/src/main/AndroidManifest.xml b/Common/src/main/AndroidManifest.xml index 5abac6f3..49bb6de5 100644 --- a/Common/src/main/AndroidManifest.xml +++ b/Common/src/main/AndroidManifest.xml @@ -11,4 +11,4 @@ ~ See the Mulan PSL v2 for more details. --> - + diff --git a/Common/src/main/java/com/github/gzuliyujiang/basepicker/ConfirmPicker.java b/Common/src/main/java/com/github/gzuliyujiang/basepicker/ConfirmPicker.java deleted file mode 100644 index b7241e6a..00000000 --- a/Common/src/main/java/com/github/gzuliyujiang/basepicker/ConfirmPicker.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2016-present 贵州纳雍穿青人李裕江<1032694760@qq.com> - * - * The software is licensed under the Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -package com.github.gzuliyujiang.basepicker; - -import android.app.Activity; -import android.view.Gravity; -import android.view.View; -import android.view.ViewGroup; -import android.widget.LinearLayout; -import android.widget.TextView; - -import androidx.annotation.CallSuper; -import androidx.annotation.Dimension; -import androidx.annotation.IntRange; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StyleRes; - -/** - * @author 贵州山野羡民(1032694760@qq.com) - * @since 2021/6/3 15:23 - */ -@SuppressWarnings("unused") -public abstract class ConfirmPicker extends BottomDialog implements View.OnClickListener { - protected View headerView; - protected TextView cancelView; - protected TextView titleView; - protected TextView okView; - protected View topLineView; - protected View bodyView; - protected View footerView; - - public ConfirmPicker(@NonNull Activity activity) { - super(activity); - } - - public ConfirmPicker(@NonNull Activity activity, @StyleRes int themeResId) { - super(activity, themeResId); - } - - @NonNull - @Override - protected View createContentView(@NonNull Activity activity) { - LinearLayout rootLayout = new LinearLayout(activity); - rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); - rootLayout.setOrientation(LinearLayout.VERTICAL); - rootLayout.setGravity(Gravity.CENTER); - rootLayout.setPadding(0, 0, 0, 0); - rootLayout.setBackgroundColor(0xFFFFFFFF); - headerView = createHeaderView(activity); - if (headerView != null) { - rootLayout.addView(headerView); - } - topLineView = createTopLineView(activity); - if (topLineView != null) { - rootLayout.addView(topLineView); - } - bodyView = createBodyView(activity); - rootLayout.addView(bodyView, new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1.0f)); - footerView = createFooterView(activity); - if (footerView != null) { - rootLayout.addView(footerView); - } - return rootLayout; - } - - @Nullable - protected View createHeaderView(@NonNull Activity activity) { - return View.inflate(activity, R.layout.picker_confirm_header, null); - } - - @Nullable - protected View createTopLineView(@NonNull Activity activity) { - View view = new View(activity); - view.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, 1)); - view.setBackgroundColor(0xFFCCCCCC); - return view; - } - - @NonNull - protected abstract View createBodyView(@NonNull Activity activity); - - @Nullable - protected View createFooterView(@NonNull Activity activity) { - return null; - } - - @CallSuper - @Override - protected void initView(@NonNull View contentView) { - super.initView(contentView); - cancelView = contentView.findViewById(R.id.confirm_picker_cancel); - titleView = contentView.findViewById(R.id.confirm_picker_title); - okView = contentView.findViewById(R.id.confirm_picker_ok); - } - - @CallSuper - @Override - protected void initData() { - super.initData(); - if (cancelView != null) { - cancelView.setOnClickListener(this); - } - if (okView != null) { - okView.setOnClickListener(this); - } - } - - @CallSuper - @Override - public void onClick(View v) { - int id = v.getId(); - if (id == R.id.confirm_picker_cancel) { - PickerLog.print("cancel clicked"); - onCancel(); - dismiss(); - } else if (id == R.id.confirm_picker_ok) { - PickerLog.print("ok clicked"); - onOk(); - dismiss(); - } - } - - protected abstract void onCancel(); - - protected abstract void onOk(); - - public final void setBodyWidth(@Dimension(unit = Dimension.DP) @IntRange(from = 50) int bodyWidth) { - ViewGroup.LayoutParams layoutParams = bodyView.getLayoutParams(); - int width = WRAP_CONTENT; - if (bodyWidth != WRAP_CONTENT && bodyWidth != MATCH_PARENT) { - width = (int) (bodyView.getResources().getDisplayMetrics().density * bodyWidth); - } - layoutParams.width = width; - bodyView.setLayoutParams(layoutParams); - } - - public final void setBodyHeight(@Dimension(unit = Dimension.DP) @IntRange(from = 50) int bodyHeight) { - ViewGroup.LayoutParams layoutParams = bodyView.getLayoutParams(); - int height = WRAP_CONTENT; - if (bodyHeight != WRAP_CONTENT && bodyHeight != MATCH_PARENT) { - height = (int) (bodyView.getResources().getDisplayMetrics().density * bodyHeight); - } - layoutParams.height = height; - bodyView.setLayoutParams(layoutParams); - } - - public final View getHeaderView() { - return headerView; - } - - public final View getTopLineView() { - return topLineView; - } - - public final View getBodyView() { - return bodyView; - } - - public final View getFooterView() { - return footerView; - } - - public final TextView getCancelView() { - return cancelView; - } - - public final TextView getTitleView() { - return titleView; - } - - public final TextView getOkView() { - return okView; - } - -} diff --git a/Common/src/main/java/com/github/gzuliyujiang/basepicker/BottomDialog.java b/Common/src/main/java/com/github/gzuliyujiang/dialog/BaseDialog.java similarity index 59% rename from Common/src/main/java/com/github/gzuliyujiang/basepicker/BottomDialog.java rename to Common/src/main/java/com/github/gzuliyujiang/dialog/BaseDialog.java index d7dc6e3a..364d2280 100644 --- a/Common/src/main/java/com/github/gzuliyujiang/basepicker/BottomDialog.java +++ b/Common/src/main/java/com/github/gzuliyujiang/dialog/BaseDialog.java @@ -11,16 +11,13 @@ * See the Mulan PSL v2 for more details. */ -package com.github.gzuliyujiang.basepicker; +package com.github.gzuliyujiang.dialog; import android.app.Activity; import android.app.Dialog; -import android.content.Context; import android.content.DialogInterface; import android.graphics.Color; import android.graphics.Paint; -import android.graphics.PixelFormat; -import android.graphics.Point; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.ShapeDrawable; @@ -28,7 +25,6 @@ import android.os.Build; import android.os.Bundle; import android.view.Gravity; -import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; import android.view.Window; @@ -49,27 +45,27 @@ * @since 2017/4/12 */ @SuppressWarnings({"WeakerAccess", "unused"}) -public abstract class BottomDialog extends Dialog implements DialogInterface.OnShowListener, DialogInterface.OnDismissListener { +public abstract class BaseDialog extends Dialog implements DialogInterface.OnShowListener, DialogInterface.OnDismissListener { public static final int MATCH_PARENT = ViewGroup.LayoutParams.MATCH_PARENT; public static final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT; protected Activity activity; protected View contentView; - protected View maskView; - public BottomDialog(@NonNull Activity activity) { - super(activity, R.style.PickerTheme); - init(activity); + public BaseDialog(@NonNull Activity activity) { + this(activity, R.style.DialogTheme_Base); } - public BottomDialog(@NonNull Activity activity, @StyleRes int themeResId) { + public BaseDialog(@NonNull Activity activity, @StyleRes int themeResId) { super(activity, themeResId); init(activity); } + public final View getContentView() { + return contentView; + } + private void init(Activity activity) { this.activity = activity; - onInit(activity); - PickerLog.print("dialog onInit"); setOwnerActivity(activity); //触摸屏幕取消窗体 setCanceledOnTouchOutside(false); @@ -86,6 +82,7 @@ private void init(Activity activity) { window.setGravity(Gravity.CENTER); window.getDecorView().setPadding(0, 0, 0, 0); } + onInit(activity, null); // 调用create或show才能触发onCreate if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { super.create(); @@ -94,98 +91,43 @@ private void init(Activity activity) { } } - protected void onInit(@NonNull Context context) { - + @CallSuper + protected void onInit(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { + DialogLog.print("dialog onInit"); } @Override protected final void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - PickerLog.print("dialog onCreate"); + DialogLog.print("dialog onCreate"); if (contentView == null) { readyView(); } } private void readyView() { - contentView = createContentView(activity); + contentView = createContentView(); contentView.setFocusable(true); contentView.setFocusableInTouchMode(true); setContentView(contentView); - if (enableMaskView()) { - addMaskView(); - } - setCancelable(true); - setCanceledOnTouchOutside(true); - setWidth(activity.getResources().getDisplayMetrics().widthPixels); - setGravity(Gravity.BOTTOM); initView(contentView); } @NonNull - protected abstract View createContentView(@NonNull Activity activity); + protected abstract View createContentView(); @CallSuper - protected void initView(@NonNull View contentView) { - PickerLog.print("dialog initView"); - } - - protected boolean enableMaskView() { - return true; - } - - private void addMaskView() { - try { - // 取消弹窗遮罩效果,通过自定义遮罩层视图解决自带弹窗遮罩致使系统导航栏亮度突兀问题 - setDimAmount(0); - WindowManager.LayoutParams params = new WindowManager.LayoutParams(); - params.width = WindowManager.LayoutParams.MATCH_PARENT; - Point screenRealSize = new Point(); - activity.getWindowManager().getDefaultDisplay().getRealSize(screenRealSize); - int navBarIdentifier = activity.getResources().getIdentifier("navigation_bar_height", "dimen", "android"); - params.height = screenRealSize.y - activity.getResources().getDimensionPixelSize(navBarIdentifier); - params.gravity = Gravity.TOP; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - // 取消弹窗遮罩效果后,异形屏的状态栏没法被自定义的遮罩试图挡住,需结合systemUiVisibility - params.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; - } - params.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - params.flags = WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; - } - params.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; - params.format = PixelFormat.TRANSLUCENT; - params.token = activity.getWindow().getDecorView().getWindowToken(); - maskView = new View(activity); - maskView.setBackgroundColor(0x7F000000); - maskView.setFitsSystemWindows(false); - maskView.setOnKeyListener(new View.OnKeyListener() { - @Override - public boolean onKey(View view, int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - dismiss(); - return true; - } - return false; - } - }); - activity.getWindowManager().addView(maskView, params); - PickerLog.print("dialog add mask view"); - } catch (Exception e) { - PickerLog.print(e); - } - } - - public final Activity getActivity() { - return activity; + protected void initView(View contentView) { + DialogLog.print("dialog initView"); } - public final View getContentView() { - return contentView; + public final void disableCancel() { + setCancelable(false); + setCanceledOnTouchOutside(false); } public final void enableRoundCorner() { - setBackgroundResource(R.drawable.picker_corner_bg); + setBackgroundResource(R.drawable.dialog_corner_round_top_white); } public final void setBackground(Drawable background) { @@ -257,12 +199,9 @@ public void setOnShowListener(@Nullable OnShowListener listener) { return; } final OnShowListener current = this; - super.setOnShowListener(new OnShowListener() { - @Override - public void onShow(DialogInterface dialog) { - current.onShow(dialog); - listener.onShow(dialog); - } + super.setOnShowListener(dialog -> { + current.onShow(dialog); + listener.onShow(dialog); }); } @@ -272,12 +211,9 @@ public void setOnDismissListener(@Nullable OnDismissListener listener) { return; } final OnDismissListener current = this; - super.setOnDismissListener(new OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - current.onDismiss(dialog); - listener.onDismiss(dialog); - } + super.setOnDismissListener(dialog -> { + current.onDismiss(dialog); + listener.onDismiss(dialog); }); } @@ -289,12 +225,12 @@ public void show() { } try { super.show(); - PickerLog.print("dialog show"); + DialogLog.print("dialog show"); } catch (Exception e) { //...not attached to window manager //...Unable to add window...is your activity running? //...Activity...has leaked window...that was originally added here - PickerLog.print(e); + DialogLog.print(e); } } @@ -306,32 +242,32 @@ public void dismiss() { } try { super.dismiss(); - PickerLog.print("dialog dismiss"); + DialogLog.print("dialog dismiss"); } catch (Exception e) { //...not attached to window manager //...Activity...has leaked window...that was originally added here - PickerLog.print(e); + DialogLog.print(e); } } @CallSuper @Override public void onAttachedToWindow() { - PickerLog.print("dialog attached to window"); + DialogLog.print("dialog attached to window"); super.onAttachedToWindow(); initData(); } @CallSuper protected void initData() { - PickerLog.print("dialog initData"); + DialogLog.print("dialog initData"); } @CallSuper @Override public void onDetachedFromWindow() { super.onDetachedFromWindow(); - PickerLog.print("dialog detached from window"); + DialogLog.print("dialog detached from window"); } /** @@ -340,7 +276,7 @@ public void onDetachedFromWindow() { @CallSuper @Override public void onShow(DialogInterface dialog) { - PickerLog.print("dialog onShow"); + DialogLog.print("dialog onShow"); } /** @@ -349,20 +285,7 @@ public void onShow(DialogInterface dialog) { @CallSuper @Override public void onDismiss(DialogInterface dialog) { - PickerLog.print("dialog onDismiss"); - removeMaskView(); - } - - private void removeMaskView() { - if (maskView == null) { - return; - } - try { - activity.getWindowManager().removeViewImmediate(maskView); - PickerLog.print("dialog remove mask view"); - } catch (Exception e) { - PickerLog.print(e); - } + DialogLog.print("dialog onDismiss"); } } diff --git a/Common/src/main/java/com/github/gzuliyujiang/dialog/BottomDialog.java b/Common/src/main/java/com/github/gzuliyujiang/dialog/BottomDialog.java new file mode 100644 index 00000000..f6f89505 --- /dev/null +++ b/Common/src/main/java/com/github/gzuliyujiang/dialog/BottomDialog.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2016-present 贵州纳雍穿青人李裕江<1032694760@qq.com> + * + * The software is licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +package com.github.gzuliyujiang.dialog; + +import android.app.Activity; +import android.content.DialogInterface; +import android.graphics.PixelFormat; +import android.graphics.Point; +import android.os.Build; +import android.os.Bundle; +import android.view.Gravity; +import android.view.KeyEvent; +import android.view.View; +import android.view.WindowManager; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StyleRes; + +/** + * 屏幕底部弹出对话框 + * + * @author 贵州山野羡民(1032694760@qq.com) + * @since 2021/4/15 20:54 + */ +public abstract class BottomDialog extends BaseDialog { + protected View maskView; + + public BottomDialog(@NonNull Activity activity) { + super(activity, R.style.DialogTheme_Sheet); + } + + public BottomDialog(@NonNull Activity activity, @StyleRes int themeResId) { + super(activity, themeResId); + } + + @Override + public void onInit(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { + super.onInit(activity, savedInstanceState); + setCancelable(true); + setCanceledOnTouchOutside(true); + setWidth(activity.getResources().getDisplayMetrics().widthPixels); + setGravity(Gravity.BOTTOM); + } + + @Override + public void onShow(DialogInterface dialog) { + super.onShow(dialog); + if (enableMaskView()) { + addMaskView(); + } + } + + protected boolean enableMaskView() { + return true; + } + + private void addMaskView() { + // 通过自定义遮罩层视图解决自带弹窗遮罩致使系统导航栏背景过暗不一体问题 + try { + // 取消弹窗遮罩效果 android:backgroundDimEnabled=false + getWindow().setDimAmount(0); + // 自定义遮罩层视图 + WindowManager.LayoutParams params = new WindowManager.LayoutParams(); + params.width = WindowManager.LayoutParams.MATCH_PARENT; + Point screenRealSize = new Point(); + activity.getWindowManager().getDefaultDisplay().getRealSize(screenRealSize); + int navBarIdentifier = activity.getResources().getIdentifier("navigation_bar_height", "dimen", "android"); + params.height = screenRealSize.y - activity.getResources().getDimensionPixelSize(navBarIdentifier); + params.gravity = Gravity.TOP; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + // 取消弹窗遮罩效果后,异形屏的状态栏没法被自定义的遮罩试图挡住,需结合systemUiVisibility + params.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; + } + params.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; + params.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; + params.format = PixelFormat.TRANSLUCENT; + params.token = activity.getWindow().getDecorView().getWindowToken(); + params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN; + maskView = new View(activity); + maskView.setBackgroundColor(0x7F000000); + maskView.setFitsSystemWindows(false); + maskView.setOnKeyListener((view, keyCode, event) -> { + if (keyCode == KeyEvent.KEYCODE_BACK) { + dismiss(); + return true; + } + return false; + }); + activity.getWindowManager().addView(maskView, params); + DialogLog.print("dialog add mask view"); + } catch (Exception e) { + DialogLog.print(e); + } + } + + @Override + public void onDismiss(DialogInterface dialog) { + removeMaskView(); + super.onDismiss(dialog); + } + + private void removeMaskView() { + if (maskView == null) { + DialogLog.print("mask view is null"); + return; + } + try { + activity.getWindowManager().removeViewImmediate(maskView); + DialogLog.print("dialog remove mask view"); + } catch (Exception e) { + DialogLog.print(e); + } + } + +} diff --git a/Common/src/main/java/com/github/gzuliyujiang/dialog/DialogConfig.java b/Common/src/main/java/com/github/gzuliyujiang/dialog/DialogConfig.java new file mode 100644 index 00000000..ad4179f3 --- /dev/null +++ b/Common/src/main/java/com/github/gzuliyujiang/dialog/DialogConfig.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2016-present 贵州纳雍穿青人李裕江<1032694760@qq.com> + * + * The software is licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +package com.github.gzuliyujiang.dialog; + +/** + * @author 贵州山魈羡民 (1032694760@qq.com) + * @since 2021/9/16 15:55 + */ +public final class DialogConfig { + private static int dialogStyle = DialogStyle.Default; + + private DialogConfig() { + super(); + } + + public static void setDialogStyle(@DialogStyle int style) { + dialogStyle = style; + } + + @DialogStyle + public static int getDialogStyle() { + return dialogStyle; + } + +} diff --git a/Common/src/main/java/com/github/gzuliyujiang/basepicker/PickerLog.java b/Common/src/main/java/com/github/gzuliyujiang/dialog/DialogLog.java similarity index 92% rename from Common/src/main/java/com/github/gzuliyujiang/basepicker/PickerLog.java rename to Common/src/main/java/com/github/gzuliyujiang/dialog/DialogLog.java index af505780..21abcd03 100644 --- a/Common/src/main/java/com/github/gzuliyujiang/basepicker/PickerLog.java +++ b/Common/src/main/java/com/github/gzuliyujiang/dialog/DialogLog.java @@ -11,7 +11,7 @@ * See the Mulan PSL v2 for more details. */ -package com.github.gzuliyujiang.basepicker; +package com.github.gzuliyujiang.dialog; import android.util.Log; @@ -23,11 +23,11 @@ * @author 贵州山魈羡民 (1032694760@qq.com) * @since 2021/3/26 21:34 */ -public final class PickerLog { +public final class DialogLog { private static final String TAG = "AndroidPicker"; private static boolean enable = false; - private PickerLog() { + private DialogLog() { super(); } diff --git a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/protocol/OnCalendarSelectListener.java b/Common/src/main/java/com/github/gzuliyujiang/dialog/DialogStyle.java similarity index 61% rename from CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/protocol/OnCalendarSelectListener.java rename to Common/src/main/java/com/github/gzuliyujiang/dialog/DialogStyle.java index 00b4bad5..e70d189d 100644 --- a/CalendarPicker/src/main/java/com/github/gzuliyujiang/calendarpicker/calendar/protocol/OnCalendarSelectListener.java +++ b/Common/src/main/java/com/github/gzuliyujiang/dialog/DialogStyle.java @@ -11,21 +11,21 @@ * See the Mulan PSL v2 for more details. */ -package com.github.gzuliyujiang.calendarpicker.calendar.protocol; +package com.github.gzuliyujiang.dialog; -import androidx.annotation.NonNull; - -import java.util.Date; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; /** - * 日历选择监听器 - * Created by peng on 2017/8/4. + * 弹窗样式枚举 + * + * @author 贵州山野羡民(1032694760@qq.com) + * @since 2021/9/16 15:31 */ -@Deprecated -public interface OnCalendarSelectListener { - - void onSingleSelect(@NonNull Date date); - - void onDoubleSelect(@NonNull Date before, @NonNull Date after); - -} \ No newline at end of file +@Retention(RetentionPolicy.SOURCE) +public @interface DialogStyle { + int Default = 0; + int One = 1; + int Two = 2; + int Three = 3; +} diff --git a/Common/src/main/java/com/github/gzuliyujiang/dialog/ModalDialog.java b/Common/src/main/java/com/github/gzuliyujiang/dialog/ModalDialog.java new file mode 100644 index 00000000..7a756d20 --- /dev/null +++ b/Common/src/main/java/com/github/gzuliyujiang/dialog/ModalDialog.java @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2016-present 贵州纳雍穿青人李裕江<1032694760@qq.com> + * + * The software is licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +package com.github.gzuliyujiang.dialog; + +import android.app.Activity; +import android.graphics.Color; +import android.os.Bundle; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.CallSuper; +import androidx.annotation.Dimension; +import androidx.annotation.IntRange; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StyleRes; + +/** + * @author 贵州山野羡民(1032694760@qq.com) + * @since 2021/6/3 15:23 + */ +@SuppressWarnings("unused") +public abstract class ModalDialog extends BottomDialog implements View.OnClickListener { + protected View headerView; + protected TextView cancelView; + protected TextView titleView; + protected TextView okView; + protected View topLineView; + protected View bodyView; + protected View footerView; + + public ModalDialog(@NonNull Activity activity) { + super(activity, DialogConfig.getDialogStyle() == DialogStyle.Three + ? R.style.DialogTheme_Fade : R.style.DialogTheme_Sheet); + } + + public ModalDialog(@NonNull Activity activity, @StyleRes int themeResId) { + super(activity, themeResId); + } + + @Override + public void onInit(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { + super.onInit(activity, savedInstanceState); + if (DialogConfig.getDialogStyle() == DialogStyle.Three) { + setWidth((int) (activity.getResources().getDisplayMetrics().widthPixels * 0.8f)); + setGravity(Gravity.CENTER); + } + } + + @Override + protected boolean enableMaskView() { + return DialogConfig.getDialogStyle() != DialogStyle.Three; + } + + @NonNull + @Override + protected View createContentView() { + LinearLayout rootLayout = new LinearLayout(activity); + rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); + rootLayout.setOrientation(LinearLayout.VERTICAL); + rootLayout.setGravity(Gravity.CENTER); + rootLayout.setPadding(0, 0, 0, 0); + switch (DialogConfig.getDialogStyle()) { + case DialogStyle.One: + case DialogStyle.Two: + rootLayout.setBackgroundResource(R.drawable.dialog_corner_round_top_white); + break; + case DialogStyle.Three: + rootLayout.setBackgroundResource(R.drawable.dialog_corner_round_all_white); + break; + default: + rootLayout.setBackgroundColor(Color.WHITE); + break; + } + headerView = createHeaderView(); + if (headerView == null) { + headerView = new View(activity); + headerView.setLayoutParams(new LinearLayout.LayoutParams(0, 0)); + } + rootLayout.addView(headerView); + topLineView = createTopLineView(); + if (topLineView == null) { + topLineView = new View(activity); + topLineView.setLayoutParams(new LinearLayout.LayoutParams(0, 0)); + } + rootLayout.addView(topLineView); + bodyView = createBodyView(); + rootLayout.addView(bodyView, new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1.0f)); + footerView = createFooterView(); + if (footerView == null) { + footerView = new View(activity); + footerView.setLayoutParams(new LinearLayout.LayoutParams(0, 0)); + } + rootLayout.addView(footerView); + return rootLayout; + } + + @Nullable + protected View createHeaderView() { + switch (DialogConfig.getDialogStyle()) { + case DialogStyle.One: + return View.inflate(activity, R.layout.dialog_header_style_1, null); + case DialogStyle.Two: + return View.inflate(activity, R.layout.dialog_header_style_2, null); + case DialogStyle.Three: + return View.inflate(activity, R.layout.dialog_header_style_3, null); + default: + return View.inflate(activity, R.layout.dialog_header_style_default, null); + } + } + + @Nullable + protected View createTopLineView() { + if (DialogConfig.getDialogStyle() == DialogStyle.Default) { + View view = new View(activity); + view.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, (int) (1 * activity.getResources().getDisplayMetrics().density))); + view.setBackgroundColor(0xFFDDDDDD); + return view; + } + return null; + } + + @NonNull + protected abstract View createBodyView(); + + @Nullable + protected View createFooterView() { + switch (DialogConfig.getDialogStyle()) { + case DialogStyle.One: + return View.inflate(activity, R.layout.dialog_footer_style_1, null); + case DialogStyle.Two: + return View.inflate(activity, R.layout.dialog_footer_style_2, null); + case DialogStyle.Three: + return View.inflate(activity, R.layout.dialog_footer_style_3, null); + default: + return null; + } + } + + @CallSuper + @Override + protected void initView(@NonNull View contentView) { + super.initView(contentView); + cancelView = contentView.findViewById(R.id.dialog_modal_cancel); + if (cancelView == null) { + throw new IllegalArgumentException("Cancel view id not found"); + } + titleView = contentView.findViewById(R.id.dialog_modal_title); + if (titleView == null) { + throw new IllegalArgumentException("Title view id not found"); + } + okView = contentView.findViewById(R.id.dialog_modal_ok); + if (okView == null) { + throw new IllegalArgumentException("Ok view id not found"); + } + } + + @CallSuper + @Override + protected void initData() { + super.initData(); + if (cancelView != null) { + cancelView.setOnClickListener(this); + } + if (okView != null) { + okView.setOnClickListener(this); + } + } + + @CallSuper + @Override + public void onClick(View v) { + int id = v.getId(); + if (id == R.id.dialog_modal_cancel) { + DialogLog.print("cancel clicked"); + onCancel(); + dismiss(); + } else if (id == R.id.dialog_modal_ok) { + DialogLog.print("ok clicked"); + onOk(); + dismiss(); + } + } + + protected abstract void onCancel(); + + protected abstract void onOk(); + + public final void setBodyWidth(@Dimension(unit = Dimension.DP) @IntRange(from = 50) int bodyWidth) { + ViewGroup.LayoutParams layoutParams = bodyView.getLayoutParams(); + int width = WRAP_CONTENT; + if (bodyWidth != WRAP_CONTENT && bodyWidth != MATCH_PARENT) { + width = (int) (bodyView.getResources().getDisplayMetrics().density * bodyWidth); + } + layoutParams.width = width; + bodyView.setLayoutParams(layoutParams); + } + + public final void setBodyHeight(@Dimension(unit = Dimension.DP) @IntRange(from = 50) int bodyHeight) { + ViewGroup.LayoutParams layoutParams = bodyView.getLayoutParams(); + int height = WRAP_CONTENT; + if (bodyHeight != WRAP_CONTENT && bodyHeight != MATCH_PARENT) { + height = (int) (bodyView.getResources().getDisplayMetrics().density * bodyHeight); + } + layoutParams.height = height; + bodyView.setLayoutParams(layoutParams); + } + + public final View getHeaderView() { + if (headerView == null) { + headerView = new View(activity); + } + return headerView; + } + + public final View getTopLineView() { + return topLineView; + } + + public final View getBodyView() { + return bodyView; + } + + public final View getFooterView() { + return footerView; + } + + public final TextView getCancelView() { + return cancelView; + } + + public final TextView getTitleView() { + return titleView; + } + + public final TextView getOkView() { + return okView; + } + +} diff --git a/Common/src/main/res/anim/picker_sheet_enter.xml b/Common/src/main/res/anim/dialog_sheet_enter.xml similarity index 100% rename from Common/src/main/res/anim/picker_sheet_enter.xml rename to Common/src/main/res/anim/dialog_sheet_enter.xml diff --git a/Common/src/main/res/anim/picker_sheet_exit.xml b/Common/src/main/res/anim/dialog_sheet_exit.xml similarity index 100% rename from Common/src/main/res/anim/picker_sheet_exit.xml rename to Common/src/main/res/anim/dialog_sheet_exit.xml diff --git a/Common/src/main/res/values/anims.xml b/Common/src/main/res/drawable/dialog_corner_round_all_white.xml similarity index 71% rename from Common/src/main/res/values/anims.xml rename to Common/src/main/res/drawable/dialog_corner_round_all_white.xml index 1cbe4fd8..30cc6596 100644 --- a/Common/src/main/res/values/anims.xml +++ b/Common/src/main/res/drawable/dialog_corner_round_all_white.xml @@ -11,11 +11,8 @@ ~ See the Mulan PSL v2 for more details. --> - - - - - + + + + diff --git a/Common/src/main/res/drawable/picker_corner_bg.xml b/Common/src/main/res/drawable/dialog_corner_round_top_white.xml similarity index 100% rename from Common/src/main/res/drawable/picker_corner_bg.xml rename to Common/src/main/res/drawable/dialog_corner_round_top_white.xml diff --git a/Common/src/main/res/values/themes.xml b/Common/src/main/res/drawable/dialog_ellipse_blue.xml similarity index 70% rename from Common/src/main/res/values/themes.xml rename to Common/src/main/res/drawable/dialog_ellipse_blue.xml index 058a31a1..72450627 100644 --- a/Common/src/main/res/values/themes.xml +++ b/Common/src/main/res/drawable/dialog_ellipse_blue.xml @@ -11,11 +11,8 @@ ~ See the Mulan PSL v2 for more details. --> - - - - - + + + + diff --git a/Common/src/main/res/drawable/dialog_ellipse_light_gray.xml b/Common/src/main/res/drawable/dialog_ellipse_light_gray.xml new file mode 100644 index 00000000..3ad789d3 --- /dev/null +++ b/Common/src/main/res/drawable/dialog_ellipse_light_gray.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/Common/src/main/res/layout/dialog_footer_style_1.xml b/Common/src/main/res/layout/dialog_footer_style_1.xml new file mode 100644 index 00000000..64bd6ee7 --- /dev/null +++ b/Common/src/main/res/layout/dialog_footer_style_1.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + diff --git a/Common/src/main/res/layout/dialog_footer_style_2.xml b/Common/src/main/res/layout/dialog_footer_style_2.xml new file mode 100644 index 00000000..a5447c1e --- /dev/null +++ b/Common/src/main/res/layout/dialog_footer_style_2.xml @@ -0,0 +1,35 @@ + + + + + + + diff --git a/Common/src/main/res/layout/dialog_footer_style_3.xml b/Common/src/main/res/layout/dialog_footer_style_3.xml new file mode 100644 index 00000000..d0785fa7 --- /dev/null +++ b/Common/src/main/res/layout/dialog_footer_style_3.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + diff --git a/Common/src/main/res/layout/dialog_header_style_1.xml b/Common/src/main/res/layout/dialog_header_style_1.xml new file mode 100644 index 00000000..981e73a0 --- /dev/null +++ b/Common/src/main/res/layout/dialog_header_style_1.xml @@ -0,0 +1,28 @@ + + + diff --git a/Common/src/main/res/layout/dialog_header_style_2.xml b/Common/src/main/res/layout/dialog_header_style_2.xml new file mode 100644 index 00000000..b2e50e34 --- /dev/null +++ b/Common/src/main/res/layout/dialog_header_style_2.xml @@ -0,0 +1,44 @@ + + + + + + + + + diff --git a/Common/src/main/res/layout/dialog_header_style_3.xml b/Common/src/main/res/layout/dialog_header_style_3.xml new file mode 100644 index 00000000..981e73a0 --- /dev/null +++ b/Common/src/main/res/layout/dialog_header_style_3.xml @@ -0,0 +1,28 @@ + + + diff --git a/Common/src/main/res/layout/picker_confirm_header.xml b/Common/src/main/res/layout/dialog_header_style_default.xml similarity index 75% rename from Common/src/main/res/layout/picker_confirm_header.xml rename to Common/src/main/res/layout/dialog_header_style_default.xml index e90b8a85..6baef174 100644 --- a/Common/src/main/res/layout/picker_confirm_header.xml +++ b/Common/src/main/res/layout/dialog_header_style_default.xml @@ -19,37 +19,50 @@ android:orientation="horizontal"> - + + + + diff --git a/Common/src/main/res/mipmap-xxhdpi/dialog_close_icon.png b/Common/src/main/res/mipmap-xxhdpi/dialog_close_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..7b68b43f42fe089df721397c46c6928ca2fdf306 GIT binary patch literal 1874 zcmV-Y2d(&tP)Px+3`s;mRCr$PT5pIIRTMwx?px_Yg?>sB%0MH*Lan4g!GC3x)|Zk<)75=*uRJJ% zG*b$LLMer!=&|?CTX!=fu)dTQshL_qQI3^CO}&j4|`~L#5Q`t?C-H8xij!qGbSZT}FdWBjRo%I-r!=pK-4< zdEo$5DwQjThK5!Hz-l6z>8wctAtD|FfS$Itww`LW`fm|DLmq_zP^nZV8pE~LYY=gY zgOcX}pg*9S3;^TP_7Kr2#@LPkh~LuaU7i;L0O$NZ0C)ue>KWdTh=;Y-M*!gXz`#I% zZ*Q*wV0d+Obc}CrZ=Xy=w;99 zy;iGznMcubxjYRKjYqAE+mDE4DP?ya-h~_i&iPXS@M2T}B03BJFZ;g#ek00-d&}kW zJVbmN5f{hs+n|(sDX*N|9w3A;L2gG>Fd{xHrFk=Z zs#Gdd1_uXE#vHxbzVCmXMS)BnV6M8s!9j!aO|}rN^~74O_Inn=jnbCOkx5U$lD}K?d|O|T{A{!0HVQ%i1zuue@`=v%F5I8ypQZF5)qw) zaTWl+wR3x|_550`X72mg#W{Zt03IZwKM}F2lzJzNVVv`a5OD($T>${^Dy0m+*k$qr z#@O%;V7?usl(SsqIRUVC?b;<;>phm6ZTEeDeUbpr^9~{6Jd0+TD+tDT0N8EqJ)xAE zo+59XoiQ@TmUeY@?M(y02>{Ny1OOf~8yXtAxx2gj`-}h>@>CFFj0Z&gMoM{GlDy8& z&gpG!ZQofmN+~6Z0>Bh3t__%-R7%~L#yHN9U{75T^6ato;GF*m08@kiomEPiqD$gR z^#CEnLL&M&AFZtc`!*=7XY>p(MIe1cly46 z**8EvAufiw(6|8Zd7k-l9R4~)#H~`wO$`CydEOg{xY7b(rtka5T@(swk_-%J?0^?; zON|#%9X!vQ5mb*ZJ|d!>zVEMU2msExasP!OlM5FvOo$dUT);>GA#QtS;|&v2R2esJ z++P;MgG#AIjRNq4mHVGlN=7`%sQ=w^|DPq_tk2wlB^TOryp3 zeN&3ByUOMA9gMLrEKl7orA(|@7+NO)Vv3Kulv0l-DHJJ)^fAUB>FVk-NlNO90U`C% zmUI3l0N7utPQ_X$0F1^$h)YUhMD##X>nmtyZDx%1YpqQM=|rmK7C~4N(^{WL#3M;1 zG0*evN5uE6w_j{YECAq=j*N?2W-+)C+GzQ$DMit^vUoH5fUbZ<`-M#_iw9nCSz{y% z+O9^q(#0iMO>2x8rGnO&$q6nQglJ`7Fa)PgfACbPRGQng)|e3b2>Omf+J(;~s1U8XN6r5sLCv$((M_Atg))f zK*%VV8rc~goUjD_3IGO#{X}#$X-p0PW--PV5YcR_%M-<|kBC-god$^mzYqYzD{|Bh zO4`Vd+ELj!_X^tTOU?akHCJ83z*zv;%NX0^(&lz$8l@}j2&5@snyjY7 + ~ + ~ The software is licensed under the Mulan PSL v2. + ~ You can use this software according to the terms and conditions of the Mulan PSL v2. + ~ You may obtain a copy of Mulan PSL v2 at: + ~ http://license.coscl.org.cn/MulanPSL2 + ~ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + ~ IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + ~ PURPOSE. + ~ See the Mulan PSL v2 for more details. + --> + + + + + + + + diff --git a/Common/src/main/res/values/dialog_themes.xml b/Common/src/main/res/values/dialog_themes.xml new file mode 100644 index 00000000..489705cd --- /dev/null +++ b/Common/src/main/res/values/dialog_themes.xml @@ -0,0 +1,28 @@ + + + + + + + + + diff --git a/FilePicker/README.md b/FilePicker/README.md index 3279ed71..056ef465 100644 --- a/FilePicker/README.md +++ b/FilePicker/README.md @@ -1,3 +1,3 @@ # 文件/目录选择器 -注意合规性,调用之前要确保已获得用户授予存储权限(READ_EXTERNAL_STORAGE)。 +注意合规性,允许APP读取外置存储器,调用之前要确保已获得用户授予`READ_EXTERNAL_STORAGE`权限。 diff --git a/FilePicker/src/main/java/com/github/gzuliyujiang/filepicker/FileExplorer.java b/FilePicker/src/main/java/com/github/gzuliyujiang/filepicker/FileExplorer.java index 75c1bd36..2943ab12 100644 --- a/FilePicker/src/main/java/com/github/gzuliyujiang/filepicker/FileExplorer.java +++ b/FilePicker/src/main/java/com/github/gzuliyujiang/filepicker/FileExplorer.java @@ -15,6 +15,7 @@ import android.content.Context; import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Environment; import android.text.TextUtils; import android.util.AttributeSet; @@ -23,9 +24,10 @@ import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.RequiresApi; import androidx.recyclerview.widget.RecyclerView; -import com.github.gzuliyujiang.basepicker.PickerLog; +import com.github.gzuliyujiang.dialog.DialogLog; import com.github.gzuliyujiang.filepicker.adapter.FileAdapter; import com.github.gzuliyujiang.filepicker.adapter.FileEntity; import com.github.gzuliyujiang.filepicker.adapter.PathAdapter; @@ -51,7 +53,6 @@ public class FileExplorer extends FrameLayout { private PathAdapter pathAdapter; private RecyclerView fileListView; private TextView emptyHintView; - private View bottomLineView; private RecyclerView pathListView; private OnFileClickedListener onFileClickedListener; @@ -70,6 +71,7 @@ public FileExplorer(Context context, AttributeSet attrs, int defStyleAttr) { init(context); } + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public FileExplorer(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(context); @@ -83,7 +85,6 @@ private void init(Context context) { emptyHint = Locale.getDefault().getDisplayLanguage().contains("中文") ? "<空>" : ""; emptyHintView = contentView.findViewById(R.id.file_picker_empty_hint); emptyHintView.setText(emptyHint); - bottomLineView = contentView.findViewById(R.id.file_picker_bottom_line); pathAdapter = new PathAdapter(context); pathListView = contentView.findViewById(R.id.file_picker_path_list); pathListView.setAdapter(pathAdapter); @@ -97,7 +98,7 @@ private void init(Context context) { @Override public void onPathClicked(int position, @NonNull String path) { FileEntity entity = fileAdapter.getItem(position); - PickerLog.print("clicked file item: " + entity); + DialogLog.print("clicked file item: " + entity); File file = entity.getFile(); if (file.isDirectory()) { refreshCurrent(file); @@ -111,7 +112,7 @@ public void onPathClicked(int position, @NonNull String path) { pathAdapter.setOnPathClickedListener(new OnPathClickedListener() { @Override public void onPathClicked(int position, @NonNull String path) { - PickerLog.print("clicked path name: " + path); + DialogLog.print("clicked path name: " + path); refreshCurrent(new File(path)); } }); @@ -167,11 +168,11 @@ public final void refreshCurrent(File current) { itemCount--; } if (itemCount < 1) { - PickerLog.print("no files, or dir is empty"); + DialogLog.print("no files, or dir is empty"); emptyHintView.setVisibility(View.VISIBLE); emptyHintView.setText(emptyHint); } else { - PickerLog.print("files or dirs count: " + itemCount); + DialogLog.print("files or dirs count: " + itemCount); emptyHintView.setVisibility(View.GONE); } } @@ -240,10 +241,6 @@ public final TextView getEmptyHintView() { return emptyHintView; } - public final View getBottomLineView() { - return bottomLineView; - } - public final RecyclerView getPathListView() { return pathListView; } diff --git a/FilePicker/src/main/java/com/github/gzuliyujiang/filepicker/FilePicker.java b/FilePicker/src/main/java/com/github/gzuliyujiang/filepicker/FilePicker.java index 973593fd..707d1cbb 100644 --- a/FilePicker/src/main/java/com/github/gzuliyujiang/filepicker/FilePicker.java +++ b/FilePicker/src/main/java/com/github/gzuliyujiang/filepicker/FilePicker.java @@ -21,8 +21,8 @@ import androidx.annotation.StyleRes; import androidx.recyclerview.widget.RecyclerView; -import com.github.gzuliyujiang.basepicker.ConfirmPicker; -import com.github.gzuliyujiang.basepicker.PickerLog; +import com.github.gzuliyujiang.dialog.DialogLog; +import com.github.gzuliyujiang.dialog.ModalDialog; import com.github.gzuliyujiang.filepicker.annotation.ExplorerMode; import com.github.gzuliyujiang.filepicker.contract.OnFileClickedListener; import com.github.gzuliyujiang.filepicker.contract.OnFilePickedListener; @@ -36,7 +36,7 @@ * @since 2015/9/29 */ @SuppressWarnings("unused") -public class FilePicker extends ConfirmPicker { +public class FilePicker extends ModalDialog { private int explorerMode = ExplorerMode.FILE; private File initDir; private FileExplorer fileExplorer; @@ -53,7 +53,7 @@ public FilePicker(@NonNull Activity activity, @StyleRes int themeResId) { @NonNull @Override - protected View createBodyView(@NonNull Activity activity) { + protected View createBodyView() { fileExplorer = new FileExplorer(activity); return fileExplorer; } @@ -63,10 +63,11 @@ protected void initData() { super.initData(); initialized = true; if (explorerMode == ExplorerMode.FILE) { - okView.setVisibility(View.INVISIBLE); + okView.setVisibility(View.GONE); } - setBodyHeight(300); + setHeight((int) (activity.getResources().getDisplayMetrics().heightPixels * 0.6f)); setInitDir(explorerMode, initDir); + titleView.setText(explorerMode == ExplorerMode.FILE ? "选择文件" : "选择目录"); } @Override @@ -77,7 +78,7 @@ protected void onCancel() { @Override protected void onOk() { File currentFile = fileExplorer.getCurrentFile(); - PickerLog.print("picked directory: " + currentFile); + DialogLog.print("picked directory: " + currentFile); if (onFilePickedListener != null) { onFilePickedListener.onFilePicked(currentFile); } @@ -120,10 +121,6 @@ public final TextView getEmptyHintView() { return fileExplorer.getEmptyHintView(); } - public final View getBottomLineView() { - return fileExplorer.getBottomLineView(); - } - public final RecyclerView getPathListView() { return fileExplorer.getPathListView(); } diff --git a/FilePicker/src/main/java/com/github/gzuliyujiang/filepicker/adapter/FileAdapter.java b/FilePicker/src/main/java/com/github/gzuliyujiang/filepicker/adapter/FileAdapter.java index 8625296d..2fb13cd4 100644 --- a/FilePicker/src/main/java/com/github/gzuliyujiang/filepicker/adapter/FileAdapter.java +++ b/FilePicker/src/main/java/com/github/gzuliyujiang/filepicker/adapter/FileAdapter.java @@ -30,7 +30,7 @@ import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; -import com.github.gzuliyujiang.basepicker.PickerLog; +import com.github.gzuliyujiang.dialog.DialogLog; import com.github.gzuliyujiang.filepicker.R; import com.github.gzuliyujiang.filepicker.annotation.FileSort; import com.github.gzuliyujiang.filepicker.contract.OnPathClickedListener; @@ -265,14 +265,14 @@ public File getCurrentFile() { public void loadData(File dir) { if (dir == null) { - PickerLog.print("current directory is null"); + DialogLog.print("current directory is null"); return; } List entities = new ArrayList<>(); if (rootDir == null) { rootDir = dir; } - PickerLog.print("current directory path: " + dir); + DialogLog.print("current directory path: " + dir); currentFile = dir; if (showHomeDir) { //添加“返回主目录” @@ -351,7 +351,7 @@ public FileEntity getItem(int position) { * 列出指定目录下的所有子目录 */ private List listFiles(File startDir, FileFilter fileFilter) { - PickerLog.print(String.format("list dir %s", startDir)); + DialogLog.print(String.format("list dir %s", startDir)); if (!startDir.isDirectory()) { return new ArrayList<>(); } diff --git a/FilePicker/src/main/res/layout/file_picker_content.xml b/FilePicker/src/main/res/layout/file_picker_content.xml index bc63e567..6994fc3c 100644 --- a/FilePicker/src/main/res/layout/file_picker_content.xml +++ b/FilePicker/src/main/res/layout/file_picker_content.xml @@ -16,18 +16,28 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:orientation="vertical"> + android:orientation="vertical" + android:paddingStart="10dp" + android:paddingEnd="10dp"> + + + android:layout_height="match_parent"> @@ -44,21 +54,4 @@ - - - - \ No newline at end of file diff --git a/ImagePicker/README.md b/ImagePicker/README.md index 91cefa73..0391408f 100644 --- a/ImagePicker/README.md +++ b/ImagePicker/README.md @@ -3,7 +3,7 @@ 图片选择(相机+相册+裁剪),改自 [ImagePicker](https://github.com/linchaolong/ImagePicker) 及 [Android-Image-Cropper](https://github.com/ArthurHub/Android-Image-Cropper) 。 -注意合规性,调用之前要确保已获得用户授予相机权限及存储权限(CAMERA、READ_EXTERNAL_STORAGE、WRITE_EXTERNAL_STORAGE)。 +注意合规性,允许APP使用摄像头,允许APP读取/写入外置存储器,调用之前要确保已获得用户授予`CAMERA`、`READ_EXTERNAL_STORAGE`、`WRITE_EXTERNAL_STORAGE`权限。 ## 简单用法 diff --git a/README.md b/README.md index 079573c3..bfb3c55a 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,8 @@ dependencies { ### 在 Java 中 ```groovy + DialogConfig.setDialogStyle(DialogStyle.XiaoMi); + ... List data = new ArrayList<>(); data.add(new GoodsCategoryBean(1, "食品生鲜")); data.add(new GoodsCategoryBean(2, "家用电器")); @@ -152,44 +154,49 @@ dependencies { data.add(new GoodsCategoryBean(5, "酒水饮料")); data.add(new GoodsCategoryBean(6, "图书音像")); OptionPicker picker = new OptionPicker(this); - picker.enableRoundCorner(); picker.setBodyWidth(140); - picker.getOkView().setTextColor(0xFFFF0000); - picker.getTopLineView().setBackgroundColor(0xFFFF0000); + picker.getWheelView().setIndicatorColor(0xFFFF0000); + picker.getWheelView().setTextColor(0xFFFF00FF); + picker.getWheelView().setSelectedTextColor(0xFFFF0000); picker.setOnOptionPickedListener(this); + picker.getWheelLayout().setOnOptionSelectedListener(new OnOptionSelectedListener() { + @Override + public void onOptionSelected(int position, Object item) { + picker.getTitleView().setText(picker.getWheelView().formatItem(position)); + } + }); picker.setData(data); picker.setDefaultPosition(2); picker.show(); ``` ```groovy + DialogConfig.setDialogStyle(DialogStyle.Default); + ... DatePicker picker = new DatePicker(this); - picker.enableRoundCorner(); picker.setBodyWidth(240); - picker.setBackgroundColor(0xEEDDDDDD); - picker.getHeaderView().setBackgroundColor(0xFFCCCCCC); DateWheelLayout wheelLayout = picker.getWheelLayout(); wheelLayout.setDateMode(DateMode.YEAR_MONTH_DAY); wheelLayout.setDateLabel("年", "月", "日"); wheelLayout.setRange(DateEntity.today(), DateEntity.yearOnFuture(30), DateEntity.yearOnFuture(10)); - //wheelLayout.setRange(DateEntity.target(1930, 1, 1), DateEntity.today(), DateEntity.target(1999, 1, 1)); wheelLayout.setCurtainEnabled(true); wheelLayout.setCurtainColor(0xFFCC0000); wheelLayout.setIndicatorEnabled(true); wheelLayout.setIndicatorColor(0xFFFF0000); wheelLayout.setIndicatorSize(view.getResources().getDisplayMetrics().density * 2); wheelLayout.setTextColor(0xCCCC0000); - wheelLayout.setSelectedTextColor(0xFF00FF00); - wheelLayout.getYearWheelView().setBackgroundColor(0x90CCCCCC); - wheelLayout.getMonthWheelView().setBackgroundColor(0x90CCCCCC); - wheelLayout.getDayWheelView().setBackgroundColor(0x90CCCCCC); + wheelLayout.setSelectedTextColor(0xFFFF0000); + wheelLayout.getYearLabelView().setTextColor(0xFF999999); + wheelLayout.getMonthLabelView().setTextColor(0xFF999999); + wheelLayout.getDayLabelView().setTextColor(0xFF999999); picker.setOnDatePickedListener(this); picker.show(); ``` ```groovy + DialogConfig.setDialogStyle(DialogStyle.IOS); + ... AddressPicker picker = new AddressPicker(this); - picker.enableRoundCorner(); picker.setAddressMode("city.json", AddressMode.PROVINCE_CITY_COUNTY, new AddressJsonParser.Builder() .provinceCodeField("code") @@ -281,6 +288,84 @@ dependencies { ``` + +### 定制样式 + +#### 在Java中集成重写 + +```java +//仿蚂蚁财富APP定投周期选择弹窗样式 +public class AntFortuneLikePicker extends LinkagePicker { + private int lastDialogStyle; + + public AntFortuneLikePicker(@NonNull Activity activity) { + super(activity); + } + + @Override + protected void onInit(@NonNull Context context) { + super.onInit(context); + lastDialogStyle = DialogConfig.getDialogStyle(); + DialogConfig.setDialogStyle(DialogStyle.Default); + } + + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + DialogConfig.setDialogStyle(lastDialogStyle); + } + + @Override + protected void initData() { + super.initData(); + setBackgroundColor(0xFFFFFFFF); + cancelView.setText("取消"); + cancelView.setTextSize(16); + cancelView.setTextColor(0xFF0081FF); + okView.setTextColor(0xFF0081FF); + okView.setText("确定"); + okView.setTextSize(16); + titleView.setTextColor(0xFF333333); + titleView.setText("定投周期"); + titleView.setTextSize(16); + wheelLayout.setData(new AntFortuneLikeProvider()); + wheelLayout.setAtmosphericEnabled(true); + wheelLayout.setVisibleItemCount(7); + wheelLayout.setCyclicEnabled(false); + wheelLayout.setIndicatorEnabled(true); + wheelLayout.setIndicatorColor(0xFFDDDDDD); + wheelLayout.setIndicatorSize((int) (contentView.getResources().getDisplayMetrics().density * 1)); + wheelLayout.setTextColor(0xFF999999); + wheelLayout.setSelectedTextColor(0xFF333333); + wheelLayout.setCurtainEnabled(false); + wheelLayout.setCurvedEnabled(false); + } + +} +```` + +#### 在``app/.../res/values/styles.xml`中重写覆盖 + +```xml + +``` ## 效果预览 以下图片显示的效果可能已修改过,实际效果请运行 demo 查看。 diff --git a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/BirthdayPicker.java b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/BirthdayPicker.java index a04fbdd1..a072003a 100644 --- a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/BirthdayPicker.java +++ b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/BirthdayPicker.java @@ -46,6 +46,7 @@ public BirthdayPicker(@NonNull Activity activity, @StyleRes int themeResId) { @Override protected void initData() { super.initData(); + titleView.setText("生日选择"); Calendar calendar = Calendar.getInstance(); int currentYear = calendar.get(Calendar.YEAR); int currentMonth = calendar.get(Calendar.MONTH) + 1; diff --git a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/CarNumberPicker.java b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/CarNumberPicker.java index 477bdf60..d7ccc114 100644 --- a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/CarNumberPicker.java +++ b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/CarNumberPicker.java @@ -56,11 +56,17 @@ public void setOnLinkagePickedListener(OnLinkagePickedListener onLinkagePickedLi @NonNull @Override - protected View createBodyView(@NonNull Activity activity) { + protected View createBodyView() { wheelLayout = new CarNumberWheelLayout(activity); return wheelLayout; } + @Override + protected void initData() { + super.initData(); + titleView.setText("车牌选择"); + } + @Override protected void onOk() { if (onCarNumberPickedListener != null) { diff --git a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/ConstellationPicker.java b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/ConstellationPicker.java index c5a6ad5f..057acc85 100644 --- a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/ConstellationPicker.java +++ b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/ConstellationPicker.java @@ -60,6 +60,12 @@ public ConstellationPicker(Activity activity, boolean includeUnlimited) { this.includeUnlimited = includeUnlimited; } + @Override + protected void initData() { + super.initData(); + titleView.setText("星座选择"); + } + @Override protected List provideData() { boolean isChinese = Locale.getDefault().getDisplayLanguage().contains("中文"); diff --git a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/DatePicker.java b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/DatePicker.java index e71670d7..c00c39df 100644 --- a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/DatePicker.java +++ b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/DatePicker.java @@ -19,7 +19,7 @@ import androidx.annotation.NonNull; import androidx.annotation.StyleRes; -import com.github.gzuliyujiang.basepicker.ConfirmPicker; +import com.github.gzuliyujiang.dialog.ModalDialog; import com.github.gzuliyujiang.wheelpicker.contract.OnDatePickedListener; import com.github.gzuliyujiang.wheelpicker.widget.DateWheelLayout; @@ -30,7 +30,7 @@ * @since 2021/6/5 18:17 */ @SuppressWarnings("unused") -public class DatePicker extends ConfirmPicker { +public class DatePicker extends ModalDialog { protected DateWheelLayout wheelLayout; private OnDatePickedListener onDatePickedListener; @@ -44,7 +44,7 @@ public DatePicker(@NonNull Activity activity, @StyleRes int themeResId) { @NonNull @Override - protected View createBodyView(@NonNull Activity activity) { + protected View createBodyView() { wheelLayout = new DateWheelLayout(activity); return wheelLayout; } @@ -54,9 +54,10 @@ protected void initView(@NonNull View contentView) { super.initView(contentView); } - @Deprecated - protected int provideDateMode() { - throw new UnsupportedOperationException("Use `picker.getWheelLayout().setDateMode()` instead"); + @Override + protected void initData() { + super.initData(); + titleView.setText("日期选择"); } @Override diff --git a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/DatimePicker.java b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/DatimePicker.java index 1a09e7ce..12cd0a0d 100644 --- a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/DatimePicker.java +++ b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/DatimePicker.java @@ -19,7 +19,7 @@ import androidx.annotation.NonNull; import androidx.annotation.StyleRes; -import com.github.gzuliyujiang.basepicker.ConfirmPicker; +import com.github.gzuliyujiang.dialog.ModalDialog; import com.github.gzuliyujiang.wheelpicker.contract.OnDatimePickedListener; import com.github.gzuliyujiang.wheelpicker.widget.DatimeWheelLayout; @@ -30,7 +30,7 @@ * @since 2021/6/5 18:21 */ @SuppressWarnings({"unused", "WeakerAccess"}) -public class DatimePicker extends ConfirmPicker { +public class DatimePicker extends ModalDialog { protected DatimeWheelLayout wheelLayout; private OnDatimePickedListener onDatimePickedListener; @@ -44,19 +44,15 @@ public DatimePicker(@NonNull Activity activity, @StyleRes int themeResId) { @NonNull @Override - protected View createBodyView(@NonNull Activity activity) { + protected View createBodyView() { wheelLayout = new DatimeWheelLayout(activity); return wheelLayout; } - @Deprecated - protected int provideDateMode() { - throw new UnsupportedOperationException("Use `picker.getWheelLayout().setDateMode()` instead"); - } - - @Deprecated - protected int provideTimeMode() { - throw new UnsupportedOperationException("Use `picker.getWheelLayout().setTimeMode()` instead"); + @Override + protected void initData() { + super.initData(); + titleView.setText("日期时间选择"); } @Override diff --git a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/EthnicPicker.java b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/EthnicPicker.java index 9dd4464b..a01bf544 100644 --- a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/EthnicPicker.java +++ b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/EthnicPicker.java @@ -17,7 +17,7 @@ import androidx.annotation.NonNull; -import com.github.gzuliyujiang.basepicker.PickerLog; +import com.github.gzuliyujiang.dialog.DialogLog; import com.github.gzuliyujiang.wheelpicker.annotation.EthnicSpec; import com.github.gzuliyujiang.wheelpicker.entity.EthnicEntity; @@ -102,6 +102,12 @@ public EthnicPicker(@NonNull Activity activity, int themeResId) { super(activity, themeResId); } + @Override + protected void initData() { + super.initData(); + titleView.setText("民族选择"); + } + public void setEthnicSpec(@EthnicSpec int ethnicSpec) { this.ethnicSpec = ethnicSpec; setData(provideData()); @@ -139,7 +145,7 @@ protected List provideData() { data.add(entity); } } catch (JSONException e) { - PickerLog.print(e); + DialogLog.print(e); } switch (ethnicSpec) { case EthnicSpec.DEFAULT: diff --git a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/LinkagePicker.java b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/LinkagePicker.java index dfadea78..737f04a0 100644 --- a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/LinkagePicker.java +++ b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/LinkagePicker.java @@ -21,7 +21,7 @@ import androidx.annotation.NonNull; import androidx.annotation.StyleRes; -import com.github.gzuliyujiang.basepicker.ConfirmPicker; +import com.github.gzuliyujiang.dialog.ModalDialog; import com.github.gzuliyujiang.wheelpicker.contract.LinkageProvider; import com.github.gzuliyujiang.wheelpicker.contract.OnLinkagePickedListener; import com.github.gzuliyujiang.wheelpicker.widget.LinkageWheelLayout; @@ -38,7 +38,7 @@ * @since 2019/6/17 11:21 */ @SuppressWarnings({"WeakerAccess", "unused"}) -public class LinkagePicker extends ConfirmPicker { +public class LinkagePicker extends ModalDialog { protected LinkageWheelLayout wheelLayout; private OnLinkagePickedListener onLinkagePickedListener; @@ -52,11 +52,17 @@ public LinkagePicker(@NonNull Activity activity, @StyleRes int themeResId) { @NonNull @Override - protected View createBodyView(@NonNull Activity activity) { + protected View createBodyView() { wheelLayout = new LinkageWheelLayout(activity); return wheelLayout; } + @Override + protected void initData() { + super.initData(); + titleView.setText("请选择"); + } + @Override protected void onCancel() { diff --git a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/NumberPicker.java b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/NumberPicker.java index 4e6463d8..d1ce9e42 100644 --- a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/NumberPicker.java +++ b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/NumberPicker.java @@ -20,7 +20,7 @@ import androidx.annotation.NonNull; import androidx.annotation.StyleRes; -import com.github.gzuliyujiang.basepicker.ConfirmPicker; +import com.github.gzuliyujiang.dialog.ModalDialog; import com.github.gzuliyujiang.wheelpicker.contract.OnNumberPickedListener; import com.github.gzuliyujiang.wheelpicker.widget.NumberWheelLayout; import com.github.gzuliyujiang.wheelview.contract.WheelFormatter; @@ -33,7 +33,7 @@ * @since 2015/10/24 */ @SuppressWarnings("unused") -public class NumberPicker extends ConfirmPicker { +public class NumberPicker extends ModalDialog { protected NumberWheelLayout wheelLayout; private OnNumberPickedListener onNumberPickedListener; @@ -47,11 +47,17 @@ public NumberPicker(@NonNull Activity activity, @StyleRes int themeResId) { @NonNull @Override - protected View createBodyView(@NonNull Activity activity) { + protected View createBodyView() { wheelLayout = new NumberWheelLayout(activity); return wheelLayout; } + @Override + protected void initData() { + super.initData(); + titleView.setText("请选择"); + } + @Override protected void onCancel() { diff --git a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/OptionPicker.java b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/OptionPicker.java index 62680ee5..1b6c8717 100644 --- a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/OptionPicker.java +++ b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/OptionPicker.java @@ -20,7 +20,7 @@ import androidx.annotation.NonNull; import androidx.annotation.StyleRes; -import com.github.gzuliyujiang.basepicker.ConfirmPicker; +import com.github.gzuliyujiang.dialog.ModalDialog; import com.github.gzuliyujiang.wheelpicker.contract.OnOptionPickedListener; import com.github.gzuliyujiang.wheelpicker.widget.OptionWheelLayout; import com.github.gzuliyujiang.wheelview.widget.WheelView; @@ -36,7 +36,7 @@ * @since 2019/5/8 10:04 */ @SuppressWarnings({"unused"}) -public class OptionPicker extends ConfirmPicker { +public class OptionPicker extends ModalDialog { protected OptionWheelLayout wheelLayout; private OnOptionPickedListener onOptionPickedListener; private boolean initialized = false; @@ -54,7 +54,7 @@ public OptionPicker(@NonNull Activity activity, @StyleRes int themeResId) { @NonNull @Override - protected View createBodyView(@NonNull Activity activity) { + protected View createBodyView() { wheelLayout = new OptionWheelLayout(activity); return wheelLayout; } @@ -77,6 +77,7 @@ protected void onOk() { protected void initData() { super.initData(); initialized = true; + titleView.setText("请选择"); if (data == null || data.size() == 0) { data = provideData(); } diff --git a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/PhoneCodePicker.java b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/PhoneCodePicker.java index 1c538483..5b8d674e 100644 --- a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/PhoneCodePicker.java +++ b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/PhoneCodePicker.java @@ -40,6 +40,12 @@ public PhoneCodePicker(@NonNull Activity activity, @StyleRes int themeResId) { super(activity, themeResId); } + @Override + protected void initData() { + super.initData(); + titleView.setText("请选择"); + } + @Override protected List provideData() { List data = new ArrayList<>(); diff --git a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/SexPicker.java b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/SexPicker.java index e27aefef..ae028578 100644 --- a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/SexPicker.java +++ b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/SexPicker.java @@ -58,6 +58,12 @@ public SexPicker(@NonNull Activity activity, @StyleRes int themeResId, boolean i this.includeSecrecy = includeSecrecy; } + @Override + protected void initData() { + super.initData(); + titleView.setText("性别选择"); + } + @Override protected List provideData() { boolean isChinese = Locale.getDefault().getDisplayLanguage().contains("中文"); diff --git a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/TimePicker.java b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/TimePicker.java index 226107ab..8e9554c1 100644 --- a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/TimePicker.java +++ b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/TimePicker.java @@ -19,7 +19,7 @@ import androidx.annotation.NonNull; import androidx.annotation.StyleRes; -import com.github.gzuliyujiang.basepicker.ConfirmPicker; +import com.github.gzuliyujiang.dialog.ModalDialog; import com.github.gzuliyujiang.wheelpicker.contract.OnTimeMeridiemPickedListener; import com.github.gzuliyujiang.wheelpicker.contract.OnTimePickedListener; import com.github.gzuliyujiang.wheelpicker.widget.TimeWheelLayout; @@ -31,7 +31,7 @@ * @since 2021/6/5 18:19 */ @SuppressWarnings("unused") -public class TimePicker extends ConfirmPicker { +public class TimePicker extends ModalDialog { protected TimeWheelLayout wheelLayout; private OnTimePickedListener onTimePickedListener; private OnTimeMeridiemPickedListener onTimeMeridiemPickedListener; @@ -46,7 +46,7 @@ public TimePicker(@NonNull Activity activity, @StyleRes int themeResId) { @NonNull @Override - protected View createBodyView(@NonNull Activity activity) { + protected View createBodyView() { wheelLayout = new TimeWheelLayout(activity); return wheelLayout; } @@ -56,9 +56,10 @@ protected void initView(@NonNull View contentView) { super.initView(contentView); } - @Deprecated - protected int provideTimeMode() { - throw new UnsupportedOperationException("Use `picker.getWheelLayout().setTimeMode()` instead"); + @Override + protected void initData() { + super.initData(); + titleView.setText("时间选择"); } @Override diff --git a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/widget/NumberWheelLayout.java b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/widget/NumberWheelLayout.java index 670d86ac..650d423b 100644 --- a/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/widget/NumberWheelLayout.java +++ b/WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/widget/NumberWheelLayout.java @@ -74,7 +74,7 @@ protected void onAttributeSet(@NonNull Context context, @NonNull TypedArray type setCyclicEnabled(typedArray.getBoolean(R.styleable.NumberWheelLayout_wheel_cyclicEnabled, false)); setIndicatorEnabled(typedArray.getBoolean(R.styleable.NumberWheelLayout_wheel_indicatorEnabled, false)); setIndicatorColor(typedArray.getColor(R.styleable.NumberWheelLayout_wheel_indicatorColor, 0xFFEE3333)); - setIndicatorSize(typedArray.getDimension(R.styleable.NumberWheelLayout_wheel_indicatorSize, 1 * density)); + setIndicatorSize(typedArray.getDimensionPixelSize(R.styleable.NumberWheelLayout_wheel_indicatorSize, (int) (1 * density))); setCurvedIndicatorSpace(typedArray.getDimensionPixelSize(R.styleable.NumberWheelLayout_wheel_curvedIndicatorSpace, (int) (1 * density))); setCurtainEnabled(typedArray.getBoolean(R.styleable.NumberWheelLayout_wheel_curtainEnabled, false)); setCurtainColor(typedArray.getColor(R.styleable.NumberWheelLayout_wheel_curtainColor, 0x88FFFFFF)); @@ -103,7 +103,7 @@ public void onWheelSelected(WheelView view, int position) { } /** - * @deprecated 使用 {@link #setRange(float, float, float)} 代替 + * @deprecated 使用 {@link #setRange} 代替 */ @Deprecated @Override @@ -112,7 +112,7 @@ public void setData(List data) { } /** - * @deprecated 使用 {@link #setOnNumberSelectedListener(OnNumberSelectedListener)} 代替 + * @deprecated 使用 {@link #setOnNumberSelectedListener} 代替 */ @Deprecated @Override diff --git a/WheelPicker/src/main/res/layout/wheel_picker_linkage.xml b/WheelPicker/src/main/res/layout/wheel_picker_linkage.xml index 25bc4c54..e4fb23fd 100644 --- a/WheelPicker/src/main/res/layout/wheel_picker_linkage.xml +++ b/WheelPicker/src/main/res/layout/wheel_picker_linkage.xml @@ -53,8 +53,7 @@ style="@style/WheelDefault" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_weight="1.0" - android:visibility="visible" /> + android:layout_weight="1.0" /> generatePreviewData() { return data; } + /** + * @deprecated 使用 {@link #setRange} 代替 + */ @Deprecated @Override public void setData(List data) { diff --git a/WheelView/src/main/java/com/github/gzuliyujiang/wheelview/widget/WheelView.java b/WheelView/src/main/java/com/github/gzuliyujiang/wheelview/widget/WheelView.java index 29aa4e12..0e4f49b3 100644 --- a/WheelView/src/main/java/com/github/gzuliyujiang/wheelview/widget/WheelView.java +++ b/WheelView/src/main/java/com/github/gzuliyujiang/wheelview/widget/WheelView.java @@ -832,7 +832,13 @@ private String obtainItemText(int drawnDataPosition) { } public String formatItem(int position) { - Object item = getItem(position); + return formatItem(getItem(position)); + } + + public String formatItem(Object item) { + if (item == null) { + return ""; + } if (item instanceof TextProvider) { return ((TextProvider) item).provideText(); } diff --git a/app/build.gradle b/app/build.gradle index a8afafba..8178ef32 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,7 +26,6 @@ dependencies { implementation project(':CalendarPicker') implementation project(':ImagePicker') debugRuntimeOnly library.orhanobut_logger - implementation library.XPopup debugRuntimeOnly library.xcrash compileOnly library.xcrash } diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/DemoApp.java b/app/src/main/java/com/github/gzuliyujiang/fallback/DemoApp.java index 920c6d24..2da49929 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/DemoApp.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/DemoApp.java @@ -18,7 +18,9 @@ import androidx.multidex.MultiDex; -import com.github.gzuliyujiang.basepicker.PickerLog; +import com.github.gzuliyujiang.dialog.DialogConfig; +import com.github.gzuliyujiang.dialog.DialogLog; +import com.github.gzuliyujiang.dialog.DialogStyle; import org.json.JSONObject; @@ -42,7 +44,8 @@ protected void attachBaseContext(Context base) { @Override public void onCreate() { super.onCreate(); - PickerLog.enable(); + DialogLog.enable(); + DialogConfig.setDialogStyle(DialogStyle.Default); initXCrash(this); } diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/AddressPickerActivity.java b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/AddressPickerActivity.java index 179c77e7..0140a287 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/AddressPickerActivity.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/AddressPickerActivity.java @@ -27,6 +27,7 @@ import com.github.gzuliyujiang.wheelpicker.AddressPicker; import com.github.gzuliyujiang.wheelpicker.annotation.AddressMode; import com.github.gzuliyujiang.wheelpicker.contract.OnAddressPickedListener; +import com.github.gzuliyujiang.wheelpicker.contract.OnLinkageSelectedListener; import com.github.gzuliyujiang.wheelpicker.entity.CityEntity; import com.github.gzuliyujiang.wheelpicker.entity.CountyEntity; import com.github.gzuliyujiang.wheelpicker.entity.ProvinceEntity; @@ -53,28 +54,52 @@ public void onAddressPicked(ProvinceEntity province, CityEntity city, CountyEnti public void onProvinceCityCounty(View view) { AddressPicker picker = new AddressPicker(this); - picker.enableRoundCorner(); picker.setAddressMode(AddressMode.PROVINCE_CITY_COUNTY); picker.setDefaultValue("贵州省", "贵阳市", "观山湖区"); picker.setOnAddressPickedListener(this); + picker.getWheelLayout().setOnLinkageSelectedListener(new OnLinkageSelectedListener() { + @Override + public void onLinkageSelected(Object first, Object second, Object third) { + picker.getTitleView().setText(String.format("%s%s%s", + picker.getFirstWheelView().formatItem(first), + picker.getSecondWheelView().formatItem(second), + picker.getThirdWheelView().formatItem(third))); + } + }); picker.show(); } public void onProvinceCity(View view) { AddressPicker picker = new AddressPicker(this); - picker.enableRoundCorner(); picker.setAddressMode(AddressMode.PROVINCE_CITY); picker.setDefaultValue("520000", "520100", "520115"); picker.setOnAddressPickedListener(this); + picker.getWheelLayout().setOnLinkageSelectedListener(new OnLinkageSelectedListener() { + @Override + public void onLinkageSelected(Object first, Object second, Object third) { + picker.getTitleView().setText(String.format("%s%s%s", + picker.getFirstWheelView().formatItem(first), + picker.getSecondWheelView().formatItem(second), + picker.getThirdWheelView().formatItem(third))); + } + }); picker.show(); } public void onCityCounty(View view) { AddressPicker picker = new AddressPicker(this); - picker.enableRoundCorner(); picker.setAddressMode(AddressMode.CITY_COUNTY); picker.setDefaultValue("贵州省", "毕节市", "纳雍县"); picker.setOnAddressPickedListener(this); + picker.getWheelLayout().setOnLinkageSelectedListener(new OnLinkageSelectedListener() { + @Override + public void onLinkageSelected(Object first, Object second, Object third) { + picker.getTitleView().setText(String.format("%s%s%s", + picker.getFirstWheelView().formatItem(first), + picker.getSecondWheelView().formatItem(second), + picker.getThirdWheelView().formatItem(third))); + } + }); picker.show(); } @@ -87,7 +112,6 @@ public void onCustomUi(View view) { public void onCustomDataByJson(View view) { AddressPicker picker = new AddressPicker(this); - picker.enableRoundCorner(); picker.setAddressMode("city.json", AddressMode.PROVINCE_CITY_COUNTY, new AddressJsonParser.Builder() .provinceCodeField("code") @@ -101,15 +125,32 @@ public void onCustomDataByJson(View view) { .build()); picker.setDefaultValue("贵州省", "毕节地区", "纳雍县"); picker.setOnAddressPickedListener(this); + picker.getWheelLayout().setOnLinkageSelectedListener(new OnLinkageSelectedListener() { + @Override + public void onLinkageSelected(Object first, Object second, Object third) { + picker.getTitleView().setText(String.format("%s%s%s", + picker.getFirstWheelView().formatItem(first), + picker.getSecondWheelView().formatItem(second), + picker.getThirdWheelView().formatItem(third))); + } + }); picker.show(); } public void onCustomDataByText(View view) { AddressPicker picker = new AddressPicker(this); - picker.enableRoundCorner(); picker.setAddressLoader(new TextAddressLoader(this), new TextAddressParser()); picker.setDefaultValue("贵州省", "毕节地区", "纳雍县"); picker.setOnAddressPickedListener(this); + picker.getWheelLayout().setOnLinkageSelectedListener(new OnLinkageSelectedListener() { + @Override + public void onLinkageSelected(Object first, Object second, Object third) { + picker.getTitleView().setText(String.format("%s%s%s", + picker.getFirstWheelView().formatItem(first), + picker.getSecondWheelView().formatItem(second), + picker.getThirdWheelView().formatItem(third))); + } + }); picker.show(); } diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/CalendarPickerActivity.java b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/CalendarPickerActivity.java index ba662005..e26fef2b 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/CalendarPickerActivity.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/CalendarPickerActivity.java @@ -63,7 +63,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { public void onCalendarDateRange(View view) { CalendarPicker picker = new CalendarPicker(this); - picker.enableRoundCorner(); Date currentDate = new Date(System.currentTimeMillis()); Calendar calendar1 = Calendar.getInstance(Locale.CHINA); calendar1.setTime(currentDate); @@ -95,7 +94,6 @@ public void onRangeDatePicked(@NonNull Date startDate, @NonNull Date endDate) { public void onCalendarDateSingle(View view) { CalendarPicker picker = new CalendarPicker(this); - picker.enableRoundCorner(); picker.setRangeDateOnFuture(3); if (singleTimeInMillis == 0) { singleTimeInMillis = System.currentTimeMillis(); diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/ColorPickerActivity.java b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/ColorPickerActivity.java index 3b26ed53..91200568 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/ColorPickerActivity.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/ColorPickerActivity.java @@ -55,7 +55,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { public void onClick(View v) { if (v.getId() == R.id.color_picker_button) { ColorPicker picker = new ColorPicker(this); - picker.enableRoundCorner(); picker.setInitColor(0xFF7FF7FF); picker.setOnColorPickListener(new OnColorPickedListener() { @Override diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/DateTimePickerActivity.java b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/DateTimePickerActivity.java index a80e90d9..9cd30baa 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/DateTimePickerActivity.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/DateTimePickerActivity.java @@ -66,7 +66,6 @@ public void onTimePicked(int hour, int minute, int second) { public void onYearMonthDayTime(View view) { DatimePicker picker = new DatimePicker(this); - picker.enableRoundCorner(); final DatimeWheelLayout wheelLayout = picker.getWheelLayout(); picker.setOnDatimePickedListener(new OnDatimePickedListener() { @Override @@ -86,10 +85,7 @@ public void onDatimePicked(int year, int month, int day, int hour, int minute, i public void onYearMonthDay(View view) { DatePicker picker = new DatePicker(this); - picker.enableRoundCorner(); picker.setBodyWidth(240); - picker.setBackgroundColor(0xEEDDDDDD); - picker.getHeaderView().setBackgroundColor(0xFFCCCCCC); DateWheelLayout wheelLayout = picker.getWheelLayout(); wheelLayout.setDateMode(DateMode.YEAR_MONTH_DAY); wheelLayout.setDateLabel("年", "月", "日"); @@ -100,17 +96,16 @@ public void onYearMonthDay(View view) { wheelLayout.setIndicatorColor(0xFFFF0000); wheelLayout.setIndicatorSize(view.getResources().getDisplayMetrics().density * 2); wheelLayout.setTextColor(0xCCCC0000); - wheelLayout.setSelectedTextColor(0xFF00FF00); - wheelLayout.getYearWheelView().setBackgroundColor(0x90CCCCCC); - wheelLayout.getMonthWheelView().setBackgroundColor(0x90CCCCCC); - wheelLayout.getDayWheelView().setBackgroundColor(0x90CCCCCC); + wheelLayout.setSelectedTextColor(0xFFFF0000); + wheelLayout.getYearLabelView().setTextColor(0xFF999999); + wheelLayout.getMonthLabelView().setTextColor(0xFF999999); + wheelLayout.getDayLabelView().setTextColor(0xFF999999); picker.setOnDatePickedListener(this); picker.show(); } public void onYearMonth(View view) { DatePicker picker = new DatePicker(this); - picker.enableRoundCorner(); picker.setBodyWidth(240); picker.getWheelLayout().setDateMode(DateMode.YEAR_MONTH); picker.getWheelLayout().setDateLabel("年", "月", ""); @@ -120,7 +115,6 @@ public void onYearMonth(View view) { public void onMonthDay(View view) { DatePicker picker = new DatePicker(this); - picker.enableRoundCorner(); picker.setBodyWidth(200); picker.getWheelLayout().setDateMode(DateMode.MONTH_DAY); picker.getWheelLayout().setDateFormatter(new UnitDateFormatter()); @@ -130,7 +124,6 @@ public void onMonthDay(View view) { public void onTime12(View view) { TimePicker picker = new TimePicker(this); - picker.enableRoundCorner(); picker.setBodyWidth(140); TimeWheelLayout wheelLayout = picker.getWheelLayout(); wheelLayout.setRange(TimeEntity.target(1, 0, 0), TimeEntity.target(12, 59, 59)); @@ -150,7 +143,6 @@ public void onTimePicked(int hour, int minute, int second, boolean isAnteMeridie public void onTime24(View view) { TimePicker picker = new TimePicker(this); - picker.enableRoundCorner(); picker.getWheelLayout().setTimeMode(TimeMode.HOUR_24_HAS_SECOND); picker.getWheelLayout().setTimeFormatter(new UnitTimeFormatter()); picker.getWheelLayout().setDefaultValue(TimeEntity.now()); @@ -160,7 +152,6 @@ public void onTime24(View view) { public void onBirthday(View view) { BirthdayPicker picker = new BirthdayPicker(this); - picker.enableRoundCorner(); picker.setDefaultValue(1991, 11, 11); picker.setOnDatePickedListener(this); picker.show(); diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/FilePickerActivity.java b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/FilePickerActivity.java index 01921543..a9f490e9 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/FilePickerActivity.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/FilePickerActivity.java @@ -52,7 +52,6 @@ public void onFilePicked(@NonNull File file) { public void onFilePick(View view) { FilePicker picker = new FilePicker(this); - picker.enableRoundCorner(); picker.setInitDir(ExplorerMode.FILE, getExternalFilesDir(null)); picker.setOnFilePickedListener(this); picker.show(); @@ -60,7 +59,6 @@ public void onFilePick(View view) { public void onDirPick(View view) { FilePicker picker = new FilePicker(this); - picker.enableRoundCorner(); picker.setInitDir(ExplorerMode.DIRECTORY, getFilesDir()); picker.setOnFilePickedListener(this); picker.show(); diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/ImagePickerActivity.java b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/ImagePickerActivity.java index fa6493a6..b101598a 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/ImagePickerActivity.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/ImagePickerActivity.java @@ -28,46 +28,12 @@ import com.github.gzuliyujiang.imagepicker.CropImageView; import com.github.gzuliyujiang.imagepicker.ImagePicker; import com.github.gzuliyujiang.imagepicker.PickCallback; -import com.lxj.xpopup.XPopup; -import com.lxj.xpopup.interfaces.OnSelectListener; /** * @author 贵州山野羡民(1032694760@qq.com) * @since 2021/7/30 12:44 */ -public class ImagePickerActivity extends FragmentActivity implements OnSelectListener { - private final PickCallback pickCallback = new PickCallback() { - @Override - public void onPermissionDenied(String[] permissions, String message) { - Toast.makeText(ImagePickerActivity.this, message, Toast.LENGTH_SHORT).show(); - } - - @Override - public void onPickImage(@Nullable Uri imageUri) { - Toast.makeText(ImagePickerActivity.this, String.valueOf(imageUri), Toast.LENGTH_SHORT).show(); - } - }; - private final PickCallback cropCallback = new PickCallback() { - @Override - public void onPermissionDenied(String[] permissions, String message) { - Toast.makeText(ImagePickerActivity.this, message, Toast.LENGTH_SHORT).show(); - } - - @Override - public void cropConfig(ActivityBuilder builder) { - builder.setMultiTouchEnabled(true) - .setGuidelines(CropImageView.Guidelines.ON_TOUCH) - .setCropShape(CropImageView.CropShape.OVAL) - .setRequestedSize(400, 400) - .setFixAspectRatio(true) - .setAspectRatio(1, 1); - } - - @Override - public void onCropImage(@Nullable Uri imageUri) { - Toast.makeText(ImagePickerActivity.this, String.valueOf(imageUri), Toast.LENGTH_SHORT).show(); - } - }; +public class ImagePickerActivity extends FragmentActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -87,32 +53,42 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis ImagePicker.getInstance().onRequestPermissionsResult(this, requestCode, permissions, grantResults); } - @Override - public void onSelect(int position, String text) { - switch (position) { - case 0: - ImagePicker.getInstance().startCamera(this, true, pickCallback); - break; - case 1: - ImagePicker.getInstance().startGallery(this, true, pickCallback); - break; - default: - break; - } - } - public void onCamera(View view) { - ImagePicker.getInstance().startCamera(this, true, cropCallback); + ImagePicker.getInstance().startCamera(this, true, new PickCallback() { + @Override + public void onPermissionDenied(String[] permissions, String message) { + Toast.makeText(ImagePickerActivity.this, message, Toast.LENGTH_SHORT).show(); + } + + @Override + public void cropConfig(ActivityBuilder builder) { + builder.setMultiTouchEnabled(true) + .setGuidelines(CropImageView.Guidelines.ON_TOUCH) + .setCropShape(CropImageView.CropShape.OVAL) + .setRequestedSize(400, 400) + .setFixAspectRatio(true) + .setAspectRatio(1, 1); + } + + @Override + public void onCropImage(@Nullable Uri imageUri) { + Toast.makeText(ImagePickerActivity.this, String.valueOf(imageUri), Toast.LENGTH_SHORT).show(); + } + }); } public void onGallery(View view) { - ImagePicker.getInstance().startGallery(this, true, cropCallback); - } - - public void onXPopup(View view) { - new XPopup.Builder(view.getContext()) - .asBottomList(null, new String[]{"拍照", "从相册选取"}, this) - .show(); + ImagePicker.getInstance().startGallery(this, false, new PickCallback() { + @Override + public void onPermissionDenied(String[] permissions, String message) { + Toast.makeText(ImagePickerActivity.this, message, Toast.LENGTH_SHORT).show(); + } + + @Override + public void onPickImage(@Nullable Uri imageUri) { + Toast.makeText(ImagePickerActivity.this, String.valueOf(imageUri), Toast.LENGTH_SHORT).show(); + } + }); } } diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/LinkagePickerActivity.java b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/LinkagePickerActivity.java index 166b8d7c..9ed5cb1c 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/LinkagePickerActivity.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/LinkagePickerActivity.java @@ -50,7 +50,6 @@ public void onLinkagePicked(Object first, Object second, Object third) { public void onCarNumber(View view) { CarNumberPicker picker = new CarNumberPicker(this); - picker.enableRoundCorner(); picker.setBodyWidth(90); picker.setOnCarNumberPickedListener(this); picker.show(); diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/MainActivity.java b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/MainActivity.java index 05a0c5f6..50cb6b87 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/MainActivity.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/MainActivity.java @@ -20,8 +20,12 @@ import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; +import com.github.gzuliyujiang.dialog.DialogConfig; +import com.github.gzuliyujiang.dialog.DialogStyle; import com.github.gzuliyujiang.fallback.R; import com.github.gzuliyujiang.fallback.custom.AntFortuneLikeProvider; +import com.github.gzuliyujiang.wheelpicker.OptionPicker; +import com.github.gzuliyujiang.wheelpicker.contract.OnOptionPickedListener; import com.github.gzuliyujiang.wheelpicker.widget.LinkageWheelLayout; import com.github.gzuliyujiang.wheelpicker.widget.OptionWheelLayout; import com.github.gzuliyujiang.wheelview.widget.WheelView; @@ -51,6 +55,32 @@ private void startActivity(Class cls) { startActivity(new Intent(this, cls)); } + public void onDialogStyle(View view) { + OptionPicker picker = new OptionPicker(this); + picker.setData("默认-屏幕底部弹窗", "样式1-屏幕底部弹窗", "样式2-屏幕底部弹窗", "样式3-屏幕中间弹窗"); + picker.setOnOptionPickedListener(new OnOptionPickedListener() { + @Override + public void onOptionPicked(int position, Object item) { + switch (position) { + case 1: + DialogConfig.setDialogStyle(DialogStyle.One); + break; + case 2: + DialogConfig.setDialogStyle(DialogStyle.Two); + break; + case 3: + DialogConfig.setDialogStyle(DialogStyle.Three); + break; + case 0: + default: + DialogConfig.setDialogStyle(DialogStyle.Default); + break; + } + } + }); + picker.show(); + } + public void onDateTimePicker(View view) { startActivity(DateTimePickerActivity.class); } diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/SinglePickerActivity.java b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/SinglePickerActivity.java index 9778b85d..fc655ce7 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/activity/SinglePickerActivity.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/activity/SinglePickerActivity.java @@ -66,7 +66,6 @@ public void onOptionPicked(int position, Object item) { public void onInteger(View view) { NumberPicker picker = new NumberPicker(this); - picker.enableRoundCorner(); picker.setOnNumberPickedListener(this); picker.getWheelLayout().setOnNumberSelectedListener(new OnNumberSelectedListener() { @Override @@ -88,7 +87,6 @@ public String formatItem(@NonNull Object item) { public void onFloat(View view) { NumberPicker picker = new NumberPicker(this); - picker.enableRoundCorner(); picker.setBodyWidth(120); picker.setOnNumberPickedListener(this); picker.getWheelLayout().setOnNumberSelectedListener(new OnNumberSelectedListener() { @@ -113,7 +111,6 @@ public String formatItem(@NonNull Object item) { public void onOptionText(View view) { OptionPicker picker = new OptionPicker(this); - picker.enableRoundCorner(); picker.setBackgroundColor(true, 0xFFFFFFFF); picker.setData("测试", "很长很长很长很长很长很长很长很长很长很长很长很长很长很长"); picker.setOnOptionPickedListener(this); @@ -138,10 +135,10 @@ public void onOptionBean(View view) { data.add(new GoodsCategoryBean(5, "酒水饮料")); data.add(new GoodsCategoryBean(6, "图书音像")); OptionPicker picker = new OptionPicker(this); - picker.enableRoundCorner(); picker.setBodyWidth(140); - picker.getOkView().setTextColor(0xFFFF0000); - picker.getTopLineView().setBackgroundColor(0xFFFF0000); + picker.getWheelView().setIndicatorColor(0xFFFF0000); + picker.getWheelView().setTextColor(0xFFFF00FF); + picker.getWheelView().setSelectedTextColor(0xFFFF0000); picker.setOnOptionPickedListener(this); picker.getWheelLayout().setOnOptionSelectedListener(new OnOptionSelectedListener() { @Override @@ -156,7 +153,6 @@ public void onOptionSelected(int position, Object item) { public void onSex(View view) { SexPicker picker = new SexPicker(this, true); - picker.enableRoundCorner(); picker.setBodyWidth(140); picker.setDefaultValue("女"); picker.setOnOptionPickedListener(this); @@ -171,7 +167,6 @@ public void onOptionSelected(int position, Object item) { public void onEthnic(View view) { EthnicPicker picker = new EthnicPicker(this); - picker.enableRoundCorner(); picker.setBodyWidth(140); picker.setEthnicSpec(EthnicSpec.SEVENTH_NATIONAL_CENSUS); picker.setDefaultValueByCode("97"); @@ -189,7 +184,6 @@ public void onOptionSelected(int position, Object item) { public void onConstellation(View view) { ConstellationPicker picker = new ConstellationPicker(this, true); - picker.enableRoundCorner(); picker.setBodyWidth(140); picker.setDefaultValue("射手座"); picker.setOnOptionPickedListener(this); @@ -204,7 +198,6 @@ public void onOptionSelected(int position, Object item) { public void onPhoneCode(View view) { PhoneCodePicker picker = new PhoneCodePicker(this); - picker.enableRoundCorner(); picker.setBodyWidth(140); picker.setDefaultPosition(2); picker.setOnOptionPickedListener(this); diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/custom/AntFortuneLikePicker.java b/app/src/main/java/com/github/gzuliyujiang/fallback/custom/AntFortuneLikePicker.java index 8ae38207..a5634873 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/custom/AntFortuneLikePicker.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/custom/AntFortuneLikePicker.java @@ -14,9 +14,16 @@ package com.github.gzuliyujiang.fallback.custom; import android.app.Activity; +import android.content.DialogInterface; +import android.os.Bundle; +import android.view.Gravity; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import com.github.gzuliyujiang.dialog.DialogConfig; +import com.github.gzuliyujiang.dialog.DialogStyle; +import com.github.gzuliyujiang.fallback.R; import com.github.gzuliyujiang.wheelpicker.LinkagePicker; /** @@ -24,28 +31,47 @@ * @since 2021/6/7 12:20 */ public class AntFortuneLikePicker extends LinkagePicker { + private int lastDialogStyle; public AntFortuneLikePicker(@NonNull Activity activity) { - super(activity); + super(activity, R.style.DialogTheme_Sheet); + } + + @Override + public void onInit(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { + super.onInit(activity, savedInstanceState); + lastDialogStyle = DialogConfig.getDialogStyle(); + DialogConfig.setDialogStyle(DialogStyle.Default); + setWidth(activity.getResources().getDisplayMetrics().widthPixels); + setGravity(Gravity.BOTTOM); + } + + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + DialogConfig.setDialogStyle(lastDialogStyle); } @Override protected void initData() { super.initData(); - enableRoundCorner(); + setBackgroundColor(0xFFFFFFFF); cancelView.setText("取消"); - cancelView.setTextColor(0xFF3355E5); - okView.setTextColor(0xFF3355E5); + cancelView.setTextSize(16); + cancelView.setTextColor(0xFF0081FF); + okView.setTextColor(0xFF0081FF); okView.setText("确定"); + okView.setTextSize(16); titleView.setTextColor(0xFF333333); titleView.setText("定投周期"); + titleView.setTextSize(16); wheelLayout.setData(new AntFortuneLikeProvider()); wheelLayout.setAtmosphericEnabled(true); wheelLayout.setVisibleItemCount(7); wheelLayout.setCyclicEnabled(false); wheelLayout.setIndicatorEnabled(true); - wheelLayout.setIndicatorColor(0xFFDCDCDC); - wheelLayout.setIndicatorSize((int) (contentView.getResources().getDisplayMetrics().density * 0.6f)); + wheelLayout.setIndicatorColor(0xFFDDDDDD); + wheelLayout.setIndicatorSize((int) (contentView.getResources().getDisplayMetrics().density * 1)); wheelLayout.setTextColor(0xFF999999); wheelLayout.setSelectedTextColor(0xFF333333); wheelLayout.setCurtainEnabled(false); diff --git a/app/src/main/java/com/github/gzuliyujiang/fallback/custom/CustomAddressPicker.java b/app/src/main/java/com/github/gzuliyujiang/fallback/custom/CustomAddressPicker.java index f35efea5..833ac840 100644 --- a/app/src/main/java/com/github/gzuliyujiang/fallback/custom/CustomAddressPicker.java +++ b/app/src/main/java/com/github/gzuliyujiang/fallback/custom/CustomAddressPicker.java @@ -15,12 +15,10 @@ import android.app.Activity; import android.view.View; -import android.widget.ProgressBar; -import android.widget.TextView; import androidx.annotation.NonNull; -import com.github.gzuliyujiang.basepicker.BottomDialog; +import com.github.gzuliyujiang.dialog.BottomDialog; import com.github.gzuliyujiang.fallback.R; import com.github.gzuliyujiang.wheelpicker.annotation.AddressMode; import com.github.gzuliyujiang.wheelpicker.contract.AddressLoader; @@ -33,7 +31,6 @@ import com.github.gzuliyujiang.wheelpicker.impl.AssetAddressLoader; import com.github.gzuliyujiang.wheelpicker.utility.AddressJsonParser; import com.github.gzuliyujiang.wheelpicker.widget.LinkageWheelLayout; -import com.github.gzuliyujiang.wheelview.widget.WheelView; import java.util.List; @@ -53,7 +50,7 @@ public CustomAddressPicker(@NonNull Activity activity) { @NonNull @Override - protected View createContentView(@NonNull Activity activity) { + protected View createContentView() { return View.inflate(activity, R.layout.wheel_picker_custom_ui_address, null); } @@ -113,36 +110,4 @@ public void setOnAddressPickedListener(OnAddressPickedListener onAddressPickedLi this.onAddressPickedListener = onAddressPickedListener; } - public final LinkageWheelLayout getWheelLayout() { - return wheelLayout; - } - - public final WheelView getProvinceWheelView() { - return wheelLayout.getFirstWheelView(); - } - - public final WheelView getCityWheelView() { - return wheelLayout.getSecondWheelView(); - } - - public final WheelView getCountyWheelView() { - return wheelLayout.getThirdWheelView(); - } - - public final TextView getProvinceLabelView() { - return wheelLayout.getFirstLabelView(); - } - - public final TextView getCityLabelView() { - return wheelLayout.getSecondLabelView(); - } - - public final TextView getCountyLabelView() { - return wheelLayout.getThirdLabelView(); - } - - public final ProgressBar getLoadingView() { - return wheelLayout.getLoadingView(); - } - } diff --git a/app/src/main/res/layout/activity_picker_image.xml b/app/src/main/res/layout/activity_picker_image.xml index 821b8290..ab932c8d 100644 --- a/app/src/main/res/layout/activity_picker_image.xml +++ b/app/src/main/res/layout/activity_picker_image.xml @@ -36,13 +36,6 @@ android:text="相册选取" android:textColor="#FF333333" /> -