Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeff Gilfelt jgilfelt

  • readyState Software Ltd
  • London, United Kingdom
View GitHub Profile
@jgilfelt
jgilfelt / MyApplication.java
Created Mar 11, 2013
Android - Set default preference values for a modern fragment-based PreferenceActivity
View MyApplication.java
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// we cannot call setDefaultValues for multiple fragment based XML preference
// files with readAgain flag set to false, so always check KEY_HAS_SET_DEFAULT_VALUES
if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
.getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) {
@jgilfelt
jgilfelt / CacheableImageView.java
Created Jan 30, 2013
Android-BitmapCache (https://github.com/chrisbanes/Android-BitmapCache) CacheableImageView with a fade-in transition display option.
View CacheableImageView.java
/*******************************************************************************
* Copyright 2011, 2012 Chris Banes. 2013 readyState Software Ltd.
*
* 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
@jgilfelt
jgilfelt / FittingLinearLayout.java
Last active Dec 10, 2015
Custom LinearLayout needed for fullscreen YouTube player when using SYSTEM_UI_FLAG_HIDE_NAVIGATION
View FittingLinearLayout.java
package com.readystatesoftware.views;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class FittingLinearLayout extends LinearLayout {
public FittingLinearLayout(Context context, AttributeSet attrs, int defStyle) {
@jgilfelt
jgilfelt / main.xml
Created Dec 17, 2012
"fix" for black surface artefact left by MapFragment when transitioned in a ViewPager on old API versions
View main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
@jgilfelt
jgilfelt / ScaleFadePageTransformer.java
Created Dec 3, 2012
An ICS+ app/widget drawer style PageTransformer for your ViewPager
View ScaleFadePageTransformer.java
/***
* Copyright (c) 2012 readyState Software Ltd
*
* 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.
@jgilfelt
jgilfelt / styles.xml
Created Oct 28, 2012
Kindle Fire typeface fix
View styles.xml
<!-- fixes for broken Holo text appearances on Kindle Fire 2/HD -->
<style name="TextAppearance.KindleFix.Small" parent="android:TextAppearance" >
<item name="android:textSize">14sp</item>
<item name="android:textColor">?android:attr/textColorSecondary</item>
</style>
<style name="TextAppearance.KindleFix.Small.Inverse" >
<item name="android:textColor">?android:attr/textColorSecondaryInverse</item>
<item name="android:textColorHint">?android:attr/textColorHintInverse</item>
@jgilfelt
jgilfelt / mapimports.sh
Created Sep 13, 2012
Toggle Google/Amazon Android map imports
View mapimports.sh
#!/bin/bash
A_IMPORT="import com.amazon.geo.maps"
G_IMPORT="import com.google.android.maps"
A_VIEW="com.amazon.geo.maps.MapView"
G_VIEW="com.google.android.maps.MapView"
if [ "$1" = "a" ]; then
FR=$G_IMPORT
@jgilfelt
jgilfelt / DoubleTapZoomMapView.java
Created Feb 8, 2012
Android - MapView implementing double tap to zoom
View DoubleTapZoomMapView.java
public class DoubleTapZoomMapView extends MapView {
private static final long TIME_INITIAL = -1;
private static final long TIME_DOUBLE_TAP = 250;
private long lastTouchTime = TIME_INITIAL;
public DoubleTapZoomMapView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@jgilfelt
jgilfelt / gist:1755312
Created Feb 6, 2012
Android - Managing single MapView Fragment state across multiple Activities
View gist:1755312
private GeoPoint center;
private int zoomLevel = -1;
@Override
public void onPause() {
super.onPause();
center = mapView.getMapCenter();
zoomLevel = mapView.getZoomLevel();
}
@jgilfelt
jgilfelt / gist:1231694
Created Sep 21, 2011
Android - AsyncTask with inline callback boilerplate
View gist:1231694
private void asyncTaskWithInlineCallback() {
// display UI progress indicator
// ...
new MyAsyncTask() {
protected void onPostExecute(Boolean result) {
// dismiss UI progress indicator
// process the result
// ...
}
You can’t perform that action at this time.