This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Int.toDp(): Int = (this / Resources.getSystem().displayMetrics.density).toInt() | |
fun Int.toPx(): Int = (this * Resources.getSystem().displayMetrics.density).toInt() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! hashmap { | |
($( $key: expr => $val: expr ),*) => {{ | |
let mut map = ::std::collections::HashMap::new(); | |
$( map.insert($key, $val); )* | |
map | |
}} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@MainThread | |
inline fun <reified VM : ViewModel> Fragment.parentViewModels( | |
noinline ownerProducer: () -> ViewModelStoreOwner = { requireParentFragment() }, | |
noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null | |
) = createViewModelLazy(VM::class, { ownerProducer().viewModelStore }, factoryProducer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |