Archive

Archive for January, 2014

Native tick sound on button click with PhoneGap

January 20, 2014 4 comments

PhoneGap is a good framework to build hybrid applications, but for a great usability the devil is in the detail. A difference with native buttons is that HTML5 rendered hyper-links don’t produce a click sound with PhoneGap. Such small difference gives directly a non standard user experience to your app. So I came up with a small PhoneGap plug-in to fix this small annoyance.

Java code:

public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
	if("click".equals(action)) {
		try {
			cordova.getActivity().runOnUiThread(new Runnable(){
				public void run(){
					try {
						View view = cordova.getActivity().getWindow().getDecorView();
						view.playSoundEffect(SoundEffectConstants.CLICK);
					}
					catch(Exception ex) {
						callbackContext.error(ex.getMessage());
					}
				}
			});
		}
		catch(Exception ex) {
			callbackContext.error(ex.getMessage());
		}

		return true;
	}

	return false;
}

JavaScript code:

$(function() {
	$(document).on("click", ".sound-click", function() {
		cordova.exec(function () { },
					function () { },
					"SoundEffects",
        			"click",
        			[]);
	});
});

In order to have the click sound, it it sufficient to add the “sound-click” class to your HTML5 buttons (and jQuery referenced in your page).

Advertisements
Categories: Cordova, Java, PhoneGap

Changing the supported media types of the default media formatters in the ASP.NET Web API client library

January 15, 2014 Leave a comment

A couple of days ago, I encountered an issue when calling a REST service. The REST service was returning JSON data, but the content type in the HTTP header was set to “text/javascript”. This caused the default JSON formatter of the ASP.NET Web API client not to recognize the data (he expects “application/json”). It took me a while to find this proper solution as I wanted to avoid creating a custom formatter, but the ASP.NET Web API client library allows to modify the supported content types for the default content formatters.

HttpClient client = new HttpClient();

MediaTypeFormatterCollection formatters = new MediaTypeFormatterCollection();
formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/javascript"));

HttpResponseMessage response = await client.GetAsync(url);
SearchResult result = await response.Content.ReadAsAsync(formatters);
Categories: ASP.NET Web API, C#, REST

Compiled Zip package for Jace 0.8.4

January 8, 2014 Leave a comment

Jace.NET is a mathematical calculation engine for .NET that can parse and execute strings containing mathematical formulas. More information on Jace can be found in previous articles published on this blog or in the following codeproject article: http://www.codeproject.com/Articles/682589/Jace-NET-Just-another-calculation-engine-for-NET.

Previously, the only way to obtain an already compiled version of Jace.Net was to use NuGet. Although I am still convinced that nowadays the recommended way to add frameworks to Visual Studio projects should be NuGet, I understand that this is not always possible. Especially in enterprise environments. For people in such situations, I have created a zip based version of Jace.NET. This zip package contains compiled versions of Jace for .NET 4.x, Windows Store, Windows Phone 7 and Windows Phone 8.

The zip version can be downloaded using the following link: https://github.com/pieterderycke/Jace/releases/download/0.8.4/Jace.0.8.4.zip.

All future zip packages will be published on the following GitHub page: https://github.com/pieterderycke/Jace/releases.

The assemblies in the zip package are currently not strongly signed. If you would rather prefer strongly singed assemblies, you can let me know by mail or by leaving a comment.

Categories: C#, Jace.NET