Skip to content

Instantly share code, notes, and snippets.

View whitipet's full-sized avatar
👨‍💻
Code Every Day

Petro Bilyi whitipet

👨‍💻
Code Every Day
View GitHub Profile
@whitipet
whitipet / adb_connect_to_hotspot.sh
Created May 24, 2023 18:18
Connect adb to the device that acts as a hotspot
adb connect $(route -n get default | grep gateway | awk '{ print $2 }')
@dzolnai
dzolnai / View.kt
Last active August 2, 2023 15:12
Expandable TextView with clickable '...read more'
import android.annotation.SuppressLint
import android.content.Context
import android.text.Layout
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.StaticLayout
import android.text.TextPaint
import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan
@dzolnai
dzolnai / DisallowToolbarExpand.kt
Created December 28, 2020 15:20
Disallow the toolbar expand on a collapsible toolbar layout
internal fun disallowToolbarExpand() {
// Taken from: https://stackoverflow.com/a/49218710/1395437
binding.appBar.setExpanded(false, false)
ViewCompat.setNestedScrollingEnabled(binding.content, false)
val params = binding.appBar.layoutParams as CoordinatorLayout.LayoutParams
if (params.behavior == null) {
params.behavior = AppBarLayout.Behavior()
}
val behaviour = params.behavior as AppBarLayout.Behavior
behaviour.setDragCallback(object : AppBarLayout.Behavior.DragCallback() {
@NathanHowell
NathanHowell / settings.gradle
Created June 25, 2019 20:04
Example settings.gradle to dynamically derive projects from build.gradle files
// find all build.gradle files in the expected locations in the build tree
fileTree('.')
.matching {
exclude '**/src/**', '**/build/**', '**/.*'
include '**/build.gradle'
}
.each {
// then convert the file path to a project path
final relative = rootProject.projectDir.relativePath(it.parentFile)
final project = ":${relative.replace('/', ':')}"
@chrisbanes
chrisbanes / ScopedViewModel.kt
Last active October 25, 2022 21:29
ScopedViewModel
open class ScopedViewModel : ViewModel() {
private val job = Job()
protected val scope: CoroutineScope = job + Dispatchers.Main
override fun onCleared() {
super.onCleared()
job.cancel()
}
}
@JulienArzul
JulienArzul / FadingEdgeRecyclerView.kt
Created July 11, 2018 06:09
RecyclerView class that supports drawing fading edges with clipToPadding=false
package com.julienarzul.android.recyclerview
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
class FadingEdgeRecyclerView : RecyclerView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
@chrisbanes
chrisbanes / code.kt
Last active August 10, 2023 10:46
Night Mode inflater
/*
* Copyright 2017 Google, Inc.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@nickbutcher
nickbutcher / MainActivity.kt
Last active February 22, 2024 21:17
Demonstrating how to tile a (Vector) Drawable
/*
* Copyright 2017 Google Inc.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@brescia123
brescia123 / ViewVisibilityExtensions.kt
Last active May 10, 2023 12:28
Useful Android Kotlin Extension functions to easily change the visibility of a View
/** Set the View visibility to VISIBLE and eventually animate the View alpha till 100% */
fun View.visible(animate: Boolean = true) {
if (animate) {
animate().alpha(1f).setDuration(300).setListener(object : AnimatorListenerAdapter() {
override fun onAnimationStart(animation: Animator) {
super.onAnimationStart(animation)
visibility = View.VISIBLE
}
})
} else {