Skip to content

Instantly share code, notes, and snippets.

View belinwu's full-sized avatar

吴上阿吉 belinwu

View GitHub Profile
@lopspower
lopspower / README.md
Last active May 28, 2025 13:09
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

@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 {
@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);
@StephaneBg
StephaneBg / build.gradle
Last active December 15, 2021 21:17
Set different signing configs with multiple flavors and dimensions
signingConfigs {
vanillaPaid {
...
}
vanillaFree {
...
}
chocolatePaid {
...
}
@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("|");
@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"
@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:
@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.
@JoseAlcerreca
JoseAlcerreca / EventObserver.kt
Created April 26, 2018 12:14
An Observer for Events, simplifying the pattern of checking if the Event's content has already been handled.
/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)
@fay59
fay59 / Quirks of C.md
Last active May 23, 2025 21:05
Quirks of C

Here's a list of mildly interesting things about the C language that I learned mostly by consuming Clang's ASTs. Although surprises are getting sparser, I might continue to update this document over time.

There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.

1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]

struct foo {
   struct bar {
 int x;