Skip to content

Instantly share code, notes, and snippets.

View RedTahr's full-sized avatar

Allister RedTahr

  • New Zealand
View GitHub Profile
@RedTahr
RedTahr / Grouping.cs
Created June 18, 2015 22:06
Xamarin.Forms (as of 1.4.2.6359) SearchBar with filter and grouping
using System.Collections.Generic;
using System.Collections.ObjectModel;
// from Xamarin Monkey demo - http://motzcod.es/post/93792500152/custom-listview-viewcells-in-xamarin-forms
namespace Interact.Core.Helper {
public class Grouping<TKey, TValue> : ObservableCollection<TValue> {
public TKey Key { get; private set; }
public Grouping(TKey key, IEnumerable<TValue> items) {
Key = key;
foreach (var item in items)
@RedTahr
RedTahr / OnAppearing
Last active August 29, 2015 14:21
Xamarin.Forms ActivityIndicator in code with FadeOut of indicator and FadeIn of content.
// Xamarin Evolve 2014: Extending Xamarin.Forms with Custom Controls - Jason Smith, Xamarin https://www.youtube.com/watch?v=pIZ8G47KPIM
protected async override void OnAppearing() {
base.OnAppearing();
var loadingView = new ActivityIndicator {
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
IsRunning = true
};
@RedTahr
RedTahr / distance-long-lat-degrees
Created November 20, 2014 22:26
Common helpers in Xamarin
// http://developer.xamarin.com/recipes/ios/content_controls/map_view/display_a_location/
/// <summary>Converts miles to latitude degrees</summary>
public static double MilesToLatitudeDegrees(double miles) {
double earthRadius = 3960.0; // in miles
double radiansToDegrees = 180.0 / Math.PI;
return (miles / earthRadius) * radiansToDegrees;
}
/// <summary>Converts miles to longitudinal degrees at a specified latitude</summary>
@RedTahr
RedTahr / color-from-hex
Created November 20, 2014 22:24
WinPhone helper functions in Xamarin
// http://social.msdn.microsoft.com/forums/windowsapps/en-us/b639cd8a-30c2-48cf-99be-559f34cbfa79/convert-string-to-color-in-metro
public static System.Windows.Media.Color GetColorFromHexString(string hexValue) {
hexValue = hexValue.Substring(1, 6); // string will be passed in with a leading #
byte a = 0xff;// Convert.ToByte(hexValue.Substring(0, 2), 16);
var r = Convert.ToByte(hexValue.Substring(0, 2), 16);
var g = Convert.ToByte(hexValue.Substring(2, 2), 16);
var b = Convert.ToByte(hexValue.Substring(4, 2), 16);
return System.Windows.Media.Color.FromArgb(a, r, g, b);
}
@RedTahr
RedTahr / color-from-hex
Created November 20, 2014 22:22
iOS helper functions in Xamarin
// http://stackoverflow.com/questions/10310917/uicolor-from-hex-in-monotouch
public static UIColor GetColorFromHexString(string hexValue) {
hexValue = hexValue.Substring(1, 6); // string will be passed in with a leading #
var r = Convert.ToByte(hexValue.Substring(0, 2), 16);
var g = Convert.ToByte(hexValue.Substring(2, 2), 16);
var b = Convert.ToByte(hexValue.Substring(4, 2), 16);
return UIColor.FromRGB(r, g, b);
}
@RedTahr
RedTahr / android-version
Created November 20, 2014 22:11
Android helper functions in Xamarin
// "return" "version" "name" - names aren't syntactically correct (they're probably upper case for starters)
// 21 5.0 lollipop
// 20 4.4.2W kitkat wear
// 19 4.4.2 kitkat
// 18 4.3.1 jelly bean mr2
// 17 4.2.2 jelly bean mr1
// 16 4.1.2 jelly bean
// 15 4.0.3 ice-cream sandwich mr1
// 14 4.0 ice-cream sandwich
// 13 3.2 honeycomb mr2