// midlet
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Display;
public class MIDlet_MRC extends MIDlet {
Display display;
boolean license;
public MIDlet_MRC(){
display = Display.getDisplay(this);
license = MyMRCSystem.validateLicense();
System.out.println("license "+license);
}
/**
* startApp
*/
protected void startApp() {
if(license){
System.out.println("run start 1");
}else{
display.setCurrent(new MyMRCSystem());
}
}
/**
* pauseApp
*/
protected void pauseApp() {
}
/**
* destroyApp
*
* @param boolean0 boolean
*/
protected void destroyApp(boolean boolean0) {
}
}
///
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.rms.RecordStore;
/*
* MyMRCSystem.java
*
* Created on 2007年3月19日, 上午10:47
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author Thomas
*/
public class MyMRCSystem extends Form implements CommandListener{
// private Form menu_MRC = null;
private Command yesCommand;
private Command noCommand;
private static String mrcTimeStore = "mrctime";
private static long purchaseDate = 0;
private static long LicenseLongTime = (long)30*86400000;//30day//24(h)*60(m)*60(s)*1000(ms) = 86400000;
/** Creates a new instance of MyMRCSystem */
public MyMRCSystem() {
super("menu_MRC");
yesCommand = new Command("YES", Command.OK, 3);
noCommand = new Command("NO", Command.BACK, 3);
this.append("3$ /30 day");
this.addCommand(yesCommand);
this.addCommand(noCommand);
this.setCommandListener(this);
}
public void commandAction(Command command, Displayable displayable) {
if ( command == yesCommand ) {
System.out.println("yesCommand");
savedateLicense();
System.out.println("run start 2");
}else if( command == noCommand ){
System.out.println("noCommand");
System.out.println("exit game");
}
}
private void savedateLicense(){
try {
RecordStore rs = RecordStore.openRecordStore(mrcTimeStore, true);
// long nowTime = System.currentTimeMillis();
purchaseDate = System.currentTimeMillis();
byte[] temp = new byte[8];
temp[0] = (byte) ( purchaseDate & 0xFF);
temp[1] = (byte) ( (purchaseDate >> 8) & 0xFF);
temp[2] = (byte) ( (purchaseDate >> 16) & 0xFF);
temp[3] = (byte) ( (purchaseDate >> 24) & 0xFF);
temp[4] = (byte) ( (purchaseDate >> 32) & 0xFF);
temp[5] = (byte) ( (purchaseDate >> 40) & 0xFF);
temp[6] = (byte) ( (purchaseDate >> 48) & 0xFF);
temp[7] = (byte) ( (purchaseDate >> 56) & 0xFF);
System.out.println("save purchaseDate "+purchaseDate);
if (rs.getNumRecords() == 0)
rs.addRecord(temp, 0, 8);
else
rs.setRecord(1, temp, 0, 8);
rs.closeRecordStore();
}catch (Exception e) {
System.err.println("savedateLicense -->> rms is error");
e.printStackTrace();
}
}
public static boolean validateLicense(){//
try {
RecordStore rs = RecordStore.openRecordStore(mrcTimeStore, true);
if (rs.getNumRecords() == 0){//first p
return false;//no purchases
}
System.out.println("rs.getNumRecords() != 0");
byte[] temp = new byte[8];
temp = rs.getRecord(1);
purchaseDate = (long) temp[0];
purchaseDate += (long)(temp[1] & 0xFF) << 8;
purchaseDate += (long)(temp[2] & 0xFF) << 16;
purchaseDate += (long)(temp[3] & 0xFF) << 24;
purchaseDate += (long)(temp[4] & 0xFF) << 32;
purchaseDate += (long)(temp[5] & 0xFF) << 40;
purchaseDate += (long)(temp[6] & 0xFF) << 48;
purchaseDate += (long)(temp[7] & 0xFF) << 56;
System.out.println("valid purchaseDate "+purchaseDate);
rs.closeRecordStore();
}catch (Exception e) {
System.err.println("validateLicense -->> rms is error");
e.printStackTrace();
}
if( System.currentTimeMillis() - purchaseDate > LicenseLongTime){
return false;//purchases time out
}else{
return true;//purchases time
}
}
// System.setExitURI(a.getAppProperty("Content-DRM-Renew-URL"));
}