Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Erik Hellman ErikHellman

🏠
Working from home
View GitHub Profile
@ErikHellman
ErikHellman / Activity showing surface switch
Created Jun 22, 2013
A simple demo of playing a video on one SurfaceView and switching to another during playback.
View Activity showing surface switch
package com.example.mediaplayersurfaceswitch;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
@ErikHellman
ErikHellman / gist:6055718
Created Jul 22, 2013
GLES Shader for edge detection
View gist:6055718
#extension GL_OES_EGL_image_external : require
precision mediump float;
varying vec2 vTextureCoord;
uniform samplerExternalOES sTexture;
uniform float uResS;
uniform float uResT;
void main() {
vec3 irgb = texture2D(sTexture, vTextureCoord).rgb;
float ResS = uResS;
@ErikHellman
ErikHellman / PaintView.java
Created Jul 24, 2013
A very simple example of using multi-touch on Android to build a custom View for finger painting. This example uses the Path class from the android.graphics package. Feel free to use this code as you wish for your own multi-touch apps.
View PaintView.java
public class PaintView extends View {
public static final int MAX_FINGERS = 5;
private Path[] mFingerPaths = new Path[MAX_FINGERS];
private Paint mFingerPaint;
private ArrayList<Path> mCompletedPaths;
private RectF mPathBounds = new RectF();
public PaintView(Context context) {
super(context);
}
View personer.json
[
{id: 1, name: "Erik", hometown: "Stockholm"},
{id: 2, name: "Anna", hometown: "Malmö"},
{id: 3, name: "Per", hometown: "Göteborg"},
{id: 4, name: "Lisa", hometown: "Umeå"},
{id: 5, name: "Johan", hometown: "Falun"},
]
@ErikHellman
ErikHellman / MyActivity.java
Created Jul 27, 2014
Android sample showing how to use Handlers for efficient foreground/background operations.
View MyActivity.java
package se.hellsoft.demo.codesnippetdemo;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.SystemClock;
import android.view.View;
@ErikHellman
ErikHellman / VisualizationRenderer
Last active Aug 29, 2015
Simple renderer for a pixel shader on Android
View VisualizationRenderer
public class VisualizationRenderer implements GLSurfaceView.Renderer {
private static final int FLOAT_SIZE_BYTES = Float.SIZE / Byte.SIZE;
private final FloatBuffer mRectData;
private final Context mContext;
private String mVertexShader;
private String mFragmentShader;
public VisualizationRenderer(Context context) {
mContext = context;
@ErikHellman
ErikHellman / MyActivity.java
Last active Aug 12, 2019
Simple LocalBinder demo for Android
View MyActivity.java
package se.hellsoft.simpleservicecallbackdemo;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
View keybase.md

Keybase proof

I hereby claim:

  • I am ErikHellman on github.
  • I am erikhellman (https://keybase.io/erikhellman) on keybase.
  • I have a public key whose fingerprint is D0CC 217D A17A 94D5 FDD4 BC03 6765 F7D5 70C3 E561

To claim this, I am signing this object:

@ErikHellman
ErikHellman / gradle_tips_for_android.md
Last active Aug 29, 2015
Boosting the performance for Gradle in your Android projects
View gradle_tips_for_android.md

Boosting the performance for Gradle in your Android projects

Ever feel like all you do is waiting for the builds to complete in Android Studio all day? Me too. Fortunately, there are a number of improvements you can do to speed things up. Some of these are still experimental and could be unsafe, but it is probably worth a try in case you’re suffering from long build times. I’ve seen project go down to 2.5 seconds when building after small code changes using the stuff I describe below. Hope it works for you as well.

Android uses Gradle for building. The default version of Gradle at the time of writing is 2.2. The latest version is 2.4 and has a huge performance boost over previous versions. In order to make your Android project use this version, add the following at the end of your root build.grade script.

task wrapper(type: Wrapper) {
    gradleVersion = '2.4'
}
@ErikHellman
ErikHellman / RxGattWrapper.java
Created Sep 24, 2015
A base for a wrapper for the Bluetooth LE API on Android
View RxGattWrapper.java
public final class RxGattWrapper {
private SerializedSubject<BluetoothGattEvent, BluetoothGattEvent> eventSubject = new SerializedSubject<>(PublishSubject.<BluetoothGattEvent>create());
private BluetoothDevice bluetoothDevice;
private BluetoothGatt bluetoothGatt;
public RxGattWrapper(BluetoothDevice bluetoothDevice) {
this.bluetoothDevice = bluetoothDevice;
}
public void connect(Context context) {