Skip to content

Instantly share code, notes, and snippets.

View ricknout's full-sized avatar
🌚
Probably coding/designing

Nick Rout ricknout

🌚
Probably coding/designing
View GitHub Profile
@ricknout
ricknout / CanvasMultilineText.kt
Last active October 13, 2022 12:01
A set of Kotlin extension functions and helper classes for drawing multiline text to Canvas on Android
package com.nickrout.canvasmultilinetext
import android.graphics.Canvas
import android.os.Build
import android.support.annotation.RequiresApi
import android.text.*
import androidx.core.graphics.withTranslation
import androidx.core.util.lruCache
@RequiresApi(Build.VERSION_CODES.O)
MIT License
Copyright (c) 2018 Nicholas Rout
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
package com.nickrout.actionmode
import android.support.annotation.MenuRes
import android.view.ActionMode
import android.view.Menu
import android.view.MenuItem
import android.view.View
class PrimaryActionModeCallback : ActionMode.Callback {
package com.nickrout.actionmode
import android.graphics.Rect
import android.os.Build
import android.support.annotation.MenuRes
import android.support.annotation.RequiresApi
import android.view.ActionMode
import android.view.Menu
import android.view.MenuItem
import android.view.View
package com.nickrout.actionmode
import android.view.MenuItem
interface OnActionItemClickListener {
fun onActionItemClick(item: MenuItem)
}
package com.nickrout.snaphelperlistener
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SnapHelper
fun SnapHelper.getSnapPosition(recyclerView: RecyclerView): Int {
val layoutManager = recyclerView.layoutManager ?: return RecyclerView.NO_POSITION
val snapView = findSnapView(layoutManager) ?: return RecyclerView.NO_POSITION
return layoutManager.getPosition(snapView)
}
package com.nickrout.snaphelperlistener
interface OnSnapPositionChangeListener {
fun onSnapPositionChange(position: Int)
}
@ricknout
ricknout / SnapOnScrollListener.kt
Last active October 10, 2023 02:14
Change order of args to enable trailing lambda syntax
package com.nickrout.snaphelperlistener
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SnapHelper
class SnapOnScrollListener(
private val snapHelper: SnapHelper,
var behavior: Behavior = Behavior.NOTIFY_ON_SCROLL,
var onSnapPositionChangeListener: OnSnapPositionChangeListener? = null
) : RecyclerView.OnScrollListener() {
@ricknout
ricknout / RecyclerViewExt.kt
Last active June 21, 2020 00:00
Change order of args to enable trailing lambda syntax
package com.nickrout.snaphelperlistener
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SnapHelper
fun RecyclerView.attachSnapHelperWithListener(
snapHelper: SnapHelper,
behavior: SnapOnScrollListener.Behavior = SnapOnScrollListener.Behavior.NOTIFY_ON_SCROLL,
onSnapPositionChangeListener: OnSnapPositionChangeListener) {
snapHelper.attachToRecyclerView(this)
@ricknout
ricknout / slider.patch
Created October 3, 2019 07:22
A Git patch to be applied to https://github.com/material-components/material-components-android to reveal the Slider catalog demo
Index: catalog/build.gradle
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- catalog/build.gradle (revision 4d719031e44ca4573e34d5c9d1ce3a72e7c5d5e4)
+++ catalog/build.gradle (date 1570086427000)
@@ -58,6 +58,7 @@
'menu',
'radiobutton',