Skip to content

Commit

Permalink
customize text faces and colors and header bg color
Browse files Browse the repository at this point in the history
  • Loading branch information
raul committed Mar 8, 2018
1 parent 7196296 commit 4551edb
Show file tree
Hide file tree
Showing 75 changed files with 5,007 additions and 4,139 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: android
jdk:
- oraclejdk8
android:
components:
- tools
- platform-tools
- build-tools-27.0.2
- android-27
- android-14
- extra-android-m2repository

script: ./gradlew check
139 changes: 119 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Join the chat at https://gitter.im/wdullaer/MaterialDateTimePicker](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/wdullaer/MaterialDateTimePicker?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
![Maven Central](https://img.shields.io/maven-central/v/com.wdullaer/materialdatetimepicker.svg)
![Build Status](https://travis-ci.org/wdullaer/MaterialDateTimePicker.svg?branch=master)


Material DateTime Picker tries to offer you the date and time pickers as shown in [the Material Design spec](http://www.google.com/design/spec/components/pickers.html), with an
Expand Down Expand Up @@ -39,9 +40,9 @@ Date Picker | Time Picker

## Setup
The easiest way to add the Material DateTime Picker library to your project is by adding it as a dependency to your `build.gradle`
```java
```groovy
dependencies {
compile 'com.wdullaer:materialdatetimepicker:3.1.3'
compile 'com.wdullaer:materialdatetimepicker:3.5.1'
}
```

Expand Down Expand Up @@ -141,7 +142,7 @@ Shows a title at the top of the `TimePickerDialog`
* `DatePickerDialog` `setTitle(String title)`
Shows a title at the top of the `DatePickerDialog` instead of the day of the week

* `setOkText()` and `setCancelText()`
* `setOkText()` and `setCancelText()`
Set a custom text for the dialog Ok and Cancel labels. Can take a resourceId of a String. Works in both the DatePickerDialog and TimePickerDialog

* `setMinTime(Timepoint time)`
Expand All @@ -150,11 +151,18 @@ Set the minimum valid time to be selected. Time values earlier in the day will b
* `setMaxTime(Timepoint time)`
Set the maximum valid time to be selected. Time values later in the day will be deactivated

* `setSelectableTimes(Timepoint[] times)`
You can pass in an array of `Timepoints`. These values are the only valid selections in the picker. `setMinTime(Timepoint time)` and `setMaxTime(Timepoint time)` will further trim this list down.
* `setSelectableTimes(Timepoint[] times)`
You can pass in an array of `Timepoints`. These values are the only valid selections in the picker. `setMinTime(Timepoint time)`, `setMaxTime(Timepoint time)` and `setDisabledTimes(Timepoint[] times)` will further trim this list down. Try to specify Timepoints only up to the resolution of your picker (i.e. do not add seconds if the resolution of the picker is minutes).

* `setDisabledTimes(Timepoint[] times)`
You can pass in an array of `Timepoints`. These values will not be available for selection. These take precedence over `setSelectableTimes` and `setTimeInterval`. Be careful when using this without selectableTimes: rounding to a valid Timepoint is a very expensive operation if a lot of consecutive Timepoints are disabled. Try to specify Timepoints only up to the resolution of your picker (i.e. do not add seconds if the resolution of the picker is minutes).

* `setTimeInterval(int hourInterval, int minuteInterval, int secondInterval)`
Set the interval for selectable times in the TimePickerDialog. This is a convenience wrapper around `setSelectableTimes`. The interval for all three time components can be set independently. If you are not using the seconds / minutes picker, set the respective item to 60 for better performance.

* `setTimeInterval(int hourInterval, int minuteInterval, int secondInterval)`
Set the interval for selectable times in the TimePickerDialog. This is a convenience wrapper around `setSelectableTimes`
* `setTimepointLimiter(TimepointLimiter limiter)`
Pass in a custom implementation of `TimeLimiter`
Disables `setSelectableTimes`, `setDisabledTimes`, `setTimeInterval`, `setMinTime` and `setMaxTime`

* `setSelectableDays(Calendar[] days)`
You can pass a `Calendar[]` to the `DatePickerDialog`. The values in this list are the only acceptable dates for the picker. It takes precedence over `setMinDate(Calendar day)` and `setMaxDate(Calendar day)`
Expand Down Expand Up @@ -185,54 +193,145 @@ Set whether the dialogs should vibrate the device when a selection is made. This
* `dismissOnPause(boolean dismissOnPause)`
Set whether the picker dismisses itself when the parent Activity is paused or whether it recreates itself when the Activity is resumed.

* `setLocale(Locale locale)`
Allows the client to set a custom locale that will be used when generating various strings in the pickers. By default the current locale of the device will be used. Because the pickers will adapt to the Locale of the device by default you should only have to use this in very rare circumstances.

* `DatePickerDialog` `autoDismiss(boolean autoDismiss)`
If set to `true` will dismiss the picker when the user selects a date. This defaults to `false`.

* `TimepickerDialog` `enableSeconds(boolean enableSconds)` and `enableMinutes(boolean enableMinutes)`
Allows you to enable or disable a seconds and minutes picker ont he `TimepickerDialog`. Enabling the seconds picker, implies enabling the minutes picker. Disabling the minute picker will disable the seconds picker. The last applied setting will be used. By default `enableSeconds = false` and `enableMinutes = true`.
Allows you to enable or disable a seconds and minutes picker on the `TimepickerDialog`. Enabling the seconds picker, implies enabling the minutes picker. Disabling the minute picker will disable the seconds picker. The last applied setting will be used. By default `enableSeconds = false` and `enableMinutes = true`.

* `DatePickerDialog` `setTimeZone(Timezone timezone)`
* `DatePickerDialog` `setTimeZone(Timezone timezone)` *deprecated*
Sets the `Timezone` used to represent time internally in the picker. Defaults to the current default Timezone of the device.
This method has been deprecated: you should use the `newInstance()` method which takes a Calendar set to the appropriate TimeZone.

* `DatePickerDialog` `setDateRangeLimiter(DateRangeLimiter limiter)`
Provide a custom implementation of DateRangeLimiter, giving you full control over which days are available for selection. This disables all of the other options that limit date selection.

* `getOnTimeSetListener()` and `getOnDateSetListener()`
Getters that allow the retrieval of a reference to the callbacks currently associated with the pickers

## FAQ

### Why not use `SupportDialogFragment`?
Not using the support library versions has been a well considered choice, based on the following considerations:

* Less than 5% of the devices using the android market do not support native `Fragments`, a number which will decrease even further going forward.
* Even if you use `SupportFragments` in your application, you can still use the normal `FragmentManager`
* Even if you use `SupportFragments` in your application, you can still use the normal `FragmentManager`. Both can exist side by side.

This means that in the current setup everyone can use the library: people using the support library and people not using the support library.

Finally changing to `SupportDialogFragment` now will break the API for all the people using this library.

If you do really need `SupportDialogFragment`, you can fork the library (It involves changing all of 2 lines of code, so it should be easy enough to keep it up to date with the upstream) or use this fork: https://github.com/infinum/MaterialDateTimePicker

```java
```groovy
dependencies {
compile 'co.infinum:materialdatetimepicker-support:3.1.3'
compile 'co.infinum:materialdatetimepicker-support:3.5.1'
}
```

### Why does the `DatePickerDialog` return the selected month -1?
In the java `Calendar` class months use 0 based indexing: January is month 0, December is month 11. This convention is widely used in the java world, for example the native Android DatePicker.

### How do I use a different version of the support library in my app?
This library depends on the android support library. Because the jvm allows only one version of a fully namespaced class to be loaded, you will run into issues if your app depends on a different version of the support library than the one used in this app. Gradle is generally quite good at resolving version conflicts (be default it will retain the latest version of a library), but should you run into problems (eg because you disabled conflict resolution), you can disable loading the support
library for MaterialDateTimePicker.

Using the following snippet in your apps `build.gradle` file you can exclude this library's transitive support library dependency from being installed.

```groovy
compile ('com.wdullaer:materialdatetimepicker:3.5.1') {
exclude group: 'com.android.support'
}
```

Your app will need to depend on at least the following pieces of the support library

```groovy
compile 'com.android.support:support-v4:26.0.1'
compile 'com.android.support:support-v13:26.0.1'
compile 'com.android.support:design:26.0.1'
```

This will work fine as long as the support library version your app depends on is recent enough (supports `RecyclerView`) and google doesn't release a version in the future that contains breaking changes. (If/When this happens I will try hard to document this). See issue [#338](https://github.com/wdullaer/MaterialDateTimePicker/issues/338) for more information.

### How do I turn this into a year and month picker?
This DatePickerDialog focusses on selecting dates, which means that it's central design element is the day picker. As this calendar like view is the center of the design it makes no sense to try and disable it. As such selecting just years and months, without a day, is not in scope for this library and will not be added.

### How do I use my custom logic to enable/disable dates?
`DatePickerDialog` exposes some utility methods to enable / disable dates for common scenario's. If your needs are not covered by these, you can override the `isOutOfRange()` method by extending the `DatePickerDialog` class.
`DatePickerDialog` exposes some utility methods to enable / disable dates for common scenario's. If your needs are not covered by these, you can supply a custom implementation of the `DateRangeLimiter` interface.
Because the `DateRangeLimiter` is preserved when the `Dialog` pauzes, your implementation must also implement `Parcelable`.

```java
class MyDatePickerDialog extends DatePickerDialog {
@override
class MyDateRangeLimiter implements DateRangeLimiter {
public MyDateRangeLimiter(Parcel in) {

}

@Override
public int getMinYear() {
return 1900;
}

@Override
public int getMaxYear() {
return 2100;
}

@Override
public Calendar getStartDate() {
Calendar output = Calendar.newInstance();
output.set(Calendar.YEAR, 1900);
output.set(Calendar.DAY_OF_MONTH, 1);
output.set(Calendar.MONTH, Calendar.JANUARY);
return output;
}

@Override
public Calendar getEndDate() {
Calendar output = Calendar.newInstance();
output.set(Calendar.YEAR, 2100);
output.set(Calendar.DAY_OF_MONTH, 1);
output.set(Calendar.MONTH, Calendar.JANUARY);
return output;
}

@Override
public boolean isOutOfRange(int year, int month, int day) {
// disable days that are odd
return day % 2 == 1;
return false;
}

@Override
public Calendar setToNearestDate(Calendar day) {
return day;
}

@Override
public void writeToParcel(Parcel out) {

}

@Override
public int describeContents() {
return 0;
}

public static final Parcelable.Creator<MyDateRangeLimiter> CREATOR
= new Parcelable.Creator<MyDateRangeLimiter>() {
public MyDateRangeLimiter createFromParcel(Parcel in) {
return new MyDateRangeLimiter(in);
}

public MyDateRangeLimiter[] newArray(int size) {
return new MyDateRangeLimiter[size];
}
};
}
```

> You need to override `isOutOfRange()` with this signature, not the one with the Calendar signature.
When you override `isOutOfRange()` the built-in methods for setting the enabled / disabled dates will no longer work. It will need to be completely handled by your implementation.
When you provide a custom `DateRangeLimiter` the built-in methods for setting the enabled / disabled dates will no longer work. It will need to be completely handled by your implementation.

### Why are my callbacks lost when the device changes orientation?
The simple solution is to dismiss the pickers when your activity is paused.
Expand Down
Loading

0 comments on commit 4551edb

Please sign in to comment.