Account.java

  1package de.gultsch.chat.entities;
  2
  3import android.content.ContentValues;
  4import android.database.Cursor;
  5import android.util.Log;
  6
  7public class Account  extends AbstractEntity{
  8
  9	private static final long serialVersionUID = 6174825093869578035L;
 10	
 11	public static final String TABLENAME = "accounts";
 12	
 13	public static final String USERNAME = "username";
 14	public static final String SERVER = "server";
 15	public static final String PASSWORD = "password";
 16	public static final String OPTIONS = "options";
 17	public static final String ROSTERVERSION = "rosterversion";
 18	
 19	public static final int OPTION_USETLS = 0;
 20	
 21	public static final int STATUS_OFFLINE = 0;
 22	public static final int STATUS_ONLINE = 1;
 23	public static final int STATUS_UNAUTHORIZED = 2;
 24	public static final int STATUS_NOINTERNET = 3;
 25	public static final int STATUS_TLS_ERROR = 4;
 26	public static final int STATUS_SERVER_NOT_FOUND = 5;
 27	
 28	protected String username;
 29	protected String server;
 30	protected String password;
 31	protected int options;
 32	protected String rosterVersion;
 33	protected String resource;
 34	protected int status = 0;
 35	
 36	protected boolean online = false;
 37	
 38	public Account() {
 39		this.uuid = "0";
 40	}
 41	
 42	public Account(String username, String server, String password) {
 43		this(java.util.UUID.randomUUID().toString(),username,server,password,0,null);
 44	}
 45	public Account(String uuid, String username, String server,String password, int options, String rosterVersion) {
 46		this.uuid = uuid;
 47		this.username = username;
 48		this.server = server;
 49		this.password = password;
 50		this.options = options;
 51		this.rosterVersion = rosterVersion;
 52	}
 53	
 54	public boolean isOptionSet(int option) {
 55		return ((options & (1 << option)) != 0);
 56	}
 57	
 58	public String getUsername() {
 59		return username;
 60	}
 61
 62	public void setUsername(String username) {
 63		this.username = username;
 64	}
 65
 66	public String getServer() {
 67		return server;
 68	}
 69
 70	public void setServer(String server) {
 71		this.server = server;
 72	}
 73
 74	public String getPassword() {
 75		return password;
 76	}
 77
 78	public void setPassword(String password) {
 79		this.password = password;
 80	}
 81	
 82	public void setStatus(int status) {
 83		this.status = status;
 84	}
 85	
 86	public int getStatus() {
 87		return this.status;
 88	}
 89	
 90	public void setResource(String resource) {
 91		this.resource = resource;
 92	}
 93	
 94	public String getJid() {
 95		return username+"@"+server;
 96	}
 97
 98	@Override
 99	public ContentValues getContentValues() {
100		ContentValues values = new ContentValues();
101		values.put(UUID,uuid);
102		values.put(USERNAME, username);
103		values.put(SERVER, server);
104		values.put(PASSWORD, password);
105		return values;
106	}
107	
108	public static Account fromCursor(Cursor cursor) {
109		return new Account(cursor.getString(cursor.getColumnIndex(UUID)),
110				cursor.getString(cursor.getColumnIndex(USERNAME)),
111				cursor.getString(cursor.getColumnIndex(SERVER)),
112				cursor.getString(cursor.getColumnIndex(PASSWORD)),
113				cursor.getInt(cursor.getColumnIndex(OPTIONS)),
114				cursor.getString(cursor.getColumnIndex(ROSTERVERSION))
115				);
116	}
117
118}