Skip to content

Instantly share code, notes, and snippets.

View yfujiki's full-sized avatar
💭
Moving around

Yuichi Fujiki yfujiki

💭
Moving around
  • Athlee Ltd
  • Japan
View GitHub Profile
@yfujiki
yfujiki / snap helper.kt
Created December 15, 2018 08:21
SnapHelper that achieves ViewPager like snap for RecyclerView
val snapHelper = object : LinearSnapHelper() {
override fun findTargetSnapPosition(
layoutManager: RecyclerView.LayoutManager?,
velocityX: Int,
velocityY: Int
): Int {
val centerView = findSnapView(layoutManager!!) ?: return RecyclerView.NO_POSITION
var targetPosition = layoutManager.getPosition(centerView)
if (currentPosition != targetPosition) {
@yfujiki
yfujiki / iOS simulator screen recording to gif
Last active January 17, 2019 19:04
Slightly modified Alfred Script of https://github.com/alexp2ad/record-ios-simulator to create gif version from mp4.
#!/bin/bash
# Starts and stops recording in the simulator
# Set your prefered output directory here
outputDirectory=~/Desktop/
# Open recordings in the default app when ending recording
openRecordings=true
@yfujiki
yfujiki / Record gif from connected Android device screen
Created January 17, 2019 20:00
Record gif from connected Android device screen. Slightly modified the script from https://gist.github.com/sveinungkb/3a5753da908489fc0c26
#!/bin/sh
PREFIX="Screenshot-$(date +%Y%m%d-%H%M%S)"
BASE="/sdcard/$PREFIX"
OUTPUT="$YOUR_OUT_PUT_DIRECTORY" # Need to modify this to suit your environment
DELAY=30
trap ctrl_c INT
function clean_up() {
@yfujiki
yfujiki / BackgroundMatchers.kt
Last active January 21, 2019 16:03
Custom matcher for Espresso to check whether the background shape has a border or not
//
// Usage :
// onView(withId(R.id...)
// .check(
// ViewAssertions.matches(
// BackgroundViewMatchers.backgroundHasBorder()
// )
// )
// )
//
@yfujiki
yfujiki / MainActivityFragment.kt
Last active February 5, 2019 05:38
RecyclerViewMemoryLeak
class MainActivityFragment : Fragment() {
// Fragment keeps the reference to the RecyclerView adapter
private lateinit var adapter: MainRecyclerViewAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
adapter = MainRecyclerViewAdapter()
retainInstance = true
}
class MainActivityFragment : Fragment() {
// Discard permanent reference to the adapter
- val adapter = MainRecyclerViewAdapter()
-
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
return inflater.inflate(R.layout.fragment_activity_main, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
class MainActivityFragment : Fragment() {
// Discard permanent reference to the adapter
val adapter = MainRecyclerViewAdapter()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
return inflater.inflate(R.layout.fragment_activity_main, container, false)
}
+ override fun onDestroyView() {
@yfujiki
yfujiki / UIScrollViewDelegate-layoutImages.swift
Last active February 5, 2019 05:48
Infinite Scrolling with UIScrollView
private func layoutImages() {
let w = scrollView.frame.size.width
let h = scrollView.frame.size.height
imageViews.enumerated().forEach { (index: Int, imageView: UIImageView) in
imageView.image = images[index]
imageView.frame = CGRect(x: w * CGFloat(index),
y: 0,
width: w,
height: h)
}
@yfujiki
yfujiki / naiiveUILabelExtension.swift
Last active February 10, 2019 23:23
Naive UILabel Extension to change font globally
extension UILabel {
@objc var substituteFontName: String {
get {
return font.fontName
}
set {
font = UIFont(name: newValue, size: font.pointSize)
}
}
}
@yfujiki
yfujiki / callSubstituteFileName.swift
Created February 10, 2019 23:26
Calling substituteFontName
class AppDelegate: UIResponder, UIApplicationDelegate {
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
UILabel.appearance().substituteFontName = "Gills Sans"
...
return true