Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

#311 issue resolved,Added background shape customisation, OK button text configurable #315

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:1.1.0"
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.jakewharton:butterknife:10.2.1'
implementation "androidx.appcompat:appcompat:1.2.0"
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'
implementation project(':singledateandtimepicker')
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.florent37.sample.singledateandtimepicker;

import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
Expand Down Expand Up @@ -99,6 +100,8 @@ public void simpleTimeClicked() {
.displayMinutes(true)
.displayHours(true)
.displayDays(false)
.minutesStep(15)
.setBackgroundShape(R.drawable.curve_shape)
//.displayMonth(true)
//.displayYears(true)

Expand All @@ -113,8 +116,13 @@ public void onClosed(SingleDateAndTimePicker picker) {
Log.d(TAG, "Dialog closed");
}
})

.title("Simple Time")
.titleTextColor(Color.parseColor("#E8EAEE"))
.mainColor(Color.parseColor("#FAFAFA"))
.backgroundColor(Color.parseColor("#1D2D51"))
.title("Pickup Time")
.setButtonName("NEXT")
.setButtonIconRight(R.drawable.ic_right_arrow_light_blue)
.setButtonTextColor(Color.parseColor("#FD9731"))
.listener(new SingleDateAndTimePickerDialog.Listener() {
@Override
public void onDateSelected(Date date) {
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/drawable/curve_shape.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
<solid android:color="#1D2D51" />
<stroke android:color="#0e0e0f" android:width="0dp" />
<corners android:topLeftRadius="20dp" android:topRightRadius="20dp"
android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/>
</shape>
</item>
</layer-list>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_right_arrow_light_blue.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="512dp"
android:height="512dp"
android:viewportWidth="451.846"
android:viewportHeight="451.847">
<path
android:pathData="M345.441,248.292L151.154,442.573c-12.359,12.365 -32.397,12.365 -44.75,0c-12.354,-12.354 -12.354,-32.391 0,-44.744L278.318,225.92L106.409,54.017c-12.354,-12.359 -12.354,-32.394 0,-44.748c12.354,-12.359 32.391,-12.359 44.75,0l194.287,194.284c6.177,6.18 9.262,14.271 9.262,22.366C354.708,234.018 351.617,242.115 345.441,248.292z"
android:fillColor="#039AEA"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<LinearLayout
android:id="@+id/doubleLayout"
android:layout_width="match_parent"
android:visibility="visible"
android:layout_height="60dp"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
Expand Down Expand Up @@ -113,6 +114,7 @@
android:id="@+id/singleDateLayout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:visibility="visible"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
Expand Down Expand Up @@ -142,6 +144,7 @@
android:id="@+id/singleDateLocaleLayout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:visibility="visible"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.android.tools.build:gradle:3.6.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -23,7 +23,7 @@ allprojects {
}

ext {
sdk = 28
sdk = 30
minSdk = 14

github = 'https://github.com/florent37/SingleDateAndTimePicker'
Expand Down
2 changes: 1 addition & 1 deletion singledateandtimepicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
}

dependencies {
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.appcompat:appcompat:1.2.0"
}

ext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class SingleDateAndTimePicker extends LinearLayout {

private View dtSelector;
private boolean mustBeOnFuture;
private View picker_divider_1;
private View picker_divider_2;

@Nullable
private Date minDate;
Expand Down Expand Up @@ -119,6 +121,8 @@ public SingleDateAndTimePicker(Context context, AttributeSet attrs, int defStyle
hoursPicker = findViewById(R.id.hoursPicker);
amPmPicker = findViewById(R.id.amPmPicker);
dtSelector = findViewById(R.id.dtSelector);
picker_divider_1 = findViewById(R.id.picker_divider_1);
picker_divider_2 = findViewById(R.id.picker_divider_2);

pickers.addAll(Arrays.asList(
daysPicker,
Expand Down Expand Up @@ -371,6 +375,9 @@ private void setFontToAllPickers(int resourceId) {

public void setSelectorColor(int selectorColor) {
dtSelector.setBackgroundColor(selectorColor);
picker_divider_1.setBackgroundColor(selectorColor);
picker_divider_2.setBackgroundColor(selectorColor);

}

public void setSelectorHeight(int selectorHeight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public abstract class BaseDialog {

protected Locale customLocale;

@Nullable
@ColorInt
protected Integer buttonTextColor = null;

public void display() {
this.isDisplaying = true;
}
Expand Down Expand Up @@ -88,6 +92,10 @@ public void setTitleTextColor(@NonNull @ColorInt int titleTextColor) {
this.titleTextColor = titleTextColor;
}

public void setButtonTextColor(@ColorInt Integer buttonTextColor){
this.buttonTextColor = buttonTextColor;
}

protected void onClose() {
this.isDisplaying = false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.github.florent37.singledateandtimepicker.dialog;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.florent37.singledateandtimepicker.DateHelper;
Expand All @@ -16,8 +20,10 @@
import java.util.TimeZone;

import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import static com.github.florent37.singledateandtimepicker.widget.SingleDateAndTimeConstants.STEP_MINUTES_DEFAULT;

Expand All @@ -39,14 +45,27 @@ public class SingleDateAndTimePickerDialog extends BaseDialog {
@Nullable
private DisplayListener displayListener;

@Nullable
private String buttonName;

@Nullable
private int backgroundShape;

@Nullable
private int buttonIconRight;

private Context mContext;

private SingleDateAndTimePickerDialog(Context context) {
this(context, false);
this.mContext = context;
}

private SingleDateAndTimePickerDialog(Context context, boolean bottomSheet) {
final int layout = bottomSheet ? R.layout.bottom_sheet_picker_bottom_sheet :
R.layout.bottom_sheet_picker;
this.bottomSheetHelper = new BottomSheetHelper(context, layout);
this.mContext = context;

this.bottomSheetHelper.setListener(new BottomSheetHelper.Listener() {
@Override
Expand Down Expand Up @@ -84,6 +103,12 @@ private void init(View view) {
}
}

final ImageView buttonIcon = view.findViewById(R.id.buttonIcon);
if (buttonIcon != null){
if (buttonIconRight != 0){
buttonIcon.setImageResource(buttonIconRight);
}
}
final TextView buttonOk = (TextView) view.findViewById(R.id.buttonOk);
if (buttonOk != null) {
buttonOk.setOnClickListener(new View.OnClickListener() {
Expand All @@ -96,11 +121,22 @@ public void onClick(View view) {

if (mainColor != null) {
buttonOk.setTextColor(mainColor);
buttonIcon.setColorFilter(mainColor, PorterDuff.Mode.SRC_IN);

}

if (titleTextSize != null) {
buttonOk.setTextSize(titleTextSize);
}

if (buttonName != null){
buttonOk.setText(buttonName);
}
if (buttonTextColor != null){
buttonOk.setTextColor(buttonTextColor);
buttonIcon.setColorFilter(buttonTextColor, PorterDuff.Mode.SRC_IN);

}
}

final View sheetContentLayout = view.findViewById(R.id.sheetContentLayout);
Expand All @@ -114,6 +150,17 @@ public void onClick(View v) {

if (backgroundColor != null) {
sheetContentLayout.setBackgroundColor(backgroundColor);

}

/** validation for shape customization **/
if (backgroundShape != 0){
final int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN){
sheetContentLayout.setBackgroundDrawable(ContextCompat.getDrawable(mContext, backgroundShape));
}else {
sheetContentLayout.setBackground(ContextCompat.getDrawable(mContext, backgroundShape));
}
}
}

Expand Down Expand Up @@ -306,6 +353,23 @@ private SingleDateAndTimePickerDialog setTimeZone(TimeZone timeZone) {
return this;
}

private SingleDateAndTimePickerDialog setButtonName(@Nullable String buttonName){
this.buttonName = buttonName;
return this;
}

private SingleDateAndTimePickerDialog setBackgroundShape(@Nullable int backgroundShape){
this.backgroundShape = backgroundShape;
return this;
}

private SingleDateAndTimePickerDialog setButtonIconRight(@Nullable int buttonIconRight){
this.buttonIconRight = buttonIconRight;
return this;
}



@Override
public void display() {
super.display();
Expand Down Expand Up @@ -402,6 +466,19 @@ public static class Builder {
private Locale customLocale;
private TimeZone timeZone;

@Nullable
private String buttonName;

@Nullable
private int backgroundShape;

@ColorInt
@Nullable
private int buttonTextColor;

@Nullable
private int buttonIconRight = 0;

public Builder(Context context) {
this.context = context;
}
Expand Down Expand Up @@ -546,6 +623,25 @@ public Builder focusable() {
return this;
}

public Builder setButtonName(@Nullable String buttonName){
this.buttonName = buttonName;
return this;
}

public Builder setBackgroundShape(@Nullable int backgroundShape){
this.backgroundShape = backgroundShape;
return this;
}
public Builder setButtonTextColor(@Nullable @ColorInt int buttonTextColor){
this.buttonTextColor = buttonTextColor;
return this;
}

public Builder setButtonIconRight(@Nullable int buttonIconRight){
this.buttonIconRight = buttonIconRight;
return this;
}

public SingleDateAndTimePickerDialog build() {
final SingleDateAndTimePickerDialog dialog = new SingleDateAndTimePickerDialog(context, bottomSheet)
.setTitle(title)
Expand All @@ -569,7 +665,10 @@ public SingleDateAndTimePickerDialog build() {
.setCustomLocale(customLocale)
.setMustBeOnFuture(mustBeOnFuture)
.setTimeZone(timeZone)
.setFocusable(focusable);
.setFocusable(focusable)
.setBackgroundShape(backgroundShape)
.setButtonName(buttonName)
.setButtonIconRight(buttonIconRight);

if (mainColor != null) {
dialog.setMainColor(mainColor);
Expand All @@ -591,6 +690,10 @@ public SingleDateAndTimePickerDialog build() {
dialog.setIsAmPm(isAmPm);
}

if (buttonTextColor != 0){
dialog.setButtonTextColor(buttonTextColor);
}

return dialog;
}

Expand Down
Loading