DialogFragments modeled after the 4.2 Alarm Clock TimePicker to improve UX for picking time, date, and numbers.
Try out the sample application on Google Play.
Android-BetterPickers is presented as an Android library project. A standalone JAR is not possible due to the theming capabilities offered by the DialogFragments.
You can include this project by referencing it as a library project in Eclipse or ant.
If you are a Maven user you can easily include the library by specifying it as a dependency:
<dependency>
<groupId>com.doomonafireball.betterpickers</groupId>
<artifactId>library</artifactId>
<version>1.0.0</version>
<type>apklib</type>
</dependency>
This project depends on Jake Wharton's ViewPagerIndicator
library. Details for
including this library are available here.
For a working implementation of this project see the sample/
folder.
-
Include the Android clock fonts in your
assets/fonts/
folder (create the folder if it doesn't already exist. You can find these fonts in thesample/assets/fonts/
folder.AndroidClockMono-Bold.ttf AndroidClockMono-Light.ttf AndroidClockMono-Thin.ttf
-
Implement the appropriate Handler callbacks:
public class MyActivity extends Activity implements DatePickerDialogFragment.DatePickerDialogHandler {
@Override public void onCreate(Bundle savedInstanceState) { // ... } @Override public void onDialogDateSet(int year, int monthOfYear, int dayOfMonth) { // Do something with your date! }
}
-
Use BetterPickerUtils to create a PickerDialog with a theme:
BetterPickerUtils.showDateEditDialog(getSupportFragmentManager(), R.style.BetterPickersDialogFragment);
For a demonstration of theming, see the sample/
folder.
You can use your own themes if you'd like to change certain attributes. BetterPickers currently allows for customization of the following attributes:
bpDialogBackground :: the drawable (preferably a 9-patch) used as a window background for the DialogFragment
bpTextColor :: the color (optionally state list) for all text in the DialogFragment
bpDeleteIcon :: the drawable (optionally state list) for the delete button
bpCheckIcon :: the drawable (optionally state list) for the check button in the DateDialogPicker
bpKeyBackground :: the drawable (optionally state list) for the keyboard buttons
bpButtonBackground :: the drawable (optionally state list) for the Set, Cancel, and Delete buttons
bpDividerColor :: the color used for the DialogFragment dividers
bpKeyboardIndicatorColor :: the color used for the ViewPagerIndicator on the DateDialogPicker
-
Create your own custom theme in
<style name="MyCustomBetterPickerTheme"> @drawable/custom_dialog_background @color/custom_text_color @drawable/ic_backspace_custom @drawable/ic_check_custom @drawable/key_background_custom @drawable/button_background_custom @color/custom_divider_color @color/custom_keyboard_indicator_color </style>styles.xml
: -
Instanstiate your
DialogFragment
using your custom theme:BetterPickerUtils.showNumberEditDialog(getSupportFragmentManager(), R.style.MyCustomBetterPickerTheme);
Feel free to contribute to BetterPickers.
If you've fixed a bug or have a feature you've added, just create a pull request.
If you've found a bug, want a new feature, or have other questions, file an issue. I'll try to answer as soon as I find the time.
Thanks to JakeWharton for his work on ViewPagerIndicator.
Thanks to OAK and WillowTree Apps for Maven assistance and possible future improvements.
Copyright 2013 Derek Brameyer
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.