Tuesday, October 2, 2007

Week4: MM Midlet




Check tasks from form.

Code File




import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import java.io.*;


public class MainScreenMidlet extends MIDlet implements CommandListener,Runnable {



private Display display; // The display

private Form main;
private Form screensaver;// form for displaying the screensaver image
private ChoiceGroup worklist1;
private Command cmdExit;
private Command cmdSelect;
public Gauge showeff;//activity indicator for alert object: test
public int total;
public String url;



public MainScreenMidlet () {

// save reference to midlet so that we can exit application

display = Display.getDisplay(this);//gets ref to the display instance..
main = new Form("Work Time");
main.setCommandListener(this);
// create list to be displayed on the form
worklist1 = new ChoiceGroup("Select tasks Completed",Choice.MULTIPLE);
worklist1.append("Pay cheques", null);
worklist1.append("Switch class to Computational Form", null);
worklist1.append("Discussion for Connected Life", null);
worklist1.insert(1, "Submit Source code for MAD", null);
main.append(worklist1);
// create command objects so we can compare them later
cmdExit = new Command("Exit", Command.EXIT, 2);
cmdSelect = new Command("Select", Command.OK, 1);
main.addCommand(cmdSelect);
main.addCommand(cmdExit);
Alert welcome = new Alert("Welcome","Time to check your tasks, are you ready?", null, AlertType.INFO);
welcome.setTimeout(3000);

display.setCurrent(welcome,main);

//create form for displaying screensaver image
screensaver=new Form ("Generating...");
screensaver.addCommand(cmdExit);
screensaver.setCommandListener(this);

}



// call this function when you want to exit application
public void exitMIDlet()
{
try {
destroyApp(true);
} catch (MIDletStateChangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
notifyDestroyed();
}
// handle commands

public void commandAction(Command cmd, Displayable dis) {



if(cmd == cmdExit )

exitMIDlet();

else

{

total=worklist1.getSelectedFlags(new boolean[worklist1.size()]);



Alert test = new Alert("Selected "+total,"Tasks completed - "+total, null, AlertType.INFO);
Gauge showeff = new Gauge(null,false,100, 0);
test.setIndicator(showeff);
showeff.setValue(total);
//test.getIndicator();
test.setTimeout(3000);
display.setCurrent(test,screensaver);
Thread t = new Thread(this);//new execution thread for screen saver operation
t.start();


// bargraph should be an alert with guage, screensaver should be canvas

//app.getDisplay().setcurrent(bargraph, screensaver);

}

}



protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub

}



protected void pauseApp() {
// TODO Auto-generated method stub

}



protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub

}


//exectution of thread t;

public void run() {
HttpConnection hc = null;
DataInputStream in = null;


try {
String url;
if(total==1)
{
url= "http://www1.istockphoto.com/file_thumbview_approve/437828/2/istockphoto_437828_giant_smiley_big_smile.jpg";

}
else
{
url= "http://www.istockphoto.com/file_closeup/who/facial_expressions/smiling/3404377_unhappy_worker.php?id=3404377";
}
System.out.println("Starting to download smiley image");
hc = (HttpConnection) Connector.open(url);
int length = (int) hc.getLength();
byte[] data = null;
if (length != -1) {
System.out.println("Content Length is " + length);
data = new byte[length];
in = new DataInputStream(hc.openInputStream());
in.readFully(data);
}

else {
// If content length is not given, read in chunks.
int chunkSize = 512;
int index = 0;
int readLength = 0;
in = new DataInputStream(hc.openInputStream());
data = new byte[chunkSize];
do {
if (data.length < index + chunkSize) {
byte[] newData = new byte[index + chunkSize];
System.arraycopy(data, 0, newData, 0, data.length);
data = newData;
}
System.out.println(".");
readLength = in.read(data, index, chunkSize);
index += readLength;
} while (readLength == chunkSize);

length = index;
}

Image smileyscr = Image.createImage(data, 0, length);
ImageItem imageItem = new ImageItem(null, smileyscr, 0, null);
screensaver.append(imageItem);
screensaver.setTitle("Done.");
}

catch (Exception ioe) {
ioe.printStackTrace();
StringItem stringItem = new StringItem(null, ioe.toString());
screensaver.append(stringItem);
screensaver.setTitle("Done.");
}

finally {
try {
if (in != null)
in.close();
if (hc != null)
hc.close();
} catch (IOException ioe) {
}
}
}
}

Week 4: Midterm Idea Brainstorm

Work Check::

Taking the initial idea from workcheck and retaining the scheduled tasks check portion.
-Syncing it with an online task list/Google calendar
-Syncing it with other system events from a online address book: eg, Birthday reminders in the form of an icon like a message icon on your cellphone.
-Creating a simple screensaver smiley game, where each task represents a task smiley.A jotter or a ticker is used to stamp out the smileys(task smileys are kind of mean looking)The strength of each smiley character is based on the time of the day, if it represents an incomplete task its movement on the screen is quick and its difficult to swamp out.




-Completed task smileys assist the jotter by blocking incomplete task smileys.

Comments:
Not too cool? No multimedia stuff?Only interactive smileys..whose expressions could possible change during the game?