Skip to content

Instantly share code, notes, and snippets.

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@xvadsan
xvadsan / LoggerHandler
Created November 1, 2020 13:10
Log handler. Writing logs to a file via Timber.
import android.os.Build
import android.os.Environment
import android.util.Log
import org.threeten.bp.LocalDateTime
import tech.dcloud.erfid.core.base.extension.getDateTimeOfPattern
import tech.dcloud.erfid.ugrokit.BuildConfig
import timber.log.Timber
import java.io.File
import java.io.FileOutputStream
@xvadsan
xvadsan / ExceptionHandler
Last active November 1, 2020 13:14
Error exception handler. Writing logs to a file.
import android.os.Build
import android.os.Environment
import android.util.Log
import org.threeten.bp.LocalDateTime
import tech.dcloud.erfid.core.base.extension.getDateTimeOfPattern
import tech.dcloud.erfid.ugrokit.BuildConfig
import tech.dcloud.erfid.ugrokit.ui.util.LoggerHandler.Companion.TXT_NAME
import java.io.File
import java.io.FileOutputStream
@xvadsan
xvadsan / shortcuts
Created November 12, 2020 07:54
shortcuts
1) in manifest in main activity
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
2) shortcuts.xml
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
@xvadsan
xvadsan / RecyclerView init animation
Last active December 19, 2020 11:15
recycler view init animation
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutAnimation="@anim/layout_animation"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
@xvadsan
xvadsan / ViewVisibilityExtensions.kt
Created December 19, 2020 07:55 — forked from brescia123/ViewVisibilityExtensions.kt
Useful Android Kotlin Extension functions to easily change the visibility of a View
/** Set the View visibility to VISIBLE and eventually animate the View alpha till 100% */
fun View.visible(animate: Boolean = true) {
if (animate) {
animate().alpha(1f).setDuration(300).setListener(object : AnimatorListenerAdapter() {
override fun onAnimationStart(animation: Animator) {
super.onAnimationStart(animation)
visibility = View.VISIBLE
}
})
} else {
@xvadsan
xvadsan / Extention.kt
Created December 19, 2020 17:44 — forked from armanso/Extention.kt
Part 2 of blog post - Control view's shadow
fun View.setShadow(
@ColorRes shadowColor: Int,
@DimenRes cornerRadius: Int,
@DimenRes elevation: Int,
shadowGravity: Int = Gravity.BOTTOM,
@ColorRes backgroundColorResource: Int = 0
) {
val resource = context.resources
val firstLayer = 0
val ratioTopBottom = 3
@xvadsan
xvadsan / keyboard listener
Created December 23, 2020 11:20
keyboard listener
private var mLastContentHeight by Delegates.notNull<Int>()
private val keyboardLayoutListener = OnGlobalLayoutListener {
val currentContentHeight: Int = requireActivity().window.findViewById<View>(Window.ID_ANDROID_CONTENT).getHeight()
if (mLastContentHeight > currentContentHeight + 100) {
showKeyboard()
mLastContentHeight = currentContentHeight
} else if (currentContentHeight > mLastContentHeight + 100) {
hideKeyboard()
mLastContentHeight = currentContentHeight
@xvadsan
xvadsan / KeyboardEventListener
Last active December 23, 2020 11:27
KeyboardEventListener
fun Activity.getRootView(): View {
return findViewById(android.R.id.content)
}
fun Context.convertDpToPx(dp: Float): Float {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
dp,
this.resources.displayMetrics
)
}
@xvadsan
xvadsan / gradle.properties
Created December 29, 2020 11:13
gradle.properties
org.gradle.jvmargs=-Xmx12g -XX:MaxPermSize=4g -Dfile.encoding=UTF-8 -XX:+UseGCOverheadLimit -XX:GCTimeLimit=10 -XX:+HeapDumpOnOutOfMemoryError
org.gradle.daemon.idletimeout=120000
org.gradle.daemon=true
org.gradle.caching=true
org.gradle.configureondemand=true
org.gradle.parallel=true
org.gradle.unsafe.watch-fs=true
org.gradle.unsafe.configuration-cache=ON
room.incremental=true
android.enableSeparateRClassCompilation=true