Skip to content

Instantly share code, notes, and snippets.

@SimonMarquis
SimonMarquis / scheme.html
Last active March 11, 2024 06:23
Trigger the provided url scheme or fallback to Google Play Store
<!DOCTYPE html>
<html>
<head>
<script src="scheme.js"></script>
<script type="text/javascript">
// myscheme://init?param1=value1&param2=value2
var scheme = "myscheme";
var data = "init?param1=value1&param2=value2";
var packagename = "com.example.scheme";
</script>
@SimonMarquis
SimonMarquis / Dockerfile
Last active January 28, 2024 14:38
Dockerfile to build Android apps (API 34 & JDK 21)
FROM eclipse-temurin:21-jdk
LABEL maintainer "Simon Marquis <contact@simon-marquis.fr>"
LABEL description "A Docker image for Android devs."
LABEL version "1.0.0"
ARG CMD_LINE_VERSION=11076708
ARG ANDROID_VERSION=34
ARG ANDROID_BUILD_TOOLS_VERSION=34.0.0

Privacy Policy

This application does not collect or store personal data.
If you installed this application from Google Play, take a look at https://policies.google.com/privacy.

@SimonMarquis
SimonMarquis / Extensions.kt
Created November 12, 2021 20:14
Sealed object instances
import kotlin.reflect.KClass
fun <T : Any> KClass<T>.sealedObjectInstances() = recursiveSealedObjectInstances()
private tailrec fun <T : Any> KClass<T>.recursiveSealedObjectInstances(
sealedSubclasses: List<KClass<out T>> = listOf(this),
acc: Set<T> = emptySet(),
): Set<T> = when {
sealedSubclasses.isEmpty() -> acc
else -> recursiveSealedObjectInstances(
@SimonMarquis
SimonMarquis / PreventScreenshot.java
Created October 21, 2016 08:23
Prevent screenshot on Activity, Dialog, Surface, etc.
import android.app.Activity;
import android.app.Dialog;
import android.app.Fragment;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.SurfaceView;
import android.view.Window;
import android.view.WindowManager;
/**
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
public abstract class LazyGetter<T> {
private final AtomicReference<Optional<T>> mCachedValue = new AtomicReference<>(Optional.<T>empty());
public final T get() {
Optional<T> value = mCachedValue.get();
if (!value.isPresent()) {
@SimonMarquis
SimonMarquis / Utils.java
Created May 22, 2016 12:46
Android utils
import android.Manifest;
import android.animation.Keyframe;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
file=$(date +%Y.%m.%d-%H.%M.%S).mp4 \
&& path="/sdcard/$file" \
&& time=${1-30} \
&& bitrate=${2-20000000} \
&& adb shell screenrecord --time-limit "$time" --bit-rate "$bitrate" "$path" \
&& echo "Success" \
&& echo "Uploading..." \
&& adb pull "$path" \
&& adb shell rm "$path" \
&& echo "Screencapture saved at $(pwd)/$file" \
file=$(date +%Y.%m.%d-%H.%M.%S).png \
&& path="/sdcard/$file" \
&& adb shell screencap -p "$path" \
&& adb pull "$path" \
&& adb shell rm "$path" \
&& echo "Screenshot saved at $(pwd)/$file" \
|| echo "Screenshot failed"