Skip to content

Instantly share code, notes, and snippets.

View matpag's full-sized avatar
🐧
Noot-Nooting around

MatPag matpag

🐧
Noot-Nooting around
View GitHub Profile
@cbeyls
cbeyls / ContentLoadingProgressBar.java
Last active December 20, 2021 22:16
ContentLoadingProgressBar implemented The Right Way™
package be.digitalia.common.widgets;
import android.content.Context;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;
/**
* ContentLoadingProgressBar implements a ProgressBar that waits a minimum time to be
@Robyer
Robyer / maven-publish-helper-usage.gradle
Last active May 22, 2024 15:56
Gradle script for publishing Android library with sources and javadoc to Maven repository using maven-publish plugin.
// You can use maven-publish-helper.gradle script without changes and even share it between multiple
// modules. Just place the maven-publish-helper.gradle file in the root directory of your project,
// then apply it at the bottom of your module's build.gradle file like this:
// ...content of module's build.gradle file...
apply from: '../maven-publish-helper.gradle'
publishing {
publications {
@xian
xian / build.gradle
Last active January 12, 2023 11:41
Download Robolectric dependencies for hermetic build
def robolectricVersion = '3.3'
def androidSdkVersions = [
'4.1.2_r1-robolectric-0',
'4.2.2_r1.2-robolectric-0',
'4.3_r2-robolectric-0',
'4.4_r1-robolectric-1',
'5.0.0_r2-robolectric-1',
'5.1.1_r9-robolectric-1',
'6.0.0_r1-robolectric-0',
@dlimpid
dlimpid / string-md5.kt
Created July 7, 2017 09:34
Get MD5 hash of the string (of length 32, with leading zeros) in Kotlin
import java.math.BigInteger
import java.security.MessageDigest
fun String.md5(): String {
val md = MessageDigest.getInstance("MD5")
return BigInteger(1, md.digest(toByteArray())).toString(16).padStart(32, '0')
}
anonymous
anonymous / EmptyAdapter.java
Created September 27, 2017 20:47
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
/**
* Created on 27/Sep.
*/
@rubixhacker
rubixhacker / RxLiveData.kt
Created September 28, 2017 04:11
Kotlin extension functions to convert LiveData to and from a Flowable
// Add the following to your build.gradle file
// implementation "android.arch.lifecycle:reactivestreams:1.0.0-beta1"
import android.arch.lifecycle.LifecycleOwner
import android.arch.lifecycle.LiveData
import android.arch.lifecycle.LiveDataReactiveStreams
import io.reactivex.Flowable
/**
@JoseAlcerreca
JoseAlcerreca / EventObserver.kt
Created April 26, 2018 12:14
An Observer for Events, simplifying the pattern of checking if the Event's content has already been handled.
/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)
import android.app.Application
import android.arch.lifecycle.LiveData
import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkInfo
import android.net.NetworkRequest
import android.os.Build
import android.support.annotation.RequiresPermission
import android.support.annotation.VisibleForTesting
@erics
erics / executeGitInGradle.txt
Last active June 2, 2023 20:40
execute git command in gradle
def getGitCommand = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'log','--date=local','--name-status','--after="2018.07.19"'
standardOutput = stdout
}
return stdout.toString().trim()
}
task prinGitLog{
@afollestad
afollestad / BroadcastReceiver.kt
Last active January 14, 2024 10:23
A Lifecycle components aware BroadcastReceiver DSL (Kotlin)
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.lifecycle.Lifecycle.Event.ON_DESTROY
import androidx.lifecycle.Lifecycle.Event.ON_START
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
import android.content.BroadcastReceiver as StockReceiver