Skip to content

Instantly share code, notes, and snippets.

View codercampos's full-sized avatar
:octocat:
Working Hard!

Carlos Campos codercampos

:octocat:
Working Hard!
View GitHub Profile
@codercampos
codercampos / ShareService.cs
Last active September 8, 2015 13:53
A simpe (I guess) code snippet to use Share service on each platform in Xamarin.Forms (this is still missing the Windows Phone implementation)
//PCL side
using System;
namespace ShareSample
{
public interface IShareService
{
void ShareAction(string textToShare, string imageUrl);
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Splash" parent="android:Theme">
<item name="android:windowBackground">@drawable/screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:scaleType">fitXY</item>
</style>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
using Xamarin.Forms;
using System;
using System.Windows.Input;
namespace YourNameSpace.UI.Controls
{
public class CustomStackLayout : StackLayout
{
public static BindableProperty CommandProperty =
BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(CustomStackLayout), default(ICommand));
@codercampos
codercampos / AndroidMobile.cs
Created April 19, 2017 17:17
Xamarin Latino How To Use Dependency Injection
public class DeviceInfo : IDeviceInfo
{
public string GetUniqueIdentifier()
{
return Android.Provider.Settings.Secure.GetString(Xamarin.Forms.Forms.Context.ContentResolver,
Android.Provider.Settings.Secure.AndroidId);
}
}
public interface IDeviceInfo
{
string GetUniqueIdentifier();
}
public class iOSDeviceInfo : IDeviceInfo
{
public string GetUniqueIdentifier()
{
return UIDevice.CurrentDevice.IdentifierForVendor.AsString();
}
}
public class AndroidDeviceInfo : IDeviceInfo
{
public string GetUniqueIdentifier()
{
return Android.Provider.Settings.Secure.GetString(Xamarin.Forms.Forms.Context.ContentResolver,
Android.Provider.Settings.Secure.AndroidId);
}
}
public class UwpDeviceInfo : IDeviceInfo
{
public string GetUniqueIdentifier()
{
var token = HardwareIdentification.GetPackageSpecificToken(null);
var hardwareId = token.Id;
var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);
byte[] bytes = new byte[hardwareId.Length];
dataReader.ReadBytes(bytes);
[assembly: Xamarin.Forms.Dependency(typeof(iOSDeviceInfo))]
namespace Mobile.Platform
{
...
}