Skip to content

Commit 187161d

Browse files
author
kgoel
committed
Moved to androidx and added gesture for left and right swipe
1 parent a6aa75d commit 187161d

File tree

7 files changed

+63
-26
lines changed

7 files changed

+63
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/build
88
/captures
99
.externalNativeBuild
10+
/.idea/*
0 Bytes
Binary file not shown.

app/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,21 @@ apply plugin: 'kotlin-android-extensions'
55

66
android {
77
compileSdkVersion 29
8+
9+
kotlinOptions {
10+
jvmTarget = '1.8'
11+
}
12+
813
defaultConfig {
914
applicationId "com.shrikanthravi.collapsiblecalendarview"
1015
minSdkVersion 21
1116
targetSdkVersion 29
1217
versionCode 1
1318
versionName "1.0"
19+
compileOptions {
20+
sourceCompatibility JavaVersion.VERSION_1_8
21+
targetCompatibility JavaVersion.VERSION_1_8
22+
}
1423
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1524
}
1625
dexOptions {

collapsiblecalendarview2/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ group = 'com.github.shrikanth7698'
77
android {
88
compileSdkVersion 29
99

10-
10+
kotlinOptions {
11+
jvmTarget = '1.8'
12+
}
1113

1214
defaultConfig {
1315
minSdkVersion 21
@@ -16,6 +18,10 @@ android {
1618
versionName "1.0"
1719

1820
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
21+
compileOptions {
22+
sourceCompatibility JavaVersion.VERSION_1_8
23+
targetCompatibility JavaVersion.VERSION_1_8
24+
}
1925

2026
}
2127
dexOptions {

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,26 @@ import android.widget.ScrollView
1212

1313
class LockScrollView : ScrollView {
1414
constructor(context: Context) : super(context) {}
15-
1615
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}
17-
1816
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {}
17+
var swipeTouchListener: OnSwipeTouchListener? = null
18+
fun setParams(swipeTouchListener: OnSwipeTouchListener){
19+
this.swipeTouchListener = swipeTouchListener
20+
}
1921

2022
override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
21-
return true
23+
swipeTouchListener?.onTouch(this, ev).let {
24+
if(it==null){
25+
return false;
26+
}
27+
else {
28+
return it
29+
}
30+
}
2231
}
2332

24-
@SuppressLint("ClickableViewAccessibility")
2533
override fun onTouchEvent(ev: MotionEvent): Boolean {
2634
super.onTouchEvent(ev)
2735
return true
2836
}
29-
}
37+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class OnSwipeTouchListener(ctx: Context) : OnTouchListener {
2424
private inner class GestureListener : SimpleOnGestureListener() {
2525

2626
override fun onDown(e: MotionEvent): Boolean {
27-
return true
27+
return false
2828
}
2929

3030
override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {

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

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ abstract class UICalendar constructor(context: Context, attrs: AttributeSet? = n
110110
/**
111111
* This can be used to defined the left icon drawable other than predefined icon
112112
*/
113-
var buttonLeftDrawable = resources.getDrawable(R.drawable.left_icon)
113+
var buttonLeftDrawable = resources.getDrawable(com.shrikanthravi.collapsiblecalendarview.R.drawable.left_icon)
114114
set(buttonLeftDrawable) {
115115
field = buttonLeftDrawable
116116
mBtnPrevMonth.setImageDrawable(buttonLeftDrawable)
@@ -120,7 +120,7 @@ abstract class UICalendar constructor(context: Context, attrs: AttributeSet? = n
120120
/**
121121
* This can be used to set the drawable for the right icon, other than predefined icon
122122
*/
123-
var buttonRightDrawable = resources.getDrawable(R.drawable.right_icon)
123+
var buttonRightDrawable = resources.getDrawable(com.shrikanthravi.collapsiblecalendarview.R.drawable.right_icon)
124124
set(buttonRightDrawable) {
125125
field = buttonRightDrawable
126126
mBtnNextMonth.setImageDrawable(buttonRightDrawable)
@@ -139,7 +139,34 @@ abstract class UICalendar constructor(context: Context, attrs: AttributeSet? = n
139139
redraw()
140140

141141
}
142+
private fun getSwipe(context:Context): OnSwipeTouchListener {
143+
return object: OnSwipeTouchListener(context){
144+
override fun onSwipeTop() {
145+
expandIconView.performClick()
142146

147+
}
148+
149+
override fun onSwipeLeft() {
150+
if (state == STATE_COLLAPSED) {
151+
mBtnNextWeek.performClick()
152+
} else if (state == STATE_EXPANDED) {
153+
mBtnNextMonth.performClick()
154+
}
155+
}
156+
157+
override fun onSwipeRight() {
158+
if (state == STATE_COLLAPSED) {
159+
mBtnPrevWeek.performClick()
160+
} else if (state == STATE_EXPANDED) {
161+
mBtnPrevMonth.performClick()
162+
}
163+
}
164+
165+
override fun onSwipeBottom() {
166+
expandIconView.performClick()
167+
}
168+
}
169+
}
143170
init {
144171
mInflater = LayoutInflater.from(context)
145172

@@ -161,23 +188,9 @@ abstract class UICalendar constructor(context: Context, attrs: AttributeSet? = n
161188
mScrollViewBody = rootView.findViewById(R.id.scroll_view_body)
162189
expandIconView = rootView.findViewById(R.id.expandIcon)
163190
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
164-
mScrollViewBody.setOnTouchListener(object: OnSwipeTouchListener(context){
165-
override fun onSwipeRight() {
166-
mBtnNextMonth.performClick()
167-
}
168-
169-
override fun onSwipeLeft() {
170-
mBtnPrevMonth.performClick()
171-
}
172-
173-
override fun onSwipeTop() {
174-
expandIconView.performClick()
175-
}
176-
177-
override fun onSwipeBottom() {
178-
expandIconView.performClick()
179-
}
180-
})
191+
mLayoutRoot.setOnTouchListener(getSwipe(context));
192+
mScrollViewBody.setOnTouchListener(getSwipe(context))
193+
mScrollViewBody.setParams(getSwipe(context))
181194
}
182195
val attributes = context.theme.obtainStyledAttributes(
183196
attrs, R.styleable.UICalendar, defStyleAttr, 0)

0 commit comments

Comments
 (0)