Skip to content

Instantly share code, notes, and snippets.

View belinwu's full-sized avatar

吴上阿吉 belinwu

View GitHub Profile
@JoseAlcerreca
JoseAlcerreca / Event.kt
Created April 26, 2018 10:25
An event wrapper for data that is exposed via a LiveData that represents an event.
/**
* Used as a wrapper for data that is exposed via a LiveData that represents an event.
*/
open class Event<out T>(private val content: T) {
var hasBeenHandled = false
private set // Allow external read but not write
/**
* Returns the content and prevents its use again.
@file:Suppress("unused", "FunctionName", "IllegalIdentifier")
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
/**
* The best way to launch yourself an activity. Your implementation should enable the following api:
@akperkins
akperkins / build.gradle
Last active July 23, 2019 03:44
Example of auto-generating the versionCode
apply plugin: 'com.android.application'
// version information
def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
@saurabhkpatel
saurabhkpatel / printActivityFlags.java
Last active May 6, 2024 10:43
[Android] : Print Activity Flags, it will be useful for the debug.
public static void printActivityFlags(String activityName, Intent intent) {
Field[] declaredFields = Intent.class.getDeclaredFields();
StringBuilder stringBuilder = new StringBuilder(activityName + " => ");
for (Field field : declaredFields) {
if (field.getName().startsWith("FLAG_")) { // Fetch all the flag names which start from "FLAG_"
try {
int flag = field.getInt(null);
if ((intent.getFlags() | flag) == intent.getFlags()) { // checking that flag is present or not.
stringBuilder.append(field.getName());
stringBuilder.append("|");
@StephaneBg
StephaneBg / build.gradle
Last active December 15, 2021 21:17
Set different signing configs with multiple flavors and dimensions
signingConfigs {
vanillaPaid {
...
}
vanillaFree {
...
}
chocolatePaid {
...
}
@awave1
awave1 / Blur.java
Created May 6, 2016 17:54
Blur drawable or bitmap on android using renderscript
public static class Blur {
private static final float BLUR_RADIUS = 20.5f; // 25 is maximum radius
// returns blur drawable if api >= 17. returns original drawable if not.
@Nullable
public static Drawable applyBlur(Drawable drawable, Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Bitmap fromDrawable = drawableToBitmap(drawable);
int width = Math.round(fromDrawable.getWidth() * 0.8f);
@maxirosson
maxirosson / build.gradle
Last active December 28, 2022 12:02
Versioning Android apps
apply plugin: 'com.android.application'
ext.versionMajor = 1
ext.versionMinor = 2
ext.versionPatch = 3
ext.versionClassifier = null
ext.isSnapshot = true
ext.minimumSdkVersion = 19
android {
@lopspower
lopspower / README.md
Last active May 5, 2025 05:07
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

Download This sample on Google Play Store

@TWiStErRob
TWiStErRob / OkHttpProgressGlideModule.java
Last active July 1, 2024 09:15
Full POC for showing progress of loading in Glide v3 via OkHttp v2
// TODO add <meta-data android:value="GlideModule" android:name="....OkHttpProgressGlideModule" />
// TODO add <meta-data android:value="GlideModule" tools:node="remove" android:name="com.bumptech.glide.integration.okhttp.OkHttpGlideModule" />
// or not use 'okhttp@aar' in Gradle depdendencies
public class OkHttpProgressGlideModule implements GlideModule {
@Override public void applyOptions(Context context, GlideBuilder builder) { }
@Override public void registerComponents(Context context, Glide glide) {
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(createInterceptor(new DispatchingProgressListener()));
glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
}
@cxyxlxdm
cxyxlxdm / GridSpacingItemDecoration.md
Last active April 19, 2024 08:43
Add column spacing in RecyclerView with GridLayoutManager

Android Recyclerview GridLayoutManager column spacing Here is the question, the first answer does not work well in my project,and it makes the spacing bigger between item and item. the second answer is quite perfect.But if RecyclerView has headers,it does not work well. Then I fixed it.

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**