Skip to content

Instantly share code, notes, and snippets.

import com.android.builder.testing.ConnectedDeviceProvider
def DEVICES_PROPERTY = "devices"
ConnectedDeviceProvider.metaClass.getProperty = { String name ->
def metaProperty = delegate.metaClass.getMetaProperty(name)
def property = metaProperty.getProperty(delegate)
if (name.equals(DEVICES_PROPERTY) && project.hasProperty(DEVICES_PROPERTY)) {
def devicesSerials = project.getProperties().get(DEVICES_PROPERTY).split(/,/)
def devices = property.findAll {devicesSerials.contains(it.serialNumber)}
property = devices
}
@Ghedeon
Ghedeon / gradlew
Created January 28, 2015 16:25
The script searches for the Gradle Wrapper in the current directory and its parent directories and executes it. https://issues.gradle.org/browse/GRADLE-1378?focusedCommentId=17529&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-17529
#!/bin/sh
D=$(pwd)
G="gradlew"
while [ ! -x "$D/$G" -a "$D" != "/" ]; do
D=$(dirname $D)
done
if [ ! -x "$D/$G" ]; then
echo "No Gradle found in current or parent directories!"
exit 1
fi
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "test.co.vv.myapplication"
minSdkVersion 15
targetSdkVersion 21
@Ghedeon
Ghedeon / HideBottomViewOnScrollBehavior.kt
Last active September 27, 2018 11:53
HideBottomViewOnScrollBehavior that ensures BottomView visibility
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.TimeInterpolator
import android.content.Context
import android.support.design.animation.AnimationUtils
import android.support.design.widget.CoordinatorLayout
import android.support.design.widget.Snackbar
import android.support.v4.view.ViewCompat
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
@Ghedeon
Ghedeon / NoSwipeabaleViewPager.kt
Last active November 3, 2018 22:20
A ViewPager with disabled swipe.
import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.KeyEvent
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager
class NoSwipeabaleViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ViewPager(context, attrs) {
@SuppressLint("ClickableViewAccessibility")
@Ghedeon
Ghedeon / Test.kt
Created February 1, 2019 18:58
Coroutine Test
class AccountOwnerTypeViewModelTest {
@Rule
@JvmField
val rule = InstantTaskExecutorRule()
val mainThreadSurrogate = newSingleThreadContext("UI thread")
@Before
fun setUp() {
@Ghedeon
Ghedeon / NotNull.kt
Created March 4, 2019 15:23
NotNull delegate with lazy message
fun <T: Any> notNull(lazyMessage: () -> Any): ReadWriteProperty<Any?, T> = NotNullVar(lazyMessage)
private class NotNullVar<T: Any>(val lazyMessage: () -> Any) : ReadWriteProperty<Any?, T> {
private var value: T? = null
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
return value ?: throw IllegalStateException(lazyMessage.toString())
}
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
@Ghedeon
Ghedeon / filter_devices.groovy
Created July 22, 2015 12:40
Android Gradle (1.3.0-beta4). Filter multiple devices
project.afterEvaluate {
project.("connectedDebugAndroidTest").doFirst {
def originalProvider = deviceProvider
deviceProvider = [
getName : { originalProvider.getName() },
init : { originalProvider.init() },
terminate : { originalProvider.terminate() },
getDevices : { filterDevices(originalProvider.getDevices()) },
getTimeoutInMs: { originalProvider.getTimeoutInMs() },
isConfigured : { originalProvider.isConfigured() },
@Ghedeon
Ghedeon / Example.kt
Created December 25, 2019 11:58
Multitype RecyclerView Adapter
recycler_view.withBindings {
+DateBinding()
+IncomingMessageBinding()
+OutgoingMessageBinding()
}
recycler_view.submitList(listOf<Widget.State>(...))
//**************************************************************//
class DateBinding : ItemBinding<DateWidget.State, DateWidget> {
@Ghedeon
Ghedeon / README.md
Last active June 26, 2020 05:26
Screenshot & Recorder

1. Screenshot

Description (no more than one connected device):

  1. Sets device in demo mode: hides your notifications, fixed clock, full battery, wifi level)
  2. Takes a screenshot and saves it into captures directory. Also to your clipboard, so it's ready for Paste
  3. Exits demo mode

Usage:

  1. Download screenshot.sh
  2. chmod +x screenshot.sh