Skip to content

Instantly share code, notes, and snippets.

View passiondroid's full-sized avatar
🏠
Working from home

Arif Khan passiondroid

🏠
Working from home
View GitHub Profile
@passiondroid
passiondroid / OpacityHex.markdown
Last active March 1, 2024 21:49
Opacity percentage in a Hex color code

Android uses hexadecimal ARGB values, which are formatted as #AARRGGBB. That first pair of letters, the AA, represent the alpha channel. You must convert your decimal opacity values to a hexadecimal value. Here are the steps:

Alpha Hex Value Process

  • Take your opacity as a decimal value and multiply it by 255. So, if you have a block that is 50% opaque the decimal value would be .5. For example: .5 x 255 = 127.5

  • The fraction won't convert to hexadecimal, so you must round your number up or down to the nearest whole number. For example: 127.5 rounds up to 128; 55.25 rounds down to 55.

  • Enter your decimal value in a decimal-to-hexadecimal converter, like http://www.binaryhexconverter.com/decimal-to-hex-converter, and convert your values.

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end
import android.support.v7.recyclerview.extensions.ListAdapter
import android.support.v7.util.DiffUtil
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
class ${NAME} : ListAdapter<${Model_Class}, ${NAME}.ItemViewholder>(DiffCallback()) {
@passiondroid
passiondroid / RuntimePermissionHelper.java
Last active February 26, 2021 05:51
Android Runtime Permission Helper class
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
plugins {
id(BuildPlugins.androidApplication)
id(BuildPlugins.kotlinAndroid)
id(BuildPlugins.kotlinAndroidExtensions)
}
android {
compileSdkVersion(AndroidSdk.compile)
defaultConfig {
applicationId = "com.gradle.kotlindsl"
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath (BuildPlugins.androidGradlePlugin)
const val kotlinVersion = "1.3.21"
object BuildPlugins {
object Versions {
const val buildToolsVersion = "3.3.1"
}
const val androidGradlePlugin = "com.android.tools.build:gradle:${Versions.buildToolsVersion}"
const val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
repositories {
jcenter()
}
plugins {
`kotlin-dsl`
}
kotlinDslPluginOptions {
experimentalWarning.set(false)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
apply from: 'dependencies.gradle'
repositories {
google()
jcenter()
}
dependencies {
ext {
minSdkVersionAndroid = 15
targetSdkVersionAndroid = 28
compileSdkVersionAndroid = 28
buildToolsVersion = '3.3.1'
jetpackVersion = '1.0.0-beta01'
constraintLayoutVersion = '1.1.2'
kotlinVersion = '1.3.21'
espressoVersion = '3.1.0-alpha4'
android {
defaultConfig {
}
signingConfigs {
release {
val signing = project.rootProject.properties("signing.properties")
if (signing != null) {