GithubHelp home page GithubHelp logo

florent37 / singledateandtimepicker Goto Github PK

View Code? Open in Web Editor NEW
1.0K 26.0 333.0 21.67 MB

You can now select a date and a time with only one widget !

License: Apache License 2.0

Java 99.89% Shell 0.11%
android picker date time range dialog material design

singledateandtimepicker's Introduction

SingleDateAndTimePicker

You can now select a date and a time with only one widget !

Android app on Google Play

screen

Usage

new SingleDateAndTimePickerDialog.Builder(context)
            //.bottomSheet()
            //.curved()
            //.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 onClosed(SingleDateAndTimePicker picker) {
                    // On dialog closed 
                }
            })
            .title("Simple")
            .listener(new SingleDateAndTimePickerDialog.Listener() {
                @Override
                public void onDateSelected(Date date) {
                    
                }
            }).display();

Select 2 dates

screen

new DoubleDateAndTimePickerDialog.Builder(context)
            //.bottomSheet()
            //.curved()
            //.stepSizeMinutes(15)
            .title("Double")
            .tab0Text("Depart")
            .tab1Text("Return")
            .listener(new DoubleDateAndTimePickerDialog.Listener() {
                @Override
                public void onDateSelected(List<Date> dates) {
                
                }
        }).display();

Display days, months and years

screen

new SingleDateAndTimePickerDialog.Builder(this)
            .bottomSheet()
            .curved()
            .displayMinutes(false)
            .displayHours(false)
            .displayDays(false)
            .displayMonth(true)
            .displayYears(true)
            .displayDaysOfMonth(true)
            .display();

Include in a layout

screen

<com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker
        android:layout_width="wrap_content"
        android:layout_height="230dp"
        app:picker_curved="true"
        app:picker_cyclic="true"
        app:picker_visibleItemCount="7"
        />

iOS like :P

screen

new SingleDateAndTimePickerDialog.Builder(context)
                                    .bottomSheet()
                                    .curved()

screen

new DoubleDateAndTimePickerDialog.Builder(context)
                                    .bottomSheet()
                                    .curved()

Customisation

You can change the minutes steps (default : 5min)

new SingleDateAndTimePickerDialog.Builder(context)
            .stepSizeMinutes(15)
            .display();

And change some colors

screen

new SingleDateAndTimePickerDialog.Builder(context)
            .backgroundColor(Color.BLACK)
            .mainColor(Color.GREEN)
            .titleColor(Color.WHITE)
            .display();

Date range

Require user to select a date between a range

new SingleDateAndTimePickerDialog.Builder(context)
            .defaultDate(defaultDate)
            .minDateRange(minDate)
            .maxDateRange(maxDate)
            .display();

Or simply require user to select a future date

new SingleDateAndTimePickerDialog.Builder(context)
            .mustBeOnFuture()
            .display();

Changing typeface

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:

    <com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker
        android:id="@+id/single_day_picker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:picker_itemSpacing="6dp"
        app:picker_curvedMaxAngle="45"
        app:picker_curved="true"
        app:picker_selectorColor="@android:color/transparent"
        app:picker_stepSizeHours="2"
        app:picker_stepSizeMinutes="5"
        app:picker_cyclic="false"        
        app:picker_dayCount="31"
        app:picker_mustBeOnFuture="true"
        app:picker_visibleItemCount="7"
        app:fontFamily="@font/dinot_bold"
        />
  • 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

    <color name="picker_default_divider_color">@android:color/transparent</color>
    <dimen name="picker_default_divider_height">1dp</dimen>
    <drawable name="picker_default_divider">@drawable/picker_divider</drawable>

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

implementation 'com.github.florent37:singledateandtimepicker:2.2.7'
//compatible with androidX

Credits

Author: Florent Champigny

Blog : http://www.tutos-android-france.com/

Fiches Plateau Moto : https://www.fiches-plateau-moto.fr/

Android app on Google Play Follow me on Google+ Follow me on Twitter Follow me on LinkedIn

License

Copyright 2016 florent37, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

singledateandtimepicker's People

Contributors

akhunzaada avatar anuress avatar arberg avatar bhavdipcreolestudios avatar bill2004158 avatar bshka avatar chupilin avatar faheemkalsekar avatar fcorbi avatar florent37 avatar francoisrouault avatar gioviq avatar guillerial avatar h4rz avatar jeffreymuir avatar kikebodi avatar kilo8yte avatar meoyawn avatar n00bman avatar nomanr avatar oleksandrbalan-etn avatar pedromassango avatar pjnous avatar ptrstovka avatar shailevy avatar shrewd avatar surya2607 avatar thubalek avatar umair-7x avatar zaros 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

singledateandtimepicker's Issues

Position of "Ok" button is not correct in some devices

Thanks for the awesome lib.

I noticed the position of this button is not right in some devices such as Samsung S6, S7, Android 6.0.0 and 6.0.1 while it is okay on Samsung Galaxy Note, Android 4.4.2.

This is my settings:

new SingleDateAndTimePickerDialog.Builder(this)
//                .bottomSheet()
//                .curved()
                .minutesStep(5)
                .title("Date & Time")
                .mustBeOnFuture()
                .backgroundColor(ContextCompat.getColor(this, R.color.black))
                .mainColor(ContextCompat.getColor(this, R.color.colorPrimaryDark))
                .titleTextColor(ContextCompat.getColor(this, R.color.white))
                .listener(new SingleDateAndTimePickerDialog.Listener() {
                    @Override
                    public void onDateSelected(Date date) {
                        SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy hh:mm a", Locale.US);
                        mSessionDate.setText(sdf.format(date));
                        mDateOfSession = date;
                    }
                })
                .display();

01
02
03

How to remove AM&PM and show in 24 hours formate.

<com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker android:id="@+id/single_day_time_picker" android:layout_width="wrap_content" android:layout_height="230dp" app:picker_curved="true" app:picker_cyclic="true" app:picker_mustBeOnFuture="true" app:picker_visibleItemCount="7" />

SingleDateAndTimePicker dateTimePicker = (SingleDateAndTimePicker) rootView.findViewById(R.id.single_day_time_picker);

dateTimePicker.setIsAmPm(false);

I have used setIsAmPm( ) but no luck.

I am using this in a dialogFragment.

inquiredialog

Minutes of SingleDateAndTimePicker are not updating using selectDate()

I am trying to update SingleDateAndTimePicker date and time every minute. For that, I have written code as below:

Thread t = new Thread() {
                        @Override
                        public void run() {
                            try {
                                while (!isInterrupted()) {
                                    Thread.sleep(60000);
                                    if (context instanceof HomeScreen && context != null) {
                                        ((HomeScreen) context).runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                Calendar calendar = Calendar.getInstance(Locale.getDefault());
                                                Date dt = new Date();
                                                calendar.set(Calendar.HOUR_OF_DAY, dt.getHours());
                                                calendar.set(Calendar.MINUTE, dt.getMinutes());
                                                calendar.set(Calendar.SECOND, dt.getSeconds());
                                                picker.selectDate(calendar);
                                                picker.setMinDate(dt);
                                            }
                                        });
                                    }
                                }
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    };
                    t.start();

But, the problem is, it's not showing correct minutes. Hours are updating properly. Please, Help. Thanks!

Bug

                                                                 java.lang.IllegalArgumentException: View=android.widget.FrameLayout{aa82bfd G.E...C.. ......ID 0,0-1440,2476 #7f0e00a8 app:id/bottom_sheet_background} not attached to window manager
                                                                     at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:451)
                                                                     at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:377)
                                                                     at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:135)
                                                                     at com.github.florent37.singledateandtimepicker.dialog.BottomSheetHelper.remove(BottomSheetHelper.java:129)
                                                                     at com.github.florent37.singledateandtimepicker.dialog.BottomSheetHelper.access$500(BottomSheetHelper.java:18)
                                                                     at com.github.florent37.singledateandtimepicker.dialog.BottomSheetHelper$3$1.onAnimationEnd(BottomSheetHelper.java:120)
                                                                     at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1239)
                                                                     at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:766)
                                                                     at android.animation.ValueAnimator$AnimationHandler$1.run(ValueAnimator.java:801)
                                                                     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
                                                                     at android.view.Choreographer.doCallbacks(Choreographer.java:686)
                                                                     at android.view.Choreographer.doFrame(Choreographer.java:619)
                                                                     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
                                                                     at android.os.Handler.handleCallback(Handler.java:739)
                                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                     at android.os.Looper.loop(Looper.java:148)
                                                                     at android.app.ActivityThread.main(ActivityThread.java:7331)
                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

DoubleDateAndTimePickerDialog demo doesn't work

If I copy paste the code from readme to my app, it crashes. If I uncomment the bottomSheet() line, it crashes on the different place since the view is not in the layout.

new SingleDateAndTimePickerDialog.Builder(context)
            //.bottomSheet()
            //.curved()
            //.minutesStep(15)
            
            //.displayHours(false)
            //.displayMinutes(false)
            
            .title("Simple")
            .listener(new SingleDateAndTimePickerDialog.Listener() {
                @Override
                public void onDateSelected(Date date) {
                    
                }
            }).display();

Here is the stack trace


                                                            java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
                                                                at com.github.florent37.singledateandtimepicker.dialog.DoubleDateAndTimePickerDialog.getTabsListDrawable(DoubleDateAndTimePickerDialog.java:226)
                                                                at com.github.florent37.singledateandtimepicker.dialog.DoubleDateAndTimePickerDialog.init(DoubleDateAndTimePickerDialog.java:139)
                                                                at com.github.florent37.singledateandtimepicker.dialog.DoubleDateAndTimePickerDialog.access$000(DoubleDateAndTimePickerDialog.java:25)
                                                                at com.github.florent37.singledateandtimepicker.dialog.DoubleDateAndTimePickerDialog$1.onLoaded(DoubleDateAndTimePickerDialog.java:60)
                                                                at com.github.florent37.singledateandtimepicker.dialog.BottomSheetHelper$1.run(BottomSheetHelper.java:73)
                                                                at android.os.Handler.handleCallback(Handler.java:769)
                                                                at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                at android.os.Looper.loop(Looper.java:164)
                                                                at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Enable the bottomSheet() and run the demo app in earlier version of API Level 21 app is crashing

When we run the Demo application by enabling the bottomSheet() inside the file MainActivityWithDoublePicker.java on the line number 63. The application is crashing in android version 4.1.2 and may be earlier all device that API Level 21.

I detected that while SingleDateAndTimePickerDialog constructor is called. Becuase in one of the layout file bottom_sheet_picker_bottom_sheet.xml see the below text view use the android properties that only available after API Level 21 or later version so either remove it or give the support.

android:background="?android:attr/selectableItemBackgroundBorderless"

<TextView
                android:id="@+id/buttonOk"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="right|center_vertical"
                android:gravity="center"
               android:background="?android:attr/selectableItemBackgroundBorderless"
                android:paddingLeft="20dp"
                android:paddingRight="25dp"
                android:text="@android:string/ok"
                android:textAllCaps="true"
                android:textColor="@color/picker_button_background_selected"
                android:textStyle="bold"
                />

By removing this line I can able to run it succesfully in android 4.1.2

switch between AM/PM and 24

I always see 24h format in datetime picker.

I see that in 1.0.1 there was an option for this, but on 1.1.0 there is none.

How to switch?

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference

Getting:

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
at com.github.florent37.singledateandtimepicker.dialog.DoubleDateAndTimePickerDialog.getTabsListDrawable(DoubleDateAndTimePickerDialog.java:200)
at com.github.florent37.singledateandtimepicker.dialog.DoubleDateAndTimePickerDialog.init(DoubleDateAndTimePickerDialog.java:130)
at com.github.florent37.singledateandtimepicker.dialog.DoubleDateAndTimePickerDialog.access$000(DoubleDateAndTimePickerDialog.java:24)
at com.github.florent37.singledateandtimepicker.dialog.DoubleDateAndTimePickerDialog$1.onLoaded(DoubleDateAndTimePickerDialog.java:55)
at com.github.florent37.singledateandtimepicker.dialog.BottomSheetHelper$1.run(BottomSheetHelper.java:73)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

When trying to load inside a Fragment textView onClick Listener:

public void onClick(View v) {
    final Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.YEAR, 2017);
    final Date minDate = calendar.getTime();
    calendar.set(Calendar.DAY_OF_MONTH, 5);
    final Date maxDate = calendar.getTime();

    DoubleDateAndTimePickerDialog.Builder doubleBuilder = new DoubleDateAndTimePickerDialog.Builder(getContext())
        //.bottomSheet()
        //.curved()
        //.backgroundColor(Color.BLACK)
        //.mainColor(Color.GREEN)
        .minutesStep(15)
        .mustBeOnFuture()
        .minDateRange(minDate)
        .maxDateRange(maxDate)
        .tab0Text("Start")
        .tab1Text("End")
        .listener(new DoubleDateAndTimePickerDialog.Listener() {
            @Override
            public void onDateSelected(List<Date> dates) {
                tvStartValue.setText(parseDate(dates.get(0)));
                tvFinishValue.setText(parseDate(dates.get(1)));
            }
        }
    );
    doubleBuilder.display();
}

Should Add some set methods

E.g
1、add custom SimpleDateFormat method ;
2、The Title can add setVisibility();
3、add cancel button and setVisibility();

Incorrect behavior when setting "must be on future"

I am using the date and time picker on my app using the xml view and the DoubleDateAndTimePickerDialog. In both cases, I get an incorrect behavior when setting mustBeOnFuture to true. Following use cases reproduce the bug

  1. Suppose it is 2:43 PM. isAmPm is set to true. When displaying the view/dialog it shows "Today - 02 -40 AM". It is supposed to show "PM". Additionally, hours like 2, 3, 4, 5 AM are allowed.

  2. In previous use case, 1 AM is considered as not valid, but in this case, the time jumps to 2 - 00 - AM. It should jump to 2 - 40 - PM (both minutes and AM/PM are wrong)

  3. Suppose it is 2:43 PM. isAmPm is set to false. The time is set to 14 - 40, as it is suppossed to be. However, when a wrong time is chosen, it jumps to 14 - 00, similar to previous use case.

  4. Suppose it is 2:57 PM. isAmPm is set to false. The time is set to 14 - 00, but it should be 14:55

Window Leak on screen rotation

Hi,

Thanks for putting together this useful library.

Unfortunately I can't seem to avoid a WindowLeaked error when the picker is opened and I rotate the screen.

I am creating and showing the picker like this:

    dateAndTimePicker = new SingleDateAndTimePickerDialog.Builder(this)
                    .curved()
                    .minutesStep(1)
                    .backgroundColor(Color.WHITE)
                    .mainColor(Color.parseColor("#1A237E"))
                    .title("Test")
                    .listener(this).build();

            dateAndTimePicker.display();

Then in the onPause() method of my activity I call this:

if (dateAndTimePicker != null && dateAndTimePicker.isDisplaying()) {
dateAndTimePicker.close();
}

Even when the close() method is executed I get the following exception when screen is rotated:

android.view.WindowLeaked: Activity com.otrathena.athena_otr.MainActivity has leaked window android.widget.FrameLayout{34ced2b V.E...C.. ........ 0,0-1080,1920 #7f0e009d app:id/bottom_sheet_background} that was originally added here
at android.view.ViewRootImpl.(ViewRootImpl.java:386)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at com.github.florent37.singledateandtimepicker.dialog.BottomSheetHelper$1.run(BottomSheetHelper.java:62)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)

Any help on how I can close the picker on rotation and avoid this error would be greatly appreciated.

Many thanks

i think it's dependent on api 24.0.0

first of all thank you because your project help me alot to achieve few views, but my another experiment failed with below issue.

->experiments based on below detail

compileSdkVersion 23
 buildToolsVersion "23.0.1"
`defaultConfig {
     applicationId "com.experiment.nu13"
     minSdkVersion 15
     targetSdkVersion 23
     versionCode 1
     versionName "1.0"
 }`

when i am integrating your dependency getting below error.
Error:A problem occurred configuring project ':app'.

Could not find appcompat-v7.jar (com.android.support:appcompat-v7:24.0.0).
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/appcompat-v7/24.0.0/appcompat-v7-24.0.0.jar

any solution will be appreciated.

mustBeOnFuture() not working as expected.

Hi, This is the implementation that i have done for date picker in my fragment:

new SingleDateAndTimePickerDialog.Builder(getActivity())
.bottomSheet()
.backgroundColor(Color.WHITE)
.mainColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary))
.titleTextColor(Color.WHITE)
.mustBeOnFuture()
.listener(new SingleDateAndTimePickerDialog.Listener() {
@OverRide
public void onDateSelected(Date date) {
date.getTime();
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
String strDate = df.format(date.getTime());
tvSelectedDate.setText(strDate);
}
}).display();

But the mustBeOnFuture() is not working properly. if i dont use it, it will work properly. but when i use it this is what happens :

Today is 13 January 2017, so when this picker is displayed and i scroll it to choose older dates, it will jump back to date 15 January and if i select this 15 jan then it gives me this date from year 2016, also it wont show today's date which is 13th and also 14th in the date picker in such case.

Can you please check this issue.

Thanks

Change day format

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");
singleDateAndTimePicker.setDayFormatter(formatter);

FATAL EXCEPTION: main
Process: parentinghugs.android.com.parentinghugs, PID: 28806
java.lang.NullPointerException: Attempt to invoke virtual method 'long java.util.Date.getTime()' on a null object reference
at java.util.Calendar.setTime(Calendar.java:1197)
at com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker.getDate(SingleDateAndTimePicker.java:346)
at com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker.updateListener(SingleDateAndTimePicker.java:389)
at com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker.access$000(SingleDateAndTimePicker.java:25)
at com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker$1.onDaySelected(SingleDateAndTimePicker.java:92)
at com.github.florent37.singledateandtimepicker.widget.WheelDayPicker.onItemSelected(WheelDayPicker.java:54)
at com.github.florent37.singledateandtimepicker.widget.WheelPicker.onItemSelected(WheelPicker.java:594)
at com.github.florent37.singledateandtimepicker.widget.WheelPicker.access$700(WheelPicker.java:34)
at com.github.florent37.singledateandtimepicker.widget.WheelPicker$1.run(WheelPicker.java:108)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

I dont know why i am getting this issue.

FATAL EXCEPTION: main
Process: com.zalonstyle.app.zalonstaff, PID: 21319
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getHeight()' on a null object reference
at com.github.florent37.singledateandtimepicker.dialog.BottomSheetHelper$2.run(BottomSheetHelper.java:93)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)

How to set Today and Tomorrow day only in WheelDayPicker of SingleDateAndTimePicker?

I am looking to set only 2 days in the SingleDateAndTimePicker that is Today & Tomorrow.
I have added all the classes of SingleDateAndTimePicker in my project and customized as per my need.

I was trying to keep only Today in WheelDayPicker and tried to comment some code to achieve it but not getting the expected output:

WheelDayPicker.java

private void updateDays() {
        final List<String> data = new ArrayList<>();

//        Calendar instance = Calendar.getInstance();
//        instance.add(Calendar.DATE, -1 * DAYS_PADDING - 1);
//        for (int i = (-1) * DAYS_PADDING; i < 0; ++i) {
//            instance.add(Calendar.DAY_OF_MONTH, 1);
//            data.add(getFormattedValue(instance.getTime()));
//        }

        todayPosition = data.size();
        defaultIndex = todayPosition;

        //today
        data.add(getResources().getString(R.string.picker_today));

//        instance = Calendar.getInstance();

//        for (int i = 0; i < DAYS_PADDING; ++i) {
//            instance.add(Calendar.DATE, 1);
//            data.add(getFormattedValue(instance.getTime()));
//        }

        adapter.setData(data);
    }

Please help me.

setIsAmPm(false) don't redraw user interface

When i set IsAmPm to false it still is showing am/pm on the view. I was fixing this by reflection
Class<?> clazz = mDateAndTimePicker.getClass();
try {
Method updatePickerMethod = clazz.getDeclaredMethod("updatePicker");
Method updateViewsMethod = clazz.getDeclaredMethod("updateViews");
updatePickerMethod.setAccessible(true);
updateViewsMethod.setAccessible(true);
updatePickerMethod.invoke(mDateAndTimePicker, new Object[]{});
updateViewsMethod.invoke(mDateAndTimePicker, new Object[]{});
} catch (NoSuchMethodException e) {
Log.e("PickDateAndTimeFragment", "NoSuch=" + e.getMessage());
} catch (IllegalAccessException e) {
Log.e("PickDateAndTimeFragment", "IllegalAccess=" + e.getMessage());
} catch (InvocationTargetException e) {
Log.e("PickDateAndTimeFragment", "InvocationTarget = " + e.getMessage());
}
It seems that you just forgot in
public void setIsAmPm(boolean isAmPm) {
this.isAmPm = isAmPm;
updateViews();
}
add updatePicker(); because updateViews(); only is changed backgroundcolor
private void updateViews() {
dtSelector.setBackgroundColor(selectorColor);
}

Language / Format

Is it possible to change the format of the displayed days? Like capitilizing and so on... Only show numbers, etc...

Also, "Today" string is missing in a lot of languages, I know it can be overriden by using
hoy in strings.xml (btw this is spanish one) in case you want to include it.

Why It's not working in Android Version 4.1.2?

@florent37 I tested the library with android version 5.0 it's working but in older version 4.1 or earlier version there was the problem in layout file that was fixed earlier.

That fix help to run into that older Android version, still there was the problem even if we try to enable or disable the bottom sheet into the demo activity it's not working. We can't scroll up and down and click on OK is nothing working.

Time not set from defaultDate

new SingleDateAndTimePickerDialog.Builder(this)
.bottomSheet()
.curved()
.listener(.....)
.defaultDate(toDate)
.displayDays(false)
.displayHours(true)
.displayMinutes(true)
.display();

picker always start with current time, not from "toDate"

SetEnable false / locking components

Usually making a component .setEnable(false) locks the component so the user can't change it.
Though this library has the method, it doesn't seem to work.

Issues while setting minDateRange or FutureDate

Hello,

I am trying to set minDateRange(date) and .setOnFutureDate(), but somehow when I open the dialog, it shows previous day for ex. if currently it is 2:10 PM, it will show Today, 2:00 PM. And thus it allows user to pick past time which my app can't let user do.

Please let me know how to fix this.

Thanks,
Arpit

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.