Skip to content

Instantly share code, notes, and snippets.

View tprochazka's full-sized avatar

Tomáš Procházka tprochazka

View GitHub Profile
@tprochazka
tprochazka / build.gradle.kts
Created April 3, 2024 22:55
Android Library module: Copy one localication to another during build time
androidComponents.onVariants { variant ->
generateCopyValuesTask(variant, "values-sr-rRS", "values-b+sr+Latn", "copySerbianValuesTaskFor")
generateCopyValuesTask(variant, "values-es", "values-ca", "copySpanishValuesTaskFor")
generateCopyValuesTask(variant, "values-iw", "values-he", "copyHebrewValuesTaskFor")
}
fun generateCopyValuesTask(variant: LibraryVariant, sourceLocale: String, targetLocale: String, taskName: String) {
variant.sources.res?.let { source: SourceDirectories.Layered ->
val assetCreationTask =
project.tasks.register<CopyLocalizedResTask>("$taskName${variant.name}") {
@tprochazka
tprochazka / ScaleToFitLayout.kt
Created September 6, 2021 01:39
Layout manager that will simply render everything inside in requested size and then scale down it to fit the parent size.
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
import androidx.core.view.children
import kotlin.math.roundToInt
/**
* Layout manager that will simply render everything inside in requested size
* and then scale down it to fit the parent size.
@tprochazka
tprochazka / TypedArrayUtils.kt
Created May 30, 2021 21:42
Access to XML based textAppearance styles from Jetpack Compose
/*
* Copyright 2020 The Android Open Source Project
*
* 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
*
* Unless required by applicable law or agreed to in writing, software
@tprochazka
tprochazka / NoMainThreadWriteSharedPreferences.kt
Last active February 10, 2024 07:44
ANR free implementation of SharedPreference
/*
* Copyright 2020 AVAST Software s.r.o.
*
* 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
@tprochazka
tprochazka / RemoteSignTask.groovy
Last active January 17, 2019 11:49
Custom sign task implementation for Android Build Plugin compatible with build plugin 3.3.0 (with app bundle support)
import com.android.annotations.NonNull
import com.android.build.api.artifact.BuildableArtifact
import com.android.build.gradle.api.ApkVariant
import com.android.build.gradle.api.ApkVariantOutput
import com.google.common.io.Files
import org.gradle.api.Action
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.Project
@tprochazka
tprochazka / ISettableView.java
Created February 27, 2016 23:36
Example of solution for universal RecyclerViewAdapter
/**
* View that can be used with this adapter must implement this interfaces.
*/
public interface ISettableView<T> {
void setData(T item);
void setEventListener(RecylerViewAdapter.ViewItemEventListener<T> listener);
}
@tprochazka
tprochazka / KnightRider.ino
Last active January 12, 2016 22:40
Simplistic Knight Rider (KIT) lights implementation
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define LEDS 9
#define SUBSTEPS 8
#define DELAY 75
/*
* Example of use ESP8266 library
* https://github.com/Diaoul/arduino-ESP8266
*
* Created: 12/30/2014 7:29:04 PM
* Author: Tomáš Procházka
*/
#include <SoftwareSerial.h>
//#include <AltSoftSerial.h>
@tprochazka
tprochazka / build.gradle
Last active July 3, 2019 01:14
Smart versionName and versionCode for android Gradle build evaluation
/**
* Will return version from properties file and replace -SNAPSHOT by GIT commit hash
* to recognize origin commit for the every build.
*/
project.ext.evalVersionName = {
def ideBuild = project.properties['android.injected.invoked.from.ide']
if (ideBuild) {
logger.info("IDE build");
return "dev"
} else if (project.VERSION.toUpperCase().contains("SNAPSHOT")) {
@tprochazka
tprochazka / ALK.ino
Created June 9, 2014 17:57
Code for my Arduino Learning Kit project
/*
* Copyright (C) 2014 Tomas Prochazka
*
* 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