Skip to content

Instantly share code, notes, and snippets.

View antoniolg's full-sized avatar

Antonio Leiva antoniolg

View GitHub Profile
@antoniolg
antoniolg / PeopleDb.kt
Created July 7, 2020 11:14
Room basic sample in Kotlin
import androidx.room.Database
import androidx.room.RoomDatabase
@Database(
entities = [Person::class],
version = 1
)
abstract class PeopleDb : RoomDatabase() {
abstract fun personDao(): PersonDao
@antoniolg
antoniolg / MainActivity.kt
Last active March 2, 2023 08:10
Shows how to use permissions with registerForActivityResult(). Code for https://devexperto.com/permisos-android-11
import android.Manifest.permission.ACCESS_COARSE_LOCATION
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import androidx.activity.ComponentActivity
import androidx.activity.result.contract.ActivityResultContracts.RequestPermission
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
@antoniolg
antoniolg / HomeActivity.kt
Last active April 11, 2024 11:03
Snackbar extensions on Kotlin, to create a useful small DSL.
class HomeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
setSupportActionBar(toolbar)
fab.setOnClickListener {
it.snack("Snack message") {
action("Action") { toast("Action clicked") }
@antoniolg
antoniolg / 0_reuse_code.js
Last active August 29, 2015 14:15
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layoutfab);
//Outline
int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
Outline outline = new Outline();
@antoniolg
antoniolg / SwipeRefreshActivity.java
Last active July 29, 2019 11:59
An activity that uses a SwipeRefreshLayout as a container for the layout of the classes that extend it.
/*
* Copyright (C) 2014 Antonio Leiva Gordillo.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software