项目作者: dewinjm

项目描述 :
Month and Year picker library for Android
高级语言: Java
项目地址: git://github.com/dewinjm/monthyear-picker.git
创建时间: 2018-03-20T13:34:20Z
项目社区:https://github.com/dewinjm/monthyear-picker

开源协议:Apache License 2.0

下载


Month and Year Picker

API
jitpack
Build Status

Month and Year picker library for Anndroid

Simple Picker With ranges Picker
Simple Picker With ranges Picker

Example

Show MonthYear-picker in a simple way

  1. int yearSelected;
  2. int monthSelected;
  3. //Set default values
  4. Calendar calendar = Calendar.getInstance();
  5. yearSelected = calendar.get(Calendar.YEAR);
  6. monthSelected = calendar.get(Calendar.MONTH);
  7. MonthYearPickerDialogFragment dialogFragment = MonthYearPickerDialogFragment
  8. .getInstance(monthSelected, yearSelected);
  9. dialogFragment.show(getSupportFragmentManager(), null);

Listening changes in values

  1. dialogFragment.setOnDateSetListener(new MonthYearPickerDialog.OnDateSetListener() {
  2. @Override
  3. public void onDateSet(int year, int monthOfYear) {
  4. // do something
  5. }
  6. });

Show with Ranges

Note: the values of the ranges are in milliseconds.

The monthOfYear value is 0 for the first month and the last is 11, (0 = January, 11= December).

  1. // Use the calendar for create ranges
  2. Calendar calendar = Calendar.getInstance();
  3. calendar.clear();
  4. calendar.set(2010, 0, 1); // Set minimum date to show in dialog
  5. long minDate = calendar.getTimeInMillis(); // Get milliseconds of the modified date
  6. calendar.clear();
  7. calendar.set(2018, 11, 31); // Set maximum date to show in dialog
  8. long maxDate = calendar.getTimeInMillis(); // Get milliseconds of the modified date
  9. // Create instance with date ranges values
  10. MonthYearPickerDialogFragment dialogFragment = MonthYearPickerDialogFragment
  11. .getInstance(monthSelected, yearSelected, minDate, maxDate);
  12. dialogFragment.show(getSupportFragmentManager(), null);

Custom title

By default the title will be the selected date. If you want to customize dialog title, add the additional custom title parameter:

  1. String customTitle = "Your Custom Title";
  2. MonthYearPickerDialogFragment dialogFragment = null;
  3. //Simple way
  4. dialogFragment = MonthYearPickerDialogFragment
  5. .getInstance(monthSelected, yearSelected, customTitle);
  6. // or with date ranges:
  7. dialogFragment = MonthYearPickerDialogFragment
  8. .getInstance(monthSelected, yearSelected, minDate, maxDate, customTitle);
  9. dialogFragment.show(getSupportFragmentManager(), null);

Month name format

By default the months names format will short. If you want to use a specific format , add the MonthFormat parameter:

  1. MonthFormat monthFormat = MonthFormat.LONG; //MonthFormat.LONG or MonthFormat.SHORT
  2. //Simple way
  3. dialogFragment = MonthYearPickerDialogFragment
  4. .getInstance(monthSelected, yearSelected, customTitle, monthFormat);
  5. //With date ranges:
  6. dialogFragment = MonthYearPickerDialogFragment
  7. .getInstance(monthSelected, yearSelected, minDate, maxDate, customTitle, monthFormat);

Accept specify Locale.

If you want to use a specific Locale , add the Locale parameter into the constructions:

  1. Locale locale = new Locale("en-US");
  2. //Simple way
  3. dialogFragment = MonthYearPickerDialogFragment
  4. .getInstance(monthSelected, yearSelected, customTitle, locale);
  5. //With date ranges:
  6. dialogFragment = MonthYearPickerDialogFragment
  7. .getInstance(monthSelected, yearSelected, minDate, maxDate, customTitle, locale);

Download

Add the repository to your project build.gradle:

  1. repositories {
  2. jcenter()
  3. maven {
  4. url "https://jitpack.io"
  5. }
  6. }

And add the library to your module build.gradle:

  1. dependencies {
  2. implementation 'com.github.dewinjm:monthyear-picker:1.0.2'
  3. }

License

  1. Copyright 2018 Dewin J. Martínez
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.