Skip to content

Instantly share code, notes, and snippets.

View stepango's full-sized avatar
👁️
Making devs happier with Bazel

Stepan Goncharov stepango

👁️
Making devs happier with Bazel
View GitHub Profile
@stepango
stepango / KotlinActivity
Created September 9, 2014 20:29
Android kotlin lazy view injector
class KotlinActivity : Activity() {
val btn: Button? by find(R.id.button)
override fun onCreate(savedInstanceState: Bundle?) {
super<Activity>.onCreate(savedInstanceState)
setContentView(R.layout.main)
btn?.setText("Hello from kotlin")
}
@stepango
stepango / Activity.kt
Last active December 24, 2015 02:28
Android Activity extensions
import android.app.Activity
import android.widget.Toast
import android.view.View
import kotlin.properties.Delegates
import android.app.Fragment
fun Activity.toast(s: CharSequence, length: Int = Toast.LENGTH_SHORT) =
Toast.makeText(this, s, length).show()
fun <T : View?>Activity.find(id: Int) =
@stepango
stepango / material_colors
Last active August 29, 2015 14:08
Google Material theme colors
<!-- RED -->
<color name="red_50">#fde0dc</color>
<color name="red_100">#f9bdbb</color>
<color name="red_200">#f69988</color>
<color name="red_300">#f36c60</color>
<color name="red_400">#e84e40</color>
<color name="red_500">#e51c23</color>
<color name="red_600">#dd191d</color>
<color name="red_700">#d01716</color>
<color name="red_800">#c41411</color>
@stepango
stepango / build.gradle
Created December 4, 2014 13:33
Version number using gradle and git
Integer getVersionCode() {
def sout = new StringBuffer()
def proc = 'git rev-list HEAD --count'.execute()
proc.consumeProcessOutput(sout, new StringBuffer())
proc.waitForOrKill(1000)
return sout.toInteger()
}
@stepango
stepango / App.java
Last active August 29, 2015 14:11
Glide crash
public class App extends Application {
public void onCreate() {
super.onCreate();
AsyncTask.execute(new Runnable() {
@Override
public void run() {
Glide.get(App.this).register(GlideUrl.class, InputStream.class,
new OkHttpUrlLoader.Factory(new OkHttpClient()));
}
});
@stepango
stepango / BlurTransform.java
Last active May 23, 2023 10:14
Glide compatible fast blur bitmap transformation.
package com.bandlab.bandlab.transformation;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.support.annotation.ColorRes;
@stepango
stepango / ktError
Created June 21, 2015 04:03
Kotlin 0.12.613 gradle error DataBindings
[ERROR]: cannot generate view binders java.lang.NoClassDefFoundError: kotlin/jvm/internal/ExtensionFunctionImpl
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
@stepango
stepango / Instagram style EllipsizingTextView
Created September 21, 2015 07:06
Android TextView not support ellipsize if your text fills more than i line. This implementation solved this problem and allow you to use Instagram style end of line mark "[...]"
/*
* Copyright (C) 2011 Micah Hainline
* Copyright (C) 2012 Triposo
* Copyright (C) 2013 Paul Imhoff
* Copyright (C) 2014 Shahin Yousefi
* Copyright (C) 2015 Stepan Goncharov
*
* 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
@stepango
stepango / EllipsizingTextView.java
Last active June 8, 2022 07:46
Android TextView not support ellipsize if your text fills more than i line. This implementation solved this problem and allow you to use Instagram style end of line mark "[...]"
/*
* Copyright (C) 2011 Micah Hainline
* Copyright (C) 2012 Triposo
* Copyright (C) 2013 Paul Imhoff
* Copyright (C) 2014 Shahin Yousefi
* Copyright (C) 2015 Stepan Goncharov
*
* 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
@stepango
stepango / String.kt
Created December 24, 2015 02:26
IsEmpty check for null string made easy
fun String?.isEmpty() :Boolean = this == null || "".equals(this)
val a :String? = null
a.isEmpty() // true