/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package EMIDA.comm;
import EMIDA.CATMainMidlet;
import EMIDA.Constants;
import EMIDA.Utils;
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
/**
*
* @author nmartinez
*/
public class ProgressControl extends Canvas implements Runnable {
private ConnectorBox box=null;
private Thread tc;
private String messageWait="";;
private boolean mTrucking;
private int mTheta = 0;
private int mDelay = 250;
private int countPaints;
private Image[] imgJag = new Image[11];
private int stepPaint = 0;
private String url;
private String smsAction=null;
private CATMainMidlet mainMidlet;
private String mobileNumber;
private String smssend;
private String operation;
/**
*
* @param mainMidlet
* @param baseURL This is data that includes user number, version, siteuser, lang etc (NOT sms_req operation)
* @param smsAction This is the operation command "bal pin"
* @param mobileNumber consumers login number
* @param SmsSend &sendSMS=
* @param operation The sms_req="+Constants.sms_req
*/
public ProgressControl(CATMainMidlet mainMidlet,
String baseURL,
String smsAction,
String mobileNumber,
String SmsSend,
String operation){
this.url = baseURL;
this.mainMidlet = mainMidlet;
this.smsAction = smsAction;
this.mobileNumber = mobileNumber;
this.smssend = SmsSend;
this.operation = operation;
}
public void start()
{
try
{
imgJag[0] = Image.createImage("/j.png");
imgJag[1] = Image.createImage("/j1.png");
imgJag[2] = Image.createImage("/j2.png");
imgJag[3] = Image.createImage("/j3.png");
imgJag[4] = Image.createImage("/j4.png");
imgJag[5] = Image.createImage("/j5.png");
imgJag[6] = Image.createImage("/j6.png");
imgJag[7] = Image.createImage("/j7.png");
imgJag[8] = Image.createImage("/j8.png");
imgJag[9] = Image.createImage("/j9.png");
imgJag[10] = Image.createImage("/j10.png");
} catch (IOException ex) {
ex.printStackTrace();
}
mTrucking = true;
countPaints=1;
runProgressControl();
}
/***
*
*/
private void runProgressControl()
{
Thread t = new Thread(this);
t.start();
String[] tokensSms = Utils.split(smsAction," ");
String pin="";
if ( tokensSms!=null && tokensSms.length>1){
pin = tokensSms[1];
}
box = new ConnectorBox(this.mainMidlet,this.url,this.smsAction, this.mobileNumber,pin, this.smssend,this.operation);
tc = new Thread(box);
tc.start();
}
protected void paint(Graphics g) {
int width = getWidth();
int height = getHeight();
g.setColor(255,255,255);
g.fillRect(0, 0, width , height);
try
{
g.drawImage(imgJag[stepPaint], width/2, height/2, Graphics.VCENTER | Graphics.HCENTER);
if ( stepPaint < 10)
{
stepPaint++;
}
else{
stepPaint=0;
}
//System.out.println(stepPaint);
g.setColor(0,0,0);
Font waitFont = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL);
g.setFont(waitFont);
g.drawString(messageWait, 0, 0, g.TOP | g.LEFT );
}
catch(Exception ex)
{
System.out.print(ex);
}
finally
{
if ( tc!=null && !tc.isAlive() )
{
this.stop();
}
}
}
public void run()
{
while (mTrucking)
{
mTheta = (mTheta + 1) % 360;
repaint();
try
{
Thread.sleep(mDelay);
if (this.box.getSb_xmlResponse()!=null){
this.messageWait = this.box.getSb_xmlResponse().toString();
}
countPaints++;
}
catch (InterruptedException ie)
{
System.out.println("RUN InterruptedException "+ie);
}
}
}
private void stop()
{
mTrucking = false;
}
}