Skip to content

Commit 66cd7f3

Browse files
committed
edit design & add control
1 parent e5e7e24 commit 66cd7f3

14 files changed

Lines changed: 212 additions & 60 deletions

File tree

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77
minSdkVersion 19
88
targetSdkVersion 28
99
versionCode 1
10-
versionName "1.0"
10+
versionName "1.0.0"
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
}
1313
buildTypes {

app/src/main/java/com/spisoft/spspersiandatetimepicker/MainActivity.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ public void onClick(View v) {
4848
datePickerDialog.show(getFragmentManager(), "MyTag");
4949
}
5050
});
51+
52+
textView.setOnLongClickListener(new View.OnLongClickListener() {
53+
@Override
54+
public boolean onLongClick(View v) {
55+
PersianCalendar persianCalendar0 = new PersianCalendar();
56+
textView.setText(persianCalendar0.getPersianShortDate());
57+
return false;
58+
}
59+
});
5160
}
5261

5362
@Override
@@ -56,6 +65,12 @@ public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayO
5665
textView.setText(mDate);
5766
}
5867

68+
@Override
69+
public void onDateSet(DatePickerDialog view, String year, String monthOfYear, String dayOfMonth) {
70+
String mDate = year + "/" + monthOfYear + "/" + dayOfMonth;
71+
textView.setText(mDate);
72+
}
73+
5974
@Override
6075
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
6176
String mDate = year + "/" + (month+1) + "/" + dayOfMonth;

persiandatetimepicker/src/main/java/com/spisoft/persiandatetimepicker/date/DatePickerDialog.java

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
* Dialog allowing users to select a date.
5555
*/
5656
public 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);

persiandatetimepicker/src/main/java/com/spisoft/persiandatetimepicker/utils/PersianCalendar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public String getPersianLongDate() {
158158
*/
159159
public String getPersianShortDate() {
160160
return "" + formatToMilitary(this.persianYear) + delimiter
161-
+ formatToMilitary(getPersianMonth()) + delimiter
161+
+ formatToMilitary(this.persianMonth+1) + delimiter
162162
+ formatToMilitary(this.persianDay);
163163
}
164164

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2013 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
17+
18+
<item android:state_pressed="true" android:color="@color/mdtp_yellow"/>
19+
<item android:state_pressed="false" android:state_selected="true" android:color="@color/mdtp_yellow_2"/>
20+
<item android:state_pressed="false" android:state_selected="false"
21+
android:color="@color/mdtp_accent_color_focused_yellow"/>
22+
23+
</selector>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (C) 2013 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<LinearLayout
18+
xmlns:android="http://schemas.android.com/apk/res/android"
19+
android:layoutDirection="ltr"
20+
android:layout_width="match_parent"
21+
android:layout_height="@dimen/mdtp_date_picker_component_width"
22+
android:background="@color/mdtp_date_picker_view_animator"
23+
android:gravity="center"
24+
android:orientation="horizontal" >
25+
26+
<include layout="@layout/mdtp_date_picker_view_animator" />
27+
28+
<LinearLayout
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:orientation="vertical">
32+
33+
<include layout="@layout/mdtp_date_picker_selected_date" />
34+
35+
<include layout="@layout/mdtp_done_button" />
36+
37+
</LinearLayout>
38+
39+
</LinearLayout>

persiandatetimepicker/src/main/res/layout/mdtp_date_picker_dialog.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
-->
1717
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
1818
android:layout_width="@dimen/mdtp_date_picker_component_width"
19+
android:layoutDirection="ltr"
1920
android:layout_height="match_parent"
2021
android:background="@color/mdtp_date_picker_view_animator"
2122
android:gravity="center"

persiandatetimepicker/src/main/res/layout/mdtp_date_picker_selected_date.xml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,43 @@
2727

2828
<com.spisoft.persiandatetimepicker.AccessibleLinearLayout
2929
android:id="@+id/date_picker_month_and_day"
30-
android:layout_width="match_parent"
30+
android:layout_width="wrap_content"
3131
android:layout_height="wrap_content"
3232
android:layout_gravity="center"
3333
android:clickable="true"
34-
android:orientation="vertical"
35-
android:textColor="@color/mdtp_date_picker_selector" >
34+
android:layoutDirection="ltr"
35+
android:orientation="horizontal"
36+
android:textColor="@color/mdtp_date_picker_selector">
3637

3738
<TextView
3839
android:id="@+id/date_picker_month"
39-
android:layout_width="match_parent"
40-
android:layout_height="wrap_content"
40+
android:layout_width="wrap_content"
41+
android:layout_height="match_parent"
4142
android:duplicateParentState="true"
42-
android:gravity="center_horizontal|bottom"
43+
android:gravity="center_vertical"
44+
android:layout_marginBottom="-10dip"
4345
android:includeFontPadding="false"
46+
android:paddingStart="10dp"
47+
android:paddingEnd="10dp"
4448
android:textColor="@color/mdtp_date_picker_selector"
4549
android:textSize="@dimen/mdtp_selected_date_month_size"
46-
tools:text="May"/>
50+
tools:text="May" />
4751

4852
<TextView
4953
android:id="@+id/date_picker_day"
50-
android:layout_width="match_parent"
51-
android:layout_height="wrap_content"
54+
android:layout_width="wrap_content"
55+
android:layout_height="78dp"
5256
android:layout_gravity="center"
53-
android:layout_marginBottom="-10dip"
5457
android:layout_marginTop="-10dip"
58+
android:layout_marginBottom="-10dip"
5559
android:duplicateParentState="true"
5660
android:gravity="center"
5761
android:includeFontPadding="false"
62+
android:paddingStart="10dp"
63+
android:paddingEnd="10dp"
5864
android:textColor="@color/mdtp_date_picker_selector"
5965
android:textSize="@dimen/mdtp_selected_date_day_size"
60-
tools:text="15"/>
66+
tools:text="15" />
6167
</com.spisoft.persiandatetimepicker.AccessibleLinearLayout>
6268

6369
<com.spisoft.persiandatetimepicker.AccessibleTextView
@@ -67,8 +73,9 @@
6773
android:layout_gravity="center"
6874
android:gravity="center_horizontal|top"
6975
android:includeFontPadding="false"
70-
android:textColor="@color/mdtp_date_picker_selector"
76+
android:textColor="@color/mdtp_date_picker_selector_2"
7177
android:textSize="@dimen/mdtp_selected_date_year_size"
7278
tools:text="2015" />
7379

80+
7481
</LinearLayout>

0 commit comments

Comments
 (0)