From 891b5c39c13713ffa673172c5f4805edcc0b5bf7 Mon Sep 17 00:00:00 2001 From: jc-yoonet Date: Thu, 4 Mar 2021 19:04:02 +0800 Subject: [PATCH] Added setTextAlign to SingleDateAndTimePickerDialog.Builder --- ...atePickerMainActivityWithDoublePicker.java | 20 ++++++++++++- ...ate_picker_activity_main_double_picker.xml | 29 +++++++++++++++++++ .../dialog/BaseDialog.java | 4 +++ .../dialog/SingleDateAndTimePickerDialog.java | 16 +++++++++- 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/florent37/sample/singledateandtimepicker/SingleDatePickerMainActivityWithDoublePicker.java b/app/src/main/java/com/github/florent37/sample/singledateandtimepicker/SingleDatePickerMainActivityWithDoublePicker.java index c6846449..dc40c4bd 100644 --- a/app/src/main/java/com/github/florent37/sample/singledateandtimepicker/SingleDatePickerMainActivityWithDoublePicker.java +++ b/app/src/main/java/com/github/florent37/sample/singledateandtimepicker/SingleDatePickerMainActivityWithDoublePicker.java @@ -39,7 +39,6 @@ public class SingleDatePickerMainActivityWithDoublePicker extends AppCompatActiv @BindView(R.id.singleDateLocaleText) TextView singleDateLocaleText; - SimpleDateFormat simpleDateFormat; SimpleDateFormat simpleTimeFormat; SimpleDateFormat simpleDateOnlyFormat; @@ -305,4 +304,23 @@ public void onDateSelected(Date date) { }); singleBuilder.display(); } + + @OnClick(R.id.datePickerAlignment) + public void dateAlignmentClicked() { + singleBuilder = new SingleDateAndTimePickerDialog.Builder(this) + .titleTextSize(17) + .bottomSheet() + .curved() + .displayMinutes(true) + .displayHours(true) + .displayAmPm(true) + .displayDays(false) + .displayDaysOfMonth(true) + .displayMonth(true) + .displayYears(true) + .setTextAlign(SingleDateAndTimePicker.ALIGN_LEFT); + + singleBuilder.display(); + + } } \ No newline at end of file diff --git a/app/src/main/res/layout/single_date_picker_activity_main_double_picker.xml b/app/src/main/res/layout/single_date_picker_activity_main_double_picker.xml index 17cb48cd..52b3f939 100644 --- a/app/src/main/res/layout/single_date_picker_activity_main_double_picker.xml +++ b/app/src/main/res/layout/single_date_picker_activity_main_double_picker.xml @@ -167,6 +167,35 @@ + + + + + + + + \ No newline at end of file diff --git a/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/dialog/BaseDialog.java b/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/dialog/BaseDialog.java index 51f77f70..c9c4c5db 100644 --- a/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/dialog/BaseDialog.java +++ b/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/dialog/BaseDialog.java @@ -5,6 +5,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker; + import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; @@ -56,6 +58,8 @@ public abstract class BaseDialog { @Nullable protected Boolean isAmPm; + protected int textAlignment = SingleDateAndTimePicker.ALIGN_CENTER; + protected SimpleDateFormat dayFormatter; protected Locale customLocale; diff --git a/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/dialog/SingleDateAndTimePickerDialog.java b/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/dialog/SingleDateAndTimePickerDialog.java index 7307e624..639f189b 100644 --- a/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/dialog/SingleDateAndTimePickerDialog.java +++ b/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/dialog/SingleDateAndTimePickerDialog.java @@ -184,6 +184,8 @@ public void onClick(View v) { picker.setDisplayDaysOfMonth(displayDaysOfMonth); picker.setDisplayMinutes(displayMinutes); picker.setDisplayHours(displayHours); + + picker.setTextAlign(textAlignment); } public SingleDateAndTimePickerDialog setListener(Listener listener) { @@ -306,6 +308,11 @@ private SingleDateAndTimePickerDialog setTimeZone(TimeZone timeZone) { return this; } + private SingleDateAndTimePickerDialog setTextAlign(int alignment) { + this.textAlignment = alignment; + return this; + } + @Override public void display() { super.display(); @@ -372,6 +379,7 @@ public static class Builder { private boolean displayYears = false; private boolean displayMonthNumbers = false; private boolean focusable = false; + private int textAlignment = SingleDateAndTimePicker.ALIGN_CENTER; @Nullable private Boolean isAmPm; @@ -546,6 +554,11 @@ public Builder focusable() { return this; } + public Builder setTextAlign(int alignment) { + this.textAlignment = alignment; + return this; + } + public SingleDateAndTimePickerDialog build() { final SingleDateAndTimePickerDialog dialog = new SingleDateAndTimePickerDialog(context, bottomSheet) .setTitle(title) @@ -569,7 +582,8 @@ public SingleDateAndTimePickerDialog build() { .setCustomLocale(customLocale) .setMustBeOnFuture(mustBeOnFuture) .setTimeZone(timeZone) - .setFocusable(focusable); + .setFocusable(focusable) + .setTextAlign(textAlignment); if (mainColor != null) { dialog.setMainColor(mainColor);