Skip to content

Instantly share code, notes, and snippets.

@jamesmontemagno
jamesmontemagno / MvxActionBarActivity.cs
Created December 27, 2013 04:57
Compatibility classes if you use Action Bar Compat (v7) with MvvmCross
using Android.Content;
using Cirrious.MvvmCross.Binding.BindingContext;
using Cirrious.MvvmCross.Binding.Droid.BindingContext;
using Cirrious.MvvmCross.ViewModels;
using MeetupManager.Droid.Helpers;
using Cirrious.MvvmCross.Droid.Views;
namespace MyProject
{
public abstract class MvxActionBarActivity
@jamesmontemagno
jamesmontemagno / MyService.cs
Last active January 2, 2016 08:19
Using Json.Net + Xamarin.iOS + PCL + MvvmCross
public Task<T> DeserializeObjectAsync<T>(string value)
{
return Task.Factory.StartNew (() => JsonConvert.DeserializeObject<T> (value))
}
public T DeserializeObject<T>(string value)
{
return JsonConvert.DeserializeObject<T>(value);
@jamesmontemagno
jamesmontemagno / Activity1.cs
Created February 1, 2014 19:29
Search-Android
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Support.V4.View;
namespace XamarinCast
@jamesmontemagno
jamesmontemagno / Activity1.cs
Created February 4, 2014 03:24
Target 4.0+
using Android.App;
using Android.OS;
namespace Notepad
{
[Activity (Label = "Notepad", MainLauncher = true, Theme="@android:style/Theme.Holo.Light")]
public class MainActivity : MvxActivity
{
int count = 1;
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="2.0.5.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
public class HttpClientHelper : IHttpClientHelper
{
private HttpMessageHandler handler;
public HttpMessageHandler MessageHandler
{
get { return handler ?? (handler = new OkHttpNetworkHandler()); }
}
}
private IHttpClientHelper httpClientHelper;
public MyService()
{
this.httpClientHelper = ServiceContainer.Resolve<IHttpClientHelper>(); //does not exist on WP
}
private HttpClient CreateClient()
{
if(httpClientHelper == null)
return new HttpClient();
@jamesmontemagno
jamesmontemagno / MvxSwipeRefreshLayout.cs
Last active April 8, 2019 13:03
MvvmCross Implementation of SwipleRefreshLayout for Xamarin.Android
public class MvxSwipeRefreshLayout : SwipeRefreshLayout
{
/// <summary>
/// Gets or sets the refresh command.
/// </summary>
/// <value>The refresh command.</value>
public ICommand RefreshCommand { get; set;}
public MvxSwipeRefreshLayout(Context context, IAttributeSet attrs)
: base(context, attrs)
@jamesmontemagno
jamesmontemagno / OnSensorChanged.cs
Created April 12, 2014 21:04
Sensor Changed Logic
private int stepCounter = 0;
private int counterSteps = 0;
private int stepDetector = 0;
public void OnSensorChanged (SensorEvent e)
{
switch (e.Sensor.Type) {
case SensorType.StepDetector:
stepDetector++;
break;
@jamesmontemagno
jamesmontemagno / RegisterSensors.cs
Created April 12, 2014 21:10
Registering sensors for android
public override void OnStart (Intent intent, int startId)
{
base.OnStart (intent, startId);
if (isRunning || !Utils.IsKitKatWithStepCounter(PackageManager))
return;
RegisterListeners (SensorType.StepCounter);
}