Skip to content

Instantly share code, notes, and snippets.

View gtomek's full-sized avatar

Tomek Giszczak gtomek

  • Zurich, CH
View GitHub Profile
@gtomek
gtomek / build.gradle.kts
Last active March 17, 2024 18:28
build gradle kts read properties file
import java.util.Properties
android {
compileSdkVersion(Config.Android.compileSdkVersion)
buildToolsVersion = Config.Android.buildToolsVersion
defaultConfig {
minSdkVersion(Config.Android.minSdkVersion)
versionCode = Config.Libs.versionCode
versionName = Config.Libs.versionName
@gtomek
gtomek / OkHttp3IdlingResource.kt
Created May 16, 2023 19:15
OkHttp3 IdlingResource in kotlin
class OkHttp3IdlingResource(
private val name: String,
private val dispatcher: Dispatcher
) : IdlingResource {
private val callbackReference = AtomicReference<ResourceCallback>()
init {
dispatcher.idleCallback = Runnable {
callbackReference.get()?.onTransitionToIdle()
102 # keep model classes e.g. kotlin data classes without need of @Keep or @SerializedName annotations
103 -keep class com.yourapppackage.app.**.model.** { <fields>; }
@gtomek
gtomek / arcCanvas.java
Last active April 20, 2022 02:16
How to draw a rounded arc on canvas Android
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(50);
// Setting the color of the circle
mPaint.setColor(Color.BLUE);
// Draw the circle at (x,y) with radius 250
@gtomek
gtomek / strictmode.kt
Created December 20, 2021 07:24
enable strict mode, just flashing
private void enableStrictMode() {
StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyFlashScreen()
.penaltyLog();
StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog();
StrictMode.setThreadPolicy(threadPolicyBuilder.build());
@gtomek
gtomek / IoUtilsWithOkIo.java
Created February 10, 2016 10:55
Read files with Okio
/**
* Utils for I/O operations.
* <p/>
* Created by Tomek on 09/06/15.
*/
public class IoUtils {
/**
* Reads file and returns a String.
*
@gtomek
gtomek / RotatingGradientView.kt
Last active February 1, 2021 09:48
example of how to rotate sweep gradient in android view
/**
* View showing rotating SweepGradient.
*/
class RotatingGradientView @JvmOverloads constructor(
context: Context?,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
private var middleX = 0f
@gtomek
gtomek / ConcurrencyHelpers.kt
Created June 9, 2020 10:38 — forked from objcode/ConcurrencyHelpers.kt
Helpers to control concurrency for one shot requests using Kotlin coroutines.
import kotlinx.coroutines.CoroutineStart.LAZY
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.yield
import java.util.concurrent.atomic.AtomicReference
import kotlin.DeprecationLevel.ERROR
@gtomek
gtomek / OkHttpCookieJar.java
Created April 30, 2020 07:59
Add cookie jar to OkHttp client
class OkHttpCookieJar {
/**
Requires okhttp-urlconnection aftefact
**/
public OkHttpClient getOkHttpWithCookies() {
// set cookies
CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
@gtomek
gtomek / CrashReportingTree.java
Last active February 4, 2020 14:26
Timber.Tree implementation for Crashlytics
/**
* Timber log tree for production.
*/
public class CrashReportingTree extends Timber.Tree{
@Override protected void log(int priority, String tag, String message, Throwable throwable) {
switch (priority) {
case Log.VERBOSE:
case Log.DEBUG:
case Log.INFO: