Skip to content

Instantly share code, notes, and snippets.

View jd-alexander's full-sized avatar
🏠
Working from home

Joel Dean jd-alexander

🏠
Working from home
View GitHub Profile
@Preview()
@Composable
fun Card() {
var rotationX by remember { mutableStateOf(0f) }
var rotationY by remember { mutableStateOf(0f) }
Box(
Modifier
.fillMaxSize()
.background(Color.Black)) {
Box(
@LennyLizowzskiy
LennyLizowzskiy / Bitmappable.kt
Created July 21, 2023 12:26
Jetpack Compose / Composable to Bitmap converter
import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import android.graphics.Bitmap
import android.os.Handler
import android.os.Looper
import android.view.PixelCopy
import android.view.View
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
@alexjlockwood
alexjlockwood / TypedArrayUtils.kt
Created August 13, 2019 16:51
Kotlin helper functions for extracting ColorStateLists and Drawables from a TypedArray using AppCompatResources.
import android.content.Context
import android.content.res.ColorStateList
import android.content.res.TypedArray
import android.graphics.drawable.Drawable
import androidx.annotation.StyleableRes
import androidx.appcompat.content.res.AppCompatResources
/**
* Utility methods for extracting [ColorStateList]s and [Drawable]s from a [TypedArray].
@ThePredators
ThePredators / AndroidWorkerInjection.java
Last active December 30, 2021 03:27
[Dagger] integration with workers (For Java People)
public class AndroidWorkerInjection {
public static void inject(Worker worker) {
checkNotNull(worker, "worker");
Object application = worker.getApplicationContext();
if (!(application instanceof HasWorkerInjector)) {
throw new RuntimeException(
String.format(
"%s does not implement %s",
application.getClass().getCanonicalName(),
@SabagRonen
SabagRonen / FakeFragmentInjector.kt
Last active August 31, 2019 15:59
Fragment espresso with Dagger
inline fun <reified F : Fragment> createFakeFragmentInjector(crossinline block : F.() -> Unit)
: DispatchingAndroidInjector<Any> {
val myApp = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as MyApp
val originalDispatchingActivityInjector = myApp.dispatchingActivityInjector
var originalFragmentInjector: AndroidInjector<Any>? = null
val fragmentInjector = AndroidInjector<Fragment> { fragment ->
originalFragmentInjector?.inject(fragment)
if (fragment is F) {
fragment.block()
}
@cbeyls
cbeyls / KotlinFunctions.md
Last active June 20, 2022 14:59
Comparison of Kotlin functions: also, apply, let, run, with
Function Function type Target passed as Returns
also Extension it Target
apply Extension this Target
let Extension it Block return value
run Extension this Block return value
with Regular this Block return value
@nightscape
nightscape / Example.java
Created October 21, 2016 19:59
Simple RxJava-based adapter for an Android RecyclerView
public class ReactiveTextViewHolder<T> extends ReactiveViewHolder<T> {
private TextView label;
private T currentItem;
public ReactiveTextViewHolder(View itemView) {
super(itemView);
label = (TextView) itemView.findViewById(android.R.id.text1);
}
@JonDouglas
JonDouglas / xamarinandroidbindings.md
Last active March 12, 2024 10:36
Xamarin Android Bindings Troubleshooting

Approaching a Xamarin.Android Bindings Case

1. Investigation

One of the best ways to investigate a problematic Xamarin.Android Binding is to first ensure you have the proper tooling available:

@danielgomezrico
danielgomezrico / AndroidManifest.xml
Last active March 26, 2023 11:57 — forked from xrigau/AndroidManifest.xml
Android - AndroidJUnitRunner that disable animations, disable screen lock and wake processor all the time to avoid Tests to fail because of test device setup. Note that my test buildType is mock to have a manifest just for tests (dont want to ship an app with SET_ANIMATION_SCALE permissions...).
<?xml version="1.0" encoding="utf-8"?>
<!-- This file should be outside of release manifest (in this case app/src/mock/Manifest.xml -->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tests">
<!-- For espresso testing purposes, this is removed in live builds, but not in dev builds -->
<uses-permission android:name="android.permission.SET_ANIMATION_SCALE" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
@curioustechizen
curioustechizen / UseApiKey.java
Created April 6, 2015 07:37
Android: Loading API Keys and other secrets from properties file using gradle
String apiKey = BuildConfig.API_KEY