Skip to content

Instantly share code, notes, and snippets.

View huuphuoc1396's full-sized avatar
🤪

Phuoc Bui huuphuoc1396

🤪
View GitHub Profile
@huuphuoc1396
huuphuoc1396 / MainActivity.kt
Last active October 19, 2020 07:45
Remove all callbacks when this activity is destroyed
override fun onDestroy() {
// Remove all callbacks when this activity is destroyed
displayManagerHelper?.unregisterCoverDisplayEnabledCallback(applicationContext.packageName)
displayManagerHelper?.unregisterSmartCoverCallback(smartCoverCallback)
super.onDestroy()
}
@huuphuoc1396
huuphuoc1396 / MainActivity.kt
Created January 13, 2020 17:03
Transform and scale animation on a View
package com.android.moveandscale
import android.animation.ObjectAnimator
import android.graphics.Point
import android.os.Bundle
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.RelativeLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
@huuphuoc1396
huuphuoc1396 / dpToPx.java
Created September 17, 2020 02:41
Convert dp, px, sp among each other (ref: https://bit.ly/35Qqyx4)
public static int dpToPx(float dp, Context context) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
}
@huuphuoc1396
huuphuoc1396 / RecyclerViewMatcher.kt
Created October 8, 2020 04:44
RecyclerView testing - Performing actions and matches on items by position
import android.content.res.Resources
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher
/**
* Performing actions and matches on items by position.
* @see <a href="https://github.com/dannyroa/espresso-samples">Android Espresso Samples by Danny Roa</a>
@huuphuoc1396
huuphuoc1396 / RecyclerViewItemCountAssertion.kt
Created October 8, 2020 04:46
RecyclerView testing - Using assert item count of RecyclerView adapter
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.ViewAssertion
import androidx.test.espresso.matcher.ViewMatchers.assertThat
import org.hamcrest.Matcher
import org.hamcrest.Matchers.`is`
/**
* Using assert item count of RecyclerView adapter
import android.view.View
import android.widget.HorizontalScrollView
import android.widget.ListView
import android.widget.ScrollView
import androidx.core.widget.NestedScrollView
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers.*
import org.hamcrest.Matcher
import org.hamcrest.Matchers
apply plugin: 'jacoco'
// Filter out modules
def jacocoCoveredProject = subprojects.findAll { project ->
project.name == "app" || project.name == "data" || project.name == "domain"
}
def coveredProject = subprojects
println("All subprojects:")
println(subprojects.name)
@huuphuoc1396
huuphuoc1396 / build.gradle
Last active July 30, 2024 20:46
Config your output file name in Gradle Kotlin DSL
import com.android.build.gradle.api.ApplicationVariant
import com.android.build.gradle.api.BaseVariantOutput
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
android {
//...
applicationVariants.all(ApplicationVariantAction())
}
@huuphuoc1396
huuphuoc1396 / HeaderItemDecoration.kt
Created November 17, 2020 08:04 — forked from filipkowicz/HeaderItemDecoration.kt
Item Decorator for sticky headers in Kotlin
package com.filipkowicz.headeritemdecorator
/*
solution based on - based on Sevastyan answer on StackOverflow
changes:
- take to account views offsets
- transformed to Kotlin
- now works on viewHolders
@huuphuoc1396
huuphuoc1396 / build.gradle.kts
Last active March 26, 2021 07:51
Fixing "Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option Adding support for Java 8 language features could solve this issue."
// Android App or Android Lib Module
plugins {
id(GradlePlugins.androidLib)
id(GradlePlugins.kotlinAndroid)
}
android {
kotlinOptions {
jvmTarget = "1.8"
}