GithubHelp home page GithubHelp logo

immortalz / bottomsheetpickers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from philliphsu/bottomsheetpickers

2.0 1.0 1.0 1.24 MB

Third-party date and time pickers for Android.

License: Apache License 2.0

Java 100.00%

bottomsheetpickers's Introduction

BottomSheetPickers

[ Download ] (https://bintray.com/philliphsu/maven/bottom-sheet-pickers/_latestVersion)

BottomSheetPickers is a library of new date and time pickers for Android, supporting API level 14 and up.

Date Picker

Time Pickers

Number Pad

Grid Picker

Installation

Add the following dependency to your module's build.gradle:

dependencies {
  compile 'com.philliphsu:bottomsheetpickers:2.0.0'
}

Usage

You must be using a android.support.v4.app.FragmentActivity or android.support.v4.app.Fragment. The pickers are indirect subclasses of android.support.v4.app.DialogFragment.

Implement callbacks

To retrieve the date or time set in the pickers, implement an appropriate callback interface.

  • com.philliphsu.bottomsheetpickers.date.DatePickerDialog.OnDateSetListener
  • BottomSheetTimePickerDialog.OnTimeSetListener
@Override
public void onDateSet(DatePickerDialog dialog, int year, int monthOfYear, int dayOfMonth) {
    Calendar cal = new java.util.GregorianCalendar();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, monthOfYear);
    cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    mText.setText("Date set: " + DateFormat.getDateFormat(this).format(cal.getTime()));
}

@Override
public void onTimeSet(ViewGroup viewGroup, int hourOfDay, int minute) {
    Calendar cal = new java.util.GregorianCalendar();
    cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
    cal.set(Calendar.MINUTE, minute);
    mText.setText("Time set: " + DateFormat.getTimeFormat(this).format(cal.getTime()));
}

Create your desired picker

Calendar now = Calendar.getInstance();
BottomSheetDatePickerDialog date = BottomSheetDatePickerDialog.newInstance(
    MainActivity.this,
    now.get(Calendar.YEAR),
    now.get(Calendar.MONTH),
    now.get(Calendar.DAY_OF_MONTH));

NumberPadTimePickerDialog pad = NumberPadTimePickerDialog.newInstance(MainActivity.this);

GridTimePickerDialog grid = GridTimePickerDialog.newInstance(
    MainActivity.this,
    now.get(Calendar.HOUR_OF_DAY),
    now.get(Calendar.MINUTE),
    DateFormat.is24HourFormat(MainActivity.this));

Show the dialog

Pass in a android.support.v4.app.FragmentManager to the dialog's show().

// For a `android.support.v4.app.FragmentActivity`:
dialog.show(getSupportFragmentManager(), TAG);

// For a `android.support.v4.app.Fragment`:
dialog.show(getFragmentManager(), TAG);

NOTE: Currently, BottomSheetDatePickerDialog cannot be dismissed by swiping the sheet down. This is to allow vertical swiping to scroll the date picker. Touching outside of the sheet also does not dismiss it. It is dismissed normally when you confirm your date selection.

Theming

The pickers automatically use your current theme's colorAccent defined in your styles.xml.

You can specify whether to use a light (default) or dark theme:

  • in code with the dialog's setThemeDark(boolean dark) method. Call this before show()ing the dialog.
  • in styles.xml by specifying a boolean value for the attribute themeDark in your theme.
<item name="themeDark">true</item>

NOTE: setThemeDark(boolean dark) overwrites the value specified in XML.

Attribution

This library is based on code from the following AOSP repositories:

License

Copyright 2016 Phillip Hsu

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.

bottomsheetpickers's People

Contributors

fleker avatar philliphsu avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

repoforks

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.