Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Erik Hellman ErikHellman

🏠
Working from home
View GitHub Profile
@ErikHellman
ErikHellman / MarkdownComposer.kt
Last active Oct 20, 2021
A simple rendered for Markdown text parsed using CommonMarks
View MarkdownComposer.kt
package se.hellsoft.markdowncomposer
import android.util.Log
import androidx.compose.foundation.Box
import androidx.compose.foundation.ContentGravity
import androidx.compose.foundation.Text
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.appendInlineContent
import androidx.compose.material.Colors
@ErikHellman
ErikHellman / LoginScreenWithCompose.kt
Created Dec 16, 2019
A simple demo of using Jetpack Compose to build a Login screen
View LoginScreenWithCompose.kt
package se.hellsoft.jetpackcomposeintro
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.Composable
import androidx.compose.Model
import androidx.compose.state
import androidx.compose.unaryPlus
import androidx.ui.core.*
import androidx.ui.foundation.shape.border.Border
@ErikHellman
ErikHellman / LitElementDialogExample.js
Last active Apr 8, 2021
Basic dialog example with LitElement
View LitElementDialogExample.js
import { LitElement, html } from '@polymer/lit-element'
import { classMap } from 'lit-html/directives/classMap'
class MyDialog extends LitElement {
constructor () {
super()
this.opened = false
}
@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 / WebViewServer.kt
Last active Oct 2, 2020
This class is no longer needed now that Google provides WebViewAssetLoader (see https://developer.android.com/reference/kotlin/androidx/webkit/WebViewAssetLoader)
View WebViewServer.kt
/*
MIT License
Copyright (c) 2019 Erik Hellman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@ErikHellman
ErikHellman / NonBlockingEchoServer.kt
Last active Sep 7, 2020
A very simple example of an echo-server using the non-blocking Java I/O APIs
View NonBlockingEchoServer.kt
package se.hellsoft.nonblocking.echo
import java.net.InetSocketAddress
import java.nio.ByteBuffer
import java.nio.channels.SelectionKey
import java.nio.channels.Selector
import java.nio.channels.ServerSocketChannel
import java.nio.channels.SocketChannel
/**
@ErikHellman
ErikHellman / TextFieldText.dart
Last active Apr 2, 2020
Testing the TextField decoration
View TextFieldText.dart
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
@ErikHellman
ErikHellman / kotlin_coroutine_android_loader.kt
Last active Mar 20, 2020
Kotlin Coroutine Android Loader
View kotlin_coroutine_android_loader.kt
internal class CoroutineLifecycleListener(private val deferred: Deferred<*>) : LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun cancelCoroutine() {
deferred.cancel()
}
}
internal var POOL = newFixedThreadPoolContext(2, "loader")
fun <T> LifecycleOwner.load(loader: () -> T): Deferred<T> {
@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);
}
@ErikHellman
ErikHellman / KittyLog.kt
Last active Sep 4, 2019
A super tiny wrapper for Android Log utility that allows log printing in unit tests. For a more advanced log wrapper for Android, see https://github.com/JakeWharton/timber/
View KittyLog.kt
/*
Licensed under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
This is a tiny log utility for Android Logcat. It allows logs to be used in code that is unit
tested on host (without Android framework available).
The only advantage with this utility above Timber is that it doesn't require any setup.
For real-world, production application I strongly recommend using Timber (see https://github.com/JakeWharton/timber/) instead.
*/
@file:Suppress("unused")