Posts

Showing posts from 2016

Use Font Awesome from Xamarin.Android for your Xamarin.Forms project

Image
Use Font Awesome from your Xamarin.Forms project Icons are important in mobile applications where space is limited. We use icon everywhere to convey action intent like + would be to add an item or a bin would be to delete one. There are two ways to add icons to our mobile app: with images with fonts Today we will see the second option - how we can add Font awesome to our Xamarin.Android project and how we can use it from Xamarin.Forms. This post will be composed by three parts: 1. Why Font Awesome 2. Add Font Awesome to the Droid project 3. Use with Xamarin.Forms 1. Why Font Awesome If you are familiar with Web development, you must have encountered Font awesome http://fontawesome.io/ . It is an icon font containing lots of icon for every type of usage. The advantaged of using a font is that we can leverage the text options, like text color or text size, to easily update the style of the icon to match our app. Let’s see how we can bring Font Awesome to the Droid pro

Output logs in Console, File and Live stream for your WebSharper sitelet

Image
Output logs in Console, File and Live stream for your WebSharper sitelet Logs are an important part of development. Extracting and analysing debug output and errors is very important especially when the web server goes live. In this post I will show how we can setup a Console target , a File target and a Live stream on a static HTML page using NLog . NLog is a log framework which can be configured to output logs on different “target”. https://github.com/nlog/NLog/wiki/Targets This post is composed by 4 parts: 1. Get NLog on your sitelet 2. Define a Console target 3. Define a File target 4. Define a Live stream target - WebSharper part 1. Get NLog on your sitelet First start by getting NLog and NLog.Configuration packages from nuget. This will install NLog package in your project and also add an xml configuration nlog.xml file with an xsd. To start logging, simply get the logger instance via let logger = LogManager.GetCurrentClassLogger() and start logging by using any o

GIMP Alpha Channel, what is it?

Image
GIMP - Alpha channel, what is it? Few months ago I made a first introduction to GIMP - https://kimsereyblog.blogspot.co.uk/2016/09/gimps-primary-features.html - the post was oriented toward the toolbox and what features were available. Today I would like to share an explanation on what the alpha channel is and show you how you can outline text using the alpha channel. 1. What is the alpha channel The channels tab can be seen from the Layers view. There are 4 channels, Red, Green, Blue and Alpha. The alpha channel is used for transparency. Transparency means that when you export to .png, the transparent parts of your image will show whatever is underneath. This is very useful for apps icons or images for web design. When your layer does not have an alpha channel, its name should be bolded. When it has one it should not be bolded. Also when right click on the layer, Add alpha channel should be grayed out. Having an alpha channel allows us to add transparency to our image.

Transform an operation from a Xamarin.Android activity to an awaitable task

Image
Transform an operation from a Xamarin.Android activity to an awaitable task Today I want to share a neat trick which I have been using a lot - transform an asynchronous operation (triggered with StartActivityFromResult) from an Android Activity to an awaitable task - which then can be used with async await keywords in a Xamarin.Forms PCL project. Problem CustomPickActivity TaskCompletionSource in service 1. Problem In order to pick a file from the device local storage and execute an action using the selected file, the pick action (StartActivityFromResult/OnActivityResult) must be turned to an awaitable Task. 2. PickActivity To pick a file from our Xamarin.Forms project, we use a service which starts a picker activity. public class FilePicked : EventArgs { public string AbsolutePath { get; set; } } [Activity] public class PickActivity: Activity { static event EventHandler<FilePicked> OnFilePicked; protected override void OnCreate(Bundle savedInstanceState

Differences between Internal and External Folders in Xamarin.Android

Differences between Internal and External Folders in Xamarin.Android and Xamarin.Forms When using Xamarin.Forms and Xamarin.Android, chances are that you had at one point of time to access a local file. Whether it is an image or a text file or even a local sqlite database, accessing a file from a Xamarin.Android project can be confusing. Today I will show you how you can get the absolute path of the different folders available in Xamarin.Android and we will see how we can get the paths from Xamarin.Forms. This post is composed 3 parts: 1. Internal folder 2. Public and private external folders 3. Access folder paths from Xamarin.Forms 1. Internal folder The internal folder is a folder specific to your application. It can only be access within your application and no other applications can touch the files within that folder. You can get it using the following: Android.App.Application.Context.FilesDir.AbsolutePath The path looks something like that: /data/user/0/com.kimserey.m

Why I created Baskee?

Image
Why I created Baskee? Few days ago, I released my first Android app Baskee built with Xamarin and F# . https://www.kimsereylam.com/baskee In this post, I would like to share with you the most common questions my friends asked me and I hope it will help you understand better why Baskee is useful for you! This post answers the following questions: 1. Where did the idea come from? 2. What are the problems Baskee solves? 3. Is Baskee free? 4. How many people worked on it? 5. What stack is it built on? 6. If you had one advice for new developers to start what would it be? 1. Where did the idea come from? I was walking at the supermarket and saw Nescafe coffee tin selling at 6 pounds. I am a big coffee consumer so I regularly buy coffee and I knew other days I did no pay for 6 pounds but I couldn’t remember how much I used to pay and even in which shop it was cheaper. I tried to check online but there was no network at the supermarket. So I didn’t get it and continue to shop. B

Fix adb server is out of date killing... Android

Fix adb server is out of date killing... Last week I showed you how to fix the error adb server version doesn't match... with Xamarin.Android - https://kimsereyblog.blogspot.co.uk/2016/11/fix-installfailed-error-adb-server.html when trying to deploy an application built in Xamarin.Studio to a Genymotion VM. This was caused by two different versions of ADB being installed on the machine. One installed during Xamarin installation and another one installed separately. The solution was to set the ADB path in the options of Genymotion. I thought all was good but turns out there was another issue. 1. Problem When running adb shell , I had the following error in bash: adb server is out of date killing... 2. Solution Again the problem was due to my machine having two adb versions and the adb location in $PATH was the wrong one. In order to check verify that, I ran echo $PATH and saw that the path was incorrect. In order to rectify that, I modified the ~/.bash_profile which is

How to use the Snackbar API in Xamarin.Android and Xamarin.Forms

Image
Use Android Snackbar for your Xamarin Android project from Xamarin Forms The Snackbar API is a sleek way to provide notifications in Android. Here’s how it look like: You might have noticed the usage of it in applications that you use daily like Chrome, get the notification that the tab was closed. This is the snackbar. Today we will see how to use the snack bar api with Xamarin Android and how we can call it from our Xamarin Forms project. This post is composed by 3 parts: 1. When is the snackbar useful 2. Implement the snackbar api 2. Call it from Xamarin.Forms 1. When is the Snackbar useful The snackbar can be use to notify the user that something had happen. You would pass it a message which would popup for few seconds to acknowledge the user action. Another useful scenario for the snackbar is to provide an instant non obstrusive way to rectify an error by providing an action button on the right . The most common action is the undo action which allows the user to rectify

Fix INSTALL_FAILED error - adb server version doesn't match in Xamarin.Android

Fix INSTALL_FAILED adb server version doesn’t match Xamarin.Android Today I would like to share with you how you can fix the following problem: INSTALL_FAILED /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.Debugging.targets: Warning: error: could not install *smartsocket* listener: Address already in use ADB server didn't ACK * failed to start daemon * error: cannot connect to daemon List of devices attached adb server version (32) doesn't match this client (36); killing... 1. Problem You might be running two different ADB and the versions collide. 2. Solution Verify the ADB version used by Xamarin: About Xamarin > Show details > Android SDK: [PATH] Make sure the PATH is the same as the one referenced in Genymotion. Genymotion > Settings > ADB > Use custom Android SDK tools > Put PATH in Android SDK This means that the adb used by Xamarin Studio to perform all deployment commands will be the same as the dae

How to fix Xamarin Android app instantly closing with error after deployment

Image
Xamarin.Android app instantly closing with error after deployment Last week I had an issue suddenly after updating Xamarin.Android and downloading the latest Android sdk 24. My application kept closing instantely after being deployed showing the following error: Unfortunately, [App name] has stopped. I looked online and all I found was answers which recommended to uninstall the app either through the Android settings or using adb uninstall <package name> , clean and rebuild but nothing did it . It was still crashing. 1. Scoping the issue I wasn’t sure what was going on until I remembered that I could access the logs via adb logcat . After inspecting the logs, I saw the following error message: AndroidRuntime: java.lang.RuntimeException: Unable to get provider mono.MonoRuntimeProvider: java.lang.RuntimeException: Unable to find application Mono.Android.Platform.ApiLevel_24 or Xamarin.Android.Platform! It was that it couldn’t find ApiLevel_24 but my manifest was configure

Build your own Line chart for Xamarin.Forms (Part 2)

Image
Build your own Line chart (Part 2) Last week we saw how we could use custom renderers with boxview to draw via the canvas api https://kimsereyblog.blogspot.co.uk/2016/10/build-your-own-line-chart-for.html . Today I will go through the steps to draw a line chart supporting markers. The line chart is very simple and has only one objective, give a rough indication of the current trend of the data displayed. In order to draw the chart, we will divide the chart in four layer which we will draw one by one. Therefore this post will be composed by the three layers. Draw background and bands Draw axis and labels Draw lines and markers 1. Draw background and bands We can see the canvas as a painting canvas. When we draw something and then draw something on top of that, the last thing drawn will hide the previous one - just like as if you are painting something on top of something else. Therefore the first thing we need to draw is the background. // Draws background paint.Color = Colo

Build your own Line chart for Xamarin.Forms (Part 1)

Image
Build your own Line chart for Xamarin.Forms with Custom renderers (Part 1) Last week I needed a line chart to plot expenses. I had two choices: use an existing library or draw the chart myself on canvas. I decided to go for the second - draw the chart using the Android Canvas API. I chose this approach because it gives me full flexibility to create a style and behaviour that match perfectly my application. Here’s the chart result: This tutorial will be composed by four points divided in two parts: 1. Xamarin.Forms custom renderer (Part 1) 2. Explore the Android Canvas API (Part 1) 3. Create a GraphView which will draw a line chart (Part 2) 4. Use it (Part 2) 1. Xamarin.Forms custom renderer Officiel documentation: https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/ A custom renderer is a class used by Xamarin.Forms to define platform specific behaviours of your views. In this tutorial, we will be using a custom renderer to access the Android native Canvas API

What does DP, DPI, PPI and PX represent in Android?

What does DP, DPI, PPI and PX represent in Android? I’ve been playing with Xamarin Android for a while now and one thing that disturbed me when I started was the units of measure. What is the difference between DP, DPI, PPI and PX in Android? I found my answers in the Material design guide and today I would like to share my undertanding of the differences and bring a different explanation which hopefully will help you get a better understanding. This post is composed by three parts: 1. PX - pixels 2. DPI / PPI - pixels per inch 3. DP - density-independent pixel 1. PX - pixels Pixels is the most granular unit of measure. When talking about resolution 1920x1080, 2560x1440, etc… It represents the amount of pixels which fit in the screen. The higher the better but a second aspect equally important has too be taken in consideration - the screen dimension . Two devices with the same resolution but different screen sizes will not have the same display. For a similar resolution, th