Coder Social home page Coder Social logo

bottomsheetpickers's Introduction

BottomSheetPickers

BottomSheetPickers is a set of new time pickers for Android that can be used in place of the stock time picker. As seen in my Clock+ app.

Number Pad

Grid Picker

Support for API level 14 and up. This library is based on code from the following AOSP repositories:

Installation

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

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

Usage

You must be using the support library version of Activity or Fragment to use this library properly. The pickers are indirect subclasses of android.support.v4.app.DialogFragment.

Implement BottomSheetTimePickerDialog.OnTimeSetListener in your Activity or Fragment:

@Override
public void onTimeSet(ViewGroup viewGroup, int hourOfDay, int minute) {
    // Do something with the time.
}

Then create an instance of your desired time picker dialog and show() it.

NumberPadTimePickerDialog dialog = NumberPadTimePickerDialog.newInstance(
    MainActivity.this  // your implementation of OnTimeSetListener
);
dialog.show(getSupportFragmentManager(), TAG);
Calendar now = Calendar.getInstance();
GridTimePickerDialog dialog = GridTimePickerDialog.newInstance(
    MainActivity.this,  // your implementation of OnTimeSetListener
    now.get(Calendar.HOUR_OF_DAY),
    now.get(Calendar.MINUTE),
    DateFormat.is24HourFormat(MainActivity.this));
dialog.show(getSupportFragmentManager(), TAG);

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) takes precedence over the value specified in XML.

FAQ

Why is the library named BottomSheetPickers if it only has time pickers? Will there be more pickers in the future other than for time (e.g. date picker)?

My original plan was to release only time pickers, but then I figured the library should have a matching date picker. So I refactored the package structure to accommodate the addition, as well as renamed the library to the more general BottomSheetPickers. However, as of October 2016, a date picker is not a priority feature. Though in case of future developments, I left the packages and library name as general as possible.

Why isn't the date picker a priority feature?

In my opinion, there's not much to improve on the stock date picker; the interaction with a bottom sheet date picker would feel almost the same as the stock date picker. Additionally, I would want to retain the general look and feel of the stock date picker, but the latest style seen in the Material Design spec and introduced in Android 6.0 is not reflected in the AOSP datetimepicker repository.

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

philliphsu avatar

Watchers

 avatar

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.