From 66cd7f3304c7e29779f60820fe31888e4bc34248 Mon Sep 17 00:00:00 2001 From: SPSpisoft Date: Tue, 5 Nov 2019 00:49:51 +0330 Subject: [PATCH] edit design & add control --- .idea/vcs.xml | 6 ++ app/build.gradle | 2 +- .../MainActivity.java | 15 ++++ .../date/DatePickerDialog.java | 64 ++++++++++++----- .../utils/PersianCalendar.java | 2 +- .../res/color/mdtp_date_picker_selector_2.xml | 23 ++++++ .../layout-land/mdtp_date_picker_dialog.xml | 39 ++++++++++ .../res/layout/mdtp_date_picker_dialog.xml | 1 + .../layout/mdtp_date_picker_selected_date.xml | 31 ++++---- .../src/main/res/layout/mdtp_done_button.xml | 71 +++++++++++++------ .../src/main/res/values/colors.xml | 7 +- .../src/main/res/values/dimens.xml | 8 +-- .../src/main/res/values/strings.xml | 1 + .../src/main/res/values/styles.xml | 2 +- 14 files changed, 212 insertions(+), 60 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 persiandatetimepicker/src/main/res/color/mdtp_date_picker_selector_2.xml create mode 100644 persiandatetimepicker/src/main/res/layout-land/mdtp_date_picker_dialog.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index eb4b0c0..0777b4b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,7 +7,7 @@ android { minSdkVersion 19 targetSdkVersion 28 versionCode 1 - versionName "1.0" + versionName "1.0.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/com/spisoft/spspersiandatetimepicker/MainActivity.java b/app/src/main/java/com/spisoft/spspersiandatetimepicker/MainActivity.java index bb18335..ab41ef3 100644 --- a/app/src/main/java/com/spisoft/spspersiandatetimepicker/MainActivity.java +++ b/app/src/main/java/com/spisoft/spspersiandatetimepicker/MainActivity.java @@ -48,6 +48,15 @@ public void onClick(View v) { datePickerDialog.show(getFragmentManager(), "MyTag"); } }); + + textView.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + PersianCalendar persianCalendar0 = new PersianCalendar(); + textView.setText(persianCalendar0.getPersianShortDate()); + return false; + } + }); } @Override @@ -56,6 +65,12 @@ public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayO textView.setText(mDate); } + @Override + public void onDateSet(DatePickerDialog view, String year, String monthOfYear, String dayOfMonth) { + String mDate = year + "/" + monthOfYear + "/" + dayOfMonth; + textView.setText(mDate); + } + @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { String mDate = year + "/" + (month+1) + "/" + dayOfMonth; diff --git a/persiandatetimepicker/src/main/java/com/spisoft/persiandatetimepicker/date/DatePickerDialog.java b/persiandatetimepicker/src/main/java/com/spisoft/persiandatetimepicker/date/DatePickerDialog.java index ba4cb8b..8b62673 100644 --- a/persiandatetimepicker/src/main/java/com/spisoft/persiandatetimepicker/date/DatePickerDialog.java +++ b/persiandatetimepicker/src/main/java/com/spisoft/persiandatetimepicker/date/DatePickerDialog.java @@ -54,7 +54,7 @@ * Dialog allowing users to select a date. */ public class DatePickerDialog extends DialogFragment implements - OnClickListener, DatePickerController { + OnClickListener, DatePickerController { private static final String TAG = "DatePickerDialog"; @@ -78,7 +78,7 @@ public class DatePickerDialog extends DialogFragment implements private static final String KEY_THEME_DARK = "theme_dark"; private static final String KEY_FONT_NAME = "font_name"; - private static final int DEFAULT_START_YEAR = 1350; + private static final int DEFAULT_START_YEAR = 1300; private static final int DEFAULT_END_YEAR = 1450; private static final int ANIMATION_DURATION = 300; @@ -137,7 +137,9 @@ public interface OnDateSetListener { */ void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth); - void onDateSet(DatePicker view, int year, int month, int dayOfMonth); + void onDateSet(DatePickerDialog view, String year, String monthOfYear, String dayOfMonth); + + void onDateSet(DatePicker view, int year, int month, int dayOfMonth); } /** @@ -178,12 +180,12 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Activity activity = getActivity(); activity.getWindow().setSoftInputMode( - WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); + WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); if (savedInstanceState != null) { mPersianCalendar.setPersianDate( - savedInstanceState.getInt(KEY_SELECTED_YEAR), - savedInstanceState.getInt(KEY_SELECTED_MONTH), - savedInstanceState.getInt(KEY_SELECTED_DAY) + savedInstanceState.getInt(KEY_SELECTED_YEAR), + savedInstanceState.getInt(KEY_SELECTED_MONTH), + savedInstanceState.getInt(KEY_SELECTED_DAY) ); } } @@ -229,6 +231,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, mYearView = view.findViewById(R.id.date_picker_year); Button okButton = view.findViewById(R.id.ok); Button cancelButton = view.findViewById(R.id.cancel); + Button todayButton = view.findViewById(R.id.today); + todayButton.setTypeface(TypefaceHelper.get(activity, fontName)); okButton.setTypeface(TypefaceHelper.get(activity, fontName)); cancelButton.setTypeface(TypefaceHelper.get(activity, fontName)); if (mDayOfWeekTextView != null) { @@ -287,11 +291,33 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, public void onClick(View v) { tryVibrate(); if (mCallBack != null) { - mCallBack.onDateSet(DatePickerDialog.this, mPersianCalendar.getPersianYear(), - mPersianCalendar.getPersianMonth(), mPersianCalendar.getPersianDay()); +// mCallBack.onDateSet(DatePickerDialog.this, mPersianCalendar.getPersianYear(), +// mPersianCalendar.getPersianMonth(), mPersianCalendar.getPersianDay()); + + mCallBack.onDateSet(DatePickerDialog.this, Padl(mPersianCalendar.getPersianYear(), 4, '0'), + Padl(mPersianCalendar.getPersianMonth()+1,2,'0'), Padl(mPersianCalendar.getPersianDay(),2,'0')); } dismiss(); } + + public String Padl(int val, Integer len, char chr ) { + String txt = String.valueOf(val); + String _txt = txt.trim(); + while (_txt.length() < len){ + _txt = chr+_txt; + } + return _txt; + } + }); + + todayButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + PersianCalendar persianCal = new PersianCalendar(); + MonthAdapter.CalendarDay day = new MonthAdapter.CalendarDay(); + day.setDay(persianCal.getPersianYear(),persianCal.getPersianMonth(),persianCal.getPersianDay()); + mDayPickerView.goTo(day,false,true,true); + } }); @@ -352,7 +378,7 @@ private void setCurrentView(final int viewIndex) { switch (viewIndex) { case MONTH_AND_DAY_VIEW: ObjectAnimator pulseAnimator = Utils.getPulseAnimator(mMonthAndDayView, 0.9f, - 1.05f); + 1.05f); if (mDelayAnimation) { pulseAnimator.setStartDelay(ANIMATION_DELAY); mDelayAnimation = false; @@ -386,7 +412,7 @@ private void setCurrentView(final int viewIndex) { pulseAnimator.start(); String yearString = LanguageUtils. - getPersianNumbers(String.valueOf(mPersianCalendar.getPersianYear())); + getPersianNumbers(String.valueOf(mPersianCalendar.getPersianYear())); mAnimator.setContentDescription(mYearPickerDescription + ": " + yearString); Utils.tryAccessibilityAnnounce(mAnimator, mSelectYear); break; @@ -399,24 +425,24 @@ private void updateDisplay(boolean announce) { } mSelectedMonthTextView.setText(LanguageUtils. - getPersianNumbers(mPersianCalendar.getPersianMonthName())); + getPersianNumbers(mPersianCalendar.getPersianMonthName())); mSelectedDayTextView.setText(LanguageUtils. - getPersianNumbers(String.valueOf(mPersianCalendar.getPersianDay()))); + getPersianNumbers(String.valueOf(mPersianCalendar.getPersianDay()))); mYearView.setText(LanguageUtils. - getPersianNumbers(String.valueOf(mPersianCalendar.getPersianYear()))); + getPersianNumbers(String.valueOf(mPersianCalendar.getPersianYear()))); // Accessibility. long millis = mPersianCalendar.getTimeInMillis(); mAnimator.setDateMillis(millis); String monthAndDayText = LanguageUtils.getPersianNumbers( - mPersianCalendar.getPersianMonthName() + " " + - mPersianCalendar.getPersianDay() + mPersianCalendar.getPersianMonthName() + " " + + mPersianCalendar.getPersianDay() ); mMonthAndDayView.setContentDescription(monthAndDayText); if (announce) { String fullDateText = LanguageUtils. - getPersianNumbers(mPersianCalendar.getPersianLongDate()); + getPersianNumbers(mPersianCalendar.getPersianLongDate()); Utils.tryAccessibilityAnnounce(mAnimator, fullDateText); } } @@ -444,7 +470,7 @@ public boolean isThemeDark() { public void setFirstDayOfWeek(int startOfWeek) { if (startOfWeek < Calendar.SUNDAY || startOfWeek > Calendar.SATURDAY) { throw new IllegalArgumentException("Value must be between Calendar.SUNDAY and " + - "Calendar.SATURDAY"); + "Calendar.SATURDAY"); } mWeekStart = startOfWeek; if (mDayPickerView != null) { @@ -593,7 +619,7 @@ public void onClick(View v) { public void onYearSelected(int year) { adjustDayInMonthIfNeeded(mPersianCalendar.getPersianMonth(), year); mPersianCalendar.setPersianDate(year, mPersianCalendar.getPersianMonth(), - mPersianCalendar.getPersianDay()); + mPersianCalendar.getPersianDay()); updatePickers(); setCurrentView(MONTH_AND_DAY_VIEW); updateDisplay(true); diff --git a/persiandatetimepicker/src/main/java/com/spisoft/persiandatetimepicker/utils/PersianCalendar.java b/persiandatetimepicker/src/main/java/com/spisoft/persiandatetimepicker/utils/PersianCalendar.java index 548ee66..fa65918 100644 --- a/persiandatetimepicker/src/main/java/com/spisoft/persiandatetimepicker/utils/PersianCalendar.java +++ b/persiandatetimepicker/src/main/java/com/spisoft/persiandatetimepicker/utils/PersianCalendar.java @@ -158,7 +158,7 @@ public String getPersianLongDate() { */ public String getPersianShortDate() { return "" + formatToMilitary(this.persianYear) + delimiter - + formatToMilitary(getPersianMonth()) + delimiter + + formatToMilitary(this.persianMonth+1) + delimiter + formatToMilitary(this.persianDay); } diff --git a/persiandatetimepicker/src/main/res/color/mdtp_date_picker_selector_2.xml b/persiandatetimepicker/src/main/res/color/mdtp_date_picker_selector_2.xml new file mode 100644 index 0000000..8cb964c --- /dev/null +++ b/persiandatetimepicker/src/main/res/color/mdtp_date_picker_selector_2.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/persiandatetimepicker/src/main/res/layout-land/mdtp_date_picker_dialog.xml b/persiandatetimepicker/src/main/res/layout-land/mdtp_date_picker_dialog.xml new file mode 100644 index 0000000..446017e --- /dev/null +++ b/persiandatetimepicker/src/main/res/layout-land/mdtp_date_picker_dialog.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persiandatetimepicker/src/main/res/layout/mdtp_date_picker_dialog.xml b/persiandatetimepicker/src/main/res/layout/mdtp_date_picker_dialog.xml index 04acb71..2eaa094 100644 --- a/persiandatetimepicker/src/main/res/layout/mdtp_date_picker_dialog.xml +++ b/persiandatetimepicker/src/main/res/layout/mdtp_date_picker_dialog.xml @@ -16,6 +16,7 @@ --> + android:layoutDirection="ltr" + android:orientation="horizontal" + android:textColor="@color/mdtp_date_picker_selector"> + tools:text="May" /> + tools:text="15" /> + \ No newline at end of file diff --git a/persiandatetimepicker/src/main/res/layout/mdtp_done_button.xml b/persiandatetimepicker/src/main/res/layout/mdtp_done_button.xml index 9df2c9a..83815e4 100644 --- a/persiandatetimepicker/src/main/res/layout/mdtp_done_button.xml +++ b/persiandatetimepicker/src/main/res/layout/mdtp_done_button.xml @@ -13,31 +13,62 @@ See the License for the specific language governing permissions and limitations under the License. --> - + android:layout_gravity="center_vertical"> -