Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Monday, July 1, 2013

Convert from jar to dll

Nowadays, development is very eased from community.
We can easily re-use our code between different platforms in so many ways, gaining time, money and above all... today have multiple skills is not so as useful as before.

By the way, I recently had necessity to bring some java code to .NET runtimes.
No difficulties with IKVM.NET !

If you follow these steps you can convert from JAR to DLL or even from Runnable JAR to EXE!

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

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 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).

Tuesday, December 20, 2011

Interrogare un Web Service ASP.NET con Android

Abbiamo il nostro bel WS in ASMX o WCF e vogliamo renderlo raggiungibile dai nostri terminali Android senza troppe rogne? Le librerie ksoap2 ci stravengo incontro!

Scarichiamo il jar relativo qui , importiamolo nel nostro progetto e aggiungiamo le referenze nella nostra classe:

 import org.ksoap2.SoapEnvelope;  
 import org.ksoap2.serialization.SoapObject;  
 import org.ksoap2.serialization.SoapPrimitive;  
 import org.ksoap2.serialization.SoapSerializationEnvelope;  
 import org.ksoap2.transport.HttpTransportSE;  

Supponendo di avere un webservice con una pagina "Service1.asmx" la quale contiene questo metodo:

 [WebMethod]  
 public string HelloWorld(string valore)  
 {  
       return valore;  
 }  

Saturday, December 17, 2011

Text To Speech (TTS) in Android


Avete mai pensato di implementare la sintesi vocale in una vostro progetto Android?
Se non sapete come fare, vi posso assicurare che è più semplice di quanto pensate.
Senza perderci in chiacchere, implementiamo nella nostra classe l'interfaccia OnInitListener la quale sarà richiesta dalla classe TextToSpeech. Ora possiamo dichiararci il nostro oggetto:

 import android.speech.tts.TextToSpeech;  
 import android.speech.tts.TextToSpeech.OnInitListener  

 private TextToSpeech tts = null;  

Le API TTS supportano diverse lingue come Inglese, Francese, Tedesco, Italiano e Spagnolo ma è necessario ogni volta specificare la lingua di output. Se diciamo all'istanza TTS configurata in italiano di pronunciare la parola "I am 21" aspettiamoci un "I am ventuno" e non un "Ai em tuenti uan". E' molto importante quindi la configurazione dell'oggetto.
Ulteriore controllo da fare, è anche la presenza delle librerie nel device. Alcuni dispositivi non le possiedono per motivi di spazio oppure possono non avere giusto la lingua che serve a noi.