Friday, November 9, 2012

That damn NFC alert after tapping a tag on WP8

In these days I had the opportunity to develop a Windows Phone 8 application for my company.
The main reason we choose WP8 was the new Proximity API for reading NFC Tags.

I don't wanna write about how to read or write a NFC Tag but I just want to notify you an issue I encountered while developing.

When you tap a Tag over a device, a system dialog appears asking you if you want to view the content of the tag. A dialog is showed even if there aren't app that can manage a specified tag content.
So read a Tag brings an annoying system dialog.

I had to realize an app that reads tags during an event and does a check-in . So in a single page I want to read several nfc tags without any kind of interruptions.
Can I read a tag without seeing this damn alert that is literally ruining my UX? The answer is yes I can.

Wednesday, August 8, 2012

String-based Socket communication classes

I recently removed an old post called "A little framework for TCP client-server communication".

That's why I think it was not so clear and useful.
Today I propose the "engine" I used.

I used those libs for some projects like:
  • A push server for Android clients
  • A server that controls some computer's feature like volume, services, tasks, also file exchange
  • A computer's mouse controller
  • Data exchange between two different processes

I think it's very useful, scalar and powerful for simple projects.

It's basically composed by two class and two interfaces.

class Server: wraps a ServerSocket object and manages incoming client connections, and messages through an interface called OnServerEventsListener.
interface OnServerEventsListener: defines some standard events like, adding a client, receiving messages, receiving errors of Server or from Clients.
class Client: wraps a Socket object and manages a simple communication through an interface called OnClientEventsListener.
interface OnClientEventsListener: defines events like connecting, disconnecting, on receiving message, on exception generated.

Sunday, August 5, 2012

SQLite wrapper based on java.lang.reflect

In Android development, data persistence is often realized with SQLite. Sometimes the act of preparing all the classes, the adapter, every kind of query (CRUD) and rewrap into model,is a bit frustrating. It's like something already done, to do again every time.

I never see this kind of class on the web, so I decided to make my own one.
What I'm talking about?

A class that simplifies the common use of SQLite with a friendly usage (inspired by .NET's LINQ one).
SQL Scripts are defined by the model, so you need to supply the object instance or just its class.

For the moment I provided:
  • select (distinct, count,where, limit, order by)
  • delete (where)
  • insert
  • transactions

Sunday, July 22, 2012

Some use of java.lang.reflect

You should remember it... a private member of a private class or a private method of a library... it's surely inaccessible at compile-time... but it's not completely inaccessible at run-time :)...


This is not the only purpose of java.lang.reflect but it's good to know how to use the main classes of this namespace.

Tuesday, March 27, 2012

Catch LogCat programmatically or export it to file

UPDATE - THIS POST IS VALID ONLY FOR API < 16 (ANDORID 4.1 JELLY BEAN), OTHERWISE YOU NEED ROOT PERMISSION 




Let'see how to catch LogCat from code.
It's very simple, just remember how to call it, and read his input stream.


LogCat process can be launched with parameters such as -help for help,
-s for silent filter,
-d for dump
-c for clear and,
-f for file export.

The (Nyan)LogCat

Monday, March 12, 2012

A month view calendar for WP7


We know that wp7 is a bit young but it has a good potential.
We also know that its youth means, for developers, poor os-controls, poor API etc...

Last week I had to demonstrate that WP7 is comparable to iOS and Android. 
I had to realize a sort of "accounting app" already done in iOS and Android.

I had no significant problems while working except for some limits of SDK.
SDK doesn't provide a datetime picker, a combo box or list picker not even a calendar.

I found on the web a Silverlight for Windows Phone Toolkit that brings some controls I've just mentioned.

No track of a calendar :(

I found only 1 calendar for wp7 on web but it didn't like me.... So..
I decided to make my own :)

Fixed layout for PhoneApplicationPage

As a beginner in WP7 I found some issues for my first applications.
One of those problems I had was the hated "fixed layout" of a page.

It's a topic already discussed (view the post for Android) but in this case, it's a bit different.

Suppose we want a "fixed header and footer" for every page, how do you do it?

Sunday, March 11, 2012

A little framework for TCP client-server communications (part2)

Here we are for the second part of this article.  I remeber to everybody that this little framework is not created for market, distrubution or diffusion. (Not even for best practices)

Let's start with some example code!

On the base of what I wrote in the first part, let' see how to create a simple server with JRR Framework.

ResponseManager server = new ResponseManager(8888); //8888 is the listening port
server.setConsoleLogEnabled(true); //enable printing log on the console
server.start(); //start listening

Wednesday, February 29, 2012

A little framework for TCP client-server communications (part1)

Hello world! I'm back from work and now it's time for requiem... :)

Today I wanna talk about a little framework written in Java for managing tcp/ip sockets connections.
Why I need a framework such this and what can I do with this framework ?

Remember that a good framework is very useful if can save you a lot of time/money on writing a lot of code. I think that JRR (Java Request Response) has a big potential and if you have to write an application,on every kind of device that supports internet, you should try it and see how it's simple to manage it all

Zooming out on features: with JRR you can:

  • Enstablish a Server that listens on a port; Provide your own implementation of handling client messages and server response. Also manages timeouts.
  • Create a Client that send requests to server, and handles response, exceptions, connection timeout and custom response timeout. 
P.S. If you don't provide your implementation, classes have their own.

Want to know more? Keep scrolling this post...

Thursday, January 26, 2012

Getting started with Lamba Expressions

C# 3.0 brought so much news (for example var, extensions ,LINQ, lambda expressions etc...).
Sometime companies have its reason to don't update .NET framework in their applications.
For this, developers who grow parallely to those applications, never have time to upgrade their knowledges.

I know companies that use 2003's IDE in 2011!

For those who never had a chance to see what's new in latest framework, like me, I dedicate this post.

What is a lambda expression and what can I do with it?

It's "an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types" (msdn).

Thursday, January 19, 2012

Manage a Database in Android


Today we will learn how to manage a database in Android using native SQLite libraries.


Tuesday, January 17, 2012

Invoking a method from its name

A few weeks ago I showed how can work a simple Server.
My client sends a pre-formatted string with the method to call and the parameters, my server processes the string and calls the correct method.
But how it can be?

Change!


I decided to change my blog language from italian to english.
I want to do this because I (finally) realized that write notes, code snippets, and comments in italian is useless for the web.
Internet community help me everyday for my development problems, and I wish to follow its example.
How can I be visible if I write my posts in a unknown language?

That's so.

The main problem is that my english is very bad... :)

But I hope in an improvement... :)


See you soon!

Thursday, January 12, 2012

Activity Template

Stiamo sviluppando la nostra applicazione Android e vogliamo che nelle nostre activity abbiano, per esempio, un header fisso e ovviamente non abbiamo intenzione di copia-incollare il codice in ognuna activity? Questo post vi può aiutare :)

Se ci pensiamo un secondo è una cosa banale: alla base della programmazione ad oggetti. L'ereditarietà.

Ci basta creare un activity contenitore con il nostro header definito e una "zona da riempire" (un layout vuoto).

Syntax Highlighter in Blogger

Effettivamente il modo con cui postavo il codice,oltre al codice stesso, ha sempre fatto un po' ridere...

Visto che su Blogger non esistono plugin simili (credo) come in WordPress per mettere in risalto le righe di codice postate io da ignorante utilizzavo questo tool e successivamente applicavo "a mano" i colori.

Il codice è abbastanza visibile ma per me ogni volta diventava un peso stare li a evidenziare stringhe, commenti ecc...
E lì che per caso noto Syntax Highlighter! Un progetto Javascript opensource, forkabile in Github, integrabile su praticamente tutti i blog compreso questo schifo di Blogger :)

Thursday, January 5, 2012

Server Multi-client in C# .NET

Un altro progetto a scopo didattico che è sempre carino da affrontare è la comunicazione Client/Server via socket TCP.

E cosa schiarisce meglio le idee di un immagine?

Il progetto in questione si divide quindi in due parti. La prima è semplicemente un server, realizzato in c# .net, che:
-riceve in ingresso delle stringhe formattate in un certo modo,
-effettua un operazione a seconda di che stringa riceve,
-rimanda al client la risposta in formato stringa.

Questo tipo di progetto può avere numerosissimi tipi di applicazione: in teoria tutto quello che può fare un applicativo .Net è "attivabile/reperibile" via socket. Le più stupide modalità di utilizzo che mi vengono in mente ora possono essere: reperire dei dati da un database, lanciare procedure, controllare funzioni di sistema ecc... ecc... 

Vediamo un po' più nel dettaglio come funziona.