Skip to content

Commit bf2eb90

Browse files
author
kgoel
committed
internationalization support
1 parent 6a4fe71 commit bf2eb90

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

collapsiblecalendarview2/src/main/java/com/shrikanthravi/collapsiblecalendarview/widget/CollapsibleCalendar.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import com.shrikanthravi.collapsiblecalendarview.data.Event
2424
import com.shrikanthravi.collapsiblecalendarview.view.ExpandIconView
2525
import java.text.SimpleDateFormat
2626
import java.util.*
27+
import java.text.DateFormatSymbols
28+
2729

2830
class CollapsibleCalendar : UICalendar, View.OnClickListener {
2931
override fun changeToToday() {
@@ -230,7 +232,7 @@ class CollapsibleCalendar : UICalendar, View.OnClickListener {
230232
for (i in 0 until mAdapter!!.count) {
231233
val day = mAdapter!!.getItem(i)
232234
val view = mAdapter!!.getView(i)
233-
val txtDay = view.findViewById<View>(R.id.txt_day) as TextView
235+
val txtDay = view.findViewById<View>(com.shrikanthravi.collapsiblecalendarview.R.id.txt_day) as TextView
234236
txtDay.setBackgroundColor(Color.TRANSPARENT)
235237
txtDay.setTextColor(textColor)
236238

@@ -254,24 +256,21 @@ class CollapsibleCalendar : UICalendar, View.OnClickListener {
254256
mAdapter.refresh()
255257

256258
// reset UI
257-
val dateFormat = SimpleDateFormat(datePattern)
259+
val dateFormat = SimpleDateFormat(datePattern, getCurrentLocale(context))
258260
dateFormat.timeZone = mAdapter.calendar.timeZone
259261
mTxtTitle.text = dateFormat.format(mAdapter.calendar.time)
260262
mTableHead.removeAllViews()
261263
mTableBody.removeAllViews()
262264

263265
var rowCurrent: TableRow
264-
265-
// set day of week
266-
val dayOfWeekIds = intArrayOf(R.string.sunday, R.string.monday, R.string.tuesday, R.string.wednesday, R.string.thursday, R.string.friday, R.string.saturday)
267266
rowCurrent = TableRow(context)
268267
rowCurrent.layoutParams = TableLayout.LayoutParams(
269268
ViewGroup.LayoutParams.MATCH_PARENT,
270269
ViewGroup.LayoutParams.WRAP_CONTENT)
271270
for (i in 0..6) {
272271
val view = mInflater.inflate(R.layout.layout_day_of_week, null)
273272
val txtDayOfWeek = view.findViewById<View>(R.id.txt_day_of_week) as TextView
274-
txtDayOfWeek.setText(dayOfWeekIds[(i + firstDayOfWeek) % 7])
273+
txtDayOfWeek.setText(DateFormatSymbols().getShortWeekdays()[(i + firstDayOfWeek) % 7])
275274
view.layoutParams = TableRow.LayoutParams(
276275
0,
277276
ViewGroup.LayoutParams.WRAP_CONTENT,
@@ -559,7 +558,7 @@ class CollapsibleCalendar : UICalendar, View.OnClickListener {
559558
mScrollViewBody.requestLayout()
560559

561560
if (interpolatedTime == 1f) {
562-
state = UICalendar.Companion.STATE_EXPANDED
561+
state = STATE_EXPANDED
563562

564563
mBtnPrevMonth.isClickable = true
565564
mBtnNextMonth.isClickable = true

collapsiblecalendarview2/src/main/java/com/shrikanthravi/collapsiblecalendarview/widget/UICalendar.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import com.shrikanthravi.collapsiblecalendarview.view.ExpandIconView
1616
import com.shrikanthravi.collapsiblecalendarview.view.LockScrollView
1717
import com.shrikanthravi.collapsiblecalendarview.view.OnSwipeTouchListener
1818
import java.util.*
19+
import android.os.Build
20+
21+
1922

2023
@SuppressLint("ClickableViewAccessibility")
2124
abstract class UICalendar constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : ScrollView(context, attrs, defStyleAttr) {
@@ -100,7 +103,7 @@ abstract class UICalendar constructor(context: Context, attrs: AttributeSet? = n
100103
field = todayItemTextColor
101104
redraw()
102105
}
103-
var todayItemBackgroundDrawable = resources.getDrawable(R.drawable.circle_black_stroke_background)
106+
var todayItemBackgroundDrawable = resources.getDrawable(com.shrikanthravi.collapsiblecalendarview.R.drawable.circle_black_stroke_background)
104107
set(todayItemBackgroundDrawable) {
105108
field = todayItemBackgroundDrawable
106109
redraw()
@@ -110,7 +113,7 @@ abstract class UICalendar constructor(context: Context, attrs: AttributeSet? = n
110113
field = selectedItemTextColor
111114
redraw()
112115
}
113-
var selectedItemBackgroundDrawable = resources.getDrawable(R.drawable.circle_black_solid_background)
116+
var selectedItemBackgroundDrawable = resources.getDrawable(com.shrikanthravi.collapsiblecalendarview.R.drawable.circle_black_solid_background)
114117
set(selectedItemBackground) {
115118
field = selectedItemBackground
116119
redraw()
@@ -119,7 +122,7 @@ abstract class UICalendar constructor(context: Context, attrs: AttributeSet? = n
119122
/**
120123
* This can be used to defined the left icon drawable other than predefined icon
121124
*/
122-
var buttonLeftDrawable = resources.getDrawable(R.drawable.left_icon)
125+
var buttonLeftDrawable = resources.getDrawable(com.shrikanthravi.collapsiblecalendarview.R.drawable.left_icon)
123126
set(buttonLeftDrawable) {
124127
field = buttonLeftDrawable
125128
mBtnPrevMonth.setImageDrawable(buttonLeftDrawable)
@@ -129,7 +132,7 @@ abstract class UICalendar constructor(context: Context, attrs: AttributeSet? = n
129132
/**
130133
* This can be used to set the drawable for the right icon, other than predefined icon
131134
*/
132-
var buttonRightDrawable = resources.getDrawable(R.drawable.right_icon)
135+
var buttonRightDrawable = resources.getDrawable(com.shrikanthravi.collapsiblecalendarview.R.drawable.right_icon)
133136
set(buttonRightDrawable) {
134137
field = buttonRightDrawable
135138
mBtnNextMonth.setImageDrawable(buttonRightDrawable)
@@ -179,6 +182,15 @@ abstract class UICalendar constructor(context: Context, attrs: AttributeSet? = n
179182
}
180183
}
181184

185+
fun getCurrentLocale(context: Context): Locale {
186+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
187+
context.resources.configuration.locales.get(0)
188+
} else {
189+
190+
context.resources.configuration.locale
191+
}
192+
}
193+
182194
init {
183195
mInflater = LayoutInflater.from(context)
184196

@@ -207,7 +219,7 @@ abstract class UICalendar constructor(context: Context, attrs: AttributeSet? = n
207219
mScrollViewBody.setOnTouchListener(getSwipe(context))
208220
mScrollViewBody.setParams(getSwipe(context))
209221
val attributes = context.theme.obtainStyledAttributes(
210-
attrs, R.styleable.UICalendar, defStyleAttr, 0)
222+
attrs, com.shrikanthravi.collapsiblecalendarview.R.styleable.UICalendar, defStyleAttr, 0)
211223
setAttributes(attributes)
212224
attributes.recycle()
213225
}
@@ -260,7 +272,7 @@ abstract class UICalendar constructor(context: Context, attrs: AttributeSet? = n
260272
selectedItemBackgroundDrawable = this.selectedItemBackgroundDrawable
261273
}
262274

263-
var buttonLeftDrawable = attrs.getDrawable(R.styleable.UICalendar_buttonLeft_drawable)
275+
var buttonLeftDrawable = attrs.getDrawable(com.shrikanthravi.collapsiblecalendarview.R.styleable.UICalendar_buttonLeft_drawable)
264276
if (buttonLeftDrawable != null) {
265277
buttonLeftDrawable = buttonLeftDrawable
266278
} else {

0 commit comments

Comments
 (0)