Skip to content

Instantly share code, notes, and snippets.

@strooooke
strooooke / AppBarBoundFabBehavior.java
Last active May 28, 2021 03:12
FAB behavior that lets FAB scroll out towards the bottom in sync with AppBarLayout scrolling out towards the top
/**
* Behavior for FABs that does not support anchoring to AppBarLayout, but instead translates the FAB
* out of the bottom in sync with the AppBarLayout collapsing towards the top.
* <p>
* Extends FloatingActionButton.Behavior to keep using the pre-Lollipop shadow padding offset.
*/
public class AppBarBoundFabBehavior extends FloatingActionButton.Behavior {
public AppBarBoundFabBehavior(Context context, AttributeSet attrs) {
super();
@strooooke
strooooke / choose_device.sh
Created April 29, 2017 11:57
Wrapper script for adb commands (and pidcat!) that take a -s device serial argument, allowing to choose between devices
#!/bin/bash
# Prompts for device to use from adb devices -l first; inserts -s parameter.
# No sanitizing, error checking or warranties!
# Use like
# $choose_device adb shell
DEVICES=`adb devices -l | sed 1d`
PS3="Choose device or Ctrl+C to quit: "
@strooooke
strooooke / ExampleAdapter.kt
Created September 10, 2020 13:39
BoundFunction - directly binding callbacks for RecyclerView items
// Using ListAdapter for the shorter example; the same holds for any use of (Async)ListDiffer - the point here
// is about easy implementation of [areContentsTheSame] by just using equality on data class items.
// The expectation here is that updates to the item list result in the correct adapter notifications (and resulting
// animations).
class ExampleAdapter : ListAdapter<ExampleViewHolder, ExampleItem>(ExampleDiffCallback) {
object ExampleDiffCallback : DiffUtil.ItemCallback<ExampleItem> {
override fun areItemsTheSame(oldItem: ExampleItem, newItem: ExampleItem) = oldItem.id == newItem.id
override fun areContentsTheSame(oldItem: ExampleItem, newItem: ExampleItem) = oldItem == newItem