Skip to content

Instantly share code, notes, and snippets.

View HugoMatilla's full-sized avatar
🏠
Working from home

Hugo Matilla HugoMatilla

🏠
Working from home
View GitHub Profile
@HugoMatilla
HugoMatilla / colors_material_design.xml
Created September 23, 2020 16:16
Material Design Colors for Android apps.
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingDefaultResource">
<!-- google's material design colours from
http://www.google.com/design/spec/style/color.html#color-ui-color-palette -->
<!--reds-->
<color name="md_red_50">#FFEBEE</color>
<color name="md_red_100">#FFCDD2</color>
<color name="md_red_200">#EF9A9A</color>
<color name="md_red_300">#E57373</color>
@HugoMatilla
HugoMatilla / AddDarkModeButton.kt
Last active July 8, 2021 05:08
Add a DarkMode Button to your activity
fun addDarkModeButton() {
val darkButton = Button(this).apply {
text = if (getDefaultNightMode() != MODE_NIGHT_YES) "Go Dark " else "Go Light"
layoutParams = LayoutParams(MATCH_PARENT, WRAP_CONTENT)
}
(window.decorView as ViewGroup).addView(darkButton) // or `yourContainer.addView(darkButton)`
darkButton.setOnClickListener {
AppCompatDelegate.setDefaultNightMode(
#!/bin/bash
grep -rnw '.' -e 'android.support'

Get dependencies tree

./gradlew app:dependencies > deps.txt

Only for one configuration

./gradlew app:dependencies --configuration <productFlavors><buildTypeCapitalized>CompileClasspath
Modifier Corresponding member Comments for classes
final Can’t be overridden Used by default for class members
open Can be overridden Should be specified explicitly
abstract Must be overridden Can be used only in abstract classes; abstract members can’t have an implementation
override Overrides a member in a superclass or interface Overridden member is open by default if not marked final
abstract class Widget {
abstract fun draw() // open and must be overridden
open fun focus() {} // can be overridden
fun hide() {} // final by deafult, can't be overridden
}
class SuperSpecificButton : SpecificButton {
final override fun click() = print("Super Specific Click")
}
open class Button {
open fun click() = print("Click")
fun doubleClick() = print("Double Click")
}
class SpecificButton() : Button { // Inheritance is now possible
override fun click() = print("Specific Click") // Now it works
override fun doubleClick() = print("Specific Double Click") // Error
}
class Button {
fun click() = print("Click")
}
class SpecificButton : Button() { // Error
override fun click() = print("Specific Click") // Error
}
@HugoMatilla
HugoMatilla / Gradle Cheat Sheet.md
Last active February 23, 2021 07:36
Gradle Cheat Sheet

DEPENDENCIES TREE

./gradlew app:dependencies

With only first item

./gradlew <module-name>:dependencies | grep '\-\-\-' | grep -Po '\w+.*$' | awk -F ' ' '{ print $1 }' | sort | grep -v '\{' | grep -v '\[' | uniq | grep '.\+:.\+:.\+'

RUN TESTS

./gradlew test