Skip to content

Instantly share code, notes, and snippets.

View dmersiyanov's full-sized avatar

Dmitry Mersiyanov dmersiyanov

  • Moscow
View GitHub Profile
@mkovalyk
mkovalyk / PermissionManager.kt
Last active November 2, 2022 08:04
Make Android permission easier
package com.example.myapplication
import android.content.pm.PackageManager
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
@JCarlosR
JCarlosR / ApiAdapter.java
Created June 1, 2020 04:19
Retrofit 2 Example: Parsing dynamic JSON responses
package com.youtube.sorcjc.proyectoprofesionales.io;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.logging.HttpLoggingInterceptor;
import com.youtube.sorcjc.proyectoprofesionales.io.deserializers.LoginDeserializer;
import com.youtube.sorcjc.proyectoprofesionales.io.responses.LoginResponse;
import retrofit.GsonConverterFactory;
@tieorange
tieorange / ThrottledOnClickListener.kt
Last active September 18, 2023 07:03
A debounced onClickListener for Android
package com.westwingnow.android.utils
import android.os.SystemClock
import android.view.View
import java.util.*
/**
* A Throttled OnClickListener
* Rejects clicks that are too close together in time.
* This class is safe to use as an OnClickListener for multiple views, and will throttle each one separately.
@darnmason
darnmason / CircleTextSpan.java
Last active June 7, 2021 11:17
A span with a circle background and different color text, intended for one or 2 characters as more will affect the height of the span
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.style.ReplacementSpan;
public class CircleTextSpan extends ReplacementSpan {
private final int backgroundColor;
private final int textColor;
@kiwiandroiddev
kiwiandroiddev / RegexMaskTextWatcher.kt
Last active October 1, 2021 09:22
Android TextWatcher to restrict user input to match a given Regular Expression
/**
* Add this to (e.g.) an EditText via addTextChangedListener() to prevent any user input
* that doesn't match its supplied regex.
*
* Inspired by original Java code here: http://stackoverflow.com/a/11545229/1405990
*/
class RegexMaskTextWatcher(regexForInputToMatch : String) : TextWatcher {
private val regex = Pattern.compile(regexForInputToMatch)
private var previousText: String = ""
@joinAero
joinAero / SightFragment.java
Created January 14, 2016 13:37
Android - Fragment for handling view after it has been created and visible to user for the first time.
package cc.cubone.turbo.core.app;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
/**
* Fragment for handling view after it has been created and visible to user for the first time.
*
* <p>Specially in {@link android.support.v4.view.ViewPager}, the page will be created beforehand
@rfreedman
rfreedman / DebouncedOnClickListener.java
Created May 14, 2013 03:09
A debounced onClickListener for Android
import android.os.SystemClock;
import android.view.View;
import java.util.Map;
import java.util.WeakHashMap;
/**
* A Debounced OnClickListener
* Rejects clicks that are too close together in time.
* This class is safe to use as an OnClickListener for multiple views, and will debounce each one separately.