Author: jerome
Date: 2009-03-20 17:08:41 +0100 (Fri, 20 Mar 2009)
New Revision: 4163
Added:
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/FriendStatut.java
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/Message.java
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/Reply.java
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/TwitterDatasStruct.java
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/.classpath
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/Configuration.java
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/GadgetTwitter.java
Log:
* Make use of serialized object to do not say messages that was said before.
* Added TwitterDatasStruct object to handle serialized object.
* Added Messages, FriendStatus and Reply classes.
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/.classpath
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/.classpath
2009-03-20 12:17:34 UTC (rev 4162)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/.classpath
2009-03-20 16:08:41 UTC (rev 4163)
@@ -3,6 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src"
path="/tuxdroid-gadget-java-kit"/>
- <classpathentry kind="lib" path="libs/jtwitter.jar"/>
+ <classpathentry kind="lib"
path="C:/Users/nux/Downloads/jtwitter-0.9.8.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/Configuration.java
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/Configuration.java
2009-03-20 12:17:34 UTC (rev 4162)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/Configuration.java
2009-03-20 16:08:41 UTC (rev 4163)
@@ -1,3 +1,24 @@
+/* This file is part of "Tux Droid Gadget Twitter".
+ * Copyright 2008, kysoh
+ * Author : Jerome Conan
+ * Site : http://www.kysoh.com/
+ *
+ * "Tux Droid Gadget Twitter" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "Tux Droid Gadget Twitter" is distributed in the hope that it will be
useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "Tux Droid Gadget Twitter"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
import com.kysoh.tuxdroid.gadget.framework.gadget.SimpleGadgetConfiguration;
@@ -3,6 +24,6 @@
public class Configuration extends SimpleGadgetConfiguration{
- private String username = "your_username";
- private String password = "your_password";
+ private String username = "jerome_conan";
+ private String password = "heitux";
private String myStatus = "Hello all from my Tux Droïd twitter gadget";
private boolean updateStatus = true;
Added:
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/FriendStatut.java
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/FriendStatut.java
(rev 0)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/FriendStatut.java
2009-03-20 16:08:41 UTC (rev 4163)
@@ -0,0 +1,81 @@
+/* This file is part of "Tux Droid Gadget Twitter".
+ * Copyright 2008, kysoh
+ * Author : Jerome Conan
+ * Site : http://www.kysoh.com/
+ *
+ * "Tux Droid Gadget Twitter" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "Tux Droid Gadget Twitter" is distributed in the hope that it will be
useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "Tux Droid Gadget Twitter"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+import java.io.Serializable;
+
+public class FriendStatut implements Serializable{
+
+ private static final long serialVersionUID = -2710016821846315218L;
+
+ private String friend = null;
+ private String Status = null;
+
+ /**
+ * Constructor.
+ * @param friendName
+ * @param status
+ */
+ public FriendStatut(String friendName, String status)
+ {
+ this.friend = friendName;
+ this.Status = status;
+ }
+
+
+ /**
+ * Return the friend name.
+ * @return
+ */
+ public String getFriendName()
+ {
+ return this.friend;
+ }
+
+
+ /**
+ * Return the friend status.
+ * @return
+ */
+ public String getFriendStatus()
+ {
+ return this.Status;
+ }
+
+
+ /**
+ * Set the friend name.
+ * @param aFriendName
+ */
+ public void setFriendName(String aFriendName)
+ {
+ this.friend = aFriendName;
+ }
+
+
+ /**
+ * Set the friend status.
+ * @param aFriendStatus
+ */
+ public void setFriendStatus(String aFriendStatus)
+ {
+ this.Status = aFriendStatus;
+ }
+}
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/GadgetTwitter.java
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/GadgetTwitter.java
2009-03-20 12:17:34 UTC (rev 4162)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/GadgetTwitter.java
2009-03-20 16:08:41 UTC (rev 4163)
@@ -1,3 +1,24 @@
+/* This file is part of "Tux Droid Gadget Twitter".
+ * Copyright 2008, kysoh
+ * Author : Jerome Conan
+ * Site : http://www.kysoh.com/
+ *
+ * "Tux Droid Gadget Twitter" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "Tux Droid Gadget Twitter" is distributed in the hope that it will be
useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "Tux Droid Gadget Twitter"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
import java.util.List;
import winterwell.jtwitter.Twitter;
@@ -10,6 +31,7 @@
public class GadgetTwitter extends SimpleGadget<Configuration>{
+ private TwitterDatasStruct savedStruct = new TwitterDatasStruct();
@Override
protected void start() throws Throwable
@@ -37,12 +59,11 @@
String username = status.getUser().getName();
//if a new status was set for this user.
- if(statusText != "null")
+ boolean said =
this.savedStruct.isRegistered(TwitterDatasStruct.FRIENDS_STATUSES, username,
statusText);
+ if((statusText != "null") && !said)
{
- if(!statusText.contains("@" +
this.configuration().getUsername()))
- {
- throwMessage(username + ", " +
statusText);
- }
+ throwMessage(username + ", " +
statusText);
+
this.savedStruct.addFriendStatus(username, statusText);
}
}
catch(NullPointerException statusNotExists)
@@ -64,10 +85,14 @@
//then give replies.
for(Message reply : replies)
{
- if(reply.getText() != "null")
+ String username = reply.getSender().getName();
+
+ boolean said =
this.savedStruct.isRegistered(TwitterDatasStruct.REPLIES, username,
reply.getText());
+
+ if((reply.getText() != "null") && !said)
{
- String username =
reply.getSender().getName();
throwMessage("reply from {0}, the reply
is: {1}", username, reply.getText());
+ this.savedStruct.addReply(username,
reply.getText());
}
}
}
@@ -81,10 +106,12 @@
//then give messages.
for(Message message : messages)
{
- if(message.getText() != "null")
+ String username =
message.getSender().getName();
+ boolean said =
this.savedStruct.isRegistered(TwitterDatasStruct.MESSAGES, username,
message.getText());
+ if((message.getText() != "null") &&
!said)
{
- String username =
message.getSender().getName();
throwMessage("message from {0},
the message is: {1}", username, message.getText());
+
this.savedStruct.addMessage(username, message.getText());
}
}
}
@@ -93,6 +120,9 @@
throwMessage("you don't have private messages");
}
}
+
+ //RegisterStruct.
+ this.savedStruct.registerStruct();
}
Added:
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/Message.java
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/Message.java
(rev 0)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/Message.java
2009-03-20 16:08:41 UTC (rev 4163)
@@ -0,0 +1,82 @@
+/* This file is part of "Tux Droid Gadget Twitter".
+ * Copyright 2008, kysoh
+ * Author : Jerome Conan
+ * Site : http://www.kysoh.com/
+ *
+ * "Tux Droid Gadget Twitter" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "Tux Droid Gadget Twitter" is distributed in the hope that it will be
useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "Tux Droid Gadget Twitter"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+import java.io.Serializable;
+
+public class Message implements Serializable{
+
+ private static final long serialVersionUID = -2723363051271966964L;
+
+ private String sender = null;
+ private String message = null;
+
+ /**
+ * Constructor.
+ * @param sender
+ * @param message
+ */
+ public Message(String sender, String message)
+ {
+ this.sender = sender;
+ this.message = message;
+ }
+
+
+ /**
+ * Return the message sender.
+ * @return
+ */
+ public String getSender()
+ {
+ return this.sender;
+ }
+
+
+ /**
+ * Return the message itself.
+ * @return
+ */
+ public String getMessage()
+ {
+ return this.message;
+ }
+
+
+ /**
+ * Set the message.
+ * @param aMessage
+ */
+ public void setMessage(String aMessage)
+ {
+ this.message = aMessage;
+ }
+
+
+ /**
+ * Set the sender.
+ * @param aSender
+ */
+ public void setSender(String aSender)
+ {
+ this.sender = aSender;
+ }
+
+}
Added:
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/Reply.java
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/Reply.java
(rev 0)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/Reply.java
2009-03-20 16:08:41 UTC (rev 4163)
@@ -0,0 +1,81 @@
+/* This file is part of "Tux Droid Gadget Twitter".
+ * Copyright 2008, kysoh
+ * Author : Jerome Conan
+ * Site : http://www.kysoh.com/
+ *
+ * "Tux Droid Gadget Twitter" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "Tux Droid Gadget Twitter" is distributed in the hope that it will be
useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "Tux Droid Gadget Twitter"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+import java.io.Serializable;
+
+public class Reply implements Serializable{
+
+ private static final long serialVersionUID = -4131206164350955300L;
+
+ private String sender = null;
+ private String reply = null;
+
+ /**
+ * Constructor.
+ * @param sender
+ * @param reply
+ */
+ public Reply(String sender, String reply)
+ {
+ this.sender = sender;
+ this.reply = reply;
+ }
+
+
+ /**
+ * Return the reply sender.
+ * @return
+ */
+ public String getSender()
+ {
+ return this.sender;
+ }
+
+
+ /**
+ * Return the reply itself.
+ * @return
+ */
+ public String getReply()
+ {
+ return this.reply;
+ }
+
+
+ /**
+ * Set the reply sender.
+ * @param aSender
+ */
+ public void setSender(String aSender)
+ {
+ this.sender = aSender;
+ }
+
+
+ /**
+ * Set the message itself.
+ * @param aReply
+ */
+ public void setReply(String aReply)
+ {
+ this.reply = aReply;
+ }
+}
Added:
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/TwitterDatasStruct.java
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/TwitterDatasStruct.java
(rev 0)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-twitter/trunk/tuxdroid-gadget-twitter/src/TwitterDatasStruct.java
2009-03-20 16:08:41 UTC (rev 4163)
@@ -0,0 +1,297 @@
+/* This file is part of "Tux Droid Gadget Twitter".
+ * Copyright 2008, kysoh
+ * Author : Jerome Conan
+ * Site : http://www.kysoh.com/
+ *
+ * "Tux Droid Gadget Twitter" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "Tux Droid Gadget Twitter" is distributed in the hope that it will be
useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "Tux Droid Gadget Twitter"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.Vector;
+
+
+public class TwitterDatasStruct extends Object implements Serializable{
+
+ private static final long serialVersionUID = 8395814134877723558L;
+
+ public static final byte FRIENDS_STATUSES = 0;
+ public static final byte REPLIES = 1;
+ public static final byte MESSAGES = 2;
+
+ public SerializedVector vktStruct;
+ private File structFile;
+
+
+ public TwitterDatasStruct()
+ {
+ //Getting file where was registered serialized vector.
+ String path = System.getProperty("user.home") + File.separator
+ "MyTux" + File.separator + "TuxdroidSettings";
+ //tds = tuxdroid datas saved.
+ structFile = new File(path + File.separator +
"twitterDatasStruct.ser");
+ if(structFile.exists())
+ {
+ //Getting serialized object struct.
+ vktStruct = this.loadStruct();
+ }
+ else
+ {
+ //Create struct.
+ vktStruct = new SerializedVector();
+ if(vktStruct == null)
+ {
+ vktStruct = new SerializedVector();
+ }
+ }
+ }
+
+
+ /**
+ * Regiter the structure.
+ */
+ public void registerStruct()
+ {
+ if(this.vktStruct.size() <= 0)
+ {
+ return;
+ }
+
+ try
+ {
+ FileOutputStream file = new
FileOutputStream(this.structFile);
+ ObjectOutputStream oos = new ObjectOutputStream(file);
+ oos.writeObject(this.vktStruct);
+ oos.flush();
+ oos.close();
+ }
+ catch (java.io.IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+
+
+ /**
+ * Load the twitterDatasStruct object.
+ */
+ private SerializedVector loadStruct()
+ {
+ try
+ {
+ FileInputStream fichier = new
FileInputStream(this.structFile);
+ ObjectInputStream ois = new ObjectInputStream(fichier);
+ return (SerializedVector) ois.readObject();
+ }
+ catch (java.io.IOException e)
+ {
+ e.printStackTrace();
+ }
+ catch (ClassNotFoundException e)
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+
+ /**
+ * Add a message to the message hashtable.
+ * @param sender
+ * @param message
+ */
+ public void addMessage(String sender, String message)
+ {
+ this.vktStruct.addMessage(sender, message);
+ }
+
+
+ /**
+ * Add a reply to the reply hashtable.
+ * @param sender
+ * @param reply
+ */
+ public void addReply(String sender, String reply)
+ {
+ this.vktStruct.addReply(sender, reply);
+ }
+
+
+ /**
+ * Add a status for selected friend.
+ * @param friens
+ * @param status
+ */
+ public void addFriendStatus(String friend, String status)
+ {
+ this.vktStruct.addFriendStatus(friend, status);
+ }
+
+
+ /**
+ * Return true if the target is registered.
+ * @param list
+ * @param sender
+ * @param value
+ * @return
+ */
+ public boolean isRegistered(byte list, String sender, String value)
+ {
+
+ switch(list)
+ {
+ case TwitterDatasStruct.FRIENDS_STATUSES:
+ {
+ for(int index=0; index < this.vktStruct.size();
index ++)
+ {
+ if(this.vktStruct.isFriendStatut(index))
+ {
+ FriendStatut friendStatus =
(FriendStatut)this.vktStruct.get(index);
+
if(friendStatus.getFriendName().equals(sender))
+ {
+
if(friendStatus.getFriendStatus().equals(value))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ }
+
+ case TwitterDatasStruct.MESSAGES:
+ {
+ for(int index=0; index < this.vktStruct.size();
index ++)
+ {
+ if(this.vktStruct.isMessage(index))
+ {
+ Message message = (Message)
this.vktStruct.get(index);
+
if(message.getSender().equals(sender))
+ {
+
if(message.getMessage().equals(value))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ }
+
+ case TwitterDatasStruct.REPLIES:
+ {
+ for(int index=0; index < this.vktStruct.size();
index ++)
+ {
+ if(this.vktStruct.isReply(index))
+ {
+ Reply reply = (Reply)
this.vktStruct.get(index);
+
if(reply.getSender().equals(sender))
+ {
+
if(reply.getReply().equals(value))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+
+/**
+ * Handle a serialized vector of hashtable typed as <string string>
+ * @author nux
+ *
+ */
+class SerializedVector extends Vector<Object> implements Serializable{
+
+ private static final long serialVersionUID = 7018170438526763017L;
+
+ public SerializedVector()
+ {
+ super();
+ }
+
+ /**
+ * Add a new message in the object.
+ * @param sender
+ * @param message
+ */
+ public void addMessage(String sender, String message)
+ {
+ this.add(new Message(sender, message));
+ }
+
+
+ /**
+ * Add a new Reply in the object.
+ * @param sender
+ * @param reply
+ */
+ public void addReply(String sender, String reply)
+ {
+ this.add(new Reply(sender, reply));
+ }
+
+
+ /**
+ * Add a new user status in the object.
+ * @param friendName
+ * @param friendStatus
+ */
+ public void addFriendStatus(String friendName, String friendStatus)
+ {
+ this.add(new FriendStatut(friendName, friendStatus));
+ }
+
+
+ /**
+ * Return true if object at 'objectIndex' is a message.
+ * @param objectIndex
+ * @return
+ */
+ public boolean isMessage(int objectIndex)
+ {
+ return this.get(objectIndex) instanceof Message;
+ }
+
+
+ /**
+ * Return true if the object at 'objectIndex' is a Reply.
+ * @param objectIndex
+ * @return
+ */
+ public boolean isReply(int objectIndex)
+ {
+ return this.get(objectIndex) instanceof Reply;
+ }
+
+
+ /**
+ * Return true if the object at 'objectIndex' is a FriendStatut.
+ * @param objectIndex
+ * @return
+ */
+ public boolean isFriendStatut(int objectIndex)
+ {
+ return this.get(objectIndex) instanceof FriendStatut;
+ }
+}
+}
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn