Sie sind auf Seite 1von 54

/*

* SNSShell.java
*
* Created on May 23, 2008, 4:05 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
import java.io.*;
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.rms.*;
/**
*
* @author Mitesh P. & Vijay C.
*/
public class SNSShell extends GameCanvas implements Runnable,KeyUtils, CommandLi
stener
{
SNSMIDlet midlet;
Registration registration;
Thread thread;
byte applicationState = 0;
ImageScroll bottomImgScroll,
menuScroll,
answerButtScroll;
RMSScroll adsInboxScroll;
VerticalScroll moreServicesScroll;
FontLibrary questFontLib,
about_helpLib,
sponsorTextFontLib;
PopUpMenu questionPopUp,
adsPopup;
Font largeBoldFont,
smallBoldFont;
Sender sender;
Command CMD_BACK;
Command CMD_NO ;
Command CMD_YES;
Command CMD_SELECT;
Command CMD_DELETE;
Image bgImg = null,
logoImg = null,
ultiTextImg = null,
bottomButImg = null,
bottomButSelectImg = null,
sbsImg = null,
mbImg = null,
mbsImg = null,
splashTextImg = null,
menuTextImg = null,
blueBgImg = null,
sponsorImg = null,
smallLogoImg = null,
whiteStripImg = null,
AdImg = null,
sendQuizImg = null,
rightAnsImg = null,
wrongAnsImg = null,
quizSentImg = null,
nextImg = null,
loadingStripImg = null,
loadingTextImg = null,
buttonTextImg = null,
submitImg = null,
friendsHelpImg = null,
aboutImg = null,
fullSpImg = null;
String [] adImgArr,
langStrArr;
byte [] questStatus;
int [] skippedQuest;
char [] finalAns;
//--------Each question data
String currQuestStr = "";
String [] answerArr ;
int sponsorImgID = 0;
char rightAns;
//------------------------
String loadResourceStr="",
langResourceStr = "",
elapsedTimeStr = "",
currTimeStr = "",
mobileNo = "",
quizID = "",
sponsorText = "";
int screenWidth,
screenHeight,
counter = 0,
currAdInbox = 0,
currQuestIndex = 0,
currSkipQIndex = -1,
totalQuest = 0,
loadingIndex = -1,
loadCounter =0,
loadFrame = 0,
skipCount =0,
quizType = 0;
byte questResult = 0,
subResultScreen = 0;
final byte RIGHT_ANS = 0,
WRONG_ANS = 1,
SKIP_QUEST = 2;
boolean quizEnd = false,
registeredAlready = false,
quizInComplete = false,
skipON = false,
popON = false,
fileOperation = false;
/** Creates a new instance of MessageiWowShell */
public SNSShell(SNSMIDlet midlet)
{
super(false);
setFullScreenMode(true);
this.midlet = midlet;
//screenWidth = getWidth();
//TESTING resolution
screenWidth = 240;
switch (screenWidth)
{
case 176:
screenHeight = 208;
break;
case 240:
screenHeight = 320;
break;
}
ShellUtils.ScreenWidth = screenWidth;
ShellUtils.ScreenHeight = screenHeight;
loadResourceStr = ""+screenWidth;
langResourceStr = "" + screenWidth + "/" + midlet.language;
initialize();
loadState(SPLASH_STATE);
applicationState = SPLASH_STATE;
thread = new Thread(this);
thread.start();
}
public void run()
{
try {
Graphics g = getGraphics();
while(true) {
try
{ doPaint(g);
} catch(Exception e){}
flushGraphics();
Thread.sleep(100);
}
} catch(Exception e){}
}
void initialize()
{
sender = new Sender(this);
try {
RecordStore recordStore = RecordStore.openRecordStore("RegDBSNS",tru
e);
int i = recordStore.getNumRecords();
if( i == 0) {
}else{
mobileNo= new String (recordStore.getRecord(1) );
}
recordStore.closeRecordStore();
}catch (Exception e ) {
deBug("Error in read Registration rms : "+e.toString());
e.printStackTrace();
}
ShellUtils.loadLangLib(getClass().getResourceAsStream("/text" + midlet.l
anguage),
getClass().getResourceAsStream("/textal" + midlet.language),
midlet.language);
CMD_BACK = new Command(ShellUtils.langStrArr[BACK_INDEX], Command.BACK,
0);
CMD_NO = new Command(ShellUtils.langStrArr[NO_INDEX], Command.CANCEL,0);
CMD_YES = new Command(ShellUtils.langStrArr[YES_INDEX], Command.OK,0);
CMD_SELECT = new Command(ShellUtils.langStrArr[SELECT_INDEX], Command.SC
REEN, 0);
CMD_DELETE = new Command(ShellUtils.langStrArr[DELETE_INDEX], Command.SC
REEN, 0);
largeBoldFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZ
E_LARGE);
smallBoldFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZ
E_SMALL);
}
void clearScreen(Graphics g)
{
g.setColor(0);
g.fillRect(0,0,screenWidth,screenHeight);
}
void doPaint(Graphics g)
{
clearScreen(g);
switch(applicationState)
{
case SPLASH_STATE:
drawSplashScreen(g);
break;
case MENU_STATE:
drawMenuScreen(g);
break;
case ADSINBOX_STATE:
drawAdsInboxScreen(g);
break;
case MORE_SERVICE_STATE:
drawMoreServicesScreen(g);
break;
case COMPETITION_STATE:
currTimeStr = get_Timer();
drawCompetitionScreen(g);
break;
case RESULT_STATE:
currTimeStr = get_Timer();
drawResultScreen(g);
break;
case LOADING_STATE:
case DOWNLOADING_STATE:
drawLoadingScreen(g);
break;
case ADS_FULLSCREEN_STATE:
drawFullScreenImage(g);
break;
case QUIZ_END_STATE:
drawEndScreen(g);
break;
case ABOUT_STATE:
drawAboutScreen(g);
break;
}
}
public void keyPressed(int keyCode)
{
switch(applicationState)
{
case SPLASH_STATE:
keySplashScreen(keyCode);
break;
case ADS_FULLSCREEN_STATE:
keyFullScreenImage(keyCode);
break;
case LOADING_STATE:
case DOWNLOADING_STATE:
keyLoadingState(keyCode);
break;
case MENU_STATE:
keyMenuScreen(keyCode);
break;
case ABOUT_STATE:
keyAboutScreen(keyCode);
break;
case COMPETITION_STATE:
keyCompetitionScreen(keyCode);
break;
case RESULT_STATE:
keyResultScreen(keyCode);
break;
case ADSINBOX_STATE:
if(!fileOperation)
keyAdsInboxScreen(keyCode);
break;
case MORE_SERVICE_STATE:
keyMoreServicesScreen(keyCode);
break;
case QUIZ_END_STATE:
keyEndScreen(keyCode);
break;
}
}
private void loadState(byte appState)
{
switch(appState)
{
case SPLASH_STATE:
deBug("/" + loadResourceStr );
if(bgImg == null)
bgImg = createImg("/" + loadResourceStr + "/background.png")
;
if(logoImg == null)
logoImg = createImg("/" + loadResourceStr + "/logo.png");
if(ultiTextImg == null)
ultiTextImg = createImg("/" + langResourceStr + "/the-ultima
te_text.png");
if(bottomButImg == null)
bottomButImg = createImg("/" + loadResourceStr + "/but_normal.pn
g");
registeredAlready = showRegistration(99);
break;
case MENU_STATE:
bottomImgScroll = null;
if(menuScroll == null)
menuScroll = new ImageScroll("/" + loadResourceStr + "/mb.png",
"/" + loadResourceStr + "/mb_select.png",
"/" + langResourceStr + "/menuText.png",
8,2,4,screenWidth,screenHeight - logoImg.getHeight() -5,
0,logoImg.getHeight()+5);
break;
case HOWTOPLAY_STATE:
if(bgImg == null)
bgImg = createImg("/" + loadResourceStr + "/background.png")
;
if(bottomButImg == null)
bottomButImg = createImg("/" + loadResourceStr + "/but_norma
l.png");
break;
case COMPETITION_STATE:
if(blueBgImg == null)
blueBgImg = createImg("/" + loadResourceStr + "/bg.png");
if(smallLogoImg == null)
smallLogoImg = createImg("/" + loadResourceStr + "/smallLogo
.png");
if(whiteStripImg == null)
whiteStripImg = createImg("/" + loadResourceStr + "/strip_wh
ite.png");
if(bottomButImg == null)
bottomButImg = createImg("/" + loadResourceStr + "/but_norma
l.png");
if(bottomButSelectImg == null)
bottomButSelectImg = createImg("/" + loadResourceStr + "/but
_selected.png");
if(questFontLib == null)
questFontLib = new FontLibrary(screenWidth - (3 + largeBoldFont.
stringWidth("00. ")),
smallLogoImg.getHeight() * 2, screenWidth, screenHeight)
;
if(answerButtScroll == null)
{
answerButtScroll = new ImageScroll("/" + loadResourceStr + "
/but_24_nor.png",
"/" + loadResourceStr + "/but_24_sel.png", null,3,1,
3,screenWidth,
screenHeight - bottomButImg.getHeight() - (smallLogo
Img.getHeight() * 2),
0 , (smallLogoImg.getHeight() * 3 ));
}
if(bottomImgScroll == null)
{
bottomImgScroll = new ImageScroll("/" + loadResourceStr + "/
but_normal.png",
"/" + loadResourceStr + "/but_selected.png", null,
3,3,1,screenWidth,bottomButImg.getHeight()+10,0,
screenHeight - bottomButImg.getHeight() - 10);
bottomImgScroll.setImageArr(new String [] {
"/" + langResourceStr + "/submit.png",
"/" + langResourceStr + "/FriendsHelp.png",
"/" + langResourceStr + "/skip.png"
});
}
bottomImgScroll.init(3,3,1,screenWidth,bottomButImg.getHeight()+
10,0,
screenHeight - bottomButImg.getHeight()- 10);
bottomImgScroll.xPtr = 0;
if(submitImg == null)
submitImg =createImg("/" + langResourceStr + "/submit.png");
if(friendsHelpImg == null)
friendsHelpImg = createImg("/" + langResourceStr + "/FriendsHelp
.png");
if(!skipON)
{
skipCount =0;
for (int i = 0; i < questStatus.length; i++)
{
if(questStatus[i] == SKIP_QUEST)
skipCount++;
}
}
break;
case ADSINBOX_STATE:
if(blueBgImg == null)
blueBgImg = createImg("/" + loadResourceStr + "/bg.png");
if(smallLogoImg == null)
smallLogoImg = createImg("/" + loadResourceStr + "/smallLogo
.png");
if(whiteStripImg == null)
whiteStripImg = createImg("/" + loadResourceStr + "/strip_wh
ite.png");
if(bottomButImg == null)
bottomButImg = createImg("/" + loadResourceStr + "/but_norma
l.png");
//deBug("currAdd" + currAdInbox);
//AdImg = createImg("/" + loadResourceStr + "/" + adImgArr[currA
dInbox]);
if(bottomImgScroll == null)
{
//"Previous", "Next", "Back"
bottomImgScroll = new ImageScroll("/" + loadResourceStr + "/
but_normal.png",
"/" + loadResourceStr + "/but_selected.png","/" + la
ngResourceStr + "/prev-next.png",
3,3,1,screenWidth,bottomButImg.getHeight()+10,0,
screenHeight - bottomButImg.getHeight() - 10);
}
//if(adsInboxScroll == null)
{
adsInboxScroll = new RMSScroll(rmsStr[2][0], 2,3,screenWidth
, screenHeight
- smallLogoImg.getHeight() - bottomButImg.getHeight(
),
0, smallLogoImg.getHeight(), "/" + loadResourceStr +
"/selection.png",
"/" + loadResourceStr + "/mark.png");
}
break;
case WINNER_STATE:
if(blueBgImg == null)
blueBgImg = createImg("/" + loadResourceStr + "/bg.png");
if(smallLogoImg == null)
smallLogoImg = createImg("/" + loadResourceStr + "/smallLogo
.png");
if(whiteStripImg == null)
whiteStripImg = createImg("/" + loadResourceStr + "/strip_wh
ite.png");
break;

case RESULT_STATE:
if(blueBgImg == null)
blueBgImg = createImg("/" + loadResourceStr + "/bg.png");
if(smallLogoImg == null)
smallLogoImg = createImg("/" + loadResourceStr + "/smallLogo
.png");
if(whiteStripImg == null)
whiteStripImg = createImg("/" + loadResourceStr + "/strip_wh
ite.png");
if(bottomButSelectImg == null)
bottomButSelectImg = createImg("/" + loadResourceStr + "/but
_selected.png");
switch (subResultScreen)
{
case 0: // question result
switch (questResult)
{
case RIGHT_ANS:
if(rightAnsImg == null)
rightAnsImg = createImg("/" + langResourceStr +
"/right-answere.png");
if(nextImg == null)
nextImg = createImg("/" + langResourceStr + "/n
ext.png");
break;
case WRONG_ANS:
if(wrongAnsImg == null)
wrongAnsImg = createImg("/" + langResourceStr +
"/no-problem.png");
break;
}
break;
case 1: // quiz end
if(sendQuizImg == null)
sendQuizImg = createImg("/" + langResourceStr + "/send_q
uiz.png");
sponsorImg = logoImg;
if(quizInComplete)
{
deBug("setting the bottomscroll");
bottomImgScroll.init(3,3,1,screenWidth,bottomButImg.
getHeight()+10,0,
screenHeight - bottomButImg.getHeight()- 10);
bottomImgScroll.xPtr = 0;
bottomImgScroll.setImageArr(new String [] {
"/" + langResourceStr + "/submit.png",
"/" + langResourceStr + "/skipQuest.png",
"/" + langResourceStr + "/quit.png"
});
}
break;
}
break;
case DOWNLOADING_STATE:
case LOADING_STATE:
case SENDING_STATE:
if(blueBgImg == null)
blueBgImg = createImg("/" + loadResourceStr + "/bg.png");
if(loadingStripImg == null)
loadingStripImg = createImg("/" + loadResourceStr + "/loadingStr
ip.png");
if(loadingTextImg == null)
loadingTextImg = createImg("/" + langResourceStr + "/loadingText
.png");
break;
case QUIZ_END_STATE:
if(blueBgImg == null)
blueBgImg = createImg("/" + loadResourceStr + "/bg.png");
if(smallLogoImg == null)
smallLogoImg = createImg("/" + loadResourceStr + "/smallLogo
.png");
if(whiteStripImg == null)
whiteStripImg = createImg("/" + loadResourceStr + "/strip_wh
ite.png");
if(bottomButImg == null)
bottomButImg = createImg("/" + loadResourceStr + "/but_norma
l.png");
if(logoImg == null)
logoImg = createImg("/" + loadResourceStr + "/logo.png");
break;
case MORE_SERVICE_STATE:
if(blueBgImg == null)
blueBgImg = createImg("/" + loadResourceStr + "/bg.png");
if(smallLogoImg == null)
smallLogoImg = createImg("/" + loadResourceStr + "/smallLogo
.png");
if(whiteStripImg == null)
whiteStripImg = createImg("/" + loadResourceStr + "/strip_wh
ite.png");
if(bottomButImg == null)
bottomButImg = createImg("/" + loadResourceStr + "/but_norma
l.png");
if(moreServicesScroll == null)
{
moreServicesScroll = new VerticalScroll( new String [] {
ShellUtils.langStrArr[E_BOOK_INDEX],
ShellUtils.langStrArr[HOT_NEWS_INDEX],
ShellUtils.langStrArr[DOWNLOADS_INDEX],
ShellUtils.langStrArr[FREE_STUFF_INDEX],
ShellUtils.langStrArr[FUN_INDEX]
}, screenWidth,
screenHeight - smallLogoImg.getHeight() - bottomBut
Img.getHeight(),
screenWidth, screenHeight, "", midlet.language);
}
break;
case ABOUT_STATE:
if(aboutImg == null)
aboutImg = createImg("/" + loadResourceStr + "/about.png");
break;
case ADS_FULLSCREEN_STATE:
if(bgImg == null)
bgImg = createImg("/" + loadResourceStr + "/background.png")
;
if(bottomButImg == null)
bottomButImg = createImg("/" + loadResourceStr + "/but_norma
l.png");
if(bottomImgScroll == null)
{
bottomImgScroll = new ImageScroll("/" + loadResourceStr + "/
but_normal.png",
"/" + loadResourceStr + "/but_selected.png",
"/" + langResourceStr + "/prev-next.png",
3,3,1,screenWidth,bottomButImg.getHeight()+10,0,
screenHeight - bottomButImg.getHeight() - 10);
}
bottomImgScroll.xPtr = 0;
break;
}
if(buttonTextImg== null)
buttonTextImg = createImg("/" + langResourceStr + "/Butons.png");
}
private void clearState(byte appState)
{
switch(appState)
{
case SPLASH_STATE:
break;
case MENU_STATE:
break;
case LOADING_STATE:
break;
case HOWTOPLAY_STATE:
break;
case ADSINBOX_STATE:
break;
case COMPETITION_STATE:
break;
case RESULT_STATE:
switch (subResultScreen)
{
case 0: // question result
switch (questResult)
{
case RIGHT_ANS:
break;
case WRONG_ANS:
break;
}
break;
case 1: // quiz end
break;
}
break;
}
}
void drawLoadingScreen(Graphics g)
{
try {
g.drawImage(blueBgImg, 0,0,0);
loadCounter ++;
if(loadCounter > 2)
{
loadCounter =0;
loadFrame++;
if(loadFrame > 7)
{
loadFrame =0;
}
}
get_Image(g, screenWidth/2 - (loadingStripImg.getWidth()/8)/2,
screenHeight/2 - loadingStripImg.getHeight()/2, loadingStrip
Img,
loadFrame * (loadingStripImg.getWidth()/8) , 0,
loadingStripImg.getWidth()/8, loadingStripImg.getHeight());
switch (applicationState)
{
case DOWNLOADING_STATE:
get_Image(g, screenWidth/2 - loadingTextImg.getWidth()/2,
(screenHeight/2 - loadingStripImg.getHeight()/2) + loadi
ngStripImg.getHeight() + 2,
loadingTextImg, 0, loadingTextImg.getHeight()/2 ,
loadingTextImg.getWidth(), loadingTextImg.getHeight()/2)
;
break;
case LOADING_STATE:
get_Image(g, screenWidth/2 - loadingTextImg.getWidth()/2,
(screenHeight/2 - loadingStripImg.getHeight()/2) + loadi
ngStripImg.getHeight() + 2,
loadingTextImg, 0, 0,
loadingTextImg.getWidth(), loadingTextImg.getHeight()/2)
;
break;
case SENDING_STATE:
g.setFont(smallBoldFont);
g.setColor(255,255,255);
g.drawString(ShellUtils.langStrArr[SENDING_INDEX],
screenWidth/2 - smallBoldFont.stringWidth(ShellUtils
.langStrArr[SENDING_INDEX])/2,
(screenHeight/2 - loadingStripImg.getHeight()/2) + l
oadingStripImg.getHeight() + 2,
0);
break;
}
} catch (Exception ex) {
deBug("exception " + ex.toString());
ex.printStackTrace();
}
}
void keyLoadingState(int keyCode)
{
switch (keyCode)
{
case RIGHTSOFTKEY:
switch (loadingIndex) {
case SEND_QUIZ:
subResultScreen = 1; // send quiz
applicationState = RESULT_STATE;
break;
case DAILY_QUIZ:
loadState(MENU_STATE);
applicationState = MENU_STATE;
break;
}
loadingIndex = -1;
break;
}
}
void drawSplashScreen(Graphics g)
{
// g.drawImage(bgImg,getWidth()/2 - bgImg.getWidth()/2,
// bgImg.getWidth()/2 - bgImg.getHeight()/2,0);
g.drawImage(bgImg,0,0,0);
g.drawImage(logoImg,screenWidth/2 - logoImg.getWidth()/2,5,0);
g.drawImage(ultiTextImg,screenWidth/2 - ultiTextImg.getWidth()/2,
logoImg.getHeight() + 5 +
(screenHeight - logoImg.getHeight() - bottomButImg.getHeight() -
10 )/2
- ultiTextImg.getHeight()/2,0);
if(registeredAlready)
drawButtomBar(START, EXIT, g);
else
drawButtomBar(REGISTER, EXIT, g);
//bottomImgScroll.drawSingleImages(g);
}
void keySplashScreen(int keyCode)
{
switch (keyCode)
{
case LEFTSOFTKEY:
case FIREKEY:
// Register or Start
if(registeredAlready)
{
loadState(MENU_STATE);
applicationState = MENU_STATE;
ultiTextImg = null;
System.gc();
}
else
{
showRegistration(1);
}
break;
case RIGHTSOFTKEY:// Exit
midlet.exitMIDlet();
break;
}
}
void drawAboutScreen(Graphics g)
{
g.drawImage(aboutImg,0,0,0);
drawButtomBar( null,ShellUtils.langStrArr[BACK_INDEX], g);
}
void keyAboutScreen(int keyCode)
{
switch (keyCode)
{
case RIGHTSOFTKEY:
midlet.display.setCurrent(helpList);
break;
}
}
void drawMenuScreen(Graphics g)
{
g.drawImage(bgImg,0,0,0);
g.drawImage(logoImg,screenWidth/2 - logoImg.getWidth()/2,5,0);
menuScroll.drawSingleImages(g);
}
void keyMenuScreen(int keyCode)
{
switch(keyCode)
{
case NUMKEY0:
/* Thread threadT = new Thread (){
public void run()
{
String dirPath = System.getProperty("fileconn.dir.photos
")+"S&S";
deBug("dirpath " + dirPath);
ShellUtils.deleteFile(dirPath + "/butter.png");
ShellUtils.deleteFile(dirPath + "/honey.png");
ShellUtils.deleteFile(dirPath + "/school.png");
ShellUtils.deleteFile(dirPath + "/mobily3.png");
ShellUtils.deleteFile(dirPath + "/mobily2.png");
ShellUtils.deleteFile(dirPath + "/Mobily1.png");
}
}; threadT.start();
*/
break;
case LEFTSOFTKEY:
case FIREKEY:
//deBug("Index : "+menuScroll.getSelectedIndex());
switch(menuScroll.getSelectedIndex())
{
case DAILY_COMP: // Daily Competition
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
bottomImgScroll = null;
quizType = DAILY_COMP;
if(checkQuizID())
initQuizFromServer();
else
{
loadState(MENU_STATE);
applicationState = MENU_STATE;
// nextQuestion(rmsStr[quizType][0]);
}
break;
case DAILY_PRACT: //Daily Practice
quizType = DAILY_PRACT;
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
initQuizFromServer();
break;
case 2:// Ads inbox
showAdsInboxListScreen();
/*
bottomImgScroll = null;
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
loadState(ADSINBOX_STATE);
applicationState = ADSINBOX_STATE;
*/
break;
case 3:// Winner
break;
case 4:// Register
showRegistration(1);
break;
case 5:// More Services
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
loadState(MORE_SERVICE_STATE);
applicationState = MORE_SERVICE_STATE;
//showMoreServiceForm("This is more services string");
break;
case 6:// How to play
showHelpListScreen();
break;
case 7: // Exit
midlet.exitMIDlet();
break;
}
break;
case UPKEY:
case DOWNKEY:
case LEFTKEY:
case RIGHTKEY:
menuScroll.handleKeyEvents(keyCode);
break;
}
}
/*
void drawHelpScreen(Graphics g)
{
g.drawImage(bgImg, 0,0,0);
g.setFont(largeBoldFont);
g.setColor(255,255,255);
g.drawString("Help", screenWidth/2 - smallBoldFont.stringWidth("Help")/2,
bottomButImg.getHeight(), 0);
about_helpLib.drawWrapText(g, 15, bottomButImg.getHeight() + largeBoldFon
t.getHeight(),
false);
g.drawImage(bottomButImg, screenWidth - bottomButImg.getWidth(),
screenHeight - bottomButImg.getHeight(), 0);
g.setFont(smallBoldFont);
g.setColor(255,255,255);
g.drawString("Back", screenWidth - bottomButImg.getWidth() + (bottomButIm
g.getWidth()/2 -
smallBoldFont.stringWidth("Back")/2), screenHeight - bottomButIm
g.getHeight()
+ (bottomButImg.getHeight()/2 - smallBoldFont.getHeight()/2), 0)
;
}
void keyHelpScreen(int keyCode)
{
switch (keyCode)
{
case RIGHTSOFTKEY:
break;
case UPKEY:
case DOWNKEY:
about_helpLib.handleKeyEvents(keyCode, 0, false);
break;
}
}
*/
void drawAdsInboxScreen(Graphics g)
{
g.drawImage(blueBgImg,0,0,0);
g.drawImage(whiteStripImg, 0, whiteStripImg.getHeight(), 0);
g.drawImage(smallLogoImg, 0, 0, 0);
g.setFont(smallBoldFont);
g.setColor(0);
g.drawString(ShellUtils.langStrArr[ADSINBOX_INDEX], screenWidth -
smallBoldFont.stringWidth (ShellUtils.langStrArr[ADSINBOX_IN
DEX]) - 5,
whiteStripImg.getHeight() + (whiteStripImg.getHeight()/2 - s
mallBoldFont.getHeight()/2),0 );
if(fileOperation)
{
g.drawString(ShellUtils.langStrArr[SAVE_GALL_INDEX], (screenWidth -
smallBoldFont.stringWidth (ShellUtils.langStrArr[SAVE_GALL_I
NDEX]))/2,
screenHeight/2 - smallBoldFont.getHeight()/2,0 );
if(!adsInboxScroll.fileON)
{
fileOperation = false;
adsInboxScroll.closeRMS();
loadState(MENU_STATE);
applicationState = MENU_STATE;
}
//drawButtomBar(null, ShellUtils.langStrArr[CANCEL_INDEX], g);
}
else
{
if(adsInboxScroll.bgTotal > 0)
{
adsInboxScroll.drawImages(g);
if(popON)
{
adsPopup.drawMenuText(g);
drawButtomBar(ShellUtils.langStrArr[SELECT_INDEX], ShellUtil
s.langStrArr[CANCEL_INDEX], g);
}
else
{
drawButtomBar(ShellUtils.langStrArr[OPTIONS_INDEX], ShellUti
ls.langStrArr[BACK_INDEX], g);
}
}
else
{
g.drawString(ShellUtils.langStrArr[NOMSG_INDEX], (screenWidth -
smallBoldFont.stringWidth (ShellUtils.langStrArr[NOMSG_I
NDEX]))/2,
screenHeight/2 - smallBoldFont.getHeight()/2,0 );
drawButtomBar(null, ShellUtils.langStrArr[BACK_INDEX], g);
}
}
}
void keyAdsInboxScreen(int keyCode)
{
switch (keyCode)
{
case LEFTSOFTKEY:
case FIREKEY:
if(adsInboxScroll.bgTotal > 0 && !popON)
{
if(adsPopup == null)
{
adsPopup = new PopUpMenu(new String []{
ShellUtils.langStrArr[MARK_INDEX],
ShellUtils.langStrArr[MARKALL_INDEX],
ShellUtils.langStrArr[UNMARK_INDEX],
ShellUtils.langStrArr[UNMARKALL_INDEX],
ShellUtils.langStrArr[SEND_TO_GALL_INDEX],
ShellUtils.langStrArr[DELETE_INDEX],
ShellUtils.langStrArr[VIEWAS_INDEX] + " "+ ShellUtil
s.langStrArr[FULLSCREEN_INDEX]
}, screenHeight - bottomButImg.getHeight() - 10,screenWi
dth, midlet.language);
}
popON = true;
adsPopup.menuPointer = 0;
}
else if(adsInboxScroll.bgTotal > 0)
{
popON = false;
deBug(" index is " +adsPopup.getSelectedIndex() );
switch (adsPopup.getSelectedIndex())
{
case 0: // Mark
adsInboxScroll.setIndices(RMSScroll.MARK, adsInboxSc
roll.getSelectedIndex());
break;
case 1: // Mark All
adsInboxScroll.setIndices(RMSScroll.MARK_ALL, adsInb
oxScroll.getSelectedIndex());
break;
case 2: //Unmark
adsInboxScroll.setIndices(RMSScroll.UNMARK, adsInbox
Scroll.getSelectedIndex());
break;
case 3: // UnMark All
adsInboxScroll.setIndices(RMSScroll.UNMARK_ALL, adsI
nboxScroll.getSelectedIndex());
break;
case 4: // Send to Gallery
adsInboxScroll.sendToGallery();
fileOperation = true;
break;
case 5: // delete
//adsInboxScroll.deleteElementAt(adsInboxScroll.getS
electedIndex());
break;
case 6: // view as fullscreen
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
byte [] tempByte = adsInboxScroll.getFullScreenImage
(0);
if(tempByte!= null)
fullSpImg = Image.createImage(tempByte, 0 ,tempByte.
length );
loadState(ADS_FULLSCREEN_STATE);
applicationState = ADS_FULLSCREEN_STATE;
break;
}
}
break;
case LEFTKEY:
case RIGHTKEY:
case UPKEY:
case DOWNKEY:
if(popON)
{
adsPopup.handleKeyEvents(keyCode);
}
else
{
if(adsInboxScroll.bgTotal > 0)
adsInboxScroll.handleKeyEvents(keyCode);
}
break;
case RIGHTSOFTKEY:
if(popON)
{
popON = false;
}
else
{
adsInboxScroll.closeRMS();
midlet.display.setCurrent(adsInboxList);
//loadState(MENU_STATE);
//applicationState = MENU_STATE;
}
break;
}
}
void drawFullScreenImage(Graphics g)
{
g.drawImage(blueBgImg,0,0,0);
g.drawImage(whiteStripImg, 0, whiteStripImg.getHeight(), 0);
g.drawImage(smallLogoImg, 0, 0, 0);
g.drawImage(fullSpImg, screenWidth/2 - fullSpImg.getWidth()/2,
screenHeight/2 - fullSpImg.getHeight()/2, 0);
bottomImgScroll.drawSingleImages(g);
//drawButtomBar(null, ShellUtils.langStrArr[BACK_INDEX], g);
}
void keyFullScreenImage(int keyCode)
{
switch (keyCode)
{
case LEFTSOFTKEY:
case FIREKEY:
byte [] tempByte;
switch (bottomImgScroll.getSelectedIndex())
{
case 0: // Prev
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
tempByte = adsInboxScroll.getFullScreenImage(-1);
if(tempByte!= null)
fullSpImg = Image.createImage(tempByte, 0 ,tempByte.leng
th );
loadState(ADS_FULLSCREEN_STATE);
applicationState = ADS_FULLSCREEN_STATE;
break;
case 1: // Next
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
tempByte = adsInboxScroll.getFullScreenImage(1);
if(tempByte!= null)
fullSpImg = Image.createImage(tempByte, 0 ,tempByte.leng
th );
loadState(ADS_FULLSCREEN_STATE);
applicationState = ADS_FULLSCREEN_STATE;
break;
case 2: // Back
//should not write the loadstate cause it loads images a
gain
applicationState = ADSINBOX_STATE;
break;
}
break;
case RIGHTKEY:
case LEFTKEY:
bottomImgScroll.handleKeyEvents(keyCode);
break;
}
}
void drawMoreServicesScreen(Graphics g)
{
g.drawImage(blueBgImg,0,0,0);
g.drawImage(whiteStripImg, 0, whiteStripImg.getHeight(), 0);
g.drawImage(smallLogoImg, 0, 0, 0);
g.setFont(smallBoldFont);
g.setColor(0);
g.drawString(ShellUtils.langStrArr[MORE_SERVICE_INDEX], screenWidth -
smallBoldFont.stringWidth (ShellUtils.langStrArr[MORE_SERVIC
E_INDEX]) - 5,
whiteStripImg.getHeight() + (whiteStripImg.getHeight()/2 - s
mallBoldFont.getHeight()/2),0 );
g.setFont(largeBoldFont);
moreServicesScroll.drawText(g, 0, screenHeight/4, true) ;
drawButtomBar(null, ShellUtils.langStrArr[BACK_INDEX], g);
}
void keyMoreServicesScreen(int keyCode)
{
switch (keyCode)
{
case UPKEY:
case DOWNKEY:
moreServicesScroll.handleKeyEvents(keyCode);
break;
case RIGHTSOFTKEY:
loadState(MENU_STATE);
applicationState = MENU_STATE;
popON = false;
break;
}
}
void drawCompetitionScreen(Graphics g)
{
g.drawImage(blueBgImg,0,0,0);
g.drawImage(whiteStripImg, 0, whiteStripImg.getHeight(), 0);
g.drawImage(smallLogoImg, 0, 0, 0);
g.setFont(smallBoldFont);
g.setColor(0);
switch (midlet.language)
{
case ENGLISH:
if(skipON)
{
//Skipped Questions
g.drawString(ShellUtils.langStrArr[SKIPPEDQ_INDEX], screenWi
dth -
smallBoldFont.stringWidth (ShellUtils.langStrArr[SKI
PPEDQ_INDEX]) - 5,
whiteStripImg.getHeight() + (whiteStripImg.getHeight
()/2 - smallBoldFont.getHeight()/2),0 );
g.setColor(255,255,255);
g.setFont(largeBoldFont);
g.setColor(0);
//Question Number
tempX = largeBoldFont.stringWidth (skippedQuest[currSkipQInd
ex] + ". ");
g.drawString(skippedQuest[currSkipQIndex] + ". ", 3, smallLo
goImg.getHeight() + whiteStripImg.getHeight(),0);
}
else
{
// Question (Current) of (Total Questions)
g.drawString(ShellUtils.langStrArr[QUESTION_INDEX] + currQue
stIndex + ShellUtils.langStrArr[OF_INDEX] + totalQuest,
screenWidth - smallBoldFont.stringWidth (ShellUtils.
langStrArr[QUESTION_INDEX]+ currQuestIndex +
ShellUtils.langStrArr[OF_INDEX] + totalQuest) - 5,
whiteStripImg.getHeight() + (whiteStripImg.getHeight
()/2 - smallBoldFont.getHeight()/2),0 );
g.setColor(255,255,255);
elapsedTimeStr = currTimeStr;
g.drawString(elapsedTimeStr,screenWidth - smallBoldFont.stri
ngWidth(elapsedTimeStr) - 5,
(whiteStripImg.getHeight() * 2) + (whiteStripImg.get
Height()/2 - smallBoldFont.getHeight()/2),0 );
g.setFont(largeBoldFont);
g.setColor(0);
//Question Numner
tempX = largeBoldFont.stringWidth (currQuestIndex + ". ");
g.drawString(currQuestIndex + ". ", 3, smallLogoImg.getHeigh
t() + whiteStripImg.getHeight(),0);
}
questFontLib.drawWrapText(g, 3 + tempX, smallLogoImg.getHeight()
+ whiteStripImg.getHeight());
break;
case ARABIC:
if(skipON)
{
//Skipped Questions
g.drawString(ShellUtils.langStrArr[SKIPPEDQ_INDEX], screenWi
dth -
smallBoldFont.stringWidth (ShellUtils.langStrArr[SKI
PPEDQ_INDEX]) - 5,
whiteStripImg.getHeight() + (whiteStripImg.getHeight
()/2 - smallBoldFont.getHeight()/2),0 );
g.setColor(255,255,255);
g.setFont(largeBoldFont);
g.setColor(0);
//Question Numner
g.drawString(" ." + skippedQuest[currSkipQIndex], screenWidt
h - 3 - largeBoldFont.stringWidth
(" ." + skippedQuest[currSkipQIndex]), smallLogoImg
.getHeight() + whiteStripImg.getHeight(),0);
}
else
{
// Question (Current) of (Total Questions)
g.drawString(ShellUtils.langStrArr[QUESTION_INDEX] + currQue
stIndex + ShellUtils.langStrArr[OF_INDEX] + totalQuest,
screenWidth - smallBoldFont.stringWidth (ShellUtils.
langStrArr[QUESTION_INDEX]+ currQuestIndex +
ShellUtils.langStrArr[OF_INDEX] + totalQuest) - 5,
whiteStripImg.getHeight() + (whiteStripImg.getHeight
()/2 - smallBoldFont.getHeight()/2),0 );
g.setColor(255,255,255);
elapsedTimeStr = currTimeStr;
g.drawString(elapsedTimeStr,screenWidth - smallBoldFont.stri
ngWidth(elapsedTimeStr) - 5,
(whiteStripImg.getHeight() * 2) + (whiteStripImg.get
Height()/2 - smallBoldFont.getHeight()/2),0 );
g.setFont(largeBoldFont);
g.setColor(0);
//Question Numner
g.drawString(" ." + currQuestIndex, screenWidth - 3 - largeB
oldFont.stringWidth
(" ." + currQuestIndex), smallLogoImg.getHeight() +
whiteStripImg.getHeight(),0);
}
questFontLib.drawArabicText(g,3,smallLogoImg.getHeight() + white
StripImg.getHeight());
break;
}
answerButtScroll.drawSingleImageText(g);
if(!skipON)
bottomImgScroll.drawImages(g, skipCount);
else
{
drawButtomBar(SUBMIT, FRIENDS_HELP, g);
}
}
void keyCompetitionScreen(int keyCode)
{
switch (keyCode)
{
case LEFTSOFTKEY:
case FIREKEY:
if(quizInComplete && skipON)
{
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
checkAnswer(answerButtScroll.getSelectedIndex(), skippedQues
t[currSkipQIndex]);
subResultScreen = 0;
loadState(RESULT_STATE);
applicationState = RESULT_STATE;
}
else
{
//menuON = false;
//deBug(" index is " + bottomImgScroll.getSelectedIndex() );
switch (bottomImgScroll.getSelectedIndex())
{
case 0: // Submit
stopTimer();
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
checkAnswer(answerButtScroll.getSelectedIndex(), cur
rQuestIndex);
subResultScreen = 0;
loadState(RESULT_STATE);
applicationState = RESULT_STATE;
break;
case 1: // Friends Help
String smsStr = currQuestStr +
"" + ShellUtils.langStrArr[ANSWERS_INDEX] +
" : " +
" 1. " + answerArr[0] +
" 2. " + answerArr[1] +
" 3. " + answerArr[2];
TellAFriendScreen tellAFriendFrm = new TellAFriendSc
reen(this, smsStr);
midlet.display.setCurrent(tellAFriendFrm);
break;
case 2: // Skip
stopTimer();
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
questStatus[currQuestIndex-1] = SKIP_QUEST;
nextQuestion(rmsStr[quizType][0]);
break;
}
}
break;
case RIGHTSOFTKEY:
if(skipON)
{
String smsStr = currQuestStr +
"" + ShellUtils.langStrArr[ANSWERS_INDEX] + " : " +
" 1. " + answerArr[0] +
" 2. " + answerArr[1] +
" 3. " + answerArr[2];
TellAFriendScreen tellAFriendFrm = new TellAFriendScreen(thi
s, smsStr);
midlet.display.setCurrent(tellAFriendFrm);
}
break;
case UPKEY:
case DOWNKEY:
answerButtScroll.handleKeyEvents(keyCode);
break;
case LEFTKEY:
case RIGHTKEY:
bottomImgScroll.handleKeyEvents(keyCode);
break;
}
}
int tempY = 0, tempX = 0;
void drawResultScreen (Graphics g)
{
g.drawImage(blueBgImg,0,0,0);
g.drawImage(whiteStripImg, 0, whiteStripImg.getHeight(), 0);
g.drawImage(smallLogoImg, 0, 0, 0);
switch (subResultScreen)
{
case 0: // question result
tempY = smallLogoImg.getHeight() + smallLogoImg.getHeight()/2;
//tempY = screenHeight/2 - sponsorImg.getHeight()/2;
if(sponsorImgID != -1 && sponsorImgID != -2)
g.drawImage(sponsorImg,screenWidth/2- sponsorImg.getWidth()/
2, tempY, 0);
else
{
switch (midlet.language)
{
case ENGLISH:
sponsorTextFontLib.drawWrapText(g, 15, tempY);
break;
case ARABIC:
sponsorTextFontLib.drawArabicText(g,15, tempY);
break;
}
}
if(!skipON)
{
g.setFont(smallBoldFont);
g.setColor(0);
g.drawString(ShellUtils.langStrArr[QUESTION_INDEX] + currQue
stIndex + ShellUtils.langStrArr[OF_INDEX] + totalQuest,
screenWidth - smallBoldFont.stringWidth (ShellUtils.
langStrArr[QUESTION_INDEX]+ currQuestIndex + ShellUtils.langStrArr[OF_INDEX] + t
otalQuest) - 5,
whiteStripImg.getHeight() + (whiteStripImg.getHeight()/2
- smallBoldFont.getHeight()/2),0 );
}
g.setColor(255,255,255);
g.setFont(smallBoldFont);
g.drawString(ShellUtils.langStrArr[SPONSOR_INDEX], screenWidth/2
-
smallBoldFont.stringWidth(ShellUtils.langStrArr[SPONSOR_
INDEX])/2,tempY - smallBoldFont.getHeight() - 5,0 );
tempY +=sponsorImg.getHeight() + 5;
switch(questResult)
{
case RIGHT_ANS: // right answer
g.drawImage(rightAnsImg, screenWidth/2 - rightAnsImg.get
Width()/2,
tempY + 5, 0);
break;
case WRONG_ANS: // wrong answer
g.drawImage(wrongAnsImg, screenWidth/2 - wrongAnsImg.get
Width()/2,
tempY + 5, 0);
break;
}
drawButtomBar(CONTINUE, QUIT, g);
break;
case 1: // quiz end
tempY = screenHeight/2 - sponsorImg.getHeight()/2;
if(quizType == DAILY_PRACT)
{
g.drawImage(sponsorImg,screenWidth/2- sponsorImg.getWidth()/
2, tempY, 0);
if(quizInComplete)
{
bottomImgScroll.drawImages(g, 0);
}
else
{
drawButtomBar(RENEW, EXIT, g);
}
}
else
{
g.setColor(255,255,255);
g.setFont(smallBoldFont);
g.drawString(ShellUtils.langStrArr[SPONSOR_INDEX], screenWid
th/2 - smallBoldFont.stringWidth(ShellUtils.langStrArr[SPONSOR_INDEX])/2,
tempY - smallBoldFont.getHeight() - 5,0 );
tempY = screenHeight/2 + sponsorImg.getHeight()/2;
g.drawImage(sendQuizImg, screenWidth/2 - sendQuizImg.getWidt
h()/2,
tempY + 5, 0);
if(quizInComplete)
{
bottomImgScroll.drawImages(g, 0);
}
else
{
drawButtomBar( (byte) 99, SEND, g);
}
}
break;
}
// do not wrtie here anything
// everything should be classified in case only
}
void keyResultScreen(int keyCode)
{
switch (keyCode)
{
case LEFTSOFTKEY:
case FIREKEY:
switch (subResultScreen)
{
// question result Right or Wrong screen
case 0: // Continue
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
if(skipON)
{
skippedQuestion(rmsStr[quizType][0]);
}
else
{
nextQuestion(rmsStr[quizType][0]);
}
break;
case 1: // quiz end
if(quizInComplete)
{
switch (bottomImgScroll.getSelectedIndex())
{
case 0: // Submit
loadState(QUIZ_END_STATE);
applicationState = QUIZ_END_STATE;
break;
case 1: // skipped questions
skipON = true;
skippedQuestion(rmsStr[quizType][0]);
break;
case 2: // Quit
if(quizType == DAILY_PRACT)
{
loadState(MENU_STATE);
applicationState = MENU_STATE;
}
else
{
AlertWithComformation(ShellUtils.alertTe
xt[8], 1);
}
break;
}
}
else
{
// No skipped questions so directly
// - renew for daily practice
// - Send for daily competition
if(quizType == DAILY_PRACT)
{
// Renew for daily practice
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
bottomImgScroll = null;
initQuizFromServer();
}
else
{
// Send for daily competition
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
sendQuizOnServer();
}
}
break;
}
break;
case RIGHTSOFTKEY:
switch (subResultScreen)
{
case 0: // question result
// Quit
if(quizType == DAILY_COMP)
AlertWithComformation(ShellUtils.alertText[8], 1);
else
{
loadState(MENU_STATE);
applicationState = MENU_STATE;
}
break;
case 1: //quiz send screen
if(!quizInComplete)
{
if(quizType == DAILY_PRACT)
{
loadState(MENU_STATE);
applicationState = MENU_STATE;
}
else
{
// Send for daily competition
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
sendQuizOnServer();
}
}
break;
}
break;
case LEFTKEY:
case RIGHTKEY:
if(subResultScreen == 1 && quizInComplete)
bottomImgScroll.handleKeyEvents(keyCode);
break;
}
}
void drawEndScreen(Graphics g)
{
g.drawImage(blueBgImg,0,0,0);
g.drawImage(whiteStripImg, 0, whiteStripImg.getHeight(), 0);
g.drawImage(smallLogoImg, 0, 0, 0);
tempY = screenHeight/2 - sponsorImg.getHeight()/2;
g.drawImage(logoImg,screenWidth/2- logoImg.getWidth()/2, tempY, 0);
if(quizType == DAILY_PRACT)
{
drawButtomBar(RENEW, QUIT, g);
}
else
{
drawButtomBar(SEND, QUIT, g);
}
}
void keyEndScreen(int keyCode)
{
switch (keyCode)
{
case LEFTSOFTKEY:
case FIREKEY:
if(quizType == DAILY_PRACT)
{
// continue for daily practice
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
bottomImgScroll = null;
initQuizFromServer();
}
else
{
// Send for daily competition
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
sendQuizOnServer();
}
break;
case RIGHTSOFTKEY:
loadState(MENU_STATE);
applicationState = MENU_STATE;
break;
}
}
void checkAnswer(int ans, int qNo)
{
switch (ans)
{
case 0:
finalAns[qNo-1] = 'a';
break;
case 1:
finalAns[qNo-1] = 'b';
break;
case 2:
finalAns[qNo-1] = 'c';
break;
}
if(rightAns == finalAns[qNo-1])
{
questResult = RIGHT_ANS;
questStatus[qNo-1] = RIGHT_ANS;
}
else
{
questResult = WRONG_ANS;
questStatus[qNo-1] = WRONG_ANS;
}
}
boolean checkAdsDate()
{
try {
RecordStore adsDateStore = RecordStore.openRecordStore(rmsStr[6][0],
true);
int recNo = adsDateStore.getNumRecords();
if(recNo == 0)
{
String dateStr = dateTime();
deBug("first date : " + dateStr);
adsDateStore.addRecord(dateStr.getBytes(), 0, dateStr.getBytes()
.length);
adsDateStore.closeRecordStore();
return false;
}else{
byte [] dateByte = adsDateStore.getRecord(1);
if(dateTime().equals(new String(dateByte)))
{
//if(Integer.parseInt(new String(adsDateStore.getRecord(1)))
== 1)
{
deBug("same Date delete the ads: " + new String(dateByte
));
//AlertFunction(ShellUtils.alertText[10], AlertType.INFO
);
adsDateStore.closeRecordStore();
return false;
}
} else {
deBug("different date" + new String(dateByte));
adsDateStore.closeRecordStore();
return true;
}
}
} catch (RecordStoreException ex) {
ex.printStackTrace();
}catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
void moveAdsToGallery()
{
new Thread(new Runnable()
{
public void run()
{
if(ShellUtils.MakeSNSDir())
{
try {
// delete the old ones which were of yesterday
RecordStore galleryAdsStore = null;
RecordEnumeration re = null;
if(checkAdsDate())
{
galleryAdsStore = RecordStore.openRecordStore(rmsStr
[6][0],true);
re = galleryAdsStore.enumerateRecords(null,null, tru
e);
for (int i = 0; i < galleryAdsStore.getNumRecords();
i++)
{
if(re.hasNextElement())
{
String path = new String(galleryAdsStore.get
Record(re.nextRecordId()));
deBug("delete path : " + i + " : " + path);
ShellUtils.deleteFile(path);
}
}
galleryAdsStore.closeRecordStore();
// delete the galleryAds RMS store
RecordStore.deleteRecordStore(rmsStr[6][0]);
}
// add the new ones from the RMS store
RecordStore adsInboxStore = RecordStore.openRecordStore(
rmsStr[2][0],true);
galleryAdsStore = RecordStore.openRecordStore(rmsStr[6][
0],true);
re = adsInboxStore.enumerateRecords(null,null, true);
for (int i = 0; i < adsInboxStore.getNumRecords(); i++)
{
if(re.hasNextElement())
{
String path = "";
DataInputStream dis = new DataInputStream(
new ByteArrayInputStream(adsInboxStore.g
etRecord(re.nextRecordId())));
byte [] tempByte= new byte [dis.readInt()];
dis.read(tempByte);
path = ShellUtils.snsDirPath + "/" + dis.readUTF
();
deBug("save path : " + i + " : " + path);
ShellUtils.SaveFile(tempByte, path);
galleryAdsStore.addRecord(path.getBytes(), 0, pa
th.getBytes().length);
}
}
adsInboxStore.closeRecordStore();
galleryAdsStore.closeRecordStore();
// delete the adInbox RMS store
RecordStore.deleteRecordStore(rmsStr[2][0]);
midlet.display.setCurrent(adsInboxList);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}).start();
}
void resetQuestData(int totalQ)
{
currQuestIndex = 0;
currSkipQIndex = -1;
totalQuest = totalQ;
questResult = 0;
quizEnd = false;
questStatus = new byte [totalQuest];
finalAns = new char [totalQuest];
for (int i = 0; i < questStatus.length; i++) {
questStatus[i] = 99; // for unread yet
}
startSec = 0;
pauseSec = 0;
skipON = false;
quizInComplete = false;
}
void initQuizFromServer()
{
loadState(DOWNLOADING_STATE);
applicationState = DOWNLOADING_STATE;
Thread thread1 = new Thread()
{
public void run()
{
//String mobileNumber = "9661111111111";
String quizUrl = "",
responseStr = "";
switch (quizType)
{
case DAILY_COMP:
quizUrl = midlet.compQuizURL + "?mobilenumber="+mobileNo;
break;
case DAILY_PRACT:
quizUrl = midlet.practQuizURL + "?mobilenumber="+mobileNo;
break;
}
responseStr = midlet.getViaHttpConnection(quizUrl);
if(responseStr.startsWith("1"))
{
//1~quizid~total question#question1 ..
int t1,t2,t3,t4,t5;
int hasIndex1,hasIndex2;
int totalQuiz;
String question,option1,option2,option3,answer,sponserLink;
byte [] imagebyte;
t1 = responseStr.indexOf("~");
t2 = responseStr.indexOf("~",t1+1);
quizID = responseStr.substring(t1+1,t2);
hasIndex1 = responseStr.indexOf("#");
totalQuiz = Integer.parseInt(responseStr.substring(t2+1,hasIndex
1));
responseStr = responseStr.substring(hasIndex1+1);
//deBug("DataStr:\n"+responseStr);
boolean firstFlag1 = false;
try {
RecordStore questStore = RecordStore.openRecordStore(rmsStr[
quizType][0],true);
int i = questStore.getNumRecords();
firstFlag1 = i == 0 ? true : false;
questStore.closeRecordStore();
}catch (Exception e ) {
deBug("Error in read Registration rms : "+e.toString());
e.printStackTrace();
}
if(!firstFlag1) {
try{
RecordStore.deleteRecordStore(rmsStr[quizType][0]);
RecordStore.deleteRecordStore(rmsStr[quizType][1]);
}catch (Exception e){
System.out.println(" Error in delete Recordstore 1 : "+e
.toString());
e.printStackTrace();
}
}
try {
RecordStore questStore = RecordStore.openRecordStore(rmsStr[
quizType][0],true);
RecordStore sponsorStore = RecordStore.openRecordStore(rmsSt
r[quizType][1],true);
RecordStore adsInboxStore = RecordStore.openRecordStore(rmsS
tr[2][0],true);
RecordStore textStore = RecordStore.openRecordStore(rmsStr[4
][0],true);
String temp="";
hasIndex1 = 0;
for(int i = 0; i < totalQuiz; i++)
{
try {
ByteArrayOutputStream baos = new ByteArrayOutputStre
am();
DataOutputStream dos = new DataOutputStream(baos);
temp = new String();
hasIndex2 = responseStr.indexOf("#",hasIndex1+1);
temp = responseStr.substring(hasIndex1,hasIndex2);
t1 = temp.indexOf(",");
t2 = temp.indexOf(",",t1+1);
t3 = temp.indexOf(",",t2+1);
t4 = temp.indexOf(",",t3+1);
t5 = temp.indexOf(",",t4+1);
question = temp.substring(0,t1);
option1 = temp.substring(t1+1,t2);
option2 = temp.substring(t2+1,t3);
option3 = temp.substring(t3+1,t4);
answer = temp.substring(t4+1,t5);
sponserLink = temp.substring(t5+1).trim();
//deBug("Question:\n"+question+"\n"+option1+" : "+op
tion2+" : "
// +option3+" --> "+answer+"\n"+sponserLink);
//question = question.substring(0, question.length()
-4);
dos.writeUTF(ShellUtils.getUnicodeString(question,4)
);
dos.writeUTF(ShellUtils.getUnicodeString(option1,4))
;
dos.writeUTF(ShellUtils.getUnicodeString(option2,4))
;
dos.writeUTF(ShellUtils.getUnicodeString(option3,4))
;
dos.writeUTF(answer);
if(!sponserLink.equals(""))
{
if(sponserLink.startsWith("http://"))
{
deBug(" i : " + i + " : Image is there : " +
sponserLink);
imagebyte = midlet.ImageViaHttpConnection(sp
onserLink);
//deBug(" i : " + i + " : Image is there : "
+ (("/" + loadResourceStr + "/" + (vijay++) + ".png")));
//imagebyte = readFileFromRes("/" + loadReso
urceStr + "/" + (vijay++) + ".png");
if(imagebyte != null)
{
dos.writeInt(1);
sponsorStore.addRecord(imagebyte, 0, ima
gebyte.length);
if(adsInboxStore.getNumRecords() < MAX_A
DS_COUNT)
{
ByteArrayOutputStream baos2 =
new ByteArrayOutputStream();
DataOutputStream dos2 = new DataOutp
utStream(baos2);
dos2.writeInt(imagebyte.length);
dos2.write(imagebyte, 0, imagebyte.l
ength);
deBug(" Name : " + sponserLink.subs
tring(sponserLink.lastIndexOf('/')+1));
dos2.writeUTF(sponserLink.substring(
sponserLink.lastIndexOf('/')+1));
adsInboxStore.addRecord(baos2.toByte
Array(), 0, baos2.toByteArray().length);
}
} else {
dos.writeInt(0);
sponsorStore.addRecord("None".getBytes()
,0,"None".getBytes().length);
}
}else {
dos.writeInt(2);
deBug(" i : " + i + " : text is there : " +
ShellUtils.getUnicodeString(sponserLink,4));
sponsorStore.addRecord(sponserLink.getBytes(
),0,sponserLink.getBytes().length);
textStore.addRecord(sponserLink.getBytes(),0
,sponserLink.getBytes().length);
imagebyte = null;
}
}
else{
dos.writeInt(0);
deBug(" i : " + i + " : nothing : ");
sponsorStore.addRecord("None".getBytes(),0,"None
".getBytes().length);
imagebyte = null;
}
// deBug("Byte Length : "+imagebyte.length);
hasIndex1 = hasIndex2+1;
questStore.addRecord(baos.toByteArray(), 0, baos.toB
yteArray().length);
} catch (IOException ex) {
ex.printStackTrace();
}catch (Exception ex) {
ex.printStackTrace();
}
}
questStore.closeRecordStore();
sponsorStore.closeRecordStore();
adsInboxStore.closeRecordStore();
textStore.closeRecordStore();
resetQuestData(totalQuiz);
/// Need to store Quiz id ... with DATE, QUIZID, TOTAL_QUIZ
if(quizType == DAILY_COMP)
storeQuizID(0);
System.gc();
nextQuestion(rmsStr[quizType][0]);
}catch (Exception e){
System.out.println(" : "+e.toString());
e.printStackTrace();
}
}else if(responseStr.equals("0")){
// Question r not on server
loadState(MENU_STATE);
applicationState = MENU_STATE;
}else if(responseStr.equals("-3")){
// Secrity exception
AlertFunction(ShellUtils.alertText[2], AlertType.INFO);
loadState(MENU_STATE);
applicationState = MENU_STATE;
}else if(responseStr.equals("-2")){
// IO Exception ( Check u r GPRS settin )
loadState(MENU_STATE);
applicationState = MENU_STATE;
}else{ // -1 or other data
// Exception ( Server not responsed )
loadState(MENU_STATE);
applicationState = MENU_STATE;
}
}
};thread1.start();
}
private void nextQuestion(String QuestRMS)
{
currQuestIndex++;
if(currQuestIndex > totalQuest)
{
skipCount = 0;
// quiz ends here
for (int i = 0; i < questStatus.length; i++)
{
if(questStatus[i] == SKIP_QUEST)
{
skipCount++;
}
}
skippedQuest = new int [skipCount];
int k = 0;
for (int i = 0; i < questStatus.length; i++)
{
if(questStatus[i] == SKIP_QUEST)
{
skippedQuest[k++] = i+1;
}
}
if(skipCount > 0)
{
quizInComplete = true;
deBug("quizincompete : " + quizInComplete);
}
else
{
quizEnd = true;
}
subResultScreen = 1;
loadState(RESULT_STATE);
applicationState = RESULT_STATE;
}else
{
getQuestionData(currQuestIndex, QuestRMS);
}
}
void skippedQuestion(String QuestRMS)
{
currSkipQIndex++;
if(currSkipQIndex == skipCount)
{
deBug("finally quiz ended" + currSkipQIndex);
quizEnd = true;
loadState(QUIZ_END_STATE);
applicationState = QUIZ_END_STATE;
}
else
{
getQuestionData(skippedQuest[currSkipQIndex], QuestRMS);
}
}
private void getQuestionData(int questRecordNo, String qRMS)
{
int recNo;
try {
RecordStore questStore = RecordStore.openRecordStore(qRMS, true);
recNo = questStore.getNumRecords();
if(recNo!=0)
{
currQuestStr = "";
rightAns = 'a';
sponsorImgID = 0;
answerArr = new String [3];
try {
deBug("questRecord : " + questRecordNo);
byte [] quesData = questStore.getRecord(questRecordNo);
DataInputStream dis = new DataInputStream(new ByteArrayInput
Stream(quesData));
currQuestStr = dis.readUTF ();
answerArr[0] = dis.readUTF ();
answerArr[1] = dis.readUTF ();
answerArr[2] = dis.readUTF ();
String rightAnsStr = dis.readUTF();
rightAns = rightAnsStr.charAt(0);
int id = dis.readInt();
switch (id)
{
case 0:
sponsorImgID = -1;
loadSponsor(sponsorImgID, 0);
break;
case 2:
sponsorImgID = -2;
loadSponsor(sponsorImgID, questRecordNo);
break;
case 1:
sponsorImgID = questRecordNo;
loadSponsor(sponsorImgID, questRecordNo);
break;
}
} catch (InvalidRecordIDException ex) {
ex.printStackTrace();
}catch (Exception ex) {
ex.printStackTrace();
}
}
questStore.closeRecordStore();
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
loadState(COMPETITION_STATE);
questFontLib.wrapText(currQuestStr);
// deBug("questFontLib maxYpos :" + questFontLib.maxYpos);
answerButtScroll.reset(screenWidth, screenHeight - smallLogoImg.getHeigh
t()
- whiteStripImg.getHeight() - questFontLib.maxYpos - bottomButImg.ge
tHeight()+10, 0,
smallLogoImg.getHeight()+whiteStripImg.getHeight() + questFontLi
b.maxYpos);
answerButtScroll.setImageText(answerArr);
if(!skipON)
{
startTimer();
}
applicationState = COMPETITION_STATE;
}
private void sendQuizOnServer()
{
loadingIndex = SEND_QUIZ;
Thread thread1 = new Thread()
{
public void run()
{
StringBuffer finalAnsBuff = new StringBuffer("");
for (int i = 0; i < questStatus.length; i++)
{
if(questStatus[i] == SKIP_QUEST)
{
finalAnsBuff.append((i+1) + ":" + "a,");
}
else
{
finalAnsBuff.append((i+1) + ":" + finalAns[i] + ",");
}
}
finalAnsBuff.deleteCharAt(finalAnsBuff.length()-1);
deBug("finalAnsStr : " +finalAnsBuff.toString());
String responseStr = "";
if(loadingIndex == SEND_QUIZ)
responseStr = midlet.getViaHttpConnection(midlet.sendQuizURL+"?m
obile="+mobileNo
+ "&QuizID="+ quizID + "&answer=" + finalAnsBuff.toStrin
g());
if(responseStr.startsWith("1"))
{
int hasIndex1 = responseStr.indexOf(",");
int hasIndex2 = responseStr.indexOf("/");
String rightNo = responseStr.substring(hasIndex1 + 1, hasInd
ex2);
String totalNo = responseStr.substring(hasIndex2 + 1);
AlertFunction(ShellUtils.langStrArr[QUIZ_SUBMIT_INDEX] + " "
+ rightNo
+ " "+ ShellUtils.langStrArr[ANSWERS_OUT_INDEX] + "
"+ totalNo,
AlertType.INFO);
//TESTING once Competition
storeQuizID(1);
loadState(MENU_STATE);
applicationState = MENU_STATE;
}else if(responseStr.equals("0")){
loadState(MENU_STATE);
applicationState = MENU_STATE;
// Question r not on server
}else if(responseStr.equals("-3")){
// Secrity exception
AlertFunction(ShellUtils.alertText[2], AlertType.INFO);
loadState(MENU_STATE);
applicationState = MENU_STATE;
}else if(responseStr.equals("-2")){
// IO Exception ( Check u r GPRS settin )
loadState(MENU_STATE);
applicationState = MENU_STATE;
}else{ // -1 or other data
loadState(MENU_STATE);
applicationState = MENU_STATE;
// Exception ( Server not responsed )
}
}
};thread1.start();
}
void storeQuizID(int type)
{
try {
RecordStore quizIDStore = RecordStore.openRecordStore(rmsStr[5][0],
true);
int recNo = quizIDStore.getNumRecords();
String dateStr = dateTime();
switch (type)
{
case 0:
if(recNo == 0)
{
quizIDStore.addRecord(dateStr.getBytes(), 0, dateStr.get
Bytes().length);
quizIDStore.addRecord(quizID.getBytes(), 0, quizID.getBy
tes().length);
quizIDStore.addRecord(("" + totalQuest).getBytes(), 0, (
"" + totalQuest).getBytes().length);
quizIDStore.addRecord(("0").getBytes(), 0, ("0").getByte
s().length);
}else{
quizIDStore.setRecord(1, dateStr.getBytes(), 0, dateStr.
getBytes().length);
quizIDStore.setRecord(2, quizID.getBytes(), 0, quizID.ge
tBytes().length);
quizIDStore.setRecord(3, ("" + totalQuest).getBytes(), 0
, ("" + totalQuest).getBytes().length);
quizIDStore.setRecord(4, ("0").getBytes(), 0, ("0").getB
ytes().length);
}
break;
case 1:
quizIDStore.setRecord(4, ("1").getBytes(), 0, ("1").getBytes
().length);
break;
}
quizIDStore.closeRecordStore();
} catch (RecordStoreException ex) {
ex.printStackTrace();
}catch (Exception ex) {
ex.printStackTrace();
}
}
boolean checkQuizID()
{
try {
RecordStore quizIDStore = RecordStore.openRecordStore(rmsStr[5][0],
true);
int recNo = quizIDStore.getNumRecords();
if(recNo == 0)
{
deBug("first date");
quizIDStore.closeRecordStore();
return true;
}else{
byte [] dateByte = quizIDStore.getRecord(1);
if(dateTime().equals(new String(dateByte)))
{
if(Integer.parseInt(new String(quizIDStore.getRecord(4))) ==
1)
{
deBug("same Date : ");
AlertFunction(ShellUtils.alertText[11], AlertType.INFO);
//resetQuestData(Integer.parseInt(new String(totalQByte)
));
quizIDStore.closeRecordStore();
return false;
}
} else {
deBug("different date");
quizIDStore.closeRecordStore();
return true;
}
//quizIDStore.closeRecordStore();
}
} catch (RecordStoreException ex) {
ex.printStackTrace();
}catch (Exception ex) {
ex.printStackTrace();
}
return true;
}
private void loadSponsor(int recID, int imgRecID)
{
switch (recID)
{
case -1: // no data
sponsorImg = createImg("/" + loadResourceStr + "/logo.png");
if(sponsorTextFontLib == null)
{
if(smallLogoImg == null)
smallLogoImg = createImg("/" + loadResourceStr + "/small
Logo.png");
sponsorTextFontLib = new FontLibrary(screenWidth - 30,smallL
ogoImg.getHeight() * 2,
screenWidth, screenHeight);
}
sponsorTextFontLib.wrapText("");
deBug("loading nothing : " + imgRecID);
break;
case -2: // sponsored text
sponsorImg = createImg("/" + loadResourceStr + "/logo.png");
try {
RecordStore sponsorStore = RecordStore.openRecordStore(rmsSt
r[quizType][1], true);
deBug("currQuestIndex :" + imgRecID + " out of " +sponsorSt
ore.getNumRecords());
byte [] sponsorBytes = sponsorStore.getRecord(imgRecID);
sponsorText = ShellUtils.getUnicodeString(new String(sponsor
Bytes), 4);
if(sponsorTextFontLib == null)
{
if(smallLogoImg == null)
smallLogoImg = createImg("/" + loadResourceStr + "/s
mallLogo.png");
sponsorTextFontLib = new FontLibrary(screenWidth - 30,sm
allLogoImg.getHeight() * 2,
screenWidth, screenHeight);
}
sponsorTextFontLib.wrapText(sponsorText);
sponsorStore.closeRecordStore();
} catch (Exception e) {
e.printStackTrace();
}
deBug("loading text : " + imgRecID);
break;
default: // sponsored image
try {
RecordStore sponsorStore = RecordStore.openRecordStore(rmsSt
r[quizType][1], true);
deBug("recID :" + recID + " out of " +sponsorStore.getNumRe
cords());
byte [] sponsorBytes = sponsorStore.getRecord(recID);
sponsorImg = Image.createImage(sponsorBytes, 0, sponsorBytes
.length);
switch (screenWidth)
{
case 176:
if(sponsorImg.getWidth() >= 176)
{
sponsorImg = ShellUtils.createThumbnail(sponsorImg
, 143,80);
}
break;
}
sponsorStore.closeRecordStore();
} catch (Exception e) {
e.printStackTrace();
}
deBug("loading image : " + imgRecID);
break;
}
}
void mainScreen()
{
//applicationState = MENU_STATE;
midlet.display.setCurrent(this);
}
List adsInboxList;
void showAdsInboxListScreen()
{
adsInboxList = new List(ShellUtils.langStrArr[ADSINBOX_INDEX],List.IMPLI
CIT,
new String [] {
ShellUtils.langStrArr[MULTI_ADS_INDEX],
ShellUtils.langStrArr[TEXT_ADS_INDEX]
},
null);
adsInboxList.addCommand(CMD_SELECT);
adsInboxList.addCommand(CMD_BACK);
adsInboxList.setCommandListener(this);
midlet.display.setCurrent(adsInboxList);
}
List textAdsList;
void showTextAdsScreen()
{
textAdsList = new List(ShellUtils.langStrArr[TEXT_ADS_INDEX],
List.IMPLICIT,getTextAdsFromDB(-1),null)
;
if(textAdsList.size() > 0)
{
textAdsList.addCommand(CMD_SELECT);
textAdsList.addCommand(CMD_DELETE);
}
else
{
textAdsList.append(ShellUtils.langStrArr[NOMSG_INDEX], null);
}
textAdsList.addCommand(CMD_BACK);
textAdsList.setCommandListener(this);
midlet.display.setCurrent(textAdsList);
}
Vector textAdsRecID;
String[] getTextAdsFromDB(int caseType)
{
String [] textAdsTemp = null;
try{
RecordStore textStore = RecordStore.openRecordStore(rmsStr[4][0], tr
ue);
switch (caseType)
{
case -1:
textAdsTemp = new String [textStore.getNumRecords()];
textAdsRecID = new Vector(textStore.getNumRecords());
RecordEnumeration re = null;
re = textStore.enumerateRecords(null,null,true);// Enumerate
s the records
int s = 0,k = 0;
while(re.hasNextElement())
{
s = re.nextRecordId();
textAdsRecID.addElement(""+ s);
}
for (int i = 0; i < textAdsRecID.size(); i++)
{
byte [] sponsorBytes = textStore.getRecord(
Integer.parseInt(textAdsRecID.elementAt(i).toStr
ing()));
textAdsTemp[i] = ShellUtils.getUnicodeString(new String(
sponsorBytes), 4);
}
textStore.closeRecordStore();
break;
default:
textStore.deleteRecord(Integer.parseInt(
textAdsRecID.elementAt(caseType).toS
tring()));
textAdsRecID.removeElementAt(caseType);
textAdsList.delete(caseType);
textStore.closeRecordStore();
break;
}
} catch (Exception e) {
e.printStackTrace();
}
return textAdsTemp;
}
Form textAdsForm;
void textAdsFormScreen()
{
textAdsForm = new Form(ShellUtils.langStrArr[TEXT_ADS_INDEX]);
textAdsForm.addCommand(CMD_BACK);
textAdsForm.setCommandListener(this);
midlet.display.setCurrent(textAdsForm);
}
List helpList;
void showHelpListScreen()
{
helpList = new List(ShellUtils.langStrArr[HOWTOPLAY_INDEX],List.IMPLICIT
,
new String [] {
ShellUtils.langStrArr[HELP_INDEX],
ShellUtils.langStrArr[ABOUT_INDEX]
} ,null);
helpList.addCommand(CMD_SELECT);
helpList.addCommand(CMD_BACK);
helpList.setCommandListener(this);
midlet.display.setCurrent(helpList);
}
Form helpForm;
void showHelpForm(String helpStr)
{
helpForm = new Form(ShellUtils.langStrArr[HELP_INDEX]);
helpForm.append(new StringItem("", helpStr));
// helpForm.addCommand(CMD_SUPPORT);
helpForm.addCommand(CMD_BACK);
helpForm.setCommandListener(this);
midlet.display.setCurrent(helpForm);
}
Form moreServiceForm;
void showMoreServiceForm(String serviceStr)
{
moreServiceForm = new Form(ShellUtils.langStrArr[MORE_SERVICE_INDEX]);
moreServiceForm.append(new StringItem("", serviceStr));
// helpForm.addCommand(CMD_SUPPORT);
moreServiceForm.addCommand(CMD_BACK);
moreServiceForm.setCommandListener(this);
midlet.display.setCurrent(moreServiceForm);
}
public void commandAction(Command c, Displayable d)
{
if (d == helpList && ( c == CMD_SELECT || c == List.SELECT_COMMAND))
{
switch (helpList.getSelectedIndex())
{
case 0:// help
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
byte [] helpTxt = readFileFromRes("/Help" + midlet.language)
;
if(midlet.language == 0)
showHelpForm(new String(helpTxt).trim());
else
showHelpForm(ShellUtils.getUnicodeString(new String(help
Txt).trim(), 5));
break;
case 1://about us
loadState(ABOUT_STATE);
applicationState = ABOUT_STATE;
midlet.display.setCurrent(this);
break;
}
return;
}
if (d == adsInboxList && ( c == CMD_SELECT || c == List.SELECT_COMMAND)
)
{
switch (adsInboxList.getSelectedIndex())
{
case 0:// Multimedia Ads
AlertWithComformation(ShellUtils.alertText[9], 2);
/*midlet.display.setCurrent(this);
loadState(LOADING_STATE);
applicationState = LOADING_STATE;
repaint();
bottomImgScroll = null;
loadState(ADSINBOX_STATE);
applicationState = ADSINBOX_STATE;
*/
break;
case 1:// Text Ads
showTextAdsScreen();
break;
}
return;
}
if (d == textAdsList && ( c == CMD_SELECT || c == List.SELECT_COMMAND))
{
if (textAdsList.size() > 0)
{
textAdsFormScreen();
textAdsForm.append(textAdsList.getString(textAdsList.getSelected
Index()));
}
return;
}
if (d == textAdsList && c == CMD_DELETE)
{
if (textAdsList.size() > 0)
{
getTextAdsFromDB(textAdsList.getSelectedIndex());
if(textAdsList.size() == 0)
{
textAdsList.removeCommand(CMD_DELETE);
textAdsList.removeCommand(CMD_SELECT);
textAdsList.append(ShellUtils.langStrArr[NOMSG_INDEX], null)
;
}
}
return;
}
if(c == CMD_BACK)
{
if ( d == helpForm)
{
midlet.display.setCurrent(helpList);
}
else if(d == adsInboxList)
{
loadState(MENU_STATE);
applicationState = MENU_STATE;
midlet.display.setCurrent(this);
}
else if (d == textAdsList)
{
midlet.display.setCurrent(adsInboxList);
}else if(d == textAdsForm){
midlet.display.setCurrent(textAdsList);
}else{
loadState(MENU_STATE);
applicationState = MENU_STATE;
midlet.display.setCurrent(this);
helpForm = null;
moreServiceForm = null;
}
return;
}
if(c == CMD_YES)
{
switch (alertChoice)
{
case 1: // Send the quiz now ?
storeQuizID(1);
loadState(MENU_STATE);
applicationState = MENU_STATE;
midlet.display.setCurrent(this);
break;
case 2: // Move the images to the gallery ?
loadState(SENDING_STATE);
applicationState = SENDING_STATE;
midlet.display.setCurrent(this);
moveAdsToGallery();
break;
}
return;
}
if(c == CMD_NO)
{
switch (alertChoice)
{
case 1: // Send the quiz now ?
midlet.display.setCurrent(this);
break;
case 2: // Move the images to the gallery ?
midlet.display.setCurrent(adsInboxList);
break;
}
return;
}
}
boolean showRegistration(int screen) {
boolean registered = false;
try {
RecordStore recordStore = RecordStore.openRecordStore("RegStatusSNS"
,true);
int i = recordStore.getNumRecords();
if( i == 0) {
recordStore.addRecord("0".getBytes(),0,"0".getBytes().length);
registered = false;
} else {
String value = new String(recordStore.getRecord(1));
deBug("i : " + i + " value : " + value);
if(value.equals("1"))
registered = true;
else
registered = false;
}
recordStore.closeRecordStore();
} catch (RecordStoreException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
switch (screen) {
case 99:
return registered;
}
if(registered) {
AlertFunction(ShellUtils.alertText[3], AlertType.INFO, this);
} else {
registration = new Registration(this);
midlet.display.setCurrent(registration);
}
return registered;
}
void sendRegistrationSMS(String smsStr, String myNumb)
{
loadState(SENDING_STATE);
applicationState = SENDING_STATE;
midlet.display.setCurrent(this);
try {
RecordStore recordStore = RecordStore.openRecordStore("RegDBSNS",tru
e);
recordStore.addRecord(myNumb.getBytes(), 0, myNumb.getBytes().length
);
recordStore.closeRecordStore();
mobileNo = myNumb;
}catch (Exception e ) {
deBug("Error in read Registration rms : "+e.toString());
e.printStackTrace();
}
//TESTING false registration
sender.connectAndSend(midlet.gateWayNumber,midlet.keyWord+smsStr, midlet
.portNo, REGISTRATION_SMS);
//smsSentSuccessfully(REGISTRATION_SMS);
}
void sendTellAFriendSMS(String number,String msg)
{
sender.connectAndSend(number,msg,midlet.portNo,TELL_FRIEND_SMS);
}
void smsSentSuccessfully(int messageType)
{
switch (messageType)
{
case REGISTRATION_SMS:
try {
RecordStore recordStore = RecordStore.openRecordStore("RegSt
atusSNS",true);
recordStore.setRecord(1, "1".getBytes(), 0, "1".getBytes().l
ength);
recordStore.closeRecordStore();
} catch (RecordStoreException ex) {
ex.printStackTrace();
}catch (Exception ex) {
ex.printStackTrace();
}
registeredAlready = true;
loadState(MENU_STATE);
applicationState = MENU_STATE;
midlet.display.setCurrent(this);
break;
case TELL_FRIEND_SMS:
applicationState = COMPETITION_STATE;
midlet.display.setCurrent(this);
break;
}
AutoAlertFunction(ShellUtils.alertText[0], AlertType.INFO);
}
void smsNotSent(byte messageType, int exception)
{
switch (messageType)
{
case REGISTRATION_SMS:
case TELL_FRIEND_SMS:
if(exception == 1)
{
AlertFunction(ShellUtils.alertText[4], AlertType.INFO);
}
else
{
AlertFunction(ShellUtils.alertText[5], AlertType.INFO);
}
break;
}
}
void AutoAlertFunction(String str,AlertType alertType)
{
Alert alert = new Alert(ShellUtils.alertText[6]);
alert.setString(str);
alert.setTimeout(1500);
alert.setType(alertType);
midlet.display.setCurrent(alert, this);
}
void AlertFunction(String str,AlertType alertType)
{
Alert alert = new Alert(ShellUtils.alertText[6]);
alert.setString(str);
alert.setTimeout(Alert.FOREVER);
alert.setType(alertType);
midlet.display.setCurrent(alert);
}
void AlertFunction(String str,AlertType alertType, Displayable d)
{
Alert alert = new Alert(ShellUtils.alertText[6]);
alert.setString(str);
alert.setTimeout(Alert.FOREVER);
alert.setType(alertType);
midlet.display.setCurrent(alert,d);
}
int alertChoice = 0;
public void AlertWithComformation(String str, int ch)
{
alertChoice = ch;
Alert alert = new Alert(ShellUtils.alertText[6]);
alert.setString(str);
alert.addCommand(CMD_YES);
alert.addCommand(CMD_NO);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.INFO);
alert.setCommandListener(this);
midlet.display.setCurrent(alert,this);
}
private void deBug(String str)
{
System.out.println("Shell : " + str);
}
private Image createImg(String path)
{
try{
return Image.createImage(path);
}catch(Exception e){
deBug(e.toString()+" : Error in Create Image: " + path);
}
return null;
}
void drawButtomBar(byte leftSide, byte rightSide,Graphics g)
{
tempY = bottomButImg.getHeight();
switch (leftSide)
{
case REGISTER:
case START:
case NEXT:
case CONTINUE:
case KNOW_MORE:
case SEND:
case RENEW:
g.drawImage(bottomButImg, 0, screenHeight - tempY, 0);
get_Image(g, bottomButImg.getWidth()/2 - buttonTextImg.getWidth()/2,
screenHeight - tempY +
(tempY/2 - buttonTextImg.getHeight()/18),
buttonTextImg, 0, leftSide * (buttonTextImg.getHeight()/9),
buttonTextImg.getWidth(), buttonTextImg.getHeight()/9);
break;
case SUBMIT:
g.drawImage(bottomButImg, 0, screenHeight - tempY, 0);
g.drawImage(submitImg, bottomButImg.getWidth()/2 - submitImg.getWidt
h()/2,
screenHeight - tempY + (tempY/2 - submitImg.getHeight()/2),
0);
break;
}
switch (rightSide)
{
case EXIT:
case QUIT:
case SEND:
case CONTINUE:
g.drawImage(bottomButImg,screenWidth - bottomButImg.getWidth(),
screenHeight - bottomButImg.getHeight(),0);
get_Image(g, screenWidth - bottomButImg.getWidth() +
(bottomButImg.getWidth()/2 - buttonTextImg.getWidth()/2),
screenHeight - tempY +
(tempY/2 - buttonTextImg.getHeight()/18),
buttonTextImg, 0, rightSide * (buttonTextImg.getHeight()/9),
buttonTextImg.getWidth(), buttonTextImg.getHeight()/9);
break;
case FRIENDS_HELP:
g.drawImage(bottomButImg,screenWidth - bottomButImg.getWidth(),
screenHeight - bottomButImg.getHeight(),0);
g.drawImage(friendsHelpImg, screenWidth - bottomButImg.getWidth() +
(bottomButImg.getWidth()/2 - friendsHelpImg.getWidth()/2),
screenHeight - tempY + (tempY/2 - friendsHelpImg.getHeight()
/2), 0);
break;
}
}
Font f1;
void drawButtomBar(String leftSide, String rightSide,Graphics g)
{
f1 = g.getFont();
tempY = bottomButImg.getHeight() + 10;
g.setFont(smallBoldFont);
g.setColor(255,255,255);
if(leftSide!=null)
{
g.drawImage(bottomButImg, 0, screenHeight - tempY, 0);
g.drawString(leftSide, bottomButImg.getWidth()/2 - smallBoldFont.stringW
idth(leftSide)/2,
screenHeight - tempY + (bottomButImg.getHeight()/2
- smallBoldFont.getHeight()/2), 0);
}
if(rightSide!=null)
{
g.drawImage(bottomButImg,screenWidth - bottomButImg.getWidth(),
screenHeight - tempY,0);
g.drawString(rightSide,screenWidth - bottomButImg.getWidth() +
(bottomButImg.getWidth()/2 - smallBoldFont.stringWidth(right
Side)/2),
screenHeight - tempY + (bottomButImg.getHeight()/2
- smallBoldFont.getHeight()/2), 0);
}
g.setFont(f1);
}
/**
* Utility function that clips the Image as it draws it
* @param graphics object
* @param X position
* @param Y position
* @param Image object
* @param off set X
* @param off set Y
* @param clip width
* @return clip height
*/
private void get_Image(Graphics g, int xPos, int yPos, Image image, int ofX,
int ofY, int width, int height)
{
try {
g.setClip(xPos, yPos, width, height);
g.drawImage(image, xPos - ofX, yPos - ofY, 0);
g.setClip(0,0,screenWidth,screenHeight);
} catch(Exception e) {
deBug("Error in get_Image function : "+e.toString());
}
}
// Read text file from Resource
byte[] readFileFromRes(String filename)
{
//String str=new String();
//deBug("file name is the " + filename);
byte [] bb=null;
try {
InputStream is = getClass( ).getResourceAsStream(filename);
DataInputStream dis = new DataInputStream(is);
ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
int ch;
while ((ch = dis.read()) != -1)
{
bStrm.write(ch);
}
bb=bStrm.toByteArray();
//deBug("bb size"+bb.length);
bStrm.close();
}catch (IOException ex){
deBug("Error in readFileFromRes : "+ex.toString());
}
return bb;
}
Calendar calendar;
String day;
String dateTime()
{
//calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
calendar = Calendar.getInstance();
//year = String.valueOf(calendar.get(Calendar.YEAR));
//month = String.valueOf(calendar.get(Calendar.MONTH)+1);
//if(month.length() < 2)
//month = "0"+month;
day = String.valueOf(calendar.get(Calendar.DATE));
/*if(day.length() < 2)
day = "0"+day;
hour = String.valueOf(calendar.get(Calendar.HOUR));
if(hour.length() < 2)
hour = "0"+hour;
min = String.valueOf(calendar.get(Calendar.MINUTE));
if(min.length() < 2)
min = "0"+min;
sec = String.valueOf(calendar.get(Calendar.SECOND));
if(sec.length() < 2)
sec = "0"+sec;
**/
//deBug(day+"/"+month+"/"+year+"~"+hour+":"+min+":"+sec);
//return (day+"/"+month+"/"+year+"~"+hour+":"+min+":"+sec);
return (day);
}
//----------------------Countdown Timer--------------------
boolean first = true,
time_Up = false,
pauseFlag = true;
long tempSec = 0, startSec = 0, totalSec, stop_Time = 0, pauseSec,
hours, min, sec;
long TOTAL_TIME = 900;
private String get_Timer()
{
String timeStr = "";
Date d=new Date();
totalSec=d.getTime();
if(first){
first=false;
startSec=totalSec;
}
tempSec=( (totalSec-startSec)/1000 );
if (!pauseFlag)
{
stop_Time=(TOTAL_TIME - (tempSec) );
if(stop_Time >= 0)
{
/*
hours=(stop_Time/3600);
if(hours % 10 != 0) {
timeStr = "0" + hours;
} else
timeStr = "" + hours;
*/
min=(stop_Time/60);
if(min < 10) {
timeStr = timeStr + "0" + min;
} else
timeStr = timeStr + "" + min;
sec=(stop_Time%60);
if(sec < 10) {
timeStr = timeStr + " : 0" + sec;
} else
timeStr = timeStr + " : " + sec;
}
if( (hours==0) && (min==0) && (sec==0) )
time_Up=true;
}
return timeStr;
}
private void startTimer()
{
if(pauseFlag)
{
pauseFlag = false;
startSec += (totalSec - pauseSec);
}
}
private void stopTimer()
{
if(!pauseFlag)
{
pauseFlag = true;
pauseSec = totalSec;
}
}
}

Das könnte Ihnen auch gefallen