Skip to content

Commit 9cc3068

Browse files
committed
Feature- Set font size and related bug fixes
1 parent 556fbd1 commit 9cc3068

8 files changed

Lines changed: 70 additions & 19 deletions

File tree

styro_custom-date-picker/src/main/java/com/matrix/styro_custom_date_picker/Adapters/CalendarAdapter.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.matrix.styro_custom_date_picker.DataHolders.CalendarSet
1212
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.calendarDaysDisabledTextColor
1313
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.calendarDaysHighlightTextColor
1414
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.calendarDaysTextColor
15+
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.calendarFontSize
1516
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.dayBackgroundDefault
1617
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.font
1718
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.dayHighlightBackground
@@ -47,6 +48,8 @@ internal class CalendarAdapter(
4748
val view = p1 ?: LayoutInflater.from(context).inflate(R.layout.day, p2, false)
4849
val dayText =
4950
view.findViewById<LinearLayout>(R.id.day_lly).findViewById<TextView>(R.id.dayText)
51+
if (calendarFontSize > 0)
52+
dayText.textSize = calendarFontSize
5053
val today = upperLimit.split("-").map { Integer.valueOf(it) }
5154
var last = calendarSet.lastDayOfMonth
5255
dayText.typeface = ResourcesCompat.getFont(context, font)

styro_custom-date-picker/src/main/java/com/matrix/styro_custom_date_picker/CalendarManager/CustomCalendarManager.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import com.matrix.styro_custom_date_picker.Adapters.CalendarAdapter
1212
import com.matrix.styro_custom_date_picker.CalendarManager.DateManager.getDateArray
1313
import com.matrix.styro_custom_date_picker.DataHolders.CalendarSet
1414
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.calendarBackgroundColor
15+
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.calendarFontSize
1516
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.yearDropDownBackground
1617
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.yearDropdownTextColor
1718
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.font
19+
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.yearDropdownfontSize
1820
import com.matrix.styro_custom_date_picker.R
1921
import java.text.SimpleDateFormat
2022
import java.time.LocalDate
@@ -202,6 +204,8 @@ object DateManager {
202204
itemText.typeface = ResourcesCompat.getFont(context, font)
203205
itemText.setTextColor(yearDropdownTextColor)
204206
itemText.text = item.toString()
207+
if (yearDropdownfontSize > 0)
208+
itemText.textSize = yearDropdownfontSize
205209
itemView.setOnClickListener {
206210
popupView.findViewById<TextView>(R.id.year_text).text = itemText.text
207211
currentDate[2] = Integer.valueOf(item)

styro_custom-date-picker/src/main/java/com/matrix/styro_custom_date_picker/CustomizableDatePicker.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import com.matrix.styro_custom_date_picker.CalendarManager.DateManager
1818
import com.matrix.styro_custom_date_picker.CalendarManager.DateManager.today
1919
import com.matrix.styro_custom_date_picker.CalendarManager.SetDates.currentDate
2020
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.buttonDrawable
21+
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.buttonFontSize
2122
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.buttonTextColor
23+
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.calendarFontSize
2224
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.daysBarVisibility
2325
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.monthSwitchIconLeft
2426
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.monthSwitchIconRight
@@ -28,6 +30,7 @@ import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.s
2830
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.topBarBackgroundColor
2931
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.font
3032
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.gestureMonthSwitching
33+
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.selectorFontSize
3134
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.topBarDaysBackground
3235
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.topBarDefaultDayColor
3336
import com.matrix.styro_custom_date_picker.DataHolders.CustomCalendarResources.topBarSundayColor
@@ -78,8 +81,13 @@ class CustomizableDatePicker {
7881
popup.findViewById<LinearLayout>(R.id.year).setBackgroundResource(
7982
selectorBackground
8083
)
84+
8185
popup.findViewById<TextView>(R.id.month).setTextColor(selectorTextColor)
8286
popup.findViewById<TextView>(R.id.year_text).setTextColor(selectorTextColor)
87+
if (selectorFontSize > 0) {
88+
popup.findViewById<TextView>(R.id.month).textSize = selectorFontSize
89+
popup.findViewById<TextView>(R.id.year_text).textSize = selectorFontSize
90+
}
8391

8492
popup.findViewById<ImageView>(R.id.month_next).setImageResource(monthSwitchIconRight)
8593
popup.findViewById<ImageView>(R.id.month_prev).setImageResource(monthSwitchIconLeft)
@@ -110,23 +118,26 @@ class CustomizableDatePicker {
110118
yearDropdown(it)
111119
}
112120

113-
val bottomSheetDialog = BottomSheetDialog(context)
114-
bottomSheetDialog.setContentView(popup)
115-
bottomSheetDialog.show()
116-
117121
val chooseButton: LinearLayout = popup.findViewById(R.id.calendar_choose)
118122
val chooseText: TextView = popup.findViewById(R.id.choose_text)
119123
chooseButton.setBackgroundResource(buttonDrawable)
120124
chooseText.setTextColor(buttonTextColor)
125+
if (buttonFontSize > 0)
126+
chooseText.textSize = buttonFontSize * context.resources.displayMetrics.scaledDensity
121127
chooseText.typeface = defaultFont
122128

129+
val bottomSheetDialog = BottomSheetDialog(context)
130+
bottomSheetDialog.setContentView(popup)
131+
bottomSheetDialog.show()
132+
123133
chooseButton.setOnClickListener {
124134
bottomSheetDialog.dismiss()
125135
if (displayView != null)
126136
(displayView as TextView).text = convert(CalendarAdapter.getSelected())
127137
selectedDate = CalendarAdapter.getSelected()
128138
todo()
129139
}
140+
130141
if (gestureMonthSwitching) {
131142
val gestureDetector = GestureDetector(context, SwipeDetector(
132143
onSwipeLeft = { switchMonth(popup.findViewById<ImageView>(R.id.month_prev)) },
@@ -154,6 +165,8 @@ class CustomizableDatePicker {
154165
val view = p1 ?: LayoutInflater.from(context).inflate(R.layout.day, p2, false)
155166
val dayText = view.findViewById<LinearLayout>(R.id.day_lly)
156167
.findViewById<TextView>(R.id.dayText)
168+
if (calendarFontSize > 0)
169+
dayText.textSize = calendarFontSize
157170
dayText.typeface = ResourcesCompat.getFont(context, font)
158171
dayText.text = days[p0]
159172
if (topBarDaysBackground != 0)

styro_custom-date-picker/src/main/java/com/matrix/styro_custom_date_picker/DataHolders/CustomCalendarResources.kt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ object CustomCalendarResources {
1919
internal var selectorBackground: Int = R.drawable.calendar_highlight
2020
internal var selectorTextColor: Int = Color.parseColor("#474747")
2121
internal var font: Int = R.font.dm_sans_medium
22-
internal var calendarBackgroundColor: Int = Color.WHITE
23-
internal var topBarBackgroundColor: Int = Color.WHITE
22+
internal var calendarBackgroundColor: Int = Color.TRANSPARENT
23+
internal var topBarBackgroundColor: Int = Color.TRANSPARENT
2424
internal var buttonDrawable: Int = R.drawable.button_bg
2525
internal var buttonTextColor: Int = Color.WHITE
2626
internal var daysBarVisibility = View.VISIBLE
@@ -35,6 +35,10 @@ object CustomCalendarResources {
3535
internal var monthSwitchIconRight = R.drawable.ic_arrow_right
3636
internal var yearSwitchIcon = R.drawable.ic_arrow_down
3737
internal var gestureMonthSwitching = true
38+
internal var calendarFontSize: Float = 0f
39+
internal var yearDropdownfontSize: Float = 0f
40+
internal var selectorFontSize: Float = 0f
41+
internal var buttonFontSize: Float = 0f
3842

3943
fun setCalendarDayHighlightBackground(backgroundDrawable: Int): CustomCalendarResources {
4044
dayHighlightBackground = backgroundDrawable
@@ -151,4 +155,24 @@ object CustomCalendarResources {
151155
return this
152156
}
153157

158+
fun setCalendarFontSize(size: Float): CustomCalendarResources {
159+
calendarFontSize = size
160+
return this
161+
}
162+
163+
fun setYearDropdownFontSize(size: Float): CustomCalendarResources {
164+
yearDropdownfontSize = size
165+
return this
166+
}
167+
168+
fun setSelectorFontSize(size: Float): CustomCalendarResources {
169+
selectorFontSize = size
170+
return this
171+
}
172+
173+
fun setButtonFontSize(size: Float): CustomCalendarResources {
174+
buttonFontSize = size
175+
return this
176+
}
177+
154178
}

styro_custom-date-picker/src/main/java/com/matrix/styro_custom_date_picker/Utils/GestureDetector.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ internal class SwipeDetector(
1313
private val onSwipeRight: () -> Unit
1414
) : GestureDetector.SimpleOnGestureListener() {
1515

16-
private val SWIPE_THRESHOLD = 40f
17-
private val SWIPE_VELOCITY_THRESHOLD = 40f
16+
private val SWIPE_THRESHOLD = 100f
17+
private val SWIPE_VELOCITY_THRESHOLD = 100f
1818

1919
override fun onFling(
2020
e1: MotionEvent?,
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2-
android:width="13dp"
3-
android:height="7dp"
4-
android:viewportWidth="13"
5-
android:viewportHeight="7">
2+
android:width="15dp"
3+
android:height="8dp"
4+
android:viewportWidth="15"
5+
android:viewportHeight="8">
66
<path
77
android:fillColor="#FF5E5E5E"
8-
android:pathData="M0 0.56c0-0.14 0.06-0.29 0.16-0.4 0.22-0.21 0.58-0.21 0.8 0L6.19 5.4l5.22-5.23c0.22-0.21 0.58-0.21 0.8 0 0.22 0.22 0.22 0.58 0 0.8L6.59 6.59C6.37 6.8 6 6.8 5.79 6.59L0.16 0.96C0.06 0.85 0 0.71 0 0.56Z"/>
8+
android:pathData="M0.03 0.67c0-0.17 0.06-0.34 0.19-0.47 0.25-0.27 0.67-0.27 0.92 0L7.2 6.4l6.06-6.2c0.26-0.27 0.67-0.27 0.92 0 0.26 0.26 0.26 0.68 0 0.94L7.66 7.8C7.41 8.07 7 8.07 6.74 7.8L0.22 1.14C0.09 1 0.02 0.84 0.02 0.67Z"/>
99
</vector>

styro_custom-date-picker/src/main/res/layout/calendar.xml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:tools="http://schemas.android.com/tools"
44
android:id="@+id/calendar_root"
55
android:layout_width="match_parent"
6+
android:background="@color/black"
67
android:layout_height="match_parent"
78
android:orientation="vertical">
89

@@ -21,6 +22,7 @@
2122
android:layout_marginRight="6dp"
2223
android:paddingHorizontal="10dp"
2324
android:paddingVertical="8dp"
25+
android:minHeight="45dp"
2426
android:layout_weight="1"
2527
android:gravity="center_vertical">
2628

@@ -39,6 +41,7 @@
3941
android:layout_weight="1"
4042
android:textStyle="bold"
4143
android:textSize="16sp"
44+
android:ellipsize="end"
4245
android:paddingVertical="5dp"
4346
android:text="Month"
4447
android:textColor="@color/black" />
@@ -60,6 +63,7 @@
6063
android:layout_marginLeft="6dp"
6164
android:paddingHorizontal="10dp"
6265
android:paddingVertical="8dp"
66+
android:minHeight="45dp"
6367
android:layout_weight="1"
6468
android:gravity="center_vertical">
6569

@@ -68,21 +72,23 @@
6872
android:layout_width="match_parent"
6973
android:layout_height="wrap_content"
7074
android:gravity="center"
71-
android:layout_weight="1"
75+
android:layout_weight="0.3"
7276
android:textStyle="bold"
7377
android:layout_marginLeft="12dp"
7478
android:paddingVertical="5dp"
79+
android:ellipsize="end"
7580
android:textSize="16sp"
7681
android:text="Year"
7782
android:textColor="@color/black" />
7883

7984

8085
<ImageView
8186
android:id="@+id/year_icon"
82-
android:layout_width="20dp"
87+
android:layout_width="match_parent"
88+
android:layout_weight="0.7"
8389
android:layout_height="match_parent"
84-
android:paddingVertical="11dp"
85-
android:layout_marginLeft="10dp"
90+
android:paddingVertical="10dp"
91+
android:layout_marginLeft="8dp"
8692
android:layout_marginRight="5dp"
8793
android:src="@drawable/ic_arrow_down"/>
8894

@@ -105,6 +111,7 @@
105111
android:layout_width="wrap_content"
106112
android:layout_height="wrap_content"
107113
android:layout_marginHorizontal="25dp"
114+
android:background="#00FFFFFF"
108115
android:layout_marginTop="2dp"
109116
android:gravity="center"
110117
android:numColumns="7"

styro_custom-date-picker/src/main/res/layout/day.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
22
android:layout_width="wrap_content"
33
android:id="@+id/day_lly"
4-
android:background="@color/white"
4+
android:background="#00FFFFFF"
55
android:layout_height="wrap_content">
66
<TextView
77
android:id="@+id/dayText"
88
android:layout_width="50dp"
9-
android:background="@color/white"
109
android:layout_height="42dp"
10+
android:background="#00FFFFFF"
1111
android:gravity="center"
1212
android:textStyle="bold"
1313
android:textColor="@android:color/black"

0 commit comments

Comments
 (0)