第4回:実機に載せよう(ダウンサイズ)
001: //package com.s_cradle.improve.client; 002: 003: import javax.microedition.midlet.*; 004: import javax.microedition.lcdui.*; 005: import javax.microedition.rms.*; 006: import java.io.IOException; 007: import java.util.*; 008: //import com.s_cradle.improve.Constants; 009: 010: /** 011: * Copyright (C) 2003 Sophia Cradle, Inc. 012: * 013: * MIDlet を継承するメインのクラスです。。 014: * 015: * @author Masaru Yoshimura 016: */ 017: public class I/*ImproveMIDlet*/ extends MIDlet implements CommandListener{ 018: public static final Command A/*okCommand*/ = new Command("OK",Command.OK,1); 019: 020: //downsize 定数展開 021: //public static String ALLOW_URL = "MIDlet-X-AllowURL-1"; 022: 023: private static Display size/*display*/; 024: public static Vector Code/*buddyList*/; 025: public static B/*BuddyListCanvas*/ StackMap/*listCanvas*/; 026: public static I/*ImproveMIDlet*/ I/*midlet*/; 027: 028: /** 029: * 開始。画面を作成し、最初のタスクをスケジュールする。 030: */ 031: protected void startApp() { 032: I/*midlet*/ = this; 033: size/*display*/ = Display.getDisplay(this); 034: StackMap/*listCanvas*/ = new B/*BuddyListCanvas*/(); 035: 036: Z/*Task*/ task = Z/*Task*/.Code/*getFirstTask*/(); 037: if(task != null){ 038: task.StackMap/*schedule*/(0,5000/*Task.POLLING_PERIOD*/); 039: } 040: } 041: 042: /** 043: * 画面の切り替え 044: */ 045: public static void Code/*setCurrent*/(Displayable disp){ 046: size/*display*/.setCurrent(disp); 047: } 048: 049: /** 050: * 画面の切り替え 051: */ 052: public static void Code/*setCurrent*/(Alert a, Displayable disp){ 053: size/*display*/.setCurrent(a, disp); 054: } 055: 056: /** 057: * 画面の取得 058: */ 059: public static Displayable StackMap/*getCurrent*/(){ 060: return size/*display*/.getCurrent(); 061: } 062: 063: /** 064: * 一時停止。 065: */ 066: protected void pauseApp() { 067: } 068: 069: /** 070: * 終了処理 071: */ 072: protected void destroyApp(boolean unconditional) 073: throws MIDletStateChangeException{ 074: if( unconditional ){ 075: Z/*Task*/.Z/*getTask*/(4/*Task.TASK_SET*/,new String[]{ 076: String.valueOf(4/*Constants.ITEM_INDEX_STATUS*/), 077: String.valueOf(0/*Constants.STATUS_LOGOFF*/)}) 078: .StackMap/*schedule*/(0); 079: throw new MIDletStateChangeException(); 080: } 081: } 082: 083: /** 084: * CommandListener実装 085: */ 086: public void commandAction(Command c, Displayable d){ 087: if( c.equals(A/*okCommand*/) ){ 088: Z/*Task*/.D/*strs*/[0]/*account*/ = ((TextBox)d).getString(); 089: //downsize 即値の利用 090: Z/*Task*/.Z/*getTask*/( 0/*Task.TASK_CREATE*/,null).StackMap/*schedule*/(0); 091: Form form = new Form("通信中"); 092: form.setTicker(new javax.microedition.lcdui.Ticker("アカウント作成中") ); 093: I/*ImproveMIDlet*/.Code/*setCurrent*/(form); 094: } 095: } 096: 097: public static void I/*callSerially*/(Runnable r){ 098: size/*display*/.callSerially(r); 099: } 100: 101: //downsize クラス融合 以下ResourceManager 102: 103: private static Image[] account/*images*/; 104: 105: /** 106: * 画像の取得 107: */ 108: public static Image Code/*getImage*/(int num){ 109: return account/*images*/[num]; 110: } 111: 112: /** 113: * レコードストアからアカウントとパスワードを読み込んでTaskに設定する。 114: */ 115: public static String I/*getAccountAndPasswordFromRecordStore*/(){ 116: String ret = null; 117: 118: RecordStore rs = null; 119: try{ 120: rs = RecordStore.openRecordStore( "account"/*RECORDSTORE_NAME_ACCOUNT*/,true); 121: RecordEnumeration re = rs.enumerateRecords(null,null,true); 122: Z/*Task*/.D/*strs*/[0]/*account*/ = new String(re.nextRecord()); 123: Z/*Task*/.D/*strs*/[1]/*password*/ = new String(re.nextRecord()); 124: } catch(RecordStoreException ex) { 125: Z/*Task*/.D/*strs*/[0]/*account*/ = null; 126: Z/*Task*/.D/*strs*/[1]/*password*/ = null; 127: } finally{ 128: if(rs != null){ 129: try{ 130: rs.closeRecordStore(); 131: } catch(RecordStoreException ex){ 132: //NOP 133: } 134: } 135: } 136: return null; 137: } 138: 139: /** 140: * Taskからアカウントとパスワードを取得し、レコードストアに書き込む。 141: */ 142: public static void Code/*setAccountAndPasswordToRecordStore*/(){ 143: //downsize 即値の利用 144: //String account = Task.getAccount(); 145: //String password = Task.getPassword(); 146: RecordStore rs = null; 147: Vector tempVec = new Vector(); 148: int id; 149: 150: try{ 151: rs = RecordStore.openRecordStore( "account"/*RECORDSTORE_NAME_ACCOUNT*/,true); 152: RecordEnumeration re = rs.enumerateRecords(null,null,true); 153: while( re.hasNextElement() ){ 154: id = re.nextRecordId(); 155: tempVec.addElement(new Integer(id)); 156: } 157: for(Enumeration e=tempVec.elements();e.hasMoreElements();){ 158: rs.deleteRecord(((Integer)e.nextElement()).intValue()); 159: } 160: } catch(RecordStoreException ex) { 161: //NOP 162: } finally{ 163: if(rs != null){ 164: try{ 165: rs.closeRecordStore(); 166: } catch(RecordStoreException ex){ 167: //NOP 168: } 169: } 170: } 171: 172: try{ 173: rs = RecordStore.openRecordStore( "account"/*RECORDSTORE_NAME_ACCOUNT*/,true); 174: addElement/*save*/(rs,Z/*Task*/.D/*strs*/[0]/*account*/.getBytes()); 175: addElement/*save*/(rs,Z/*Task*/.D/*strs*/[1]/*password*/.getBytes()); 176: } catch(RecordStoreException ex) { 177: //NOP 178: } finally{ 179: if(rs != null){ 180: try{ 181: rs.closeRecordStore(); 182: } catch(RecordStoreException ex){ 183: //NOP 184: } 185: } 186: } 187: } 188: 189: /** 190: * 保存します。 191: */ 192: private static int addElement/*save*/( RecordStore rs, byte[] data) throws RecordStoreException{ 193: return rs.addRecord(data,0,data.length); 194: } 195: 196: //downsize クラス融合 以下Ticker 197: 198: //downsize 定数展開 199: /* 200: public static final int STATUS_IDLE = 0; 201: public static final int STATUS_BLINK = 1; 202: public static final int STATUS_HOLD = 2; 203: public static final int STATUS_SCROLL = 3; 204: public static final int STATUS_LIMIT = 4; 205: 206: public static final int LEVEL_CLASP = 0; 207: public static final int LEVEL_NORMAL = 1; 208: public static final int LEVEL_INFORMATION = 2; 209: public static final int LEVEL_WARNING = 3; 210: public static final int LEVEL_LIMIT = 4; 211: */ 212: 213: /** 214: * 描画領域を指定するコンストラクタです。 215: */ 216: //public Ticker(int x_, int y_,int width_, int height_){ 217: public void Code/*initializeTicker*/(int x_, int y_,int width_, int height_){ 218: } 219: 220: /** 221: * タイマーが発火するたびに呼ばれます。 222: */ 223: public void Z/*timerExpired*/(){ 224: } 225: 226: /** 227: * ティッカーに文字列を追加します。 228: */ 229: public void Code/*insert*/(int level, String data){ 230: } 231: 232: /** 233: * 描画時に呼ばれます。 234: */ 235: public void Code/*paint*/(Graphics graph){ 236: } 237: }