-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates a Focusable Layout Managers and Smooth Scrollers
This creates two layout managers and new smooth scroller that will set the Focus after scrolling has completed. This gets around the hack of using a handler to set focus after a delay. No delay is need here.
- Loading branch information
1 parent
5727c95
commit 6a4ceb3
Showing
10 changed files
with
78 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...-app/src/main/kotlin/us/nineworlds/serenity/ui/recyclerview/FocusableGridLayoutManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package us.nineworlds.serenity.ui.recyclerview | ||
|
||
import android.content.Context | ||
import android.support.v7.widget.GridLayoutManager | ||
import android.support.v7.widget.RecyclerView | ||
|
||
open class FocusableGridLayoutManager(val context: Context, spanCount: Int, orientation: Int, reverseLayout: Boolean) : GridLayoutManager(context, spanCount, orientation, reverseLayout) { | ||
|
||
override fun smoothScrollToPosition(recyclerView: RecyclerView?, state: RecyclerView.State?, position: Int) { | ||
val smoothScroller = FocusableLinearSmoothScroller(context) | ||
|
||
smoothScroller.targetPosition = position | ||
startSmoothScroll(smoothScroller) | ||
} | ||
|
||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...pp/src/main/kotlin/us/nineworlds/serenity/ui/recyclerview/FocusableLinearLayoutManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package us.nineworlds.serenity.ui.recyclerview | ||
|
||
import android.content.Context | ||
import android.support.v7.widget.LinearLayoutManager | ||
import android.support.v7.widget.RecyclerView | ||
|
||
class FocusableLinearLayoutManager(val context: Context) : LinearLayoutManager(context) { | ||
|
||
override fun smoothScrollToPosition(recyclerView: RecyclerView?, state: RecyclerView.State?, position: Int) { | ||
val smoothScroller = FocusableLinearSmoothScroller(context) | ||
smoothScroller.targetPosition = position | ||
startSmoothScroll(smoothScroller) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...p/src/main/kotlin/us/nineworlds/serenity/ui/recyclerview/FocusableLinearSmoothScroller.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package us.nineworlds.serenity.ui.recyclerview | ||
|
||
import android.content.Context | ||
import android.support.v7.widget.LinearSmoothScroller | ||
import android.support.v7.widget.RecyclerView | ||
import android.view.View | ||
|
||
class FocusableLinearSmoothScroller(context: Context) : LinearSmoothScroller(context) { | ||
|
||
var targetView : View? = null | ||
|
||
override fun onTargetFound(targetView: View?, state: RecyclerView.State?, action: Action?) { | ||
super.onTargetFound(targetView, state, action) | ||
this.targetView = targetView | ||
} | ||
|
||
override fun onStop() { | ||
super.onStop() | ||
|
||
if (targetView != null && !targetView!!.hasFocus()) { | ||
targetView!!.requestFocusFromTouch() | ||
} | ||
} | ||
} |