Skip to content

Instantly share code, notes, and snippets.

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

Simone Mapelli nadar71

🏠
Working from home
View GitHub Profile
@nadar71
nadar71 / TimerUtility.kt
Created October 21, 2020 09:39
Count Down timer utility
import android.os.CountDownTimer
class CountdownTimerUtility {
var countdowntimer: CountDownTimer? = null
//start timer function
fun startTimer(duration: Long, countDownStep: Long, executeOnFinish: ()->Unit) {
countdowntimer = object : CountDownTimer(duration, countDownStep) {
override fun onTick(millisUntilFinished: Long) {}
@nadar71
nadar71 / OnSingleClickListener.kt
Created October 21, 2020 09:38
Avoid single click
import android.view.View
// * for issue 1189:
// https://stackoverflow.com/questions/51060762/illegalargumentexception-navigation-destination-xxx-is-unknown-to-this-navcontr
class OnSingleClickListener : View.OnClickListener {
private val onClickListener: View.OnClickListener
constructor(listener: View.OnClickListener) {
onClickListener = listener
@nadar71
nadar71 / ColorConverter.kt
Created October 21, 2020 09:37
From Argb to CIE XY and viceversa
import android.graphics.Color
import android.os.Build
import android.util.Log
import androidx.annotation.ColorInt
import it.diceworld.dicehome.utility.common.extensions.round
import kotlin.math.pow
class ColorConverter {
companion object {
@nadar71
nadar71 / AppExecutors.kt
Created October 21, 2020 09:36
class for executors
import android.os.Handler
import android.os.Looper
import java.util.concurrent.Executor
import java.util.concurrent.Executors
// Global executor pools.
class AppExecutors // singleton constructor
private constructor(private val diskIO: Executor, private val mainThread: Executor,
private val networkIO: Executor) {
@nadar71
nadar71 / convert.kt
Last active June 14, 2020 05:52
Kotlin, ArrayList<String> to String comma delimited and viceversa
fun ArrayListStringToStringComma(arrayList: ArrayList<String>):String{
var result = ""
for (i in arrayList.indices) {
if (i >= 1 && i <= arrayList.size-1) result += ","
result += arrayList[i]
}
return result
}
@nadar71
nadar71 / card_device.xml
Last active June 11, 2020 08:46
Square shaped layout with shadow : Make a card with elevation (cardElevation with layout_margin property valorized with near values) inside a constraintLayout with dynamically resizable square shape (aspect ratio 1:1))
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.material.card.MaterialCardView
style="@style/HomeCard.White"
@nadar71
nadar71 / card_home.xml
Last active June 11, 2020 08:25
Material card with elevation & shadow : using cardElevation=8dp and (fundamental) layout_margin= 5dp (a greater value isn't work, must be similar to that of the cardElevation to work)
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="@style/HomeCard.White"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_5ssp"
app:cardCornerRadius="12dp"
app:cardElevation="8dp">
//In local.properties
tmdb_api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
//In build.gradle (Module: app)
buildTypes.each {
Properties properties = new Properties()
properties.load(project.rootProject.file("local.properties").newDataInputStream())
def tmdbApiKey = properties.getProperty("tmdb_api_key", "")
it.buildConfigField 'String', "TMDB_API_KEY", tmdbApiKey
@nadar71
nadar71 / .java
Last active January 26, 2019 14:34
Google maps : animate camera moving to a defined target. Working.
/**
* ---------------------------------------------------------------------------------------------
* Animating camera to a target point
* @param lat
* @param lon
* ---------------------------------------------------------------------------------------------
*/
private void animateCameraTo(double lat, double lon){
final CameraPosition target =
new CameraPosition.Builder().target(new LatLng(lat, lon))
@nadar71
nadar71 / .java
Created January 23, 2019 14:17
Android text blinking animation.
// giving a blink animation on TextView
txtLocationResult.setAlpha(0);
txtLocationResult.animate().alpha(1).setDuration(300);