Skip to content

Instantly share code, notes, and snippets.

@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 / 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);
}
<uses-feature android:name="android.hardware.sensor.stepcounter" />
<uses-feature android:name="android.hardware.sensor.stepdetector" />
@jamesmontemagno
jamesmontemagno / StepServiceBinder.cs
Last active August 29, 2015 13:59
Service binder and connection
using Android.OS;
namespace StepCounter.Services
{
public class StepServiceBinder : Binder
{
StepService stepService;
public StepServiceBinder (StepService service)
{
this.stepService = service;
@jamesmontemagno
jamesmontemagno / StepService.cs
Created April 17, 2014 06:32
StepService code with INotifyPropertyChanged
using System;
using Android.App;
using Android.Hardware;
using Android.Content;
using System.ComponentModel;
using StepCounter.Helpers;
using StepCounter.Database;
using StepCounter.Activities;
namespace StepCounter.Services