Skip to content

Instantly share code, notes, and snippets.

Avatar

Bruno Van Thournout BrunoVT1992

View GitHub Profile
@BrunoVT1992
BrunoVT1992 / ThreadUtil.cs
Created Jun 23, 2016
Extension to see if a thread is the main(UI) thread for Xamarin Android.
View ThreadUtil.cs
using Android.OS;
using Java.Lang;
namespace Droid
{
public static class ThreadUtil
{
public static bool IsMainThread(this Thread currentThread)
{
return currentThread == Looper.MainLooper.Thread;
@BrunoVT1992
BrunoVT1992 / AsyncLock.cs
Last active May 13, 2016
This class makes a lock statement async so you can use await operators inside the lock statement
View AsyncLock.cs
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace CSharp
{
// http://blogs.msdn.com/b/pfxteam/archive/2012/02/12/10266988.aspx
public class AsyncLock
{
@BrunoVT1992
BrunoVT1992 / DpiToPixelConverter.cs
Last active May 13, 2016
Converter to convert dpi sizes to pixel sizes in Xamarin Android
View DpiToPixelConverter.cs
using Android.App;
using Android.Content;
namespace Droid
{
public static class DpiToPixelConverter
{
public static int Convert(int dpi)
{
float scale = Application.Context.Resources.DisplayMetrics.Density;
@BrunoVT1992
BrunoVT1992 / UIImageConverter.cs
Last active May 13, 2016
Converter to blur an UIImage in Xamarin iOS
View UIImageConverter.cs
using UIKit;
using CoreImage;
namespace iOS
{
public static class UIImageConverter
{
public static UIImage Blur(UIImage image)
{
var ciImage = new CIImage(image);
@BrunoVT1992
BrunoVT1992 / StringConverter.cs
Created May 13, 2016
Converter to capitalize the first character of a string in C#
View StringConverter.cs
namespace CSharp
{
public static class StringConverter
{
public static string Capitalized(string text)
{
if (string.IsNullOrEmpty(text))
{
return text;
}
@BrunoVT1992
BrunoVT1992 / BytesConverter.cs
Last active May 13, 2016
Converter to convert number of bytes to kB, MB, GB, TB or PB in C#
View BytesConverter.cs
using System;
namespace CSharp
{
public static class BytesConverter
{
public static double ConvertBytesToKB(long bytes)
{
return bytes / 1024f;
}
@BrunoVT1992
BrunoVT1992 / RoundedCornersFrameLayout.cs
Created May 13, 2016
Rounded corners for a framelayout in Xamarin Android
View RoundedCornersFrameLayout.cs
using Android.Content;
using Android.Graphics;
using Android.Util;
using Android.Widget;
namespace Droid
{
public class RoundedCornersFrameLayout : FrameLayout
{
private const float CornerRadius = 5.0f;
@BrunoVT1992
BrunoVT1992 / Distance.cs
Last active Apr 26, 2016
Calculate the spline fling distance for Xamarin Android
View Distance.cs
using System;
using Android.App;
using Android.Hardware;
using Android.Views;
namespace Droid
{
public static class Distance
{
public static double CalculateSplineFlingDistance(float velocity)
@BrunoVT1992
BrunoVT1992 / Command.cs
Last active Apr 26, 2016
Mvvm ICommand implementation
View Command.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace Mvvm
{
public class Command : ICommand
@BrunoVT1992
BrunoVT1992 / NotifyPropertyChanged.cs
Last active Apr 26, 2016
Mvvm INotifyPropertyChanged implementation
View NotifyPropertyChanged.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace Mvvm
{