Giter Club home page Giter Club logo

horizontalpicker's Introduction

Horizontal Picker

What is this?

HorizontalPicker is a custom-build Android View used for choosing dates (similar to the native date picker) but draws horizontally into a vertically narrow container. It allows easy day picking using the horizontal pan gesture.

Too see it in action, download the demo app to try it out.

This is what it looks like.

Screenshot_1 Screenshot_2

Features

  • Date selection using a smooth swipe gesture
  • Date selection by clicking on a day slot
  • Date selection from code using the HorizontalPicker java object
  • Month and year view
  • Today button to jump to the current day
  • Localized day and month names
  • Configurable number of generated days (default: 120)
  • Configurable number of offset generated days before the current date (default: 7)
  • Customizable set of colors, or themed through the app theming engine

Note: This library uses the JodaTime library to work with days.

Requirements

  • Android 4.1 or later (Minimum SDK level 16)
  • Android Studio (to compile and use)
  • Eclipse is not supported

Getting Started

In your app module's Gradle config file, add the following dependency:

dependencies {
    compile 'com.github.jhonnyx2012:horizontal-picker:1.0.6'
}

Then to include it into your layout, add the following:

<com.github.jhonnyx2012.horizontalpicker.HorizontalPicker
    android:id="@+id/datePicker"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

In your activity, you need to initialize it and set a listener, like this:

public class MainActivity extends AppCompatActivity implements DatePickerListener {
    @Override
    protected void onCreate(@Nullable final Bundle savedInstanceState) {
        // setup activity
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // find the picker
        HorizontalPicker picker = (HorizontalPicker) findViewById(R.id.datePicker);

        // initialize it and attach a listener
        picker
            .setListener(this)
            .init();
    }

    @Override
    public void onDateSelected(@NonNull final DateTime dateSelected) {
        // log it for demo
        Log.i("HorizontalPicker", "Selected date is " + dateSelected.toString());
    }
}

Finally, you can also configure the number of days to show, the date offset, or set a date directly to the picker. For all options, see the full configuration below.

    // at init time
    picker
        .setListener(listner)
        .setDays(20)
        .setOffset(10)
        .setDateSelectedColor(Color.DKGRAY)
        .setDateSelectedTextColor(Color.WHITE)
        .setMonthAndYearTextColor(Color.DKGRAY)
        .setTodayButtonTextColor(getColor(R.color.colorPrimary))
        .setTodayDateTextColor(getColor(R.color.colorPrimary))
        .setTodayDateBackgroundColor(Color.GRAY)
        .setUnselectedDayTextColor(Color.DKGRAY)
        .setDayOfWeekTextColor(Color.DKGRAY)
        .setUnselectedDayTextColor(getColor(R.color.textColor))
        .showTodayButton(false)
        .init();

    // or on the View directly after init was completed
    picker.setBackgroundColor(Color.LTGRAY);
    picker.setDate(new DateTime().plusDays(4));
Copyright 2017 Jhonny Barrios

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.

horizontalpicker's People

Contributors

anaistroncoso avatar dabarnard avatar demogorgorn avatar jhonnypapinotas avatar jhonnyx2012 avatar milosmns 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

horizontalpicker's Issues

setDate() not working as expected

This date picker is great. But I encounter an issue below, hope someone can advise:
I initialise the picker with days=7, offset=0, then select a date by default via setDate() function. But no matter what date I set, it's always set to the date in the middle of that 7 days, not the date I wanted to set. Is this the intended behaviour?

Remove allowBackup from manifest

Hi @jhonnyx2012 , thanks for your efforts with this library. It's been very helpful and I haven't found any other library that works as well as yours. I came across the following issue whilst using your lib and thought I would share some info:

If the library is used by any app which sets the value for allowBackup to false within their manifest, the manifest merger will fail with an error similar to the one below:

Manifest merger failed : Attribute application@allowBackup value=(false) from AndroidManifest.xml:10:9-36 is also present at [com.github.jhonnyx2012:horizontal-picker:1.0.6] AndroidManifest.xml:12:9-35 value=(true). Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:8:5-63:19 to override.

I believe by simply removing the android:allowBackup part at this line it would fix this issue. I will see if I can create a PR for this, but thought I would create the issue in the meantime until I get around to it.

This article gives some more background

Gradle 7 & JCenter

It doesn't seem to be possible to use this with Gradle 7 and Jcentre being depreciated.

Can you explain how it works setDays and setOffset?

In my case, I need to set currentDate as endDate and total no. of days are 14.

So as per today, 16-03-2019 is last date (end date) and 02-03-2019 will be starting date.

I think it will be done using setDays with setOffset.

Can you please elaborate how it works?

DatePickerListener

Error-
Inconvertible types; cannot cast 'anonymous android.view.View.OnClickListener' to 'com.github.jhonnyx2012.horizontalpicker.DatePickerListener'

when I click alt+ enter it gives
-Introduce Local Variable
-merge sequential method calls into call chain

Need some information +possible bug.

I want to be able to deselect programmatically, is this possible today?

A other thing is that you cannot select first day of the calendar if its the first thing you want to select. Is that normal?

Unable to change colors

Besides the background color, whenever I try changing the color of any of the entities, it still remains default grey. Below is the code.

picker
.setListener(this)
.setDateSelectedColor(Color.WHITE)
.setDateSelectedTextColor(Color.WHITE)
.setMonthAndYearTextColor(Color.WHITE)
.setTodayDateBackgroundColor(Color.GRAY)
.setUnselectedDayTextColor(Color.WHITE)
.setDayOfWeekTextColor(Color.WHITE)
.setUnselectedDayTextColor(Color.WHITE)
.init();

Any suggestions?

Issue while using on Kotlin

I m getting following issue after selecting a date

                                                             java.lang.NullPointerException: Attempt to invoke virtual method 'void devs.mulham.horizontalcalendar.utils.HorizontalCalendarListener.onDateSelected(java.util.Calendar, int)' on a null object reference
                                                                 at devs.mulham.horizontalcalendar.utils.HorizontalSnapHelper.notifyCalendarListener(HorizontalSnapHelper.java:46)
                                                                 at devs.mulham.horizontalcalendar.utils.HorizontalSnapHelper.findSnapView(HorizontalSnapHelper.java:37)
                                                                 at android.support.v7.widget.SnapHelper.snapToTargetExistingView(SnapHelper.java:191)
                                                                 at android.support.v7.widget.SnapHelper$1.onScrollStateChanged(SnapHelper.java:53)
                                                                 at android.support.v7.widget.RecyclerView.dispatchOnScrollStateChanged(RecyclerView.java:4759)
                                                                 at android.support.v7.widget.RecyclerView.setScrollState(RecyclerView.java:1434)
                                                                 at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:4908)
                                                                 at android.view.Choreographer$CallbackRecord.run(Choreographer.java:773)
                                                                 at android.view.Choreographer.doCallbacks(Choreographer.java:586)
                                                                 at android.view.Choreographer.doFrame(Choreographer.java:555)
                                                                 at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:759)
                                                                 at android.os.Handler.handleCallback(Handler.java:739)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                 at android.os.Looper.loop(Looper.java:135)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:5422)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at java.lang.reflect.Method.invoke(Method.java:372)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)

Change DEFAULT_DAYS_TO_PLUS

Hello

In your description we have: Configurable number of generated days (default: 120).

How can chage this value?

visibility gone and hide issue.

visibility gone and visible is not working. when i set visibility visible of picker it show unrecognized string instead of showing dates. can you fix it immediately??

Internationalization

Dude this needs to be in English, it's great. Can you do it yourself? I can help with that if you need it :)

Also, 'horizontal picker' is not really a good name, it might collide with other number pickers (trust me, I know) - consider changing to horizontal 'date' picker.

Cheers

Bad appearance in dialog

Picker looks not the way it should in my dialog. Have no idea why. Hope you'll see this message and try to solve it.
fczycrm8fka

MainActivity.class

package tyan.hainee.datepicker;

import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.github.jhonnyx2012.horizontalpicker.HorizontalPicker;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        View dialogView = getLayoutInflater().inflate(R.layout.dialog, null);

        HorizontalPicker dialogPicker = (HorizontalPicker) dialogView.findViewById(R.id.date_picker);
        dialogPicker.init();

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(dialogView);
        final AlertDialog dialog = builder.create();

        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.show();
            }
        });
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="tyan.hainee.datepicker.MainActivity"
    android:orientation="vertical"
    android:padding="16dp">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="DIALOG"/>
</LinearLayout>

dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:padding="16dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <com.github.jhonnyx2012.horizontalpicker.HorizontalPicker
        android:id="@+id/date_picker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

styles.xml

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>

View Previous Months/Dates

Is there any way to configure the datepicker so that you can scroll through past months/dates? Right now, mine starts on the current month and lets you scroll forward but not back, however, I need to make it so that you can scroll back and look at entries made on earlier dates.

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.