diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..9121ffa7 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +ko_fi: FlorentChampigny +github: florent37 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1c9422fe..cded514b 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ freeline/ freeline_project_description.json SingleDateAndTimePicker.iml app/app.iml +# OS specific (mac) +.DS_Store diff --git a/README.md b/README.md index 94cd470e..5520c1bb 100644 --- a/README.md +++ b/README.md @@ -17,20 +17,21 @@ You can now select a date and a time with only one widget ! new SingleDateAndTimePickerDialog.Builder(context) //.bottomSheet() //.curved() - //.minutesStep(15) - + //.stepSizeMinutes(15) //.displayHours(false) //.displayMinutes(false) - //.todayText("aujourd'hui") - .displayListener(new SingleDateAndTimePickerDialog.DisplayListener() { - @Override - public void onDisplayed(SingleDateAndTimePicker picker) { - //retrieve the SingleDateAndTimePicker - } - }) - + @Override + public void onDisplayed(SingleDateAndTimePicker picker) { + // Retrieve the SingleDateAndTimePicker + } + + @Override + public void onClosed(SingleDateAndTimePicker picker) { + // On dialog closed + } + }) .title("Simple") .listener(new SingleDateAndTimePickerDialog.Listener() { @Override @@ -48,7 +49,7 @@ new SingleDateAndTimePickerDialog.Builder(context) new DoubleDateAndTimePickerDialog.Builder(context) //.bottomSheet() //.curved() - //.minutesStep(15) + //.stepSizeMinutes(15) .title("Double") .tab0Text("Depart") .tab1Text("Return") @@ -66,7 +67,6 @@ new DoubleDateAndTimePickerDialog.Builder(context) ```java new SingleDateAndTimePickerDialog.Builder(this) - .bottomSheet() .curved() .displayMinutes(false) @@ -88,7 +88,6 @@ new SingleDateAndTimePickerDialog.Builder(this) android:layout_height="230dp" app:picker_curved="true" app:picker_cyclic="true" - app:picker_canBeOnPast="false" app:picker_visibleItemCount="7" /> ``` @@ -116,9 +115,7 @@ new DoubleDateAndTimePickerDialog.Builder(context) You can change the minutes steps (default : 5min) ```java new SingleDateAndTimePickerDialog.Builder(context) - - .minutesStep(15) - + .stepSizeMinutes(15) .display(); ``` @@ -128,53 +125,99 @@ And change some colors ```java new SingleDateAndTimePickerDialog.Builder(context) - .backgroundColor(Color.BLACK) .mainColor(Color.GREEN) .titleColor(Color.WHITE) - .display(); ``` # Date range -Force user to select a date between a range +Require user to select a date between a range ```java new SingleDateAndTimePickerDialog.Builder(context) - .defaultDate(defaultDate) .minDateRange(minDate) .maxDateRange(maxDate) - .display(); ``` -Or simply force user to select a future date +Or simply require user to select a future date ```java new SingleDateAndTimePickerDialog.Builder(context) - .mustBeOnFuture() - .display(); ``` +# Changing typeface + +```java +final SingleDateAndTimePicker singleDateAndTimePicker2 = findViewById(R.id.single_day_picker2); +singleDateAndTimePicker2.setTypeface(ResourcesCompat.getFont(this, R.font.dinot_regular)); +``` + +Or pass it as an attribute in the XML layout. (See XML section on how to use it.) + +# XML + +Some/most options are also available via XML: + +``` + +``` + +* picker_itemSpacing: Margin between items. Only has effect with + height=wrap-content +* picker_curvedMaxAngle sets the max angle of top/bottom items. If 45 + then the visible 'window' of the wheel is a 'quarter' of the circle. + If 90 (default) its rolling on a half-circle +* `app:fontFamily` or `android:fontFamily` sets the typeface/font to be + used with the date picker. + Note - For api below v-16 use `app:fontFamily` + +Get divider lines around selected by overwriting one or more of +``` + @android:color/transparent + 1dp + @drawable/picker_divider +``` +Use in conjuction with +`app:picker_selectorColor="@android:color/transparent"` on layout. + # Download Buy Me a Coffee at ko-fi.com In your module [![Download](https://api.bintray.com/packages/florent37/maven/SingleDateAndTimePicker/images/download.svg)](https://bintray.com/florent37/maven/SingleDateAndTimePicker/_latestVersion) ```groovy -compile 'com.github.florent37:singledateandtimepicker:(last version)' +implementation 'com.github.florent37:singledateandtimepicker:2.2.7' +//compatible with androidX ``` # Credits -Author: Florent Champigny [http://www.florentchampigny.com/](http://www.florentchampigny.com/) +Author: Florent Champigny Blog : [http://www.tutos-android-france.com/](http://www.tutos-android-france.com/) +Fiches Plateau Moto : [https://www.fiches-plateau-moto.fr/](https://www.fiches-plateau-moto.fr/) Android app on Google Play diff --git a/app/build.gradle b/app/build.gradle index 4dacfe62..afec38dd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,7 +14,11 @@ android { packagingOptions { exclude 'META-INF/DEPENDENCIES' } - + // The demo-app uses butterknife which require java8 + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } android { lintOptions { abortOnError false @@ -24,9 +28,9 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.android.support:appcompat-v7:' + project.supportVersion - implementation 'com.android.support:design:' + project.supportVersion - implementation 'com.jakewharton:butterknife:8.8.1' - annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' + implementation "androidx.appcompat:appcompat:1.1.0" + implementation 'com.google.android.material:material:1.1.0' + implementation 'com.jakewharton:butterknife:10.2.1' + annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1' implementation project(':singledateandtimepicker') } \ No newline at end of file diff --git a/app/src/main/java/com/github/florent37/sample/singledateandtimepicker/SingleDatePickerMainActivity.java b/app/src/main/java/com/github/florent37/sample/singledateandtimepicker/SingleDatePickerMainActivity.java index 776c8edc..fa7e9dfe 100644 --- a/app/src/main/java/com/github/florent37/sample/singledateandtimepicker/SingleDatePickerMainActivity.java +++ b/app/src/main/java/com/github/florent37/sample/singledateandtimepicker/SingleDatePickerMainActivity.java @@ -1,11 +1,12 @@ package com.github.florent37.sample.singledateandtimepicker; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.view.View; import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.res.ResourcesCompat; + import com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker; -import java.util.Date; public class SingleDatePickerMainActivity extends AppCompatActivity { @@ -14,19 +15,22 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.single_date_picker_activity_main); - final SingleDateAndTimePicker singleDateAndTimePicker = (SingleDateAndTimePicker) findViewById(R.id.single_day_picker); - singleDateAndTimePicker.addOnDateChangedListener(new SingleDateAndTimePicker.OnDateChangedListener() { - @Override - public void onDateChanged(String displayed, Date date) { - display(displayed); - } - }); + final SingleDateAndTimePicker singleDateAndTimePicker = findViewById(R.id.single_day_picker); + final SingleDateAndTimePicker singleDateAndTimePicker2 = findViewById(R.id.single_day_picker2); + // Example for setting default selected date to yesterday +// Calendar instance = Calendar.getInstance(); +// instance.add(Calendar.DATE, -1 ); +// singleDateAndTimePicker.setDefaultDate(instance.getTime()); + SingleDateAndTimePicker.OnDateChangedListener changeListener = (displayed, date) -> display(displayed); + singleDateAndTimePicker.addOnDateChangedListener(changeListener); + singleDateAndTimePicker2.addOnDateChangedListener(changeListener); + + //singleDateAndTimePicker.setTypeface(Typeface.DEFAULT); + singleDateAndTimePicker2.setTypeface(ResourcesCompat.getFont(this, R.font.dinot_regular)); - findViewById(R.id.toggleEnabled).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - singleDateAndTimePicker.setEnabled(!singleDateAndTimePicker.isEnabled()); - } + findViewById(R.id.toggleEnabled).setOnClickListener(v -> { + singleDateAndTimePicker.setEnabled(!singleDateAndTimePicker.isEnabled()); + singleDateAndTimePicker2.setEnabled(!singleDateAndTimePicker2.isEnabled()); }); } 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 496eaa5b..c6846449 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 @@ -1,9 +1,9 @@ package com.github.florent37.sample.singledateandtimepicker; -import android.graphics.Color; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import android.util.Log; import android.widget.TextView; +import android.widget.Toast; import com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker; import com.github.florent37.singledateandtimepicker.dialog.DoubleDateAndTimePickerDialog; @@ -14,8 +14,10 @@ import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.TimeZone; import java.util.concurrent.TimeUnit; +import androidx.appcompat.app.AppCompatActivity; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; @@ -24,6 +26,7 @@ public class SingleDatePickerMainActivityWithDoublePicker extends AppCompatActiv @BindView(R.id.doubleText) TextView doubleText; + @BindView(R.id.singleText) TextView singleText; @@ -33,14 +36,19 @@ public class SingleDatePickerMainActivityWithDoublePicker extends AppCompatActiv @BindView(R.id.singleDateText) TextView singleDateText; + @BindView(R.id.singleDateLocaleText) + TextView singleDateLocaleText; SimpleDateFormat simpleDateFormat; SimpleDateFormat simpleTimeFormat; SimpleDateFormat simpleDateOnlyFormat; + SimpleDateFormat simpleDateLocaleFormat; SingleDateAndTimePickerDialog.Builder singleBuilder; DoubleDateAndTimePickerDialog.Builder doubleBuilder; + private static String TAG = "SingleDatePickerMainActivityWithDoublePicker"; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -52,6 +60,8 @@ protected void onCreate(Bundle savedInstanceState) { this.simpleTimeFormat = new SimpleDateFormat("hh:mm aa", Locale.getDefault()); this.simpleDateOnlyFormat = new SimpleDateFormat("EEE d MMM", Locale.getDefault()); + + this.simpleDateLocaleFormat = new SimpleDateFormat("EEE d MMM", Locale.GERMAN); } @Override @@ -76,7 +86,7 @@ public void simpleTimeClicked() { final Date defaultDate = calendar.getTime(); singleBuilder = new SingleDateAndTimePickerDialog.Builder(this) - + .setTimeZone(TimeZone.getDefault()) .bottomSheet() .curved() @@ -88,14 +98,19 @@ public void simpleTimeClicked() { .displayMinutes(true) .displayHours(true) - .displayDays(true) + .displayDays(false) //.displayMonth(true) //.displayYears(true) .displayListener(new SingleDateAndTimePickerDialog.DisplayListener() { @Override public void onDisplayed(SingleDateAndTimePicker picker) { + Log.d(TAG, "Dialog displayed"); + } + @Override + public void onClosed(SingleDateAndTimePicker picker) { + Log.d(TAG, "Dialog closed"); } }) @@ -117,7 +132,7 @@ public void simpleDateClicked() { final Date defaultDate = calendar.getTime(); singleBuilder = new SingleDateAndTimePickerDialog.Builder(this) - + .setTimeZone(TimeZone.getDefault()) .bottomSheet() .curved() @@ -132,7 +147,12 @@ public void simpleDateClicked() { .displayListener(new SingleDateAndTimePickerDialog.DisplayListener() { @Override public void onDisplayed(SingleDateAndTimePicker picker) { + Log.d(TAG, "Dialog displayed"); + } + @Override + public void onClosed(SingleDateAndTimePicker picker) { + Log.d(TAG, "Dialog closed"); } }) @@ -159,6 +179,7 @@ public void simpleClicked() { final Date defaultDate = calendar.getTime(); singleBuilder = new SingleDateAndTimePickerDialog.Builder(this) + .setTimeZone(TimeZone.getDefault()) .bottomSheet() .curved() @@ -185,7 +206,12 @@ public void simpleClicked() { .displayListener(new SingleDateAndTimePickerDialog.DisplayListener() { @Override public void onDisplayed(SingleDateAndTimePicker picker) { + Log.d(TAG, "Dialog displayed"); + } + @Override + public void onClosed(SingleDateAndTimePicker picker) { + Log.d(TAG, "Dialog closed"); } }) @@ -213,6 +239,7 @@ public void doubleClicked() { final Date maxDate = calendarMax.getTime(); doubleBuilder = new DoubleDateAndTimePickerDialog.Builder(this) + .setTimeZone(TimeZone.getDefault()) //.bottomSheet() //.curved() @@ -246,4 +273,36 @@ public void onDateSelected(List dates) { }); doubleBuilder.display(); } + + @OnClick(R.id.singleDateLocaleLayout) + public void singleDateLocaleClicked() { + singleBuilder = new SingleDateAndTimePickerDialog.Builder(this) + .customLocale(Locale.GERMAN) + .bottomSheet() + .curved() + .displayHours(false) + .displayMinutes(false) + .displayDays(true) + + .displayListener(new SingleDateAndTimePickerDialog.DisplayListener() { + @Override + public void onDisplayed(SingleDateAndTimePicker picker) { + Log.d(TAG, "Dialog displayed"); + } + + @Override + public void onClosed(SingleDateAndTimePicker picker) { + Log.d(TAG, "Dialog closed"); + } + }) + + .title("") + .listener(new SingleDateAndTimePickerDialog.Listener() { + @Override + public void onDateSelected(Date date) { + singleDateLocaleText.setText(simpleDateLocaleFormat.format(date)); + } + }); + singleBuilder.display(); + } } \ No newline at end of file diff --git a/app/src/main/res/font/dinot_bold.ttf b/app/src/main/res/font/dinot_bold.ttf new file mode 100644 index 00000000..25b996c5 Binary files /dev/null and b/app/src/main/res/font/dinot_bold.ttf differ diff --git a/app/src/main/res/font/dinot_regular.ttf b/app/src/main/res/font/dinot_regular.ttf new file mode 100644 index 00000000..c379f2fb Binary files /dev/null and b/app/src/main/res/font/dinot_regular.ttf differ diff --git a/app/src/main/res/layout/single_date_picker_activity_main.xml b/app/src/main/res/layout/single_date_picker_activity_main.xml index e357689e..bb618c4f 100644 --- a/app/src/main/res/layout/single_date_picker_activity_main.xml +++ b/app/src/main/res/layout/single_date_picker_activity_main.xml @@ -1,28 +1,65 @@ + android:orientation="vertical">