Skip to content

Instantly share code, notes, and snippets.

@Jthomas54
Jthomas54 / StartLinearSnapHelper.kt
Created January 24, 2019 19:46
SnapHelper for RecyclerView to snap to the child's start instead of center
import android.support.v7.widget.LinearSnapHelper
import android.support.v7.widget.OrientationHelper
import android.support.v7.widget.RecyclerView
import android.view.View
open class StartLinearSnapHelper : LinearSnapHelper() {
protected var _verticalHelper: OrientationHelper? = null
protected var _horizontalHelper: OrientationHelper? = null
@nickbutcher
nickbutcher / 10: animator-morph_ridge_2_to_tick.xml
Last active September 4, 2024 05:58
Demonstrating an animation for scanning a fingerprint and showing success or failure. This uses a number of AnimatedVectorDrawables (https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html) to 'morph' parts of the fingerprint into the tick or cross to report success or failure. It also uses a moving clip-pat…
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The Android Open Source Project
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
@bunjix
bunjix / Activity_or_Fragment.java
Last active January 9, 2020 10:28
Pick an image on Android
private static final int PICK_PHOTO_FOR_AVATAR = 0;
public void pickImage() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, PICK_PHOTO_FOR_AVATAR);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
@manishk3008
manishk3008 / Android Persistent Cookies Store
Last active December 29, 2020 09:17
CookieStore for dealing with persistent cookies in Android
//HOW TO USE
SiCookieStore2 siCookieStore = new SiCookieStore2(context);
CookieManager cookieManager = new CookieManager((CookieStore) siCookieStore, CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cookieManager);
@burgalon
burgalon / AccountAuthenticator.java
Last active July 15, 2023 08:29
Implementing OAuth2 with AccountManager, Retrofit and Dagger
public class AccountAuthenticator extends AbstractAccountAuthenticator {
private final Context context;
@Inject @ClientId String clientId;
@Inject @ClientSecret String clientSecret;
@Inject ApiService apiService;
public AccountAuthenticator(Context context) {
super(context);
@whitfin
whitfin / LinkMovementMethod.java
Created January 28, 2014 21:09
Custom Link Movement to open any clicked links inside an inline browser. Requires either a custom inline browser, or the one I created in a gist.
package com.zackehh.example;
import com.zackehh.example.MinimalBrowser;
import android.content.Context;
import android.content.Intent;
import android.text.Layout;
import android.text.Spannable;
import android.text.method.MovementMethod;
import android.text.style.URLSpan;
@dodyg
dodyg / gist:5823184
Last active August 10, 2024 04:53
Kotlin Programming Language Cheat Sheet Part 1

#Intro

Kotlin is a new programming language for the JVM. It produces Java bytecode, supports Android and generates JavaScript. The latest version of the language is Kotlin M5.3

Kotlin project website is at kotlin.jetbrains.org.

All the codes here can be copied and run on Kotlin online editor.

Let's get started.

@ianbarber
ianbarber / gist:5170508
Last active September 4, 2024 05:58
Example Sign In activity for Google Sign-In on Android that retrieves an authorization code for use with server side authentication. See http://www.riskcompletefailure.com/2016/07/server-side-google-api-access-from.html for more background and links.
package com.example.anothersignintest;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.OptionalPendingResult;
import com.google.android.gms.common.api.ResultCallback;