Skip to content

Instantly share code, notes, and snippets.

@mjohnsullivan
mjohnsullivan / TimerActivity.java
Created July 9, 2015 13:15
Example of how to create a long running timer service that survives activity destruction by moving to the foreground, and back to the background when a new activity bind to it.
//
// Copyright 2015 Google Inc. All Rights Reserved.
//
// 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
@mjohnsullivan
mjohnsullivan / smiley.dart
Created February 5, 2019 23:30
A custom painter that draws a smiley face in Flutter
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'dart:math' as Math;
void main() => runApp(MyApp());
@mjohnsullivan
mjohnsullivan / generate_cloudfront_signed_cookies.py
Created January 1, 2017 16:34
Python script that generates signed cookies to control access to CloudFront content
#!/usr/bin/env python
"""
Copyright (C) 2017 Matt Sullivan
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
@mjohnsullivan
mjohnsullivan / WifiReceiver.java
Created July 8, 2015 09:02
Broadcast receiver to detect when wifi connects on an Android device, displaying the SSID name and MAC address in a notfication
//
// Copyright 2015 Google Inc. All Rights Reserved.
//
// 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
@mjohnsullivan
mjohnsullivan / expanding_app_bar.dart
Last active August 27, 2021 16:53
Expanding AppBar in Flutter
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Expanding AppBar Example',
theme: new ThemeData(
@mjohnsullivan
mjohnsullivan / bouncy_truck.dart
Created June 18, 2021 21:54
An example of mixing and controlling multiple animations in Rive
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
void main() => runApp(MaterialApp(
home: BouncyTruckAnimation(),
));
class BouncyTruckAnimation extends StatefulWidget {
const BouncyTruckAnimation({Key? key}) : super(key: key);
@mjohnsullivan
mjohnsullivan / quote.dart
Created June 25, 2018 23:20
Simple Flutter app to retrieve and display a quote of the day
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@mjohnsullivan
mjohnsullivan / draggable_custom_painter.dart
Created November 26, 2019 21:32
Handling draggable areas or elements drawn on a Flutter CustomPainter
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Draggable Custom Painter',
home: Scaffold(
@mjohnsullivan
mjohnsullivan / curved_appbar.dart
Created November 28, 2019 19:59
A curved Flutter AppBar where widgets scroll nicely beneath the curved portion
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(home: MyHomePage()),
);
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
const curveHeight = 50.0;
void determineDragPosition(BuildContext itemContext,
DragUpdateDetails details, Item draggedItem, double itemHeight) {
_dragOperation.offset.value = details.globalPosition;
// Find the fixed extent list renderer.
RenderSliverFixedExtentList extentList;
for (var p = itemContext.findRenderObject();
p != null;
p = p is RenderObject ? p.parent as RenderObject : null) {
if (p is RenderSliverFixedExtentList) {