- /*
- * Copyright 1999,2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /*
- * Created on 2007-1-23
- *
- */
- package peaklau.eaglefund;
-
- import javax.microedition.lcdui.Alert;
- import javax.microedition.lcdui.AlertType;
- import javax.microedition.lcdui.Canvas;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.midlet.MIDlet;
- import javax.microedition.midlet.MIDletStateChangeException;
-
- /**
- * This is the application entry. <br>
- *
- * <br>
- *
- * @author peaklau <br>
- * email:<A HREF="mailto:peaklau@hotmail.com">peaklau@hotmail.com</A> <br>
- * <a href="http://www.peaklau.com/fund/english/">HomePage</a>
- * @version $Revision: 1.1 $ $Date: 2007/05/09 16:07:04 $
- */
-
- public class Main extends MIDlet implements INavigator,CommandListener{
- private Display display = null;
-
- private MainScreen mainScreen=null;
- private FundAddScreen fundAddScreen=null;
- private FundModifyScreen fundModifyScreen=null;
- private FundDeleteScreen fundDeleteScreen=null;
- private ScrollScreen valueScreen=null;
- private ScrollScreen stockScreen=null;
- private StockImage stock30ImageScreen=null;
- private StockImage stock90ImageScreen=null;
- private StockImage stock360ImageScreen=null;
-
- private Command value= new Command("每日基金",Command.SCREEN, 1);
- private Command addFund= new Command("添加基金",Command.SCREEN, 1);
- private Command modifyFund= new Command("修改基金",Command.SCREEN, 1);
- private Command deleteFund= new Command("删除基金", Command.SCREEN, 1);
- private Command stock= new Command("大盘指数",Command.SCREEN, 1);
- private Command stock30Image= new Command("30日走势图",Command.SCREEN, 1);
- private Command stock90Image= new Command("90日走势图",Command.SCREEN, 1);
- private Command stock360Image= new Command("360日走势图",Command.SCREEN, 1);
- private Command checkVersion= new Command("软件更新信息",Command.SCREEN, 1);
- private Command exit = new Command("越狱",Command.EXIT, 1);
-
- private Alert alert=null;
-
- public Main() {
- display = Display.getDisplay(this);
- mainScreen=new MainScreen(this);
- mainScreen.addCommand(exit);
-
- mainScreen.addCommand(value);
- mainScreen.addCommand(addFund);
- mainScreen.addCommand(modifyFund);
- mainScreen.addCommand(deleteFund);
- mainScreen.addCommand(stock);
- mainScreen.addCommand(stock30Image);
- mainScreen.addCommand(stock90Image);
- mainScreen.addCommand(stock360Image);
- mainScreen.addCommand(checkVersion);
- mainScreen.setCommandListener(this);
-
- fundAddScreen=new FundAddScreen(this);
- fundModifyScreen=new FundModifyScreen(this);
- fundDeleteScreen=new FundDeleteScreen(this);
- valueScreen=new ValueScreen("每日基金",DataCenter.getValueDesc(),"mainScreen",this);
- stockScreen=new StockScreen("大盘指数","","mainScreen",this);
- stock30ImageScreen=new StockImage(30,"30日走势图","mainScreen",this);
- stock90ImageScreen=new StockImage(90,"90日走势图","mainScreen",this);
- stock360ImageScreen=new StockImage(360,"360日走势图","mainScreen",this);
-
- alert=new Alert("提示信息");
- }
-
- public BaseCanvas getCanvas(String name){
- if("stockScreen".equals(name)){
- return stockScreen;
- }else if("valueScreen".equals(name)){
- return valueScreen;
- }else if("stock30ImageScreen".equals(name)){
- return stock30ImageScreen;
- }else if("stock90ImageScreen".equals(name)){
- return stock90ImageScreen;
- }else if("stock360ImageScreen".equals(name)){
- return stock360ImageScreen;
- }else{
- return mainScreen;
- }
- }
- public Displayable getDisplayable(String name){
- if("fundAddScreen".equals(name)){
- return fundAddScreen;
- }else if("fundModifyScreen".equals(name)){
- return fundModifyScreen;
- }else if("fundDeleteScreen".equals(name)){
- return fundDeleteScreen;
- }else{
- return getCanvas(name);
- }
- }
-
-
- public void commandAction(Command command, Displayable displayable) {
- if(command == value){
- keyPressed(Canvas.KEY_NUM1);
- }else if(command == addFund){
- keyPressed(Canvas.KEY_NUM2);
- }else if(command == modifyFund){
- keyPressed(Canvas.KEY_NUM3);
- }else if(command == deleteFund){
- keyPressed(Canvas.KEY_NUM4);
- }else if(command == stock){
- keyPressed(Canvas.KEY_NUM5);
- }else if(command == stock30Image){
- keyPressed(Canvas.KEY_NUM6);
- }else if(command == stock90Image){
- keyPressed(Canvas.KEY_NUM7);
- }else if(command == stock360Image){
- keyPressed(Canvas.KEY_NUM8);
- }else if(command == checkVersion){
- keyPressed(Canvas.KEY_NUM9);
- }else if(command == exit){
- try{
- destroyApp(true);
- }catch(Exception e){
- }
- this.notifyDestroyed();
- }
- }
-
- public void keyPressed(int keyCode) {
- switch (keyCode) {
- case Canvas.KEY_NUM0:
- display.setCurrent(getDisplayable("mainScreen"));
- break;
- case Canvas.KEY_NUM1:
- display.setCurrent(getDisplayable("valueScreen"));
- break;
- case Canvas.KEY_NUM2:
- display.setCurrent(getDisplayable("fundAddScreen"));
- break;
- case Canvas.KEY_NUM3:
- display.setCurrent(getDisplayable("fundModifyScreen"));
- break;
- case Canvas.KEY_NUM4:
- display.setCurrent(getDisplayable("fundDeleteScreen"));
- break;
- case Canvas.KEY_NUM5:
- display.setCurrent(getDisplayable("stockScreen"));
- break;
- case Canvas.KEY_NUM6:
- display.setCurrent(getDisplayable("stock30ImageScreen"));
- break;
- case Canvas.KEY_NUM7:
- display.setCurrent(getDisplayable("stock90ImageScreen"));
- break;
- case Canvas.KEY_NUM8:
- display.setCurrent(getDisplayable("stock360ImageScreen"));
- break;
- case Canvas.KEY_NUM9:
- alert.setTitle("软件更新信息");
- if(!getAppVersion().equals(version)){
- alert.setString("软件主页 http://www.peaklau.com");
- }else{
- alert.setString("新版本号"+version+" 软件主页 http://www.peaklau.com");
- }
-
-
- alert.setType(AlertType.CONFIRMATION);
- alert.setTimeout(5000);
- display.setCurrent(alert);
-
- break;
- default:
- break;
- }
- }
-
-
- protected void startApp() throws MIDletStateChangeException {
- display.setCurrent(mainScreen);
- }
- private HttpClient httpClient=new HttpClient();
- public HttpClient getHttpClient(){
- return httpClient;
- }
- public String getAppVersion(){
- return this.getAppProperty("MIDlet-Version");
- }
- private String version="";
- public void setAppVersion(String version){
- this.version=version;
- }
-
- public Display getDisplay(){
- return display;
- }
- protected void pauseApp() {
- }
- protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
- }
- }