Skip to content

Instantly share code, notes, and snippets.

View scottyab's full-sized avatar

Scott Alexander-Bown scottyab

View GitHub Profile
@chrisjenx
chrisjenx / ContentLoadingFrameLayoyt..java
Created May 21, 2014 09:56
Similar to the LoadingProgressSpinner which doesnt flicker if you change stages quickly.
public abstract class ContentLoadingFrameLayout extends FrameLayout {
private static final int MIN_SHOW_TIME = 200; // ms
private static final int MIN_DELAY = 200; // ms
private ProgressBar mProgressBar;
private View mContent;
private long mStartTime = -1;
private boolean mPostedHide = false;
private boolean mPostedShow = false;
/*
* Copyright (C) 2014 Chris Banes
*
* 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
@esteluk
esteluk / layout.xml
Created August 5, 2011 17:42
Example XML file using ModifiedScrollView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout android:id="@+id/topLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:id="@+id/backgroundImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
@chrisjenx
chrisjenx / GsonBuilder.java
Last active October 19, 2015 18:47
Custom Gson Serialiser for android.support.v4.util.SimpleArrayMap;
return new GsonBuilder()
.registerTypeAdapter(SimpleArrayMapJsonSerializer.TYPE, new SimpleArrayMapJsonSerializer())
.create();
@jdamcd
jdamcd / EmailAdapter.java
Last active December 12, 2015 07:48
Email adapter for AutoCompleteTextView
private ArrayAdapter<String> getEmailAddressAdapter(Context context) {
Account[] accounts = AccountManager.get(context).getAccountsByType("com.google");
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);
}
@jdamcd
jdamcd / AllEmailAdapter.java
Last active December 12, 2015 10:49
Email adapter for AutoCompleteTextView that looks for emails from all account types, not just Google.
private static final String EMAIL_REGEX = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX);
private ArrayAdapter<String> getEmailAddressAdapter(Context context) {
Account[] accounts = AccountManager.get(context).getAccounts();
HashSet<String> emailSet = new HashSet<String>();
for (int i = 0; i < accounts.length; i++) {
if (isEmailAddress(accounts[i].name)) {
emailSet.add(accounts[i].name);
}
@imminent
imminent / GateKeeper.java
Created March 22, 2013 21:48
Android version gate keeper utility.
import javax.annotation.Nonnull;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
/**
* <p>Keeper of the {@linkplain Build#VERSION_CODES Android version gates}, used to guarantee non shall pass,
* unless they are worthy.</p>
* @author Dandre Allison
@jamiehuson
jamiehuson / JacksonConverter
Created September 16, 2013 21:32
A Jackson Converter for use with Square's Tape queue library
public class JacksonConverter<T> implements FileObjectQueue.Converter<T> {
private final ObjectMapper mMapper;
private final Class<T> mType;
public JacksonConverter(ObjectMapper mapper, Class<T> type) {
this.mType = type;
this.mMapper = mapper;
}
@commonsguy
commonsguy / SQLCipherV3Helper.java
Last active December 25, 2015 23:39
SQLiteHookedHelper and SQLCipherV3Helper
/***
Copyright (c) 2013 CommonsWare, LLC
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 distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
*/