Skip to content

Commit

Permalink
blockable callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Taras Koshkin authored and Taras Koshkin committed Jul 23, 2016
1 parent 0e0ef26 commit 15fa50c
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import com.koshkin.tehras.activetouch.fragments.ActiveTouchFragment
import com.koshkin.tehras.activetouch.views.ActiveTouchLinearLayoutManager
import java.io.Serializable

/**
Expand All @@ -35,31 +34,10 @@ class ActiveTouchBehavior : View.OnTouchListener, ActiveTouchFragment.OnLoadHelp

if (builder.hoverCallback != null)
activeTouchHoverHelper = ActiveTouchHoverHelper(builder.hoverCallback!!)

blockRecyclerView()
}

private var recyclerView: RecyclerView? = null

private fun blockRecyclerView() {

var view = builder.v
while (view!!.parent != null) {
if (view.parent is View) {
view = view.parent as View
if (view is RecyclerView) {
if (view.layoutManager is ActiveTouchLinearLayoutManager) {//todo include others
Log.d(TAG, "found recycler view")
recyclerView = view

break
}
}
} else
break
}
}

companion object Factory {
fun builder(v: View): Factory.Builder {
return Factory.Builder(v)
Expand Down Expand Up @@ -89,13 +67,20 @@ class ActiveTouchBehavior : View.OnTouchListener, ActiveTouchFragment.OnLoadHelp
var contentFrag: android.app.Fragment? = null
var parentView: ViewGroup? = null
var hoverCallback: OnViewHoverOverListener? = null
var blockCallback: BlockScrollableParentListener? = null

@Suppress("unused")
fun setHoverCallback(callback: OnViewHoverOverListener): Builder {
hoverCallback = callback
return this
}

@Suppress("unused")
fun setBlockScrollableCallback(callback: BlockScrollableParentListener): Builder {
blockCallback = callback
return this
}

@Suppress("unused")
fun setContentView(view: View?): Builder {
contentView = view
Expand Down Expand Up @@ -144,10 +129,8 @@ class ActiveTouchBehavior : View.OnTouchListener, ActiveTouchFragment.OnLoadHelp


private fun blockScroll(b: Boolean) {
if (recyclerView != null) {
if (recyclerView!!.layoutManager is ActiveTouchLinearLayoutManager) {
(recyclerView!!.layoutManager as ActiveTouchLinearLayoutManager).blockScroll = b
}
if (builder.blockCallback != null) {
builder.blockCallback!!.onBlock(b)
}
}

Expand Down Expand Up @@ -223,4 +206,9 @@ class ActiveTouchBehavior : View.OnTouchListener, ActiveTouchFragment.OnLoadHelp
@Suppress("unused")
fun onHover(v: View?, isInside: Boolean)
}

interface BlockScrollableParentListener {
@Suppress("unused")
fun onBlock(b: Boolean)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.koshkin.tehras.activetouch.views

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.MotionEvent
import android.widget.LinearLayout

/**
* Created by tehras on 7/23/16.
*/
class ActiveTouchInterceptorLayout(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) {
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context) : this(context, null)

private val TAG = "ActiveTouchInter"

override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
Log.d(TAG, "onInterceptTouchEvent")
return true
}

override fun onTouchEvent(event: MotionEvent?): Boolean {
Log.d(TAG, "onTouchEvent")

return true
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.koshkin.tehras.activetouch.views.ActiveTouchInterceptorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparentGray"
Expand All @@ -15,4 +15,4 @@
android:layout_marginTop="80dp"
android:orientation="vertical" />

</LinearLayout>
</com.koshkin.tehras.activetouch.views.ActiveTouchInterceptorLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.koshkin.tehras.activetouchsample

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet

/**
* Created by tehras on 7/23/16.
*/
class BlockableRecyclerView(context: Context?, attrs: AttributeSet?, defStyle: Int) : RecyclerView(context, attrs, defStyle) {
constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context?) : this(context, null)

var blockScroll = false


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,30 @@ package com.koshkin.tehras.activetouchsample
import android.graphics.Color
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.koshkin.tehras.activetouch.touchlisteners.ActiveTouchBehavior
import com.koshkin.tehras.activetouch.views.ActiveTouchLinearLayoutManager

class MainActivity : AppCompatActivity() {

private var recyclerView: RecyclerView? = null
private var blockedScroll = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

recyclerView = findViewById(R.id.recycler_view) as RecyclerView
recyclerView!!.layoutManager = ActiveTouchLinearLayoutManager(this)
recyclerView!!.layoutManager = object : LinearLayoutManager(this) {
override fun canScrollVertically(): Boolean {
return !blockedScroll
}
}
recyclerView!!.setHasFixedSize(true)
recyclerView!!.adapter = SampleAdapter(this)
}
Expand Down Expand Up @@ -58,6 +63,12 @@ class MainActivity : AppCompatActivity() {
Log.d("MainActivity", "addingView")
ActiveTouchBehavior.builder(v!!)
.setContainerView(this.findViewById(R.id.container_view) as ViewGroup)
.setBlockScrollableCallback(object : ActiveTouchBehavior.BlockScrollableParentListener {
override fun onBlock(b: Boolean) {
blockedScroll = b
}

})
.setHoverCallback(object : ActiveTouchBehavior.OnViewHoverOverListener {

override fun onHover(v: View?, isInside: Boolean) {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':activetouch', ':activetouchsample'
include ':activetouchsample', ':activetouch'

0 comments on commit 15fa50c

Please sign in to comment.