5454 * Dialog allowing users to select a date.
5555 */
5656public class DatePickerDialog extends DialogFragment implements
57- OnClickListener , DatePickerController {
57+ OnClickListener , DatePickerController {
5858
5959 private static final String TAG = "DatePickerDialog" ;
6060
@@ -78,7 +78,7 @@ public class DatePickerDialog extends DialogFragment implements
7878 private static final String KEY_THEME_DARK = "theme_dark" ;
7979 private static final String KEY_FONT_NAME = "font_name" ;
8080
81- private static final int DEFAULT_START_YEAR = 1350 ;
81+ private static final int DEFAULT_START_YEAR = 1300 ;
8282 private static final int DEFAULT_END_YEAR = 1450 ;
8383
8484 private static final int ANIMATION_DURATION = 300 ;
@@ -137,7 +137,9 @@ public interface OnDateSetListener {
137137 */
138138 void onDateSet (DatePickerDialog view , int year , int monthOfYear , int dayOfMonth );
139139
140- void onDateSet (DatePicker view , int year , int month , int dayOfMonth );
140+ void onDateSet (DatePickerDialog view , String year , String monthOfYear , String dayOfMonth );
141+
142+ void onDateSet (DatePicker view , int year , int month , int dayOfMonth );
141143 }
142144
143145 /**
@@ -178,12 +180,12 @@ public void onCreate(Bundle savedInstanceState) {
178180 super .onCreate (savedInstanceState );
179181 final Activity activity = getActivity ();
180182 activity .getWindow ().setSoftInputMode (
181- WindowManager .LayoutParams .SOFT_INPUT_STATE_ALWAYS_HIDDEN );
183+ WindowManager .LayoutParams .SOFT_INPUT_STATE_ALWAYS_HIDDEN );
182184 if (savedInstanceState != null ) {
183185 mPersianCalendar .setPersianDate (
184- savedInstanceState .getInt (KEY_SELECTED_YEAR ),
185- savedInstanceState .getInt (KEY_SELECTED_MONTH ),
186- savedInstanceState .getInt (KEY_SELECTED_DAY )
186+ savedInstanceState .getInt (KEY_SELECTED_YEAR ),
187+ savedInstanceState .getInt (KEY_SELECTED_MONTH ),
188+ savedInstanceState .getInt (KEY_SELECTED_DAY )
187189 );
188190 }
189191 }
@@ -229,6 +231,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
229231 mYearView = view .findViewById (R .id .date_picker_year );
230232 Button okButton = view .findViewById (R .id .ok );
231233 Button cancelButton = view .findViewById (R .id .cancel );
234+ Button todayButton = view .findViewById (R .id .today );
235+ todayButton .setTypeface (TypefaceHelper .get (activity , fontName ));
232236 okButton .setTypeface (TypefaceHelper .get (activity , fontName ));
233237 cancelButton .setTypeface (TypefaceHelper .get (activity , fontName ));
234238 if (mDayOfWeekTextView != null ) {
@@ -287,11 +291,33 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
287291 public void onClick (View v ) {
288292 tryVibrate ();
289293 if (mCallBack != null ) {
290- mCallBack .onDateSet (DatePickerDialog .this , mPersianCalendar .getPersianYear (),
291- mPersianCalendar .getPersianMonth (), mPersianCalendar .getPersianDay ());
294+ // mCallBack.onDateSet(DatePickerDialog.this, mPersianCalendar.getPersianYear(),
295+ // mPersianCalendar.getPersianMonth(), mPersianCalendar.getPersianDay());
296+
297+ mCallBack .onDateSet (DatePickerDialog .this , Padl (mPersianCalendar .getPersianYear (), 4 , '0' ),
298+ Padl (mPersianCalendar .getPersianMonth ()+1 ,2 ,'0' ), Padl (mPersianCalendar .getPersianDay (),2 ,'0' ));
292299 }
293300 dismiss ();
294301 }
302+
303+ public String Padl (int val , Integer len , char chr ) {
304+ String txt = String .valueOf (val );
305+ String _txt = txt .trim ();
306+ while (_txt .length () < len ){
307+ _txt = chr +_txt ;
308+ }
309+ return _txt ;
310+ }
311+ });
312+
313+ todayButton .setOnClickListener (new OnClickListener () {
314+ @ Override
315+ public void onClick (View v ) {
316+ PersianCalendar persianCal = new PersianCalendar ();
317+ MonthAdapter .CalendarDay day = new MonthAdapter .CalendarDay ();
318+ day .setDay (persianCal .getPersianYear (),persianCal .getPersianMonth (),persianCal .getPersianDay ());
319+ mDayPickerView .goTo (day ,false ,true ,true );
320+ }
295321 });
296322
297323
@@ -352,7 +378,7 @@ private void setCurrentView(final int viewIndex) {
352378 switch (viewIndex ) {
353379 case MONTH_AND_DAY_VIEW :
354380 ObjectAnimator pulseAnimator = Utils .getPulseAnimator (mMonthAndDayView , 0.9f ,
355- 1.05f );
381+ 1.05f );
356382 if (mDelayAnimation ) {
357383 pulseAnimator .setStartDelay (ANIMATION_DELAY );
358384 mDelayAnimation = false ;
@@ -386,7 +412,7 @@ private void setCurrentView(final int viewIndex) {
386412 pulseAnimator .start ();
387413
388414 String yearString = LanguageUtils .
389- getPersianNumbers (String .valueOf (mPersianCalendar .getPersianYear ()));
415+ getPersianNumbers (String .valueOf (mPersianCalendar .getPersianYear ()));
390416 mAnimator .setContentDescription (mYearPickerDescription + ": " + yearString );
391417 Utils .tryAccessibilityAnnounce (mAnimator , mSelectYear );
392418 break ;
@@ -399,24 +425,24 @@ private void updateDisplay(boolean announce) {
399425 }
400426
401427 mSelectedMonthTextView .setText (LanguageUtils .
402- getPersianNumbers (mPersianCalendar .getPersianMonthName ()));
428+ getPersianNumbers (mPersianCalendar .getPersianMonthName ()));
403429 mSelectedDayTextView .setText (LanguageUtils .
404- getPersianNumbers (String .valueOf (mPersianCalendar .getPersianDay ())));
430+ getPersianNumbers (String .valueOf (mPersianCalendar .getPersianDay ())));
405431 mYearView .setText (LanguageUtils .
406- getPersianNumbers (String .valueOf (mPersianCalendar .getPersianYear ())));
432+ getPersianNumbers (String .valueOf (mPersianCalendar .getPersianYear ())));
407433
408434 // Accessibility.
409435 long millis = mPersianCalendar .getTimeInMillis ();
410436 mAnimator .setDateMillis (millis );
411437 String monthAndDayText = LanguageUtils .getPersianNumbers (
412- mPersianCalendar .getPersianMonthName () + " " +
413- mPersianCalendar .getPersianDay ()
438+ mPersianCalendar .getPersianMonthName () + " " +
439+ mPersianCalendar .getPersianDay ()
414440 );
415441 mMonthAndDayView .setContentDescription (monthAndDayText );
416442
417443 if (announce ) {
418444 String fullDateText = LanguageUtils .
419- getPersianNumbers (mPersianCalendar .getPersianLongDate ());
445+ getPersianNumbers (mPersianCalendar .getPersianLongDate ());
420446 Utils .tryAccessibilityAnnounce (mAnimator , fullDateText );
421447 }
422448 }
@@ -444,7 +470,7 @@ public boolean isThemeDark() {
444470 public void setFirstDayOfWeek (int startOfWeek ) {
445471 if (startOfWeek < Calendar .SUNDAY || startOfWeek > Calendar .SATURDAY ) {
446472 throw new IllegalArgumentException ("Value must be between Calendar.SUNDAY and " +
447- "Calendar.SATURDAY" );
473+ "Calendar.SATURDAY" );
448474 }
449475 mWeekStart = startOfWeek ;
450476 if (mDayPickerView != null ) {
@@ -593,7 +619,7 @@ public void onClick(View v) {
593619 public void onYearSelected (int year ) {
594620 adjustDayInMonthIfNeeded (mPersianCalendar .getPersianMonth (), year );
595621 mPersianCalendar .setPersianDate (year , mPersianCalendar .getPersianMonth (),
596- mPersianCalendar .getPersianDay ());
622+ mPersianCalendar .getPersianDay ());
597623 updatePickers ();
598624 setCurrentView (MONTH_AND_DAY_VIEW );
599625 updateDisplay (true );
0 commit comments