Skip to content

Commit

Permalink
edit design & add control
Browse files Browse the repository at this point in the history
  • Loading branch information
SPSpisoft committed Nov 4, 2019
1 parent e5e7e24 commit 66cd7f3
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 60 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
versionName "1.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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)
);
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
});


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true" android:color="@color/mdtp_yellow"/>
<item android:state_pressed="false" android:state_selected="true" android:color="@color/mdtp_yellow_2"/>
<item android:state_pressed="false" android:state_selected="false"
android:color="@color/mdtp_accent_color_focused_yellow"/>

</selector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layoutDirection="ltr"
android:layout_width="match_parent"
android:layout_height="@dimen/mdtp_date_picker_component_width"
android:background="@color/mdtp_date_picker_view_animator"
android:gravity="center"
android:orientation="horizontal" >

<include layout="@layout/mdtp_date_picker_view_animator" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<include layout="@layout/mdtp_date_picker_selected_date" />

<include layout="@layout/mdtp_done_button" />

</LinearLayout>

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/mdtp_date_picker_component_width"
android:layoutDirection="ltr"
android:layout_height="match_parent"
android:background="@color/mdtp_date_picker_view_animator"
android:gravity="center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,43 @@

<com.spisoft.persiandatetimepicker.AccessibleLinearLayout
android:id="@+id/date_picker_month_and_day"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="true"
android:orientation="vertical"
android:textColor="@color/mdtp_date_picker_selector" >
android:layoutDirection="ltr"
android:orientation="horizontal"
android:textColor="@color/mdtp_date_picker_selector">

<TextView
android:id="@+id/date_picker_month"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:duplicateParentState="true"
android:gravity="center_horizontal|bottom"
android:gravity="center_vertical"
android:layout_marginBottom="-10dip"
android:includeFontPadding="false"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textColor="@color/mdtp_date_picker_selector"
android:textSize="@dimen/mdtp_selected_date_month_size"
tools:text="May"/>
tools:text="May" />

<TextView
android:id="@+id/date_picker_day"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_height="78dp"
android:layout_gravity="center"
android:layout_marginBottom="-10dip"
android:layout_marginTop="-10dip"
android:layout_marginBottom="-10dip"
android:duplicateParentState="true"
android:gravity="center"
android:includeFontPadding="false"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textColor="@color/mdtp_date_picker_selector"
android:textSize="@dimen/mdtp_selected_date_day_size"
tools:text="15"/>
tools:text="15" />
</com.spisoft.persiandatetimepicker.AccessibleLinearLayout>

<com.spisoft.persiandatetimepicker.AccessibleTextView
Expand All @@ -67,8 +73,9 @@
android:layout_gravity="center"
android:gravity="center_horizontal|top"
android:includeFontPadding="false"
android:textColor="@color/mdtp_date_picker_selector"
android:textColor="@color/mdtp_date_picker_selector_2"
android:textSize="@dimen/mdtp_selected_date_year_size"
tools:text="2015" />


</LinearLayout>
Loading

0 comments on commit 66cd7f3

Please sign in to comment.