diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index ec7ce5f..749c2fb 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/README.md b/README.md index 123bfd2..a5eb2e6 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ Step 1. Add the JitPack repository to your build file. Add it in your root build ```groovy allprojects { repositories { - ... maven { url "https://jitpack.io" } } } diff --git a/app/build.gradle b/app/build.gradle index 04bc374..f2971b0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,7 +4,7 @@ android { compileSdkVersion 27 defaultConfig { applicationId "com.sardari.persianrangedatepicker" - minSdkVersion 16 + minSdkVersion 17 targetSdkVersion 27 versionCode 1 versionName "1.0" diff --git a/app/src/androidTest/java/com/sardari/ali/persianrangedatepicker/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/sardari/ali/persianrangedatepicker/ExampleInstrumentedTest.java deleted file mode 100644 index 3cd1644..0000000 --- a/app/src/androidTest/java/com/sardari/ali/persianrangedatepicker/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.sardari.ali.persianrangedatepicker; - -import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("com.sardari.ali.persianrangedatepicker", appContext.getPackageName()); - } -} diff --git a/app/src/main/java/com/sardari/ali/persianrangedatepicker/MainActivity.java b/app/src/main/java/com/sardari/ali/persianrangedatepicker/MainActivity.java index 0918ce2..a5ead07 100644 --- a/app/src/main/java/com/sardari/ali/persianrangedatepicker/MainActivity.java +++ b/app/src/main/java/com/sardari/ali/persianrangedatepicker/MainActivity.java @@ -7,7 +7,7 @@ import android.widget.TextView; import com.sardari.daterangepicker.customviews.DateRangeCalendarView; -import com.sardari.daterangepicker.dialog_fragment.DatePickerDialog; +import com.sardari.daterangepicker.dialog.DatePickerDialog; import com.sardari.daterangepicker.utils.PersianCalendar; public class MainActivity extends AppCompatActivity { @@ -31,32 +31,22 @@ private void initSingleDate() { btn_ShowDatePicker.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - ShowDatePicker(DateRangeCalendarView.SelectionMode.Range); + ShowDatePicker(DateRangeCalendarView.SelectionMode.None); } }); } private void ShowDatePicker(DateRangeCalendarView.SelectionMode selectionMode) { -// PersianCalendar today = new PersianCalendar(); -// -// PersianCalendar persianCalendar_Max = (PersianCalendar) today.clone(); -// persianCalendar_Max.setPersianYear(today.getPersianYear() + 1); - DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this); -// datePickerDialog.setTypeface(FontUtils.Default()); - datePickerDialog.setCalendarType(DateRangeCalendarView.CalendarType.Persian); - datePickerDialog.setSelectionMode(selectionMode); - datePickerDialog.setSelectableDaysCount(5); +// datePickerDialog.setCalendarType(DateRangeCalendarView.CalendarType.Persian); +// datePickerDialog.setSelectionMode(selectionMode); +// datePickerDialog.setSelectableDaysCount(5); datePickerDialog.setCanceledOnTouchOutside(true); -// datePickerDialog.setCurrentDate(today); -// datePickerDialog.setMinDate(persianCalendar_Min); -// datePickerDialog.setMaxDate(persianCalendar_Max); - datePickerDialog.setOnRangeDateSelectedListener(new DatePickerDialog.OnRangeDateSelectedListener() { @Override public void onRangeDateSelected(PersianCalendar startDate, PersianCalendar endDate) { - txtStartDate.setText(startDate.getPersianShortDate()); - txtEndDate.setText(endDate.getPersianShortDate()); + txtStartDate.setText(startDate.getPersianShortDateTime()); + txtEndDate.setText(endDate.getPersianShortDateTime()); } }); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index aeda230..fd534e2 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -8,17 +8,17 @@ @@ -39,7 +39,7 @@ android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_marginLeft="10dp" - android:layout_marginTop="10dp" + android:layout_marginTop="50dp" android:text="انتخاب تاریخ" /> \ No newline at end of file diff --git a/app/src/test/java/com/sardari/ali/persianrangedatepicker/ExampleUnitTest.java b/app/src/test/java/com/sardari/ali/persianrangedatepicker/ExampleUnitTest.java deleted file mode 100644 index 008aa27..0000000 --- a/app/src/test/java/com/sardari/ali/persianrangedatepicker/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.sardari.ali.persianrangedatepicker; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/daterangepicker/build.gradle b/daterangepicker/build.gradle index 5236381..54b21f7 100644 --- a/daterangepicker/build.gradle +++ b/daterangepicker/build.gradle @@ -1,34 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' -group = 'com.github.persianrangedatepicker' // Maven Group ID for the artifact - -//apply plugin: 'com.github.kt3k.coveralls' - -//ext { -// bintrayRepo = 'maven' -// bintrayName = 'PersianRangeDatePicker' -// -// publishedGroupId = 'com.sardari' -// libraryName = 'PersianRangeDatePicker' -// artifact = 'PersianRangeDatePicker' -// -// libraryDescription = 'Persian Range Date Picker' -// -// siteUrl = 'https://github.com/ali-sardari/PersianRangeDatePicker' -// gitUrl = 'https://github.com/ali-sardari/PersianRangeDatePicker.git' -// -// libraryVersion = '0.1.3' -// -// developerId = 'ali-sardari' -// developerName = 'Ali Sardari' -// developerEmail = 'ali.sardari@yahoo.com' -// -// licenseName = 'The Apache Software License, Version 2.0' -// licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' -// allLicenses = ["Apache-2.0"] -//} - +group = 'com.github.persianrangedatepicker' android { compileSdkVersion 27 @@ -36,7 +9,7 @@ android { flavorDimensions "default" defaultConfig { - minSdkVersion 16 + minSdkVersion 17 targetSdkVersion 27 versionCode 1 versionName "1.0.1" @@ -47,122 +20,4 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:27.1.1' -} - -//--------------------------------------------------------------------- -//coveralls { -// jacocoReportPath = "${buildDir}/reports/coverage/debug/report.xml" -//} -// -//tasks.coveralls { -// dependsOn 'connectedAndroidTest' -// onlyIf { System.env.'CI' } -//} -// - -//apply plugin: 'com.github.dcendents.android-maven' -// -//group = publishedGroupId // Maven Group ID for the artifact -// -//install { -// repositories.mavenInstaller { -// // This generates POM.xml with proper parameters -// pom { -// project { -// packaging 'aar' -// groupId publishedGroupId -// artifactId artifact -// -// // Add your description here -// name libraryName -// description libraryDescription -// url siteUrl -// -// // Set your license -// licenses { -// license { -// name licenseName -// url licenseUrl -// } -// } -// developers { -// developer { -// id developerId -// name developerName -// email developerEmail -// } -// } -// scm { -// connection gitUrl -// developerConnection gitUrl -// url siteUrl -// -// } -// } -// } -// } -//} -// -//apply plugin: 'com.jfrog.bintray' -// -//version = libraryVersion -// -//if (project.hasProperty("android")) { // Android libraries -// task sourcesJar(type: Jar) { -// classifier = 'sources' -// from android.sourceSets.main.java.srcDirs -// } -// -// task javadoc(type: Javadoc) { -// source = android.sourceSets.main.java.srcDirs -// classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) -// } -//} else { // Java libraries -// task sourcesJar(type: Jar, dependsOn: classes) { -// classifier = 'sources' -// from sourceSets.main.allSource -// } -//} -// -//task javadocJar(type: Jar, dependsOn: javadoc) { -// classifier = 'javadoc' -// from javadoc.destinationDir -//} -// -//artifacts { -// archives javadocJar -// archives sourcesJar -//} -// -//// Bintray -//File localProps = project.rootProject.file('local.properties') -// -//if (localProps.exists()) { -// Properties properties = new Properties() -// properties.load(localProps.newDataInputStream()) -// -// bintray { -// user = properties.getProperty("bintray.user") -// key = properties.getProperty("bintray.apikey") -// -// configurations = ['archives'] -// pkg { -// repo = bintrayRepo -// name = bintrayName -// desc = libraryDescription -// websiteUrl = siteUrl -// vcsUrl = gitUrl -// licenses = allLicenses -// publish = true -// publicDownloadNumbers = true -// version { -// desc = libraryDescription -// gpg { -// sign = true //Determines whether to GPG sign the files. The default is false -// passphrase = properties.getProperty("bintray.gpg.password") -// //Optional. The passphrase for GPG signing' -// } -// } -// } -// } -//} \ No newline at end of file +} \ No newline at end of file diff --git a/daterangepicker/src/main/assets/fonts/Yekan.ttf b/daterangepicker/src/main/assets/fonts/Yekan.ttf deleted file mode 100644 index 3cd474a..0000000 Binary files a/daterangepicker/src/main/assets/fonts/Yekan.ttf and /dev/null differ diff --git a/daterangepicker/src/main/java/com/sardari/daterangepicker/customviews/DateRangeCalendarView.java b/daterangepicker/src/main/java/com/sardari/daterangepicker/customviews/DateRangeCalendarView.java index 1e41bdd..bff82fe 100644 --- a/daterangepicker/src/main/java/com/sardari/daterangepicker/customviews/DateRangeCalendarView.java +++ b/daterangepicker/src/main/java/com/sardari/daterangepicker/customviews/DateRangeCalendarView.java @@ -1,15 +1,12 @@ package com.sardari.daterangepicker.customviews; -import android.annotation.SuppressLint; -import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.GradientDrawable; -import android.os.Build; -import android.support.annotation.ColorInt; import android.support.v4.content.ContextCompat; +import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; @@ -20,8 +17,9 @@ import android.widget.TextView; import com.sardari.daterangepicker.R; -import com.sardari.daterangepicker.dialog_fragment.TimePickerDialog; +import com.sardari.daterangepicker.dialog.TimePickerDialog; import com.sardari.daterangepicker.models.DayContainer; +import com.sardari.daterangepicker.utils.FontUtils; import com.sardari.daterangepicker.utils.MyUtils; import com.sardari.daterangepicker.utils.PersianCalendar; @@ -29,13 +27,13 @@ import java.util.Calendar; import java.util.Locale; -import static com.sardari.daterangepicker.customviews.DateRangeCalendarView.SelectionMode.Multiple; import static com.sardari.daterangepicker.customviews.DateRangeCalendarView.SelectionMode.Range; import static com.sardari.daterangepicker.customviews.DateRangeCalendarView.SelectionMode.Single; public class DateRangeCalendarView extends LinearLayout { //region Fields private Context mContext; + private AttributeSet attrs; private LinearLayout llDaysContainer; private LinearLayout llTitleWeekContainer; private CustomTextView tvYearTitle; @@ -51,37 +49,17 @@ public class DateRangeCalendarView extends LinearLayout { private static final int STRIP_TYPE_LEFT = 1; private static final int STRIP_TYPE_RIGHT = 2; - private int weekColor; - private int titleColor; - private int rangeStripColor; - private int selectedDateCircleColor; - private int selectedDateColor, defaultDateColor, disableDateColor, rangeDateColor, holidayColor, headerColor, todayColor; + private int headerBackgroundColor, weekColor, rangeStripColor, selectedDateCircleColor, selectedDateColor, defaultDateColor, disableDateColor, rangeDateColor, holidayColor, todayColor; private boolean shouldEnabledTime = false; private float textSizeTitle, textSizeWeek, textSizeDate; private PersianCalendar selectedCal, date; //endregion //region Enum - public enum CalendarType { - Persian(1), - Gregorian(2); - - private final int value; - - CalendarType(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - } - public enum SelectionMode { Single(1), - Multiple(2), - Range(3), - None(4); + Range(2), + None(3); private final int value; @@ -98,110 +76,109 @@ public int getValue() { //region Constructor public DateRangeCalendarView(Context context) { super(context); - initView(context, null); + + this.mContext = context; + this.attrs = null; + + initView(); } public DateRangeCalendarView(Context context, AttributeSet attrs) { super(context, attrs); - initView(context, attrs); - } - public DateRangeCalendarView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - initView(context, attrs); - } + this.mContext = context; + this.attrs = attrs; - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public DateRangeCalendarView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - initView(context, attrs); + initView(); } - /** - * To initialize child views - * - * @param context - App context - * @param attributeSet - Attr set - */ - private void initView(Context context, AttributeSet attributeSet) { - mContext = context; - locale = context.getResources().getConfiguration().locale; - setAttributes(attributeSet); + private void initView() { + typeface = FontUtils.Default(mContext); + locale = mContext.getResources().getConfiguration().locale; - LayoutInflater layoutInflater = LayoutInflater.from(mContext); + setDefaultValues(); - LinearLayout mainView = (LinearLayout) layoutInflater.inflate(R.layout.layout_calendar_month, this, true); - llDaysContainer = mainView.findViewById(R.id.llDaysContainer); - llTitleWeekContainer = mainView.findViewById(R.id.llTitleWeekContainer); - tvYearTitle = mainView.findViewById(R.id.tvYearTitle); - tvYearGeorgianTitle = mainView.findViewById(R.id.tvYearGeorgianTitle); - imgVNavLeft = mainView.findViewById(R.id.imgVNavLeft); - imgVNavRight = mainView.findViewById(R.id.imgVNavRight); - - RelativeLayout rlHeaderCalendar = mainView.findViewById(R.id.rlHeaderCalendar); - rlHeaderCalendar.setBackgroundColor(headerColor); + setAttributes(); - setListeners(); - - if (isInEditMode()) { - return; - } - - drawCalendarForMonth(getCurrentMonth(new PersianCalendar())); - - setWeekTitleColor(weekColor); + init(); } - /** - * To parse attributes from xml layout to configure calendar views. - * - * @param attributeSet - Attribute set - */ - private void setAttributes(AttributeSet attributeSet) { + private void setDefaultValues() { textSizeTitle = getResources().getDimension(R.dimen.text_size_title); textSizeWeek = getResources().getDimension(R.dimen.text_size_week); textSizeDate = getResources().getDimension(R.dimen.text_size_date); + headerBackgroundColor = ContextCompat.getColor(mContext, R.color.headerBackgroundColor); + weekColor = ContextCompat.getColor(mContext, R.color.week_color); - titleColor = ContextCompat.getColor(mContext, R.color.title_color); - rangeStripColor = ContextCompat.getColor(mContext, R.color.range_bg_color); selectedDateCircleColor = ContextCompat.getColor(mContext, R.color.selected_date_circle_color); selectedDateColor = ContextCompat.getColor(mContext, R.color.selected_date_color); defaultDateColor = ContextCompat.getColor(mContext, R.color.default_date_color); - holidayColor = ContextCompat.getColor(mContext, R.color.holiday_date_color); - todayColor = ContextCompat.getColor(mContext, R.color.today_date_color); rangeDateColor = ContextCompat.getColor(mContext, R.color.range_date_color); disableDateColor = ContextCompat.getColor(mContext, R.color.disable_date_color); - headerColor = ContextCompat.getColor(mContext, R.color.header_color); + rangeStripColor = ContextCompat.getColor(mContext, R.color.range_bg_color); + holidayColor = ContextCompat.getColor(mContext, R.color.holiday_date_color); + todayColor = ContextCompat.getColor(mContext, R.color.today_date_color); + } -// if (attributeSet != null) { - TypedArray ta = mContext.obtainStyledAttributes(attributeSet, R.styleable.DateRangeCalendarView, 0, 0); + private void setAttributes() { + TypedArray ta = mContext.obtainStyledAttributes(attrs, R.styleable.DateRangeCalendarView, 0, 0); try { - weekColor = ta.getColor(R.styleable.DateRangeCalendarView_week_color, weekColor); - titleColor = ta.getColor(R.styleable.DateRangeCalendarView_title_color, titleColor); -// rangeStripColor = ta.getColor(R.styleable.DateRangeCalendarView_range_color, rangeStripColor); - selectedDateCircleColor = ta.getColor(R.styleable.DateRangeCalendarView_selected_date_circle_color, selectedDateCircleColor); shouldEnabledTime = ta.getBoolean(R.styleable.DateRangeCalendarView_enable_time_selection, false); + //text size textSizeTitle = ta.getDimension(R.styleable.DateRangeCalendarView_text_size_title, textSizeTitle); textSizeWeek = ta.getDimension(R.styleable.DateRangeCalendarView_text_size_week, textSizeWeek); textSizeDate = ta.getDimension(R.styleable.DateRangeCalendarView_text_size_date, textSizeDate); + //header color + headerBackgroundColor = ta.getColor(R.styleable.DateRangeCalendarView_header_background_color, headerBackgroundColor); + + //weekColor + weekColor = ta.getColor(R.styleable.DateRangeCalendarView_week_color, weekColor); + selectedDateCircleColor = ta.getColor(R.styleable.DateRangeCalendarView_selected_date_circle_color, selectedDateCircleColor); selectedDateColor = ta.getColor(R.styleable.DateRangeCalendarView_selected_date_color, selectedDateColor); defaultDateColor = ta.getColor(R.styleable.DateRangeCalendarView_default_date_color, defaultDateColor); rangeDateColor = ta.getColor(R.styleable.DateRangeCalendarView_range_date_color, rangeDateColor); disableDateColor = ta.getColor(R.styleable.DateRangeCalendarView_disable_date_color, disableDateColor); - headerColor = ta.getColor(R.styleable.DateRangeCalendarView_header_color, headerColor); + rangeStripColor = ta.getColor(R.styleable.DateRangeCalendarView_range_color, rangeStripColor); + holidayColor = ta.getColor(R.styleable.DateRangeCalendarView_holidayColor, holidayColor); + todayColor = ta.getColor(R.styleable.DateRangeCalendarView_todayColor, todayColor); - selectionMode = ta.getInt(R.styleable.DateRangeCalendarView_selectionMode, Single.getValue()); + selectionMode = ta.getInt(R.styleable.DateRangeCalendarView_selectionMode, selectionMode); + } catch (Exception e) { + Log.e("setAttributes", e.getMessage()); } finally { ta.recycle(); } -// } + } + + private void init() { + LayoutInflater layoutInflater = LayoutInflater.from(mContext); + + LinearLayout mainView = (LinearLayout) layoutInflater.inflate(R.layout.layout_calendar_month, this, true); + llDaysContainer = mainView.findViewById(R.id.llDaysContainer); + llTitleWeekContainer = mainView.findViewById(R.id.llTitleWeekContainer); + tvYearTitle = mainView.findViewById(R.id.tvYearTitle); + tvYearGeorgianTitle = mainView.findViewById(R.id.tvYearGeorgianTitle); + imgVNavLeft = mainView.findViewById(R.id.imgVNavLeft); + imgVNavRight = mainView.findViewById(R.id.imgVNavRight); + + RelativeLayout rlHeaderCalendar = mainView.findViewById(R.id.rlHeaderCalendar); + rlHeaderCalendar.setBackgroundColor(headerBackgroundColor); + + setListeners(); + + if (isInEditMode()) { + return; + } + + build(); } //endregion + //region Core //region NavigationClickListener & dayClickListener private void setListeners() { //region imgVNavLeft.setOnClickListener @@ -255,8 +232,13 @@ public void onClick(View view) { TimePickerDialog awesomeTimePickerDialog = new TimePickerDialog(mContext, mContext.getString(R.string.select_time), new TimePickerDialog.TimePickerCallback() { @Override public void onTimeSelected(int hours, int mins) { + PersianCalendar p = (PersianCalendar) selectedCal.clone(); + selectedCal.set(Calendar.HOUR, hours); selectedCal.set(Calendar.MINUTE, mins); + selectedCal.set(Calendar.SECOND, 0); + selectedCal.set(Calendar.MILLISECOND, 0); + selectedCal.setPersianDate(p.getPersianYear(), p.getPersianMonth(), p.getPersianDay()); if (calendarListener != null) { calendarListener.onDateSelected(selectedCal); @@ -278,9 +260,6 @@ public void onCancel() { //endregion } //endregion - } else if (selectionMode == Multiple.getValue()) { - //region SelectionMode.Multiple - //endregion } else if (selectionMode == Range.getValue()) { //region SelectionMode.Range if (minSelectedDate != null) { @@ -288,7 +267,9 @@ public void onCancel() { maxSelectedDate = selectedCal; drawSelectedDateRange(minSelectedDate, maxSelectedDate); } else { - MyUtils.getInstance().Toast(mContext, "تاریخ برگشت را وارد کنید"); + if (!TextUtils.isEmpty(getMessageEnterEndDate())) { + MyUtils.getInstance().Toast(mContext, getMessageEnterEndDate()); + } resetAllSelectedViews(); @@ -298,7 +279,9 @@ public void onCancel() { makeAsSelectedDate(container, 0); } } else { - MyUtils.getInstance().Toast(mContext, "تاریخ برگشت را وارد کنید"); + if (!TextUtils.isEmpty(getMessageEnterEndDate())) { + MyUtils.getInstance().Toast(mContext, getMessageEnterEndDate()); + } minSelectedDate = selectedCal; maxSelectedDate = null; @@ -311,10 +294,14 @@ public void onCancel() { TimePickerDialog awesomeTimePickerDialog = new TimePickerDialog(mContext, mContext.getString(R.string.select_time), new TimePickerDialog.TimePickerCallback() { @Override public void onTimeSelected(int hours, int mins) { + PersianCalendar p = (PersianCalendar) selectedCal.clone(); + selectedCal.set(Calendar.HOUR, hours); selectedCal.set(Calendar.MINUTE, mins); + selectedCal.set(Calendar.SECOND, 0); + selectedCal.set(Calendar.MILLISECOND, 0); + selectedCal.setPersianDate(p.getPersianYear(), p.getPersianMonth(), p.getPersianDay()); - Log.i("Tag", "Time: " + selectedCal.getTime().toString()); if (calendarListener != null && minSelectedDate != null && maxSelectedDate != null) { calendarListener.onDateRangeSelected(minSelectedDate, maxSelectedDate); } @@ -361,49 +348,46 @@ private PersianCalendar getCurrentMonth(PersianCalendar calendar) { * * @param month */ - @SuppressLint("SetTextI18n") private void drawCalendarForMonth(PersianCalendar month) { tvYearTitle.setText(String.format(locale, "%s %d", month.getPersianMonthName(), month.getPersianYear())); - Log.w("TAG", "DateRangeCalendarView_drawCalendarForMonth_358-> :" + month.getPersianMonth()); - int _month = month.getPersianMonth() + 1; switch (_month) { case 1: - tvYearGeorgianTitle.setText("March - April " + month.get(Calendar.YEAR)); + tvYearGeorgianTitle.setText(String.format(locale, "March - April %d", month.get(Calendar.YEAR))); break; case 2: - tvYearGeorgianTitle.setText("April - May " + month.get(Calendar.YEAR)); + tvYearGeorgianTitle.setText(String.format(locale, "April - May %d", month.get(Calendar.YEAR))); break; case 3: - tvYearGeorgianTitle.setText("May - June " + month.get(Calendar.YEAR)); + tvYearGeorgianTitle.setText(String.format(locale, "May - June %d", month.get(Calendar.YEAR))); break; case 4: - tvYearGeorgianTitle.setText("June - July " + month.get(Calendar.YEAR)); + tvYearGeorgianTitle.setText(String.format(locale, "June - July %d", month.get(Calendar.YEAR))); break; case 5: - tvYearGeorgianTitle.setText("July - August " + month.get(Calendar.YEAR)); + tvYearGeorgianTitle.setText(String.format(locale, "July - August %d", month.get(Calendar.YEAR))); break; case 6: - tvYearGeorgianTitle.setText("August - September " + month.get(Calendar.YEAR)); + tvYearGeorgianTitle.setText(String.format(locale, "August - September %d", month.get(Calendar.YEAR))); break; case 7: - tvYearGeorgianTitle.setText("September - October " + month.get(Calendar.YEAR)); + tvYearGeorgianTitle.setText(String.format(locale, "September - October %d", month.get(Calendar.YEAR))); break; case 8: - tvYearGeorgianTitle.setText("October - November " + month.get(Calendar.YEAR)); + tvYearGeorgianTitle.setText(String.format(locale, "October - November %d", month.get(Calendar.YEAR))); break; case 9: - tvYearGeorgianTitle.setText("November - December " + month.get(Calendar.YEAR)); + tvYearGeorgianTitle.setText(String.format(locale, "November - December %d", month.get(Calendar.YEAR))); break; case 10: tvYearGeorgianTitle.setText(String.format("December %s - January %s ", month.get(Calendar.YEAR), month.get(Calendar.YEAR) + 1)); break; case 11: - tvYearGeorgianTitle.setText("January - February " + month.get(Calendar.YEAR)); + tvYearGeorgianTitle.setText(String.format(locale, "January - February %d", month.get(Calendar.YEAR))); break; case 12: - tvYearGeorgianTitle.setText("February - March " + month.get(Calendar.YEAR)); + tvYearGeorgianTitle.setText(String.format(locale, "February - March %d", month.get(Calendar.YEAR))); break; } @@ -441,15 +425,8 @@ private void drawCalendarForMonth(PersianCalendar month) { * @param calendar - Calendar obj of specific date of the month. */ private void drawDayContainer(DayContainer container, PersianCalendar calendar) { - int date; - int dateGR; - if (calendarType == CalendarType.Persian.getValue()) { - date = calendar.getPersianDay(); - dateGR = calendar.get(Calendar.DATE); - } else { - date = calendar.getPersianDay(); - dateGR = calendar.get(Calendar.DATE); - } + int date = calendar.getPersianDay(); + int dateGR = calendar.get(Calendar.DATE); //---------------------------------------------------------------- if (currentCalendarMonth.getPersianMonth() != calendar.getPersianMonth()) { @@ -458,11 +435,11 @@ private void drawDayContainer(DayContainer container, PersianCalendar calendar) disableDayContainer(container); // container.tvDate.setText(String.valueOf(date)); - isToday(container, calendar); + setToday(container, calendar); } else { int key = DayContainer.GetContainerKey(calendar); - isToday(container, calendar); + setToday(container, calendar); if (selectedDatesRange.indexOf(key) == 0) { makeAsSelectedDate(container, STRIP_TYPE_LEFT); @@ -487,29 +464,24 @@ private void drawDayContainer(DayContainer container, PersianCalendar calendar) disableDayContainer(container); // container.tvDate.setText(String.valueOf(date)); } - } container.tvDate.setText(String.valueOf(date)); container.tvDateGeorgian.setText(String.valueOf(dateGR)); - + container.tvDateGeorgian.setVisibility(showGregorianDate ? VISIBLE : GONE); container.rootView.setTag(DayContainer.GetContainerKey(calendar)); } //--------------------------------------------------------------------------------------------- - private boolean isToday(DayContainer container, PersianCalendar persianCalendar) { - if (getCurrentDate().compareTo(persianCalendar) == 0) { + private void setToday(DayContainer container, PersianCalendar persianCalendar) { + if (getCurrentDate().getPersianShortDate().compareTo(persianCalendar.getPersianShortDate()) == 0) { container.imgEvent.setVisibility(VISIBLE); container.imgEvent.setColorFilter(todayColor, android.graphics.PorterDuff.Mode.SRC_IN); // container.tvDate.setTextColor(todayColor); container.tvDate.setTypeface(typeface, Typeface.BOLD); - - return true; } else { container.imgEvent.setVisibility(GONE); container.tvDate.setTypeface(typeface, Typeface.NORMAL); - - return false; } } @@ -720,40 +692,39 @@ public void resetAllSelectedViews() { } } - /** - * To set week title color - * - * @param color - resource color value - */ - public void setWeekTitleColor(@ColorInt int color) { - weekColor = color; + private void setWeekTitleColor() { for (int i = 0; i < llTitleWeekContainer.getChildCount(); i++) { CustomTextView textView = (CustomTextView) llTitleWeekContainer.getChildAt(i); - textView.setTextColor(color); + textView.setTextColor(weekColor); } } - /** - * To apply custom fonts to all the text views - * - * @param fonts - Typeface that you want to apply - */ - public void setFonts(Typeface fonts) { - this.typeface = fonts; - if (fonts != null) { + public void setTypeface(Typeface typeface) { + if (typeface != null) { + this.typeface = typeface; + drawCalendarForMonth(currentCalendarMonth); - tvYearTitle.setTypeface(fonts); + tvYearTitle.setTypeface(this.typeface); for (int i = 0; i < llTitleWeekContainer.getChildCount(); i++) { CustomTextView textView = (CustomTextView) llTitleWeekContainer.getChildAt(i); - textView.setTypeface(fonts); + textView.setTypeface(this.typeface); } } } + //endregion //--------------------------------------------------------------------------------------------- + //region Properties + public void build() { + + drawCalendarForMonth(getCurrentMonth(currentDate)); + + setWeekTitleColor(); + } + //region selectionMode -> Getter/Setter - private int selectionMode = SelectionMode.Single.getValue(); + private int selectionMode = SelectionMode.Range.getValue(); public int getSelectionMode() { return selectionMode; @@ -764,18 +735,6 @@ public void setSelectionMode(int selectionMode) { } //endregion - //region calendarType -> Getter/Setter - private int calendarType = CalendarType.Persian.getValue(); - - public int getCalendarType() { - return calendarType; - } - - public void setCalendarType(int calendarType) { - this.calendarType = calendarType; - } - //endregion - //region currentDate -> Getter/Setter private PersianCalendar currentDate = new PersianCalendar(); @@ -786,12 +745,12 @@ public PersianCalendar getCurrentDate() { public void setCurrentDate(PersianCalendar currentDate) { this.currentDate = currentDate; - if (currentDate != null) { - currentCalendarMonth = (PersianCalendar) currentDate.clone(); - currentCalendarMonth.setPersianDay(1); - - resetAllSelectedViews(); - } +// if (currentDate != null) { +// currentCalendarMonth = (PersianCalendar) currentDate.clone(); +// currentCalendarMonth.setPersianDay(1); +// +// resetAllSelectedViews(); +// } } //endregion @@ -831,27 +790,15 @@ public void setDisableDaysAgo(boolean disableDaysAgo) { } //endregion - //region messageEnterDate - String messageEnterDate; + //region showGregorianDate -> Default = false + private boolean showGregorianDate = false; - public String getMessageEnterDate() { - return messageEnterDate; + public boolean isShowGregorianDate() { + return showGregorianDate; } - public void setMessageEnterDate(String messageEnterDate) { - this.messageEnterDate = messageEnterDate; - } - //endregion - - //region messageEnterStartDate - String messageEnterStartDate; - - public String getMessageEnterStartDate() { - return messageEnterStartDate; - } - - public void setMessageEnterStartDate(String messageEnterStartDate) { - this.messageEnterStartDate = messageEnterStartDate; + public void setShowGregorianDate(boolean showGregorianDate) { + this.showGregorianDate = showGregorianDate; } //endregion @@ -865,8 +812,126 @@ public String getMessageEnterEndDate() { public void setMessageEnterEndDate(String messageEnterEndDate) { this.messageEnterEndDate = messageEnterEndDate; } + //endregion + //-------------------------------------------------------------------------------------------- + //region theme + public int getHeaderBackgroundColor() { + return headerBackgroundColor; + } + + public void setHeaderBackgroundColor(int headerBackgroundColor) { + this.headerBackgroundColor = headerBackgroundColor; + } + + public int getWeekColor() { + return weekColor; + } + + public void setWeekColor(int weekColor) { + this.weekColor = weekColor; + } + + public int getRangeStripColor() { + return rangeStripColor; + } + + public void setRangeStripColor(int rangeStripColor) { + this.rangeStripColor = rangeStripColor; + } + + public int getSelectedDateCircleColor() { + return selectedDateCircleColor; + } + + public void setSelectedDateCircleColor(int selectedDateCircleColor) { + this.selectedDateCircleColor = selectedDateCircleColor; + } + + public int getSelectedDateColor() { + return selectedDateColor; + } + + public void setSelectedDateColor(int selectedDateColor) { + this.selectedDateColor = selectedDateColor; + } + + public int getDefaultDateColor() { + return defaultDateColor; + } + + public void setDefaultDateColor(int defaultDateColor) { + this.defaultDateColor = defaultDateColor; + } + + public int getDisableDateColor() { + return disableDateColor; + } + + public void setDisableDateColor(int disableDateColor) { + this.disableDateColor = disableDateColor; + } + + public int getRangeDateColor() { + return rangeDateColor; + } + + public void setRangeDateColor(int rangeDateColor) { + this.rangeDateColor = rangeDateColor; + } + + public int getHolidayColor() { + return holidayColor; + } + + public void setHolidayColor(int holidayColor) { + this.holidayColor = holidayColor; + + setAttributes(); + } + + public int getTodayColor() { + return todayColor; + } + public void setTodayColor(int todayColor) { + this.todayColor = todayColor; + } + + public boolean isShouldEnabledTime() { + return shouldEnabledTime; + } + + public void setShouldEnabledTime(boolean shouldEnabledTime) { + this.shouldEnabledTime = shouldEnabledTime; + } + + public float getTextSizeTitle() { + return textSizeTitle; + } + + public void setTextSizeTitle(float textSizeTitle) { + this.textSizeTitle = textSizeTitle; + } + + public float getTextSizeWeek() { + return textSizeWeek; + } + + public void setTextSizeWeek(float textSizeWeek) { + this.textSizeWeek = textSizeWeek; + } + + public float getTextSizeDate() { + return textSizeDate; + } + + public void setTextSizeDate(float textSizeDate) { + this.textSizeDate = textSizeDate; + } + + //endregion + //-------------------------------------------------------------------------------------------- //region Listener -> Getter/Setter private CalendarListener calendarListener; @@ -878,6 +943,7 @@ public void setCalendarListener(CalendarListener calendarListener) { this.calendarListener = calendarListener; } //endregion + //endregion //-------------------------------------------------------------------------------------------- public interface CalendarListener { diff --git a/daterangepicker/src/main/java/com/sardari/daterangepicker/dialog_fragment/DatePickerDialog.java b/daterangepicker/src/main/java/com/sardari/daterangepicker/dialog/DatePickerDialog.java similarity index 78% rename from daterangepicker/src/main/java/com/sardari/daterangepicker/dialog_fragment/DatePickerDialog.java rename to daterangepicker/src/main/java/com/sardari/daterangepicker/dialog/DatePickerDialog.java index aa45d57..a2c7ece 100644 --- a/daterangepicker/src/main/java/com/sardari/daterangepicker/dialog_fragment/DatePickerDialog.java +++ b/daterangepicker/src/main/java/com/sardari/daterangepicker/dialog/DatePickerDialog.java @@ -1,15 +1,17 @@ -package com.sardari.daterangepicker.dialog_fragment; +package com.sardari.daterangepicker.dialog; import android.app.Dialog; import android.content.Context; import android.graphics.Typeface; import android.view.Gravity; import android.view.View; +import android.view.ViewGroup; import android.view.Window; import android.widget.Button; import com.sardari.daterangepicker.R; import com.sardari.daterangepicker.customviews.DateRangeCalendarView; +import com.sardari.daterangepicker.utils.FontUtils; import com.sardari.daterangepicker.utils.MyUtils; import com.sardari.daterangepicker.utils.PersianCalendar; @@ -21,6 +23,7 @@ public class DatePickerDialog extends Dialog { private DateRangeCalendarView calendar; private Button btn_Accept; private PersianCalendar date, startDate, endDate; + private Typeface typeface; //endregion public DatePickerDialog(Context context) { @@ -31,6 +34,8 @@ public DatePickerDialog(Context context) { if (getWindow() != null) getWindow().setGravity(Gravity.CENTER); + this.typeface = FontUtils.Default(mContext); + initView(); PersianCalendar today = new PersianCalendar(); @@ -42,11 +47,12 @@ private void initView() { setContentView(R.layout.dialog_date_picker); btn_Accept = findViewById(R.id.btn_Accept); - calendar = findViewById(R.id.calendar); +// calendar = findViewById(R.id.calendar); //endregion } public void showDialog() { + calendar = new DateRangeCalendarView(mContext); calendar.setCalendarListener(new DateRangeCalendarView.CalendarListener() { @Override public void onDateSelected(PersianCalendar _date) { @@ -100,27 +106,51 @@ public void onClick(View v) { } }); + calendar.setSelectionMode(selectionMode.getValue()); + calendar.setDisableDaysAgo(disableDaysAgo); + calendar.setTypeface(typeface); + calendar.setCurrentDate(currentDate); calendar.setMaxDate(maxDate); calendar.setMinDate(minDate); - calendar.setCurrentDate(currentDate); - calendar.setCalendarType(calendarType.getValue()); - calendar.setSelectionMode(selectionMode.getValue()); - calendar.setDisableDaysAgo(true); + calendar.setShowGregorianDate(showGregorianDate); + calendar.setShouldEnabledTime(false); + + calendar.build(); + + ViewGroup insertPoint = findViewById(R.id.content); + insertPoint.addView(calendar); + + + if (selectionMode.getValue() == DateRangeCalendarView.SelectionMode.None.getValue()) { + btn_Accept.setVisibility(View.GONE); + } this.show(); } //region Properties - //region Typeface -> Getter/Setter + //region DisableDaysAgo -> Default = True + private boolean disableDaysAgo = true; + + public boolean isDisableDaysAgo() { + return disableDaysAgo; + } + + public void setDisableDaysAgo(boolean disableDaysAgo) { + this.disableDaysAgo = disableDaysAgo; + } + //endregion + + //region Typeface -> Default = IranYekan public void setTypeface(Typeface typeface) { if (typeface != null) { - calendar.setFonts(typeface); + this.typeface = typeface; } } //endregion - //region SelectionMode -> Getter/Setter {Single(1),Multiple(2),Range(3),None(4)} - private DateRangeCalendarView.SelectionMode selectionMode = DateRangeCalendarView.SelectionMode.Single; + //region SelectionMode -> Default = Range | Enum -> {Single(1),Range(2),None(3)} + private DateRangeCalendarView.SelectionMode selectionMode = DateRangeCalendarView.SelectionMode.Range; public DateRangeCalendarView.SelectionMode getSelectionMode() { return selectionMode; @@ -134,22 +164,8 @@ public void setSelectionMode(DateRangeCalendarView.SelectionMode selectionMode) } //endregion - //region CalendarType -> Getter/Setter { Persian(1),Gregorian(2)} - private DateRangeCalendarView.CalendarType calendarType = DateRangeCalendarView.CalendarType.Persian; - - public DateRangeCalendarView.CalendarType getCalendarType() { - return calendarType; - } - - public void setCalendarType(DateRangeCalendarView.CalendarType calendarType) { - this.calendarType = calendarType; - - calendar.setCalendarType(calendarType.getValue()); - } - //endregion - - //region currentDate -> Getter/Setter - private PersianCalendar currentDate; + //region CurrentDate -> Default = Today + private PersianCalendar currentDate = new PersianCalendar(); public PersianCalendar getCurrentDate() { return currentDate; @@ -157,11 +173,10 @@ public PersianCalendar getCurrentDate() { public void setCurrentDate(PersianCalendar currentDate) { this.currentDate = currentDate; - calendar.setCurrentDate(currentDate); } //endregion - //region MinDate -> Getter/Setter + //region MinDate -> Default = Today private PersianCalendar minDate; public PersianCalendar getMinDate() { @@ -174,7 +189,7 @@ public void setMinDate(PersianCalendar minDate) { } //endregion - //region MaxDate -> Getter/Setter + //region MaxDate -> Default = Today + 1 year private PersianCalendar maxDate; public PersianCalendar getMaxDate() { @@ -187,15 +202,15 @@ public void setMaxDate(PersianCalendar maxDate) { } //endregion - //region SelectableDaysCount -> Getter/Setter - private int selectableDaysCount; + //region showGregorianDate -> Default = false + private boolean showGregorianDate = false; - public int getSelectableDaysCount() { - return selectableDaysCount; + public boolean isShowGregorianDate() { + return showGregorianDate; } - public void setSelectableDaysCount(int selectableDaysCount) { - this.selectableDaysCount = selectableDaysCount; + public void setShowGregorianDate(boolean showGregorianDate) { + this.showGregorianDate = showGregorianDate; } //endregion diff --git a/daterangepicker/src/main/java/com/sardari/daterangepicker/dialog_fragment/TimePickerDialog.java b/daterangepicker/src/main/java/com/sardari/daterangepicker/dialog/TimePickerDialog.java similarity index 98% rename from daterangepicker/src/main/java/com/sardari/daterangepicker/dialog_fragment/TimePickerDialog.java rename to daterangepicker/src/main/java/com/sardari/daterangepicker/dialog/TimePickerDialog.java index 433a7a6..2097a94 100644 --- a/daterangepicker/src/main/java/com/sardari/daterangepicker/dialog_fragment/TimePickerDialog.java +++ b/daterangepicker/src/main/java/com/sardari/daterangepicker/dialog/TimePickerDialog.java @@ -1,4 +1,4 @@ -package com.sardari.daterangepicker.dialog_fragment; +package com.sardari.daterangepicker.dialog; import android.app.Dialog; import android.content.Context; diff --git a/daterangepicker/src/main/java/com/sardari/daterangepicker/utils/FontUtils.java b/daterangepicker/src/main/java/com/sardari/daterangepicker/utils/FontUtils.java new file mode 100644 index 0000000..0fa4f35 --- /dev/null +++ b/daterangepicker/src/main/java/com/sardari/daterangepicker/utils/FontUtils.java @@ -0,0 +1,22 @@ +package com.sardari.daterangepicker.utils; + +import android.content.Context; +import android.graphics.Typeface; +import android.support.v4.util.SimpleArrayMap; + +public class FontUtils { + private static String FONT_NAME = "IranYekan"; + + private static final SimpleArrayMap cache = new SimpleArrayMap<>(); + + public static Typeface Default(Context context) { + synchronized (cache) { + if (!cache.containsKey(FONT_NAME)) { + Typeface t = Typeface.createFromAsset(context.getAssets(), "fonts/" + FONT_NAME + ".ttf"); + cache.put(FONT_NAME, t); + return t; + } + return cache.get(FONT_NAME); + } + } +} diff --git a/daterangepicker/src/main/res/drawable/calendar_header.xml b/daterangepicker/src/main/res/drawable/calendar_header.xml deleted file mode 100644 index a9a8f74..0000000 --- a/daterangepicker/src/main/res/drawable/calendar_header.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/daterangepicker/src/main/res/layout/dialog_date_picker.xml b/daterangepicker/src/main/res/layout/dialog_date_picker.xml index 4d7aa7e..966942a 100644 --- a/daterangepicker/src/main/res/layout/dialog_date_picker.xml +++ b/daterangepicker/src/main/res/layout/dialog_date_picker.xml @@ -1,18 +1,24 @@ - + android:orientation="horizontal"> + + + + + + + + + android:text="0" /> + android:text="1" + android:textColor="@android:color/darker_gray" + android:textSize="10.5sp" /> diff --git a/daterangepicker/src/main/res/layout/layout_calendar_nav.xml b/daterangepicker/src/main/res/layout/layout_calendar_nav.xml index ed7410f..25882e7 100644 --- a/daterangepicker/src/main/res/layout/layout_calendar_nav.xml +++ b/daterangepicker/src/main/res/layout/layout_calendar_nav.xml @@ -4,7 +4,7 @@ android:id="@+id/rlHeaderCalendar" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@color/header_color"> + android:background="@color/headerBackgroundColor"> + + @@ -8,14 +10,16 @@ + + + - - + diff --git a/daterangepicker/src/main/res/values/colors.xml b/daterangepicker/src/main/res/values/colors.xml index 6af4269..30ff309 100644 --- a/daterangepicker/src/main/res/values/colors.xml +++ b/daterangepicker/src/main/res/values/colors.xml @@ -1,7 +1,12 @@ + + #040078 + + + @color/headerBackgroundColor + - #000 #000 #717171 @@ -12,22 +17,16 @@ #FFF #deccddf7 - - - #474747 #e4215d #ffffff - #FF006B - + #bf00bf #0097e2 - - - - #51bf4b + #2b303d #ccddf7 + \ No newline at end of file diff --git a/daterangepicker/src/main/res/values/styles.xml b/daterangepicker/src/main/res/values/styles.xml index 042b1ee..203a3b8 100644 --- a/daterangepicker/src/main/res/values/styles.xml +++ b/daterangepicker/src/main/res/values/styles.xml @@ -1,4 +1,5 @@ + \ No newline at end of file