项目作者: koji-1009

项目描述 :
Time picker dialog preference and Date picker dialog preference.
高级语言: Java
项目地址: git://github.com/koji-1009/ChronoDialogPreference.git
创建时间: 2018-09-30T02:47:11Z
项目社区:https://github.com/koji-1009/ChronoDialogPreference

开源协议:MIT License

下载


ChronoDialogPreference

Time picker dialog preference and Date picker dialog preference.

Gradle

NOTE: 2.x only supports Jetpack. If you use appcompat 1.x which is almost stable is the way to go.

Step1. Add it in your root build.gradle at the end of repositories:

  1. allprojects {
  2. repositories {
  3. maven { url 'https://jitpack.io' } // Add this line
  4. }
  5. }

Step2. Add the dependency

  1. dependencies {
  2. implementation 'com.github.koji-1009:ChronoDialogPreference:x.y.z'
  3. }

How to use

Add TimeDialogPreference or DateDialogPreference to your preference’s xml. See demo app.

  1. <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:app="http://schemas.android.com/apk/res-auto">
  3. <com.dr1009.app.chronodialogpreference.TimeDialogPreference
  4. android:defaultValue="01:10"
  5. android:key="test1"
  6. android:title="Time Test"
  7. app:customFormat="HH-MM" // (optional) custom SimpleDateFormat pattern instead of system default
  8. app:force12HourMode="true" // (optional) force 12 hour mode (AM/PM) instead of system default
  9. app:force24HourMode="false" ></com.dr1009.app.chronodialogpreference.TimeDialogPreference> // (optional) force 24 hour mode (not AM/PM) instead of system default
  10. <com.dr1009.app.chronodialogpreference.DateDialogPreference
  11. android:defaultValue="2000.1.1"
  12. android:key="test2"
  13. android:title="Date Test"
  14. app:customFormat="dd.MM.yyyy" // (optional) custom SimpleDateFormat pattern instead of system default
  15. app:maxDate="2020-1-1" // (optional) set Max Date to select on Calendar
  16. app:minDate="1970-1-1" ></com.dr1009.app.chronodialogpreference.DateDialogPreference> // (optional) set Min Date to select on Calendar
  17. </PreferenceScreen>

Then, extend ‘ChronoPreferenceFragment’ instead of ‘PreferenceFragment’.

  1. class SettingsFragment : ChronoPreferenceFragment() {
  2. override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
  3. setPreferencesFromResource(R.xml.pref_chrono, rootKey)
  4. }
  5. }

License

  1. MIT License
  2. Copyright (c) 2018-2019 Koji Wakamiya, Serhii Yolkin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.