/** * Update URL and gauge of the progress form. * * @param url new URL, null to remove, "" to not change * @param size 0 if unknown, else size of object to download in K bytes * @param gaugeLabel label for progress gauge */ private void updateProgressForm(String url, int size, String gaugeLabel) { Gauge oldProgressGauge; Gauge progressGauge; StringItem urlItem; // We need to prevent "flashing" on fast development platforms. while (System.currentTimeMillis() - lastDisplayChange < GraphicalInstaller.ALERT_TIMEOUT) ; if (size <= 0) { progressGauge = new Gauge(gaugeLabel, false, Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING); } else { progressGauge = new Gauge(gaugeLabel, false, size, 0); } oldProgressGauge = (Gauge) progressForm.get(progressGaugeIndex); progressForm.set(progressGaugeIndex, progressGauge); // this ends the background thread of gauge. oldProgressGauge.setValue(Gauge.CONTINUOUS_IDLE); if (url == null) { urlItem = new StringItem("", ""); progressForm.set(progressUrlIndex, urlItem); } else if (url.length() != 0) { urlItem = new StringItem(Resource.getString(ResourceConstants.AMS_WEBSITE) + ": ", url); progressForm.set(progressUrlIndex, urlItem); } lastDisplayChange = System.currentTimeMillis(); }
public TrafficCams(Controller controller) { super("Traffic Status", Choice.EXCLUSIVE); this.controller = controller; traf = this; TrafOption = new Command("OK", Command.SCREEN, 1); bckMenu = new Command("back", Command.BACK, 2); VehicleOk = new Command("OK", Command.SCREEN, 1); Vehicleback = new Command("Back", Command.BACK, 2); this.addCommand(TrafOption); this.addCommand(bckMenu); setCommandListener(this); if (fmViewPng == null) { fmViewPng = new Form(""); cmBack = new Command("Back", Command.BACK, 1); RefreshImage = new Command("refresh", Command.OK, 2); fmViewPng.addCommand(cmBack); fmViewPng.addCommand(RefreshImage); fmViewPng.setCommandListener(this); } }
/** * Display the connecting form to the user, let call set actions. * * @param action action to put in the form's title * @param name name to in the form's title * @param url URL of a JAD * @param size 0 if unknown, else size of object to download in K bytes * @param gaugeLabel label for progress gauge * @return displayed form */ private Form displayProgressForm( String action, String name, String url, int size, String gaugeLabel) { Gauge progressGauge; StringItem urlItem; progressForm = new Form(null); progressForm.setTitle(action + " " + name); if (size <= 0) { progressGauge = new Gauge(gaugeLabel, false, Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING); } else { progressGauge = new Gauge(gaugeLabel, false, size, 0); } progressGaugeIndex = progressForm.append(progressGauge); if (url == null) { urlItem = new StringItem("", ""); } else { urlItem = new StringItem(Resource.getString(ResourceConstants.AMS_WEBSITE) + ": ", url); } progressUrlIndex = progressForm.append(urlItem); display.setCurrent(progressForm); lastDisplayChange = System.currentTimeMillis(); return progressForm; }
public void commandAction(Command c, Displayable d) { if (c == startCmd) { form.deleteAll(); form.removeCommand(startCmd); form.addCommand(byeCmd); Thread t = new Thread() { public void run() { startSession(); } }; t.start(); // startSession(); return; } else if (c == exitCmd) { destroyApp(true); return; } else if (c == byeCmd) { form.removeCommand(byeCmd); form.addCommand(restartCmd); sendBYE(); return; } else if (c == restartCmd) { stopListener(); form.removeCommand(restartCmd); form.addCommand(startCmd); form.deleteAll(); form.append(address); return; } }
public OriginatingINVITE() { // <i><b>Initialize MIDlet display</b></i> display = Display.getDisplay(this); // <i><b>create a Form for progess info printings</b></i> form = new Form("Session example"); address = new TextField("INVITE:", "sip:[email protected]:5070", 40, TextField.LAYOUT_LEFT); form.append(address); byeCmd = new Command("Bye", Command.ITEM, 1); restartCmd = new Command("Restart", Command.ITEM, 1); startCmd = new Command("Start", Command.ITEM, 1); form.addCommand(startCmd); exitCmd = new Command("Exit", Command.EXIT, 1); form.addCommand(exitCmd); form.setCommandListener(this); }
public void notifyRequest(SipConnectionNotifier sn) { try { ssc = scn.acceptAndOpen(); // <i><b>blocking</b></i> if (ssc.getMethod().equals("BYE")) { // <i><b>respond 200 OK to BYE</b></i> ssc.initResponse(200); ssc.send(); str = new StringItem("Other side hang-up!", ""); form.append(str); } form.append("Closing notifier..."); form.removeCommand(byeCmd); form.addCommand(restartCmd); scn.close(); } catch (IOException ex) { // <i><b>handle IOException</b></i> } }
/** Handle incoming response here */ public void notifyResponse(SipClientConnection scc) { int statusCode = 0; boolean received = false; try { scc.receive(0); // <i><b>fetch resent response</b></i> statusCode = scc.getStatusCode(); str = new StringItem("Response: ", statusCode + " " + scc.getReasonPhrase()); form.append(str); if (statusCode < 200) { dialog = scc.getDialog(); form.append("Early-Dialog state: " + dialog.getState()); } if (statusCode == 200) { String contentType = scc.getHeader("Content-Type"); String contentLength = scc.getHeader("Content-Length"); int length = Integer.parseInt(contentLength); if (contentType.equals("application/sdp")) { // // <i><b>handle SDP here</b></i> // } dialog = scc.getDialog(); // <i><b>save dialog info</b></i> form.append("Dialog state: " + dialog.getState()); scc.initAck(); // <i><b>initialize and send ACK</b></i> scc.send(); str = new StringItem("Session established: ", scc.getHeader("Call-ID")); form.append(str); scc.close(); } else if (statusCode >= 300) { str = new StringItem("Session failed: ", scc.getHeader("Call-ID")); form.append(str); form.removeCommand(byeCmd); form.addCommand(restartCmd); scc.close(); } } catch (IOException ioe) { // <i><b>handle e.g. transaction timeout here</b></i> str = new StringItem("No answer: ", ioe.getMessage()); form.append(str); form.removeCommand(byeCmd); form.addCommand(restartCmd); } }
private void startSession() { SipClientConnection scc = null; try { // <i><b>start a listener for incoming requests</b></i> startListener(); // <i><b>open SIP connection with remote user</b></i> scc = (SipClientConnection) Connector.open(address.getString()); scc.setListener(this); // <i><b>initialize INVITE request</b></i> scc.initRequest("INVITE", scn); scc.setHeader("Content-Length", "" + sdp.length()); scc.setHeader("Content-Type", "application/sdp"); OutputStream os = scc.openContentOutputStream(); os.write(sdp.getBytes()); os.close(); // <i><b>close and send</b></i> str = new StringItem("Inviting... ", scc.getHeader("To")); form.append(str); } catch (Exception ex) { ex.printStackTrace(); // <i><b>handle IOException</b></i> } }
/** end session with BYE */ private void sendBYE() { if (dialog != null) { try { SipClientConnection sc = dialog.getNewClientConnection("BYE"); sc.send(); str = new StringItem("user hang-up: ", "BYE sent..."); form.append(str); boolean gotit = sc.receive(10000); if (gotit) { if (sc.getStatusCode() == 200) { form.append("Session closed successfully..."); form.append("Dialog state: " + dialog.getState()); } else form.append("Error: " + sc.getReasonPhrase()); } sc.close(); } catch (IOException iox) { form.append("Exception: " + iox.getMessage()); } } else { form.append("No dialog information!"); } }
public void commandAction(Command command, Displayable displayable) { if (command == camList) { controller.setCurrentScreen(this); controller.setCurrentScreen(this); } if (command == refreshList) { controller.showProgressBar(); refreshCamList(); } if (command == cmBack) { controller.getDisp().setCurrent(LiveCameras); } if (command == RefreshImage) { refreshImage(); } if (command == viewImage) { refreshImage(); } if (command == TrafOption) { if (this.getString(this.getSelectedIndex()).equals("Cameras")) { LiveCameras(); } else if (this.getString(this.getSelectedIndex()).equals("Traffic Fines")) { if (VehicleNoForm == null) { VehicleNoForm = new Form("Traffic Fines"); vehNo = new TextField("Vehicle Number", "", 100, TextField.ANY); VehicleNoForm.append(vehNo); VehicleNoForm.addCommand(Vehicleback); VehicleNoForm.addCommand(VehicleOk); VehicleNoForm.setCommandListener(this); } controller.setCurrentScreen(VehicleNoForm); } else { new Thread() { public void run() { getTrafficSpots(); } }.start(); } } if (command == bckMenu) { controller.MainMenu(); } if (command == Vehicleback) { controller.setCurrentScreen(this); } if (command == VehicleOk) { if (vehNo.getString().equals("")) { controller.showAlert("Enter the vehicle number", 0, AlertType.ERROR); } else { controller.showProgressBar(); new Thread() { public void run() { Downloader dwn = new Downloader(controller); String message = dwn.requestForData( "http://125.17.140.50/notices/vehiclefinedetails.aspx?veh_no=" + vehNo.getString()); vehNo.setString(""); controller.showAlert(message, 0, AlertType.INFO); } }.start(); new Thread() { public void run() { controller.setCurrentScreen(VehicleNoForm); } }.start(); } } }