Skip to content

Instantly share code, notes, and snippets.

View glennstephens's full-sized avatar

Glenn Stephens glennstephens

  • Sunshine Coast, Australia
View GitHub Profile
@glennstephens
glennstephens / gist:a122b3b93057a51f572c
Created September 16, 2015 22:48
MapBox Static Images Implementation. Useful for Devices without Google Maps, like the Kindle Fire devices or for offline Map Display
public enum QualityFormat
{
iOSRetina,
PNG32,
PNG64,
PNG128,
PNG256,
JPG70,
JPG80,
JPG90
@glennstephens
glennstephens / ConstraintsHelper.cs
Created October 26, 2015 05:13
An alternative to working with constraints in code using a nice fluent style interface. A work in progress, but hopefully helps
// // Just an example of making a fluent style interface. It's a work in progress but I'd rather not use the NSLayoutContraint code
// // As it seems like a poorly designed API. I've wrapped it with some fluent style access for common issues
//
// var mainButton = new UIButton ();
// mainButton.SetTitle ("Click me dude", UIControlState.Normal);
// mainButton.BackgroundColor = UIColor.Blue;
// Add (mainButton);
//
// var secondButton = new UIButton ();
// secondButton.SetTitle ("The other one", UIControlState.Normal);
@glennstephens
glennstephens / gist:76e7e347ca6c19d4ef15
Created December 15, 2015 04:01
Multi-select in Xamarin in Forms
using System;
using System.Linq;
using Xamarin.Forms;
using System.Collections.Generic;
using System.ComponentModel;
namespace SampleApp
{
// Inherit from this page to get a multi-select option in XF
public class SelectMultipleBasePage<T> : ContentPage
@glennstephens
glennstephens / gist:8bedb3a0c9709ac402645e3d7666f14a
Created June 28, 2017 03:48
Swipeable View Cell. You could add some animations to make it slightly prettier.
using System;
using Xamarin.Forms;
namespace PanningAViewCellDemo
{
public class PanningViewCell<V1, V2> : ViewCell
where V1 : View, new()
where V2 : View, new()
{
V1 mainView;
@glennstephens
glennstephens / TheDateTime.cs
Last active May 3, 2018 07:36
If you have an app that is designed to be used over a long period of time (say a year). To write tests you need to simulate the passage of time. I've been using this little helper to allow to simulated tests in the fourth dimension
// Instead of using calls like DateTime.Now, use TheDateTime.Now instead. In your production code it will default to using
// the read details and for testing you would make calls like:
// TheDateTime.SwitchToMockDate(new DateTime(2018, 12, 3);
// and then test what the outcome would be. It assumes that you have this throughout
public static class TheDateTime
{
static Lazy<LiveDateTimeFunctions> _liveDates = new Lazy<LiveDateTimeFunctions>(() => new LiveDateTimeFunctions());
static Lazy<MockDateTimeFunctions> _mockDates = new Lazy<MockDateTimeFunctions>(() => new MockDateTimeFunctions());
static IDateTimeFunctions _instance = _liveDates.Value;
@glennstephens
glennstephens / gist:ea77a7a5d2d4cd16af19e33a654de840
Created February 21, 2019 11:00
A simple modification/POC to test the Foldable support in Xamarin.Android
/*
Looking at the Samsung Fold, I wanted to see what it would take to support it from a Xamarin.Android app
It turns out, not a great deal to test the proof of concept.
Step 1. Download the emulator APK at https://developer.samsung.com/galaxy/foldable/test and follow the instructions to install it
Step 2. Update the ConfigurationChanges property in the Activity Attribute - see line 24
Step 3. Override OnSaveInstanceState and OnRestoreInstanceState to save/restore state
Step 4. Perform any updates (if needed) in OnConfigurationChanged
Step 5. Add the MetaData attribute for Allowing Multiple Resumed Activities
@glennstephens
glennstephens / CometSnippets.code-snippets
Created June 29, 2020 14:40
Snippets file for Visual Studio Code for use with Comet
{
"Comet Page View": {
"scope": "csharp",
"prefix": "mvuPage",
"body": [
"public class ${1:PageName} : View \n{\n\t[Body]\n\tView body() => new VStack\n\t{\n\t};\n}"
],
"description": "Comet Page View"
},
"Comet State Field": {
@glennstephens
glennstephens / SimpleDataCollection.cs
Created June 29, 2020 14:58
Simple Example of using Comet to collect some data
public class MainPage : View
{
readonly State<string> Name = "";
readonly State<string> Email = "";
readonly State<string> MessageDetails = "";
[Body]
View body() => new VStack(spacing: 10)
{
new Text(() => $"Name"),
@glennstephens
glennstephens / AndroidServiceSnippet.cs
Created June 29, 2020 21:03
A C# snippet example for coding an Android Service
public class $ServiceName$Binder : Binder
{
public $ServiceName$ Service { get; private set; }
public $ServiceName$Binder($ServiceName$ service)
{
this.Service = service;
}
}