Skip to content

Instantly share code, notes, and snippets.

View yasukotelin's full-sized avatar

Yasuhiro Kikura yasukotelin

View GitHub Profile
@yasukotelin
yasukotelin / Extentions.kt
Last active October 14, 2020 02:16
Epoxy Spacer item
fun Int.toDp(): Int = (this / Resources.getSystem().displayMetrics.density).toInt()
fun Int.toPx(): Int = (this * Resources.getSystem().displayMetrics.density).toInt()
class NoSwipeViewPager(context: Context, attrs: AttributeSet) : ViewPager(context, attrs) {
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
// disable swipe
return false
}
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
// disable swipe
@yasukotelin
yasukotelin / BottomWidgetBehavior.kt
Created August 19, 2020 16:37
CoordinatorLayoutでBottomの要素を消す挙動をするBehavior
class BottomWidgetBehavior<V : View>(context: Context, attrs: AttributeSet) :
CoordinatorLayout.Behavior<V>(context, attrs) {
override fun onStartNestedScroll(
coordinatorLayout: CoordinatorLayout,
child: V,
directTargetChild: View,
target: View,
axes: Int,
type: Int
import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.NestedScrollingChild
import androidx.core.view.NestedScrollingChildHelper
class NestedCoordinatorLayout : CoordinatorLayout, NestedScrollingChild {
private var mChildHelper: NestedScrollingChildHelper
@yasukotelin
yasukotelin / FabScrollAwareBehavior.kt
Last active August 26, 2020 16:15
FAB in CoordinatorLayoutでスクロール時にShow/HideするBehavior
import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.ViewCompat
import com.google.android.material.floatingactionbutton.FloatingActionButton
class ScrollAwareBehavior(context: Context?, attrs: AttributeSet?) :
FloatingActionButton.Behavior(context, attrs) {
@yasukotelin
yasukotelin / ViewPagerScrollingViewBehavior.kt
Created August 19, 2020 16:34
ViewPager2 in CoordinatorLayoutでBottomのViewを固定するBehavior
import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.google.android.material.appbar.AppBarLayout
class ViewPagerScrollingViewBehavior(context: Context?, attrs: AttributeSet?) :
AppBarLayout.ScrollingViewBehavior(context, attrs) {
override fun layoutDependsOn(
macro_rules! hashmap {
($( $key: expr => $val: expr ),*) => {{
let mut map = ::std::collections::HashMap::new();
$( map.insert($key, $val); )*
map
}}
}
@MainThread
inline fun <reified VM : ViewModel> Fragment.parentViewModels(
noinline ownerProducer: () -> ViewModelStoreOwner = { requireParentFragment() },
noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null
) = createViewModelLazy(VM::class, { ownerProducer().viewModelStore }, factoryProducer)
@yasukotelin
yasukotelin / main.rs
Last active August 16, 2020 07:30
Rust 競技プログラミング用テンプレート
fn main() {
}
fn read<T: std::str::FromStr>() -> T {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
@yasukotelin
yasukotelin / Event.kt
Last active July 2, 2020 06:57
Multiple observe single LiveData.
package [YOUR PACKAGE]
/*
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0