Skip to content

Instantly share code, notes, and snippets.

@dannycabrera
dannycabrera / AwaitAlertAsync.cs
Last active June 14, 2018 14:10
Xamarin.Android await AlertDialog.Builder
await AlertAsync(this, "My Title", "My Message", "Yes", "No");
public Task<bool> AlertAsync(Context context, string title, string message, string positiveButton, string negativeButton)
{
var tcs = new TaskCompletionSource<bool>();
using (var db = new AlertDialog.Builder(context))
{
db.SetTitle(title);
db.SetMessage(message);
@dannycabrera
dannycabrera / AwaitAlertAsync.cs
Created June 14, 2018 13:49
Xamarin.Android await AlertDialog.Builder
public Task<bool> AlertAsync(Context context, string title, string message, string positiveButton, string negativeButton)
{
var tcs = new TaskCompletionSource<bool>();
using (var db = new AlertDialog.Builder(context))
{
db.SetTitle(title);
db.SetMessage(message);
db.SetPositiveButton(positiveButton, (sender, args) => { tcs.TrySetResult(true); });
db.SetNegativeButton(negativeButton, (sender, args) => { tcs.TrySetResult(false); });
@dannycabrera
dannycabrera / WriteWavHeader.cs
Last active June 1, 2018 22:16
Xamarin.Android Wave Header Method
using System;
using System.IO;
public void WriteWavHeader(string filePath, int sampleRate, short bitsPerSample, short channels)
{
using (var fs = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite))
{
using (BinaryWriter writer = new BinaryWriter(fs, System.Text.Encoding.UTF8))
{
writer.Seek(0, SeekOrigin.Begin);
@dannycabrera
dannycabrera / QuickZip.cs
Created May 21, 2018 13:50
QuickZip using .NET Framework System.IO.Compression assembly
using System.IO.Compression;
public bool QuickZip(string[] filesToZip, string destinationZipFullPath)
{
try
{
// Delete existing zip file if exists
if (File.Exists(destinationZipFullPath))
File.Delete(destinationZipFullPath);
@dannycabrera
dannycabrera / DismissAlertDialogOnDialogClickEventArgs.cs
Last active April 19, 2018 13:18
Xamarin.Android Dismiss SetSingleChoiceItems on DialogClickEventArgs handler
var dialogBuilder = new Android.App.AlertDialog.Builder(Context);
dialgBuilder.SetTitle("My Title");
string[] items = new string[] { "Item 1", "Item 2", "Item 3", "Item 4" };
dialogBuilder.SetSingleChoiceItems(items, 0, new EventHandler<DialogClickEventArgs>(delegate (object sender, DialogClickEventArgs e) {
// Get reference to AlertDialog
var d = (sender as Android.App.AlertDialog);
// Do something with selected index
Toast.MakeText(Context, $"SelectedItemIndex: {e.Which}", ToastLength.Short).Show();
@dannycabrera
dannycabrera / FontsAvailableOniOS.txt
Created April 2, 2018 15:46
Fonts available on iOS
AcademyEngravedLetPlain
AmericanTypewriter-CondensedLight
AmericanTypewriter-Light
AmericanTypewriter
AmericanTypewriter-Condensed
AmericanTypewriter-Bold
AmericanTypewriter-CondensedBold
AppleColorEmoji
AppleSDGothicNeo-Medium
AppleSDGothicNeo-Bold
@dannycabrera
dannycabrera / GetDroidModel_Changes_3-30-2018.csv
Created March 30, 2018 20:08
GetDroidModel device changes 3-30-2018
Retail Branding Marketing Name Device Model
AVH San Luis S.A. ActionKids3.0 ActionKids3_0 ActionKids3.0
AVH San Luis S.A. Vortech3.0 Vortech3_0 Vortech3.0
Advan digital G3 ADVAN_G3 6001
Advan digital i5D ADVAN_i5D i5D
AllView AX502 AX502 AX502
AllView X4 Soul Infinity SV X4_Soul_Infinity_SV X4_Soul_Infinity_S
AllView X4 Soul Infinity Z X4_Soul_Infinity_ZV X4_Soul_Infinity_Z
Altice ALTICE S60 S60 S60
Altice ALTICE S70 S70 S70
@dannycabrera
dannycabrera / MoveToTop.cs
Created March 26, 2018 21:03
MoveToTop Extension
// Create our model
class Model {
public int Id {get;set;}
public string Name {get;set;}
}
// Create handy extension (from: https://stackoverflow.com/a/2576736/461998)
static void MoveToTop<T>(this List<T> list, int index)
{
T item = list[index];
@dannycabrera
dannycabrera / ImageGetPropertyItem.cs
Last active February 26, 2018 22:45
Image.GetPropertyItem
Image image = Image.FromFile(@"C:\ArthroscopyImages\1.jpg");
var userComment = Encoding.UTF8.GetString(image.GetPropertyItem(0x9286).Value);

Keybase proof

I hereby claim:

  • I am dannycabrera on github.
  • I am dannyc (https://keybase.io/dannyc) on keybase.
  • I have a public key ASAQdo3ygYwQ9-kyIy9iP8hX1969zoXtQFb4vorZMYtX5go

To claim this, I am signing this object: