Skip to content

Instantly share code, notes, and snippets.

jdamcd /
Last active Dec 12, 2015
Email adapter for AutoCompleteTextView
private ArrayAdapter<String> getEmailAddressAdapter(Context context) {
Account[] accounts = AccountManager.get(context).getAccountsByType("");
String[] addresses = new String[accounts.length];
for (int i = 0; i < accounts.length; i++) {
addresses[i] = accounts[i].name;
return new ArrayAdapter<String>(context, android.R.layout.simple_dropdown_item_1line, addresses);
galex /
Created Dec 27, 2012
Google Maps v2 + ActionBarSherlock = SherlockMapFragment
PomepuyN / Watch face Ambient mode detection
Last active Nov 5, 2018
Allow to detect Ambient mode to switch Watch face display on Wear devices
View Watch face Ambient mode detection
Handler handler = new Handler(Looper.getMainLooper());
final DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
displayManager.registerDisplayListener(new DisplayManager.DisplayListener() {
public void onDisplayAdded(int displayId) {
peterkuterna /
Created Jul 19, 2012
A FragmentPagerAdapter that exposes data from a Cursor
package com.example;
import android.content.Context;
import android.database.Cursor;
import android.util.SparseIntArray;
import android.view.ViewGroup;
romannurik / AndroidManifest.xml
Last active Oct 20, 2020
Android example of how to programmatically instantiate a View with a custom style.
View AndroidManifest.xml
<manifest ...>
<!-- Make sure your app (or individual activity) uses the
theme with the custom attribute defined. -->
<application android:theme="@style/AppTheme" ...>
liberorignanese /
Last active Dec 28, 2020
Android TextInputLayout with credit card mask
* Created by Libero Rignanese.
nickbutcher / 10: animator-morph_ridge_2_to_tick.xml
Last active Feb 20, 2021
Demonstrating an animation for scanning a fingerprint and showing success or failure. This uses a number of AnimatedVectorDrawables ( to 'morph' parts of the fingerprint into the tick or cross to report success or failure. It also uses a moving clip-pat…
View 10: animator-morph_ridge_2_to_tick.xml
<?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
TomTasche /
Created Oct 21, 2012
Use built-in feedback mechanism on Android
// more information here:
try {
int i = 3 / 0;
} catch (Exception e) {
ApplicationErrorReport report = new ApplicationErrorReport();
report.packageName = report.processName = getApplication()
report.time = System.currentTimeMillis();
report.type = ApplicationErrorReport.TYPE_CRASH;
romannurik /
Last active Dec 17, 2021
Demonstrates how to identify and avoid line-length issues with TextView. The measure, or characters per line, of a block of text plays a key role in how comfortable it is to read (sometimes referred to as readability). A widely accepted optimal range for a text block's measure is between 45 and 75 characters. This code demonstrates two phases of…
* Copyright 2013 Google Inc.
* 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
* Unless required by applicable law or agreed to in writing, software
/* Copyright 2013 Google Inc.
Licensed under Apache 2.0: */
package com.example.latlnginterpolation;
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.os.Build;