Skip to content

Instantly share code, notes, and snippets.

View RedTahr's full-sized avatar

Allister RedTahr

  • New Zealand
View GitHub Profile
@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
@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 / 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 / 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 / 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 / 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 / DisableScPnP.ps1
Last active August 29, 2015 14:23
SmartCard PnP Disable
# Disable Smart Card PnP
# [x86]
# [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\ScPnP]
# "EnableScPnP"=dword:00000000
# [64-bit]
# HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\ScPnP]
# "EnableScPnP"=dword:00000000
# this Wow6432Node entry is a "hardlink" to the above entry, so you create/delete/edit that and the changes are mirrored in Wow6432Node
@RedTahr
RedTahr / BaseViewModel.cs
Last active January 27, 2016 19:25
Xamarin.Forms BaseViewModel
namespace ... {
public abstract class BaseViewModel : BindableObject { // yeah its overkill, can't recall why my colleague did it this way
private string title = string.Empty;
public string Title {
get { return title; }
set {
if(title != value) {
title = value;
RaisePropertyChanged();
@RedTahr
RedTahr / BasePage.cs
Last active January 27, 2016 19:22
Xamarin.Forms BasePage
namespace ... {
// for supporting this
// public partial class "Derived"Page : "Derived"PageXaml {.... } for a xaml/cs page
// then
// <?xml version="1.0" encoding="utf-8" ?><local:"Derived"tPageXaml xmlns="ht...
// with this bit in the cs file
// public partial class "Derived"PageXaml : BasePageOverrideBackButton<ViewModel."Derived"ViewModel> { }
public class BasePageOverrideBackButton<T> : BasePage<T> where T : ViewModel.BaseViewModel, new() {
public BasePageOverrideBackButton() : base() {
}
@RedTahr
RedTahr / AboutPage.xaml
Created July 15, 2015 21:06
Xamarin.Forms DerivedPage.xaml/cs from BasePage, Binding ViewModel in XAML.
<?xml version="1.0" encoding="utf-8" ?>
<derived:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="....AboutPage"
xmlns:local="clr-namespace:...;assembly=..."
xmlns:derived="clr-namespace:....View;assembly=..."
BindingContext="{x:Static local:App.AboutViewModel}"
Title="About">
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Label Text="{Binding Detail}"/>