GithubHelp home page GithubHelp logo

heysupratim / material-daterange-picker Goto Github PK

View Code? Open in Web Editor NEW
1.3K 42.0 269.0 868 KB

A material Date Range Picker based on wdullaers MaterialDateTimePicker

License: Apache License 2.0

Java 100.00%
picker material range-selection datepicker timepicker datetimepicker

material-daterange-picker's Introduction

Android Arsenal

Download

Maven Central

Material Date and Time Picker with Range Selection

Credits to the original amazing material date picker library by wdullaer - https://github.com/wdullaer/MaterialDateTimePicker

Adding to your project

Add the jcenter repository information in your build.gradle file like this

repositories {
  jcenter()
}


dependencies {
  implementation 'com.borax12.materialdaterangepicker:library:2.0'
}

Beginning Version 2.0 now also available on Maven Central

Date Selection

FROM TO

Time Selection

FROM TO

Support for Android 4.0 and up.

From the original library documentation -

You may also add the library as an Android Library to your project. All the library files live in library.

Using the Pickers

  1. Implement an OnDateSetListener or OnTimeSetListener
  2. Create a ``DatePickerDialog` using the supplied factory

Implement an OnDateSetListener

In order to receive the date set in the picker, you will need to implement the OnDateSetListener interfaces. Typically this will be the Activity or Fragment that creates the Pickers.

or

Implement an OnTimeSetListener

In order to receive the time set in the picker, you will need to implement the OnTimeSetListener interfaces. Typically this will be the Activity or Fragment that creates the Pickers.

//new onDateSet
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth,int yearEnd, int monthOfYearEnd, int dayOfMonthEnd) {

}

@Override
public void onTimeSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth,int yearEnd, int monthOfYearEnd, int dayOfMonthEnd) {
        String hourString = hourOfDay < 10 ? "0"+hourOfDay : ""+hourOfDay;
        String minuteString = minute < 10 ? "0"+minute : ""+minute;
        String hourStringEnd = hourOfDayEnd < 10 ? "0"+hourOfDayEnd : ""+hourOfDayEnd;
        String minuteStringEnd = minuteEnd < 10 ? "0"+minuteEnd : ""+minuteEnd;
        String time = "You picked the following time: From - "+hourString+"h"+minuteString+" To - "+hourStringEnd+"h"+minuteStringEnd;

        timeTextView.setText(time);

}

Create a DatePickerDialog` using the supplied factory

You will need to create a new instance of DatePickerDialog using the static newInstance() method, supplying proper default values and a callback. Once the dialogs are configured, you can call show().

Calendar now = Calendar.getInstance();
DatePickerDialog dpd = DatePickerDialog.newInstance(
  MainActivity.this,
  now.get(Calendar.YEAR),
  now.get(Calendar.MONTH),
  now.get(Calendar.DAY_OF_MONTH)
);
dpd.show(getFragmentManager(), "Datepickerdialog");

Create a TimePickerDialog` using the supplied factory

You will need to create a new instance of TimePickerDialog using the static newInstance() method, supplying proper default values and a callback. Once the dialogs are configured, you can call show().

Calendar now = Calendar.getInstance();
TimePickerDialog tpd = TimePickerDialog.newInstance(
                        MainActivity.this,
                        now.get(Calendar.HOUR_OF_DAY),
                        now.get(Calendar.MINUTE),
                        false
                );
tpd.show(getFragmentManager(), "Timepickerdialog");

For other documentation regarding theming , handling orientation changes , and callbacks - check out the original documentation - https://github.com/wdullaer/MaterialDateTimePicker

material-daterange-picker's People

Contributors

ardacebi avatar bryant1410 avatar curliq avatar filipebezerra avatar fusion44 avatar heysupratim avatar joakimsa avatar mtrakal avatar oliviadodge avatar onyanov avatar paralen avatar prayagverma avatar sonique6784 avatar wdullaer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

material-daterange-picker's Issues

It doesn't work with original wdullaer/MaterialDateTimePicker

If I want to use this library (for data ranges), and original library https://github.com/wdullaer/MaterialDateTimePicker (for one date picker) - then my gradle didn't sync, because of some ids conflicts:

/myApp/app/build/intermediates/exploded-aar/com.wdullaer/materialdatetimepicker/3.0.0/res/layout-land/mdtp_time_header_label.xml
Error:(72, 31) No resource found that matches the given name (at 'layout_above' with value '@id/seconds_space').
Warning:string 'mdtp_sans_serif' has no default translation.
/myApp/app/build/intermediates/res/merged/debug/layout-land/mdtp_time_header_label.xml
Error:(72, 31) No resource found that matches the given name (at 'layout_above' with value '@id/seconds_space').
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

Use the original library by wdullaer

I am interested in using your library but also by the original, is it possible to use both ?
I have this when I add the second library :

java.lang.ClassCastException: com.wdullaer.materialdatetimepicker.date.AccessibleDateAnimator cannot be cast to com.borax12.materialdaterangepicker.date.AccessibleDateAnimator

In my gradle :

    compile 'com.wdullaer:materialdatetimepicker:2.1.1'
    compile 'com.borax12.materialdaterangepicker:library:1.5'

Is it possible not to use the from-to in MaterialDateRangePicker ?

Best regards,

Date picker To jump back after click on day

Date picker on To card jump back on current month after select some day in onother month/year than is current.

  • select some day in FROM card
  • swipe to next month
  • click on some day
  • ! calendar jump back on actual month selected in FROM card.

The behavior on FROM and TO cards is different.
Tested on Android 5.0

Translate texts

Hi,

How can I change the language of the texts to pt-br, for example?

TimePicker theme bug

When setting a custom color for the dialog theme, the bottom is correctly themed, but the top layout isn't.

Listener for seperate FROM and TO tabs

It is necessary to track if user pressed both from and to tabs (and set time or date) because sometime user only set time (FROM) and forget to set (TO)

TimePickerDialog

Is there a way to detect when just the start time is updated, or when the tabs change? Basically I'm looking to automatically set the To time to be an hour ahead of the From time when they change the From value and switch tabs.

Issue in displaying pickerdailog in fragment

hello,i have tried this code
Calendar now = Calendar.getInstance(); DatePickerDialog dpd = DatePickerDialog.newInstance( MainActivity.this, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH) ); dpd.show(getFragmentManager(), "Datepickerdialog");
in my fragment,since we need to change the context where in the above code passes MainActivity.this,i also tried with this code.
Calendar now = Calendar.getInstance(); DatePickerDialog dpd = new DatePickerDialog(); dpd.show(getFragmentManager(), "Datepickerdialog");
this code displays the dailog but its interface doesnt get called when picking a date range

i have also tried passing getActivty() and getContecxt() but none works,please help

setting initial date range

initializing a new instance can only set date from and to with the same date,
can there be a way to set both date from and to independently.

Scroll to Correct Month on Tab Change

Hi, for the date range picker I noticed the scrolling behavior is faulty when you change tabs if you are not already at the position of the selected day. It will scroll to the month before the day you selected.

How to detect user tap FROM/TO

Is there a way for us to know if user tap From/To?

Also, can we automatically jump to To when user has selected a date on From?

I would also like to highlight the selected range of dates, how is that possible?

It also looks like we can't detect date change?

Instantiate DatePickerDialog from Fragment

Am using the v4 support version of the android Fragment and am unable to instate the date picker with version 1.7 of the library. All attempts to set the listener and the fragmentManager fail. The parameters are not being accepted. The listener is implemented on the Fragment and the fragment is hosted in an activity that extends AppCompatActivity.

Disable To older than From

Hello,

is possible to disable days on To view which are older than From selected day by dialog settings?

I can calculate it manually and show Toast, but I didn't found any solution, how to cancel dismissing dialog after OK clicked.
I check setOnDismissListener which dismiss dialog, but I'm not able to stop dialog dismissing.

ClassCastException

Hello,
I saw different posts exposing this issue but any of those solved my case.
I specify full namespace of the DatePickerDialog
Calendar now = Calendar.getInstance(); com.borax12.materialdaterangepicker.date.DatePickerDialog.newInstance( null, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH) ).show( getActivity().getFragmentManager(), "Datepickerdialog" );
but it gives me a class cast exception,
java.lang.ClassCastException: com.wdullaer.materialdatetimepicker.date.AccessibleDateAnimator cannot be cast to com.borax12.materialdaterangepicker.date.AccessibleDateAnimator

The build.gradle file includes both libraries as follow
compile 'com.wdullaer:materialdatetimepicker:2.5.0' compile 'com.borax12.materialdaterangepicker:library:1.9'

Any suggestion to how solve this case?

Thanks in advance @borax12 !

Only one option, instead of From & To

Is there a way to only enable one option dialog, no two (From & To). I know the whole point of this library is that it is a range picker, but it's probably worth asking.

I need a range picker for date, but only single picker for time. My options are to use android picker for time, but I want it to look the same for older versions of Android.

In "To" date calendar How to show selected date according to "From" date calendar

Hello,
i am developing an app with range calendar its awesome and helpful.
i have a problem,
i want that if user select a date from first calendar ("FROM calendar" )
then in second calendar ("To calendar") that date show selected so that user can select relative date from first calendar
please add a listener or method for that

please help
Thanks in advance

Expose TabHost or key methods

Want to intialise the date picker with the "end" tab.

With TabHost it is a simple method:
tabHost.setCurrentTab(n);

Is there a way to do this?

Crash when the library is used along with wdullaer/MaterialDateTimePicker

Fatal Exception: java.lang.ClassCastException: com.wdullaer.materialdatetimepicker.date.AccessibleDateAnimator cannot be cast to com.borax12.materialdaterangepicker.date.AccessibleDateAnimator
       at com.borax12.materialdaterangepicker.date.DatePickerDialog.onCreateView(DatePickerDialog.java:371)
       at android.app.Fragment.performCreateView(Fragment.java:2114)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
       at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
       at android.app.BackStackRecord.run(BackStackRecord.java:834)
       at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1469)
       at android.app.FragmentManagerImpl$1.run(FragmentManager.java:452)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6946)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

Persian Calendar

cool, this is great.
i love ur lib. its awesome

can u add persian calendar too??

TnQ

Crash on android 4.4.2

Hey,
I'm getting this error on android 4.4.2 devices
java.lang.RuntimeException: Unable to start activity ComponentInfo{package/package.MainActivity}: android.view.InflateException: Binary XML file line #26: Error inflating class Button.
It works fine on other devices

Change HEADER["FROM" "TO"]

I need to change the "FROM" and "TO" strings on top of DatePicker, such that I am using multilanguage app. Which string I have to define in strings.xml file in order to change this headers.

Hardcoded strings

DatePickerDialog defines "FROM" and "TO" strings in the code. Should be done via a string resource so that it's possible to localise those strings...

Enable custom theme color

Can you add a function to allow custom theme color? I saw the DatePickerDialog retrieves the accent color from the theme in it's onCreateView. It would already be good enough to add a protected function getAccentColor() and implement your default code in this function so that I can at least overwrite it with a custom function...

NoSuchFieldError

i implemented the sample code, but got the following error:

java.lang.NoSuchFieldError: com.borax12.materialdaterangepicker.R$id.tabHost at com.borax12.materialdaterangepicker.time.TimePickerDialog.onCreateView(TimePickerDialog.java:281)

Change readme for TabWidget background

Hey, I was looking how to change style but as you can see the other Repo does not include guide in how to change TabWidget background analizing your code I found that you can use "@color/mdtp_circle_background"
You can specify this on you readme and save people time :)

How to I change the text colour of the Tabs - FROM and TO?

HI! First of all, thank you for the awesome library. It is very easy to use. I just have one question. How to change the colour of the two tabs at the top of the picker (TimePickerDialog more specificly). Currently, it looks like that:

device-2017-02-27-123444

Thank you in advance!

strange comment at onDayOfMonthSelected

@Override
    public void onDayOfMonthSelected(int year, int month, int day) {

        if(tabHost.getCurrentTab()==0){
            mCalendar.set(Calendar.YEAR, year);
            mCalendar.set(Calendar.MONTH, month);
            mCalendar.set(Calendar.DAY_OF_MONTH, day);
        }
       else{
            mCalendarEnd.set(Calendar.YEAR, year);
            mCalendarEnd.set(Calendar.MONTH, month);
            mCalendarEnd.set(Calendar.DAY_OF_MONTH, day);
        }

        //updatePickers(); <======= why is it commented?
        updateDisplay(true);
    }

Because of this comment onDateChanged callback is not called when I choose a date. Was it commented for some reason?

The user should not be able to select a "FROM" date before the "TO" date

When the user selects a date from the "FROM" tab, that date should be the maximum date so when the user clicks on the "TO" tab the date will be greater than or equal to the date in the "FROM" tab.

ex) if the user selects 10/11/16 in the "FROM" tab, the user should not be able to select a date earlier than that in the "TO" tab

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.