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
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
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
fun Fragment.performHapticFeedback(effectId: Int) { | |
val vibrator = requireContext().getSystemService(Context.VIBRATOR_SERVICE) as Vibrator | |
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { | |
vibrator.vibrate(VibrationEffect.createPredefined(effectId)) | |
} | |
} |
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.view.HapticFeedbackConstants | |
import android.view.MotionEvent | |
import android.view.View | |
/** | |
* Viewへのタップイベントに対してHaptic feedbackするヘルパー | |
*/ | |
class HapticOnTapHelper : HapticOnTouchHelper { | |
override fun onTouch(v: View, e: MotionEvent): Boolean { | |
val isHandled = v.onTouchEvent(e) |
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 main(args: Array<String>) { | |
when (val r1 = getUser()) { | |
is Result.Success -> { | |
when (val r2 = login(r1.data)) { | |
is Result.Success -> { | |
when (val r3 = setupSomething()) { | |
is Result.Success -> { | |
println("Success") | |
} |
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 androidx.compose.foundation.layout.Arrangement | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.Alignment | |
import androidx.compose.ui.Modifier | |
@Composable | |
fun Center( | |
modifier: Modifier = Modifier, |
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
/** | |
* BottomSheetDialogを全画面表示する | |
*/ | |
fun BottomSheetDialogFragment.fullScreen() { | |
dialog?.setOnShowListener { dialog -> | |
val d = dialog as BottomSheetDialog | |
val bottomSheet = | |
d.findViewById<FrameLayout>(R.id.design_bottom_sheet) ?: return@setOnShowListener | |
bottomSheet.layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT | |
val screenHeight = Resources.getSystem().displayMetrics.heightPixels |
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.view.ViewGroup | |
import com.google.android.material.tabs.TabLayout | |
/** | |
* Tab表示が画面に収まる場合と収まらない場合とでTab mode指定を切り替える | |
* | |
* Tabサイズが画面に収まる場合は[TabLayout.MODE_FIXED] | |
* Tabサイズが画面に収まらない場合は[TabLayout.MODE_SCROLLABLE] | |
*/ | |
fun TabLayout.adjustTabMode() { |