Skip to content

Commit 8bf86c1

Browse files
author
kgoel
committed
Added bounce on Stopping calender event, will make it more graceful later
1 parent 482917c commit 8bf86c1

File tree

5 files changed

+76
-20
lines changed

5 files changed

+76
-20
lines changed

collapsiblecalendarview2/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ dependencies {
4646
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
4747
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4848
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
49+
implementation 'androidx.cardview:cardview:1.0.0'
4950
}
5051
repositories {
5152
mavenCentral()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.shrikanthravi.collapsiblecalendarview.view
2+
3+
class BounceAnimator(amplitude: Double, frequency: Double) : android.view.animation.Interpolator {
4+
private var mAmplitude = 1.0
5+
private var mFrequency = 10.0
6+
7+
init {
8+
mAmplitude = amplitude
9+
mFrequency = frequency
10+
}
11+
12+
override fun getInterpolation(time: Float): Float {
13+
return (-1.0 * Math.pow(Math.E, -time / mAmplitude) *
14+
Math.cos(mFrequency * time) + 1).toFloat()
15+
}
16+
}

collapsiblecalendarview2/src/main/java/com/shrikanthravi/collapsiblecalendarview/view/LockScrollView.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class LockScrollView : ScrollView {
3030
}
3131
}
3232

33+
@SuppressLint("ClickableViewAccessibility")
3334
override fun onTouchEvent(ev: MotionEvent): Boolean {
3435
super.onTouchEvent(ev)
3536
return true

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

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import android.util.AttributeSet
1212
import android.view.View
1313
import android.view.ViewGroup
1414
import android.view.animation.Animation
15+
import android.view.animation.AnimationUtils
1516
import android.view.animation.Transformation
1617
import android.widget.LinearLayout
1718
import android.widget.TableLayout
@@ -21,6 +22,7 @@ import com.shrikanthravi.collapsiblecalendarview.R
2122
import com.shrikanthravi.collapsiblecalendarview.data.CalendarAdapter
2223
import com.shrikanthravi.collapsiblecalendarview.data.Day
2324
import com.shrikanthravi.collapsiblecalendarview.data.Event
25+
import com.shrikanthravi.collapsiblecalendarview.view.BounceAnimator
2426
import com.shrikanthravi.collapsiblecalendarview.view.ExpandIconView
2527
import java.text.DateFormatSymbols
2628
import java.text.SimpleDateFormat
@@ -30,10 +32,10 @@ import java.util.*
3032
class CollapsibleCalendar : UICalendar, View.OnClickListener {
3133
override fun changeToToday() {
3234
val calendar = Calendar.getInstance()
33-
var calenderAdapter = CalendarAdapter(context, calendar);
35+
val calenderAdapter = CalendarAdapter(context, calendar);
3436
calenderAdapter.mEventList = mAdapter!!.mEventList
3537
calenderAdapter.setFirstDayOfWeek(firstDayOfWeek)
36-
var today = GregorianCalendar()
38+
val today = GregorianCalendar()
3739
this.selectedItem = null
3840
this.selectedItemPosition = -1
3941
this.selectedDay = Day(today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH))
@@ -254,9 +256,15 @@ class CollapsibleCalendar : UICalendar, View.OnClickListener {
254256
override fun reload() {
255257
mAdapter?.let { mAdapter ->
256258
mAdapter.refresh()
257-
259+
val calendar = Calendar.getInstance()
260+
val tempDatePattern: String
261+
if (calendar.get(Calendar.YEAR) != mAdapter.calendar.get(Calendar.YEAR)) {
262+
tempDatePattern = "MMMM YYYY"
263+
} else {
264+
tempDatePattern = datePattern
265+
}
258266
// reset UI
259-
val dateFormat = SimpleDateFormat(datePattern, getCurrentLocale(context))
267+
val dateFormat = SimpleDateFormat(tempDatePattern, getCurrentLocale(context))
260268
dateFormat.timeZone = mAdapter.calendar.timeZone
261269
mTxtTitle.text = dateFormat.format(mAdapter.calendar.time)
262270
mTableHead.removeAllViews()
@@ -297,6 +305,7 @@ class CollapsibleCalendar : UICalendar, View.OnClickListener {
297305
params.let { params ->
298306
if (params != null && (mAdapter.getItem(i).diff < params.prevDays || mAdapter.getItem(i).diff > params.nextDaysBlocked)) {
299307
view.isClickable = false
308+
view.alpha = 0.3f
300309
} else {
301310
view.setOnClickListener { v -> onItemClicked(v, mAdapter.getItem(i)) }
302311
}
@@ -364,27 +373,46 @@ class CollapsibleCalendar : UICalendar, View.OnClickListener {
364373

365374
fun prevMonth() {
366375
val cal = mAdapter!!.calendar
367-
if (cal.get(Calendar.MONTH) == cal.getActualMinimum(Calendar.MONTH)) {
368-
cal.set(cal.get(Calendar.YEAR) - 1, cal.getActualMaximum(Calendar.MONTH), 1)
369-
} else {
370-
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1)
371-
}
372-
reload()
373-
if (mListener != null) {
374-
mListener!!.onMonthChange()
376+
params.let {
377+
if (it != null && (Calendar.getInstance().get(Calendar.YEAR) * 12 + Calendar.getInstance().get(Calendar.MONTH) + it.prevDays / 30) > (cal.get(Calendar.YEAR) * 12 + cal.get(Calendar.MONTH))) {
378+
val myAnim = AnimationUtils.loadAnimation(context, R.anim.bounce)
379+
val interpolator = BounceAnimator(0.1, 10.0)
380+
myAnim.setInterpolator(interpolator)
381+
mLayoutRoot.startAnimation(myAnim)
382+
return
383+
}
384+
if (cal.get(Calendar.MONTH) == cal.getActualMinimum(Calendar.MONTH)) {
385+
cal.set(cal.get(Calendar.YEAR) - 1, cal.getActualMaximum(Calendar.MONTH), 1)
386+
} else {
387+
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1)
388+
}
389+
reload()
390+
if (mListener != null) {
391+
mListener!!.onMonthChange()
392+
}
375393
}
394+
376395
}
377396

378397
fun nextMonth() {
379398
val cal = mAdapter!!.calendar
380-
if (cal.get(Calendar.MONTH) == cal.getActualMaximum(Calendar.MONTH)) {
381-
cal.set(cal.get(Calendar.YEAR) + 1, cal.getActualMinimum(Calendar.MONTH), 1)
382-
} else {
383-
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1)
384-
}
385-
reload()
386-
if (mListener != null) {
387-
mListener!!.onMonthChange()
399+
params.let {
400+
if (it != null && (Calendar.getInstance().get(Calendar.YEAR) * 12 + Calendar.getInstance().get(Calendar.MONTH) + it.nextDaysBlocked / 30) < (cal.get(Calendar.YEAR) * 12 + cal.get(Calendar.MONTH))) {
401+
val myAnim = AnimationUtils.loadAnimation(context, R.anim.bounce)
402+
val interpolator = BounceAnimator(0.1, 10.0)
403+
myAnim.setInterpolator(interpolator)
404+
this.startAnimation(myAnim)
405+
return
406+
}
407+
if (cal.get(Calendar.MONTH) == cal.getActualMaximum(Calendar.MONTH)) {
408+
cal.set(cal.get(Calendar.YEAR) + 1, cal.getActualMinimum(Calendar.MONTH), 1)
409+
} else {
410+
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1)
411+
}
412+
reload()
413+
if (mListener != null) {
414+
mListener!!.onMonthChange()
415+
}
388416
}
389417
}
390418

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<set xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:fillAfter="true"
4+
android:interpolator="@android:anim/bounce_interpolator">
5+
6+
<translate
7+
android:duration="300"
8+
android:fromXDelta="100%p"
9+
android:toXDelta="0%p" />
10+
</set>

0 commit comments

Comments
 (0)