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 / UserLocation_using_FusedLocationApi.java
Last active January 23, 2019 10:05
Map use location with marker activity, one with deprecated FusedLocationApi, the other updated using FusedLocationProviderClient. Requesting permissions template. Got from here : https://stackoverflow.com/questions/34582370/how-can-i-show-current-location-on-a-google-map-on-android-marshmallow/34582595#34582595. Checked only the second with vali…
import android.Manifest;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
@nadar71
nadar71 / longPress.java
Last active January 23, 2019 10:01
Set position in a map by long pressing. Used in Android, google maps v2.
// set position by long press
mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng latLng) {
// First check if myMarker is null
if (myManualPositionMarker == null) {
// Marker was not set yet. Add marker:
myManualPositionMarker = mMap.addMarker(new MarkerOptions()
.position(latLng)
.title("My positions")
@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);
@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))
//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 / 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">
@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 / 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 / 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 / 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 {