Skip to content

Instantly share code, notes, and snippets.


Saurabh saurabharora90

View GitHub Profile
View MissingNightColorDetector.kt
private const val COLOR = "color"
class MissingNightColorDetector : ResourceXmlDetector() {
private val nightModeColors = mutableListOf<String>()
private val regularColors = mutableMapOf<String, Location>()
override fun appliesTo(folderType: ResourceFolderType): Boolean {
return folderType == ResourceFolderType.VALUES
saurabharora90 / colors.xml
Last active Aug 3, 2019
Missing Night Color
View colors.xml
<?xml version="1.0" encoding="utf-8"?>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
View MissingNightColorIssue.kt
object MissingNightColorIssue {
private const val ID = "MissingNightColor"
private const val DESCRIPTION = "Night Color missing"
const val EXPLANATION =
'''Night color value for this color resource seems to be missing.
If your app supports dark theme, then you should add an equivalent color resource for it in the night values folder.'''
private val CATEGORY = Category.CORRECTNESS
private const val PRIORITY = 6
private val SEVERITY = Severity.WARNING
View DarkThemeLintRegistry.kt
class DarkThemeLintRegistry : IssueRegistry() {
override val issues: List<Issue>
get() = listOf(DirectColorUseIssue.ISSUE)
View DirectColorUseDetector.kt
private const val BACKGROUND = "background"
private const val FOREGROUND = "foreground"
private const val SRC = "src"
private const val TEXT_COLOR = "textColor"
private const val TINT = "tint"
//Vector Drawables.
private const val FILL_COLOR = "fillColor"
private const val STROKE_COLOR = "strokeColor"
private const val COLOR = "color"
View DirectColorUseIssue.kt
object DirectColorUseIssue {
private const val ID = "DirectColorUse"
private const val DESCRIPTION = "Color used directly"
const val EXPLANATION =
'''Avoid direct use of colors in XML files.
This will cause issues with different theme (dark-theme?) support'''
private val CATEGORY = Category.CORRECTNESS
private const val PRIORITY = 6
private val SEVERITY = Severity.WARNING
View lint-module-build.gradle
apply plugin: 'java-library'
apply plugin: 'kotlin'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
compileOnly ''
compileOnly ''
saurabharora90 / MoveFab.kt
Created Jul 10, 2019
Move FAB above so that it doesn't conflict with transparent floating navigation bar
View MoveFab.kt
root.setOnApplyWindowInsetsListener { _, insets ->
val fabLp = fab.layoutParams as CoordinatorLayout.LayoutParams
fabLp.bottomMargin = fabOriginalBottomMargin + insets.systemWindowInsetBottom
fab.layoutParams = fabLp
saurabharora90 / BGLocation.kt
Last active Jul 10, 2019
Request access to location while app is in background,
View BGLocation.kt
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
//Request for the permission like any other permission request:
saurabharora90 / FullScreenPendingIntent.kt
Created Jul 9, 2019
Beginning with Android Q, Background Activity Starts should be done by notification triggered activities.
View FullScreenPendingIntent.kt
val fullScreenIntent = Intent(this,
val fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT)
val notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID)
.setFullScreenIntent(fullScreenPendingIntent, true)