Skip to content

Instantly share code, notes, and snippets.

View saurabharora90's full-sized avatar

Saurabh saurabharora90

View GitHub Profile
@saurabharora90
saurabharora90 / DarkThemeLintRegistry.kt
Created July 29, 2019 16:33
Dark Theme Lint Checks
class DarkThemeLintRegistry : IssueRegistry() {
override val issues: List<Issue>
get() = listOf(DirectColorUseIssue.ISSUE)
}
@saurabharora90
saurabharora90 / DirectColorUseDetector.kt
Last active July 29, 2019 16:25
Dark Theme Lint Checks
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"
@saurabharora90
saurabharora90 / DirectColorUseIssue.kt
Last active July 29, 2019 16:04
Dark Theme Lint Checks
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
@saurabharora90
saurabharora90 / lint-module-build.gradle
Last active July 29, 2019 15:54
Dark Theme Lint Checks
apply plugin: 'java-library'
apply plugin: 'kotlin'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
compileOnly 'com.android.tools.lint:lint-api:26.4.1'
compileOnly 'com.android.tools.lint:lint-checks:26.4.1'
}
@saurabharora90
saurabharora90 / MoveFab.kt
Created July 10, 2019 17:16
Move FAB above so that it doesn't conflict with transparent floating navigation bar
root.setOnApplyWindowInsetsListener { _, insets ->
val fabLp = fab.layoutParams as CoordinatorLayout.LayoutParams
fabLp.bottomMargin = fabOriginalBottomMargin + insets.systemWindowInsetBottom
fab.layoutParams = fabLp
insets.consumeSystemWindowInsets()
}
@saurabharora90
saurabharora90 / BGLocation.kt
Last active July 10, 2019 16:01
Request access to location while app is in background,
<manifest>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
</manifest>
//Request for the permission like any other permission request:
ActivityCompat.requestPermissions(this,
arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION),
your-permission-request-code)
@saurabharora90
saurabharora90 / layout.xml
Created September 30, 2018 07:56
Motion Layout Example - Building the example shown at Google IO: https://youtu.be/ytZteMo4ETk?t=31m59s
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
app:layoutDescription="@xml/scene_05"
android:layout_height="match_parent">
<ImageView
android:id="@+id/ivDusk"
android:layout_width="0dp"
private val customTabActivityHelper: CustomTabActivityHelper =
CustomTabActivityHelper(this, lifecycle, this)
override fun onClick(view: View) {
val viewId = view.id
val uri = Uri.parse(urlEditText.text.toString())
when (viewId) {
R.id.button_may_launch_url -> customTabActivityHelper.mayLaunchUrl(uri)
R.id.start_custom_tab -> {
val customTabsIntent = CustomTabsIntent.Builder(customTabActivityHelper.session)
@Override
protected void onDestroy() {
super.onDestroy();
customTabActivityHelper.setConnectionCallback(null);
}
@Override
protected void onStart() {
super.onStart();
customTabActivityHelper.bindCustomTabsService(this);
@saurabharora90
saurabharora90 / Manfiest.xml
Last active February 17, 2018 17:19
Primer on Styles and Themes - Seekbar theme
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme">
</activity>