Skip to content

Instantly share code, notes, and snippets.

View slightfoot's full-sized avatar
💙
Fluttering

Simon Lightfoot slightfoot

💙
Fluttering
View GitHub Profile
@slightfoot
slightfoot / TweetsAdapter.java
Created July 20, 2013 23:52
Example of using the older Twitter v1 API.
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Locale;
@slightfoot
slightfoot / ScrollingSyncListView.java
Created August 4, 2013 01:23
ScrollingSyncListView lets a ListView position its sibiling views based on the postions of its children.
import android.content.Context;
import android.database.DataSetObserver;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ListAdapter;
import android.widget.ListView;
@slightfoot
slightfoot / gist:6256258
Created August 17, 2013 10:26
Listening for GSM signal strength changes.
public void registerListenForSignalStrengths(Context context)
{
TelephonyManager tm = (TelephonyManager)context.getSystemService(TELEPHONY_SERVICE);
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
public void unregisterListenForSignalStrengths(Context context)
{
TelephonyManager tm = (TelephonyManager)context.getSystemService(TELEPHONY_SERVICE);
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
@slightfoot
slightfoot / CommentStripper.java
Created August 22, 2013 20:36
Comment Stripper.. not much else to say.
import java.io.IOException;
/**
* Comment Stripper
*
* Usage: cat inputfile.blah | java CommentStripper > outptufile.blah
*
*
*/
public class CommentStripper
@slightfoot
slightfoot / gist:6330866
Last active December 12, 2022 22:31
Android Tone Generator
// Usage:
// AudioTrack tone = generateTone(440, 250);
// tone.play();
//
private AudioTrack generateTone(double freqHz, int durationMs)
{
int count = (int)(44100.0 * 2.0 * (durationMs / 1000.0)) & ~1;
short[] samples = new short[count];
for(int i = 0; i < count; i += 2){
short sample = (short)(Math.sin(2 * Math.PI * i / (44100.0 / freqHz)) * 0x7FFF);
@slightfoot
slightfoot / MainActivity.java
Created September 5, 2013 01:25
Example of synchronized animated markers on Android 2.3 and up. (Android without Object Animators or JB's Choreographer.)
package com.demondevelopers.example.markers;
import java.util.HashSet;
import java.util.Iterator;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
@slightfoot
slightfoot / MainActivity.java
Created September 6, 2013 10:50
FadeyTextView example.. will animate text in like "H, He, Hel, Hell, Hello, etc"
package com.example.fadeytextthingy;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.view.ViewCompat;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
public class DoubleRangeSeekBar extends RangeSeekBar<Double>
{
public DoubleRangeSeekBar(Context context)
{
super(context);
@slightfoot
slightfoot / gist:7482675
Last active August 27, 2016 08:53
com.google.android.apps.now.REMOTE_ACCESS permission details. Only the apps with one of the SHA1 hashes are allowed to access the functions in the interface.
<permission
android:label="@string/permission_remote_access_label"
android:name="com.google.android.apps.now.REMOTE_ACCESS"
android:protectionLevel="normal"
android:description="@string/permission_remote_access_desc"
/>
<service android:name="com.google.android.sidekick.main.remoteservice.GoogleNowRemoteService"
android:permission="com.google.android.apps.now.REMOTE_ACCESS" android:process=":search">
<intent-filter>
@slightfoot
slightfoot / DateTimeTest.java
Last active August 29, 2015 13:56
Date time with TimeZone
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import java.text.ParsePosition;
import java.text.DateFormat;
import java.util.Date;
public class DateTimeTest
{