Skip to content

Instantly share code, notes, and snippets.

View jfversluis's full-sized avatar

Gerald Versluis jfversluis

View GitHub Profile
@jfversluis
jfversluis / FileChooserWebChromeClient.cs
Created April 16, 2017 11:21
Inheritance of the WebChromeClient to intercept the FileChooser event
public class FileChooserWebChromeClient : WebChromeClient
{
private Action<IValueCallback, Java.Lang.String, Java.Lang.String> callback;
public FileChooserWebChromeClient (Action<IValueCallback, Java.Lang.String, Java.Lang.String> callback)
{
callback = callback;
}
// For Android < 5.0
@jfversluis
jfversluis / MainActivity.cs
Created April 16, 2017 11:29
OnActivityResult on the MainActivity for enabling camera in file upload control
public class MainActivity : FormsAppCompatActivity
{
public static IValueCallback UploadMessage;
private static int FILECHOOSER_RESULTCODE = 1;
public static Android.Net.Uri mCapturedImageURI;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
@jfversluis
jfversluis / MainPage.xaml.cs
Created April 16, 2017 11:41
Codebehind for the mainpage of my application
private void WebView_OnNavigating (object sender, WebNavigatingEventArgs e)
{
var url = e.Url.ToLowerInvariant ();
if (url.Contains ("thirdparty.com") || url.Contains ("vimeo.com") || url.Contains ("bid.g.doubleclick.net")) {
// Do nothing, links are loaded as embedded
} else if (url.StartsWith ("https://getmypdfurl.com", StringComparison.Ordinal)) {
e.Cancel = true;
if (Device.OS == TargetPlatform.Windows)
@jfversluis
jfversluis / TextCellRenderer.cs
Created May 8, 2017 10:42
Implementation of the TextCellRenderer for my blog post
using System;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer (typeof (TextCell), typeof (RightDetailSample.iOS.TextCellRenderer))]
namespace RightDetailSample.iOS
{
public class TextCellRenderer : Xamarin.Forms.Platform.iOS.TextCellRenderer
{
@jfversluis
jfversluis / PlatformToColorConverter.cs
Created July 4, 2017 07:50
Empty implementation of the value converter
using System;
using System.Globalization;
using Xamarin.Forms;
namespace SampleValueConverters.ValueConverters
{
public class PlatformToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
@jfversluis
jfversluis / PlatformToColorConverter.cs
Created July 4, 2017 08:02
Implemented Convert method
using System;
using System.Globalization;
using SampleValueConverters.Enums;
using Xamarin.Forms;
namespace SampleValueConverters.ValueConverters
{
public class PlatformToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
@jfversluis
jfversluis / SampleValueConvertersPage.xaml
Created July 4, 2017 08:17
UI page to show our games
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:SampleValueConverters" x:Class="SampleValueConverters.SampleValueConvertersPage" xmlns:converters="clr-namespace:SampleValueConverters.ValueConverters;assembly=SampleValueConverters">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS" Value="0,20,0,0" />
</OnPlatform>
</ContentPage.Padding>
<ContentPage.Resources>
<ResourceDictionary>
@jfversluis
jfversluis / badcode.xaml
Last active August 11, 2017 06:49
The XAML culprit...
<Image Grid.Row="0" Source="MyImage.png" WidthRequest="280" Aspect="AspectFit" Margin="0,0,0,20">
<Image.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="10" Command="{Binding DoSomethingCommand}" />
</Image.GestureRecognizers>
</Image>
private readonly ObservableRangeCollection<Breach> _breaches = new ObservableRangeCollection<Breach>();
public ObservableCollection<Breach> Breaches => _breaches;
private ICommand refreshCommand;
public ICommand RefreshCommand
{
get
{
return refreshCommand ??
(refreshCommand = new Command(() => LoadBreaches(), () => !IsLoading));
<?xml version="1.0" encoding="utf-8"?>
<ContentPage Title="Akavache sample" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:AkavacheSample" x:Class="AkavacheSample.AkavacheSamplePage">
<ListView ItemsSource="{Binding Breaches}" IsRefreshing="{Binding IsLoading}" RefreshCommand="{Binding RefreshCommand}" IsPullToRefreshEnabled="true">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" Detail="{Binding NoOfAccounts, StringFormat='{0} of pwned accounts'}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>