Skip to content

Instantly share code, notes, and snippets.

View Miha-x64's full-sized avatar
🍵
へ‿(◉‿◉)‿ㄏ

Mike Miha-x64

🍵
へ‿(◉‿◉)‿ㄏ
View GitHub Profile
import android.graphics.Bitmap;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import java.util.Arrays;
/**
* This is copied from https://stackoverflow.com/a/10028267/3050249
* and optimized for less memory consumption & better locality, and creates less GC pressure.
@Miha-x64
Miha-x64 / EditableAdapter.kt
Last active July 10, 2023 09:24
Another approach to EditTexts inside RecyclerView
import android.text.Editable
import android.text.SpannableStringBuilder
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.EditText
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
@Miha-x64
Miha-x64 / SpanningLinearLayoutManager.java
Last active May 24, 2023 16:37 — forked from heinrichreimer/LICENSE
LinearLayoutManager which distributes available space equally between all items. Changed: works also when items are added or removed.
package net.aquadc.recycler;
import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
/**
@Miha-x64
Miha-x64 / _AsyncVox.md
Last active April 10, 2023 09:29
async-await for VoxImplant VoxEngine

This library provides several awaitable commands to VoxImplant VoxEngine API.

This is unnofficial community-driven software licensed under Apache 2.0 and provided “as is”, without warranty of any kind.

Idea

There's a plenty of event listeners and async callbacks, as always in JS. The idea is to provide a handy way of managing async operations and awaiting their results.

Singleton

  1. Roll-your-own lazy singleton

    public final class Single {
        private static Single INSTANCE;
        private Single() {}
        
@Miha-x64
Miha-x64 / proguard-rules.pro
Last active March 13, 2023 07:27
Healthy person's ProGuard rules for Android and Kotlin.
# preverify is useful only for J2ME
# R8 doesn't preverify by default
#-dontpreverify
-optimizationpasses 5
# this seems to be enough
# remove indirection
-allowaccessmodification
@Miha-x64
Miha-x64 / DynamicActivity.java
Created May 23, 2017 14:58
An activity which copies an APK from assets to private directory, and loads a class and resources from it.
package whatever.dynamicapkloading;
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.TextView;
@Miha-x64
Miha-x64 / Xml.java
Last active December 22, 2022 14:03
HTML/XML escaping utils, answering https://stackoverflow.com/a/61215915/3050249
import java.io.IOException;
import java.io.UncheckedIOException;
/**
* XML escaping utils.
*
* Source: https://gist.github.com/Miha-x64/4ed50f1d5593e45a452efbf456aa1db4
*/
public final class Xml {
class GradientStrokeDrawable : Drawable() {
var radius: Float = 0f
set(radius) {
if (field != radius) {
check(radius.isFinite() && radius >= 0f)
field = radius
path.rewind()
invalidateSelf()
}
@Miha-x64
Miha-x64 / GsonNullValueSkipping.java
Last active June 9, 2022 14:19
Gson has serializeNulls() setting but doesn't have dontDeserializeNulls(). This is useful to avoid assigning nulls to properties keeping their default values assigned in constructor instead.
import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.TypeAdapter;
import com.google.gson.internal.JsonReaderInternalAccess;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import com.google.gson.stream.MalformedJsonException;
import okhttp3.MediaType;