<repo_name>brizio31/Android.FabTel<file_sep>/FabTel/src/main/java/it/cloudhome/android/fabtel/MySQLiteHelper.java
package it.cloudhome.android.fabtel;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MySQLiteHelper extends SQLiteOpenHelper {


	private static final String DATABASE_NAME = "comunicacon.db";
	private static final int DATABASE_VERSION = 1;

	// Database creation sql statement
	private static final String DATABASE_CREATE1 = "create table utenti "
			+ "(id integer primary key autoincrement, "
			+ " interno text not null, "
			+ " nominativo text not null, "
			+ " chat text not null "
			+ "); ";
			
	private static final String DATABASE_CREATE2 = "create table chat_messages "
			+ "(id integer primary key autoincrement,"
			+ "chat_from text not null,"
			+ "chat_to text not null,"
			+ "message text not null,"
			+ "timestamp text not null)"
			+ ";";
			

	public MySQLiteHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE1);
		database.execSQL(DATABASE_CREATE2);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(MySQLiteHelper.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS utenti DROP TABLE IF EXISTS chat_messages;");
		onCreate(db);
	}
}
<file_sep>/settings.gradle
include ':FabTel'
<file_sep>/FabTel/src/main/java/it/cloudhome/android/fabtel/ClsChatMessage.java
package it.cloudhome.android.fabtel;

import java.sql.Timestamp;
import java.util.Date;

public class ClsChatMessage {

	private String _from,_to,_chatMessage,_timestamp;
	private int id;
	
	public ClsChatMessage(String sFrom, String sTo, String sMessage) {
		// TODO Auto-generated constructor stub
		super();
		this._from=sFrom;
		this._to=sTo;
		this._chatMessage=sMessage;
		Date now = new Date();
		Long ts =now.getTime();
		this._timestamp = ts.toString();
	}

	public ClsChatMessage(String sFrom, String sTo, String sMessage,String sTimeStamp) {
		// TODO Auto-generated constructor stub
		super();
		this._from=sFrom;
		this._to=sTo;
		this._chatMessage=sMessage;
		this._timestamp = sTimeStamp;
	}
	
	public int getId(){return id;}
	public String getFrom() {return this._from;}
	public String getTo(){ return this._to;}
	public String getMessage(){ return this._chatMessage;}
	public String getTimeStamp(){ return this._timestamp;}
	@SuppressWarnings("deprecation")
	public String getDateTime()
	{ 
		Timestamp ts=new Timestamp(Long.valueOf(this._timestamp));
		String tmpStr=String.valueOf(ts.getDate())+"/"+String.valueOf(ts.getMonth()+1)+"/"+
						String.valueOf(1900+ts.getYear())+" "+String.valueOf(ts.getHours())+":";
		String min="0"+String.valueOf(ts.getMinutes()).trim();
		min=min.substring(min.length()-2, min.length());
		tmpStr += min;
		min="0"+String.valueOf(ts.getSeconds()).trim();
		min=min.substring(min.length()-2, min.length());
		tmpStr += ":"+ min;
		return tmpStr;
	}
	
	public void setId(int id){this.id=id;}
	public void setFrom(String sFrom){this._from=sFrom;}
	public void setTo(String sTo){this._to=sTo;}
	public void setMessage(String message){this._chatMessage=message;}
	public void setTimeStamp(String ts){this._timestamp=ts;}
	
}
<file_sep>/FabTel/src/main/java/it/cloudhome/android/fabtel/SplashScreen.java
package it.cloudhome.android.fabtel;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

/**
 * Created by Fabrizio.Clerici on 06/12/13.
 */
public class SplashScreen extends Activity {

    protected int _splashTime = 2000; // time to display the splash screen in ms
    protected boolean _active=true;
    private Context ctx;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.v_splash);
        ctx=this;

        Thread splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while(_active && (waited < _splashTime)) {
                        sleep(100);
                        if(_active) {
                            waited += 100;
                        }
                    }
                } catch(InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
                    Intent i = new Intent(ctx,CentraleMain.class);
                    startActivity(i);
                }
            }
        };
        splashTread.start();
    }

}
<file_sep>/FabTel/src/main/java/it/cloudhome/android/fabtel/DBChatMessage.java
package it.cloudhome.android.fabtel;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class DBChatMessage {
	// Database fields
	private SQLiteDatabase database;
	private MySQLiteHelper dbHelper;
	private String[] allColumns = { "id","chat_from","chat_to","message","timestamp" };
	
	public DBChatMessage(Context context) {
		dbHelper = new MySQLiteHelper(context);
	}
	
	public void open() throws SQLException {
		database = dbHelper.getWritableDatabase();
	}
	
	public void close() {
		dbHelper.close();
	}
	
	public List<ClsChatMessage> GetCollection(String filter,String[] filterPar,String order)
	{
		return GetCollection(filter, filterPar, order,null);
	}
	public List<ClsChatMessage> GetCollection(String filter,String[] filterPar,String order,String limit)
	{
		List<ClsChatMessage> msgs = new ArrayList<ClsChatMessage>();
		Cursor cursor=database.query("chat_messages", allColumns, filter, filterPar, null, null, order,limit);
		cursor.moveToFirst();
		while (!cursor.isAfterLast()) {
			ClsChatMessage msg = new ClsChatMessage(cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4));
			msgs.add(msg);
			cursor.moveToNext();
		}
		// Make sure to close the cursor
		cursor.close();
		return msgs;
	}
	
	public ClsChatMessage GetByFilter(String filter,String[] filterPar,String order)
	{
		Cursor cursor=database.query("chat_messages", allColumns, filter, filterPar, null, null, order);
		cursor.moveToFirst();
		ClsChatMessage msg = new ClsChatMessage(cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4));
		msg.setId(cursor.getInt(0));
		// Make sure to close the cursor
		cursor.close();
		return msg;
	}

	public void Insert(ClsChatMessage msg)
	{
		ContentValues values = new ContentValues();
		values.put("chat_from", msg.getFrom());
		values.put("chat_to", msg.getTo());
		values.put("message", msg.getMessage());
		values.put("timestamp", msg.getTimeStamp());
		database.insert("chat_messages", null,values);
	}
	public void Delete(String id)
	{
		database.delete("chat_messages", "id="+id,null);
	}

	public void upgradeDB()
	{
		this.open();
		database.execSQL("DROP TABLE IF EXISTS chat_messages");
		String Sql = "create table chat_messages "
		+ "(id integer primary key autoincrement,"
		+ "chat_from text not null,"
		+ "chat_to text not null,"
		+ "message text not null,"
		+ "timestamp text not null)"
		+ ";";

		database.execSQL(Sql);
		this.close();
	}

	public void executeSQL(String sql) {
		// TODO Auto-generated method stub
		database.execSQL(sql);
	}
}
<file_sep>/FabTel/src/main/java/it/cloudhome/android/fabtel/ClsContatto.java
package it.cloudhome.android.fabtel;

public class ClsContatto {

	private String nome;
	private String interno;
	private String stato;
	private String chat_address;
	private int id;
	
	public ClsContatto(String nome, String interno, String stato, String chat_address) {
		// TODO Auto-generated constructor stub
		super();
		this.nome=nome;
		this.interno=interno;
		this.stato=stato;
		this.chat_address=chat_address;
	}
	public ClsContatto(String nome, String interno, String chat_address) {
		// TODO Auto-generated constructor stub
		super();
		this.nome=nome;
		this.interno=interno;
		this.stato="";
		this.chat_address=chat_address;
	}

	public String getNome(){
		return this.nome;
	}
	
	public int getId(){return id;}
	public String getInterno(){ return this.interno;}
	public String getStato(){ return this.stato;}
	public String getChatAddress(){ return this.chat_address;}
	
	public void setId(int id){this.id=id;}
	public void setInterno(String interno){this.interno=interno;}
	public void setNome(String nome){this.nome=nome;}
	public void setChatAddress(String chat_address){this.chat_address=chat_address;}
	public void setStato(String stato){this.stato=stato;}
	
	public int getImage_old(){
        /*
		if (this.stato.equalsIgnoreCase("ONLINE"))
			return R.drawable.ico_profilo;
		if (this.stato.equalsIgnoreCase("BUSY"))
			return R.drawable.ico_profilo_busy;
		if (this.stato.equalsIgnoreCase("DND"))
			return R.drawable.ico_profilo_dnd;
		if (this.stato.startsWith("DIVERT"))
			return R.drawable.ico_profilo_out;
		return R.drawable.ico_profilo_off;
		*/
        return R.drawable.ico_profilo;
	}
	public int getImage(){
		return R.drawable.ico_profilo;
	}
	public int getPhoneImage()
	{
		//Nuova Funzione Non esegue pi� il controllo sullo stato dell'interno
		return R.drawable.call_user;
	}
	public int getPhoneImage_old(){
        /*
		if (this.stato.equalsIgnoreCase("ONLINE"))
			return R.drawable.call_user;
		if (this.stato.equalsIgnoreCase("BUSY"))
			return R.drawable.call_user_off;
			*/
		return R.drawable.call_user;
	}
}
