Skip to content

Instantly share code, notes, and snippets.

View jfversluis's full-sized avatar

Gerald Versluis jfversluis

View GitHub Profile
@jfversluis
jfversluis / RefitTestAppPage.xaml.cs
Created March 23, 2017 21:23
Traditional code for creating a REST API call
private async void Handle_Clicked (object sender, System.EventArgs e)
{
using (HttpClient client = new HttpClient ()) {
client.BaseAddress = new Uri (_baseApiUrl);
var fooString = await client.GetStringAsync ("posts");
var fooCollection = JsonConvert.DeserializeObject<Foo []> (fooString);
ResultLabel.Text = $"{fooCollection [0].id} - {fooCollection [0].title}";
}
@jfversluis
jfversluis / RefitTestAppPage.xaml.cs
Created March 23, 2017 21:48
Refit code to call our REST API
private async void Handle_Clicked_Awesome (object sender, System.EventArgs e)
{
var fooCollection = await _restClient.GetPosts ();
ResultLabel.Text = $"{fooCollection [0].id} - {fooCollection [0].title}";
}
@jfversluis
jfversluis / IRestClient.cs
Created March 23, 2017 21:56
Refit interface
using System.Threading.Tasks;
using Refit;
namespace RefitTestApp
{
public interface IRestClient
{
[Get ("/posts")]
Task<Foo []> GetPosts ();
}
@jfversluis
jfversluis / RestClient.cs
Last active March 24, 2017 10:35
Invoking the Refit code
using Refit;
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace RefitTestApp
{
public class RestClient
{
private readonly IRestClient _restClient;
@jfversluis
jfversluis / IRestClient.cs
Created March 24, 2017 10:46
Expanding the Refit interface
using System.Threading.Tasks;
using Refit;
namespace RefitTestApp
{
public interface IRestClient
{
[Get ("/posts")]
Task<Foo []> GetPosts ();
@jfversluis
jfversluis / multiplefiles.cs
Created March 24, 2017 11:07
Implementation in the RestClient.cs and calling from code-behind
// RestClient.cs
public async Task<Foo> GetPost (int id)
{
return await _restClient.GetPost (id);
}
// Implementing event to retrieve post 3
private async void Handle_Clicked_Awesome_3 (object sender, System.EventArgs e)
{
var foo = await _restClient.GetPost (3);
@jfversluis
jfversluis / multiplefiles.cs
Last active March 24, 2017 11:31
Implementing a POST method
// IRestClient.cs
[Post ("/posts")]
Task AddPost (Foo foo);
// RestClient.cs
public async Task AddPost (Foo foo)
{
await _restClient.AddPost (foo);
}
@jfversluis
jfversluis / androidmanifest.xml
Created April 14, 2017 07:17
Setting hardware acceleration at application level
<application android:hardwareAccelerated="true" ...>
@jfversluis
jfversluis / CustomWebViewRenderer.cs
Created April 16, 2017 11:02
Enabling hardware acceleration on Xamarin Android
if ((int)Build.VERSION.SdkInt >= 19) {
Control.SetLayerType (Android.Views.LayerType.Hardware, null);
} else {
Control.SetLayerType (Android.Views.LayerType.Software, null);
}
@jfversluis
jfversluis / CustomWebViewRenderer.cs
Created April 16, 2017 11:16
Using the camera in a HTML File upload control
public class CustomWebViewRenderer : WebViewRenderer
{
private static int FILECHOOSER_RESULTCODE = 1;
protected override void OnElementChanged (ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged (e);
var chromeClient = new FileChooserWebChromeClient ((uploadMsg, acceptType, capture) => {
MainActivity.UploadMessage = uploadMsg;