Skip to content

Commit

Permalink
Merge pull request #1 from jc-yoonet/master
Browse files Browse the repository at this point in the history
Added setTextAlign to SingleDateAndTimePickerDialog.Builder
  • Loading branch information
johnchrisdc authored Mar 4, 2021
2 parents 5c703d6 + 891b5c3 commit cea825f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class SingleDatePickerMainActivityWithDoublePicker extends AppCompatActiv
@BindView(R.id.singleDateLocaleText)
TextView singleDateLocaleText;


SimpleDateFormat simpleDateFormat;
SimpleDateFormat simpleTimeFormat;
SimpleDateFormat simpleDateOnlyFormat;
Expand Down Expand Up @@ -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();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,35 @@

</LinearLayout>

<LinearLayout
android:id="@+id/datePickerAlignment"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
app:srcCompat="@drawable/ic_event_available_black_24dp"
/>

<TextView
android:id="@+id/datePickerAlignmentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="15sp"
android:text="Click me to open single dialog for DATE with custom alignment"
android:textColor="@color/textColor"
/>

</LinearLayout>

</LinearLayout>

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +58,8 @@ public abstract class BaseDialog {
@Nullable
protected Boolean isAmPm;

protected int textAlignment = SingleDateAndTimePicker.ALIGN_CENTER;

protected SimpleDateFormat dayFormatter;

protected Locale customLocale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit cea825f

Please sign in to comment.