Skip to content

Instantly share code, notes, and snippets.

@bolot
bolot / PeekingLinearLayoutManager.kt
Last active August 30, 2023 07:19
LinearLayoutManager subclass that "peeks", shows a portion of the adjacent child views.
class PeekingLinearLayoutManager : LinearLayoutManager {
@Suppress("Unused")
@JvmOverloads
constructor(context: Context?, @RecyclerView.Orientation orientation: Int = RecyclerView.VERTICAL, reverseLayout: Boolean = false) : super(context, orientation, reverseLayout)
@Suppress("Unused")
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)
override fun generateDefaultLayoutParams() =
scaledLayoutParams(super.generateDefaultLayoutParams())
@bolot
bolot / SingleFragmentActivity.kt
Last active August 15, 2017 14:24
Kotlin SingleFragmentActivity
package com.bignerdranch.android.kotlin
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v7.app.AppCompatActivity
abstract class SingleFragmentActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@bolot
bolot / adb_examples.md
Created June 13, 2017 20:13
adb examples

adb -d logcat -d > log_dump.txt

  • Write the current Android device logs to the file.
  • The first -d applies to adb and means "the only connected device".
  • The second -d applies to logcat and means "dump the contents and exit".

adb -s CAFEBABEDEADBEEF logcat -d > log_dump.txt

  • Same as previous, but connect to the device with the given serial number.
@bolot
bolot / android.xml
Created June 22, 2015 18:57
A few live templates for Android Studio. On my Mac, this file lives in `~/Library/Preferences/AndroidStudioPreview1.3/templates/android.xml`. The location of the file depends on the version of Android Studio and the type of the operating system.
<templateSet group="android">
<template name="focvb" value="@Override&#10;public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {&#10; View view = inflater.inflate(R.layout.fragment_$END$, container, false);&#10; ButterKnife.inject(this, view);&#10; return view;&#10;}&#10;" description="Fragment onCreateView with ButterKnife" toReformat="true" toShortenFQNames="true">
<context>
<option name="JAVA_CODE" value="false" />
<option name="JAVA_STATEMENT" value="false" />
<option name="JAVA_EXPRESSION" value="true" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_STRING" value="false" />
<option name="COMPLETION" value="false" />
@bolot
bolot / gist:3812249
Created October 1, 2012 14:50
Simulate memory warning in iOS
[[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)];