📄 devicecapabilities.java
字号:
/* * Movino J2ME Client * Copyright (C) 2007 Johannes Berg * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */package org.movino.device;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import java.util.Vector;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Form;import javax.microedition.lcdui.Ticker;import javax.microedition.rms.RecordEnumeration;import javax.microedition.rms.RecordStore;import org.movino.MovinoMenu;import org.movino.MovinoMidlet;import org.movino.Options;import org.movino.Showable;public class DeviceCapabilities implements Showable, Runnable, CommandListener{ public static final String CAPABILITIES_RECORD_STORE="movino_capablities"; public static Camera[] deviceCameras=new Camera[0]; private Form infoForm; private Command continueCommand; private Command skipCommand; private String infoText; private boolean testStarted; private boolean testPassed; private Showable nextShowable; private MovinoMidlet movinoMidlet; private boolean isVerbose; public DeviceCapabilities(){ movinoMidlet = MovinoMidlet.movinoMidlet; infoText = "Welcome to Movino!\nPlease press \"continue\" to test device capabilities."; nextShowable = new MovinoMenu(movinoMidlet); isVerbose=false; } public DeviceCapabilities(Showable next_showable){ movinoMidlet = MovinoMidlet.movinoMidlet; infoText = "Please press \"continue\" to test device capabilities."; nextShowable = next_showable; isVerbose = true; } public boolean loadFromRMS(){ //load cameras and formats from RMS try { RecordStore rs = RecordStore.openRecordStore(CAPABILITIES_RECORD_STORE, false); RecordEnumeration re = rs.enumerateRecords(null, null, false); if(re.hasNextElement()){ byte[] rec_data = re.nextRecord(); if(rec_data!=null){ DataInputStream in = new DataInputStream(new ByteArrayInputStream(rec_data)); int cam_count = in.readInt(); deviceCameras = new Camera[cam_count]; for(int i=0;i<deviceCameras.length;i++){ deviceCameras[i] = new Camera(in); } return true; } } } catch (Exception e) { System.out.println("exception : "+e+" "+e.getMessage()); } return false; } public void writeToRMS(){ try { RecordStore rs = RecordStore.openRecordStore(CAPABILITIES_RECORD_STORE, true); ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bout); out.writeInt(deviceCameras.length); for(int i=0;i<deviceCameras.length;i++){ deviceCameras[i].write(out); } out.flush(); byte[] barray = bout.toByteArray(); RecordEnumeration re = rs.enumerateRecords(null, null, false); if(re.hasNextElement()){ int rec_id = re.nextRecordId(); rs.setRecord(rec_id, barray, 0, barray.length); } else{ rs.addRecord(barray, 0, barray.length); } } catch (Exception e){ System.out.println("exception : "+e+" "+e.getMessage()); } } public void show(Display display){ show(display,true); } public void show(Display display, boolean load){ if(load){ if(loadFromRMS()){ setDefaultOptions(); Options.loadOptions(); nextShowable.show(Display.getDisplay(movinoMidlet)); return; } } infoForm = new Form("Device test"); infoForm.append(infoText); continueCommand = new Command("Continue", Command.ITEM, 1); infoForm.addCommand(continueCommand); infoForm.setCommandListener(this); skipCommand = new Command("Skip",Command.CANCEL,1); infoForm.addCommand(skipCommand); testStarted=false; testPassed=false; display.setCurrent(infoForm); } public void reShow(Display display){ display.setCurrent(infoForm); } public void commandAction(Command cmd, Displayable disp) { if(cmd==continueCommand){ if(!testStarted){ startTest(); infoForm.removeCommand(skipCommand); } else if(testPassed){ nextShowable.show(Display.getDisplay(movinoMidlet)); } } else if(cmd==skipCommand){ nextShowable.show(Display.getDisplay(movinoMidlet)); } } public void startTest(){ if(testStarted) return; infoForm.removeCommand(continueCommand); testStarted=true; new Thread(this).start(); } public void run(){ infoForm.deleteAll(); infoForm.append("Be patient! This may take a while...\nPhone supports:\n"); String[] fs = Camera.getSnapshotFormatStrings(); for(int i=0;i<fs.length;i++){ infoForm.append(fs[i]+"\n"); } infoForm.setTicker(new Ticker("Testing...")); Vector cameras=new Vector(); for(int i=0;i<Camera.CAMERA_DEVICES.length;i++){ Camera cam = new Camera(Camera.CAMERA_DEVICES[i]); String mess = cam.testCamera(); if(isVerbose) infoForm.append(mess); if(cam.isAvailable() && cam.hasSnapshots()){ infoForm.append("found camera: "+Camera.CAMERA_DEVICES[i]+"\n"); cameras.addElement(cam); } } deviceCameras = new Camera[cameras.size()]; for(int i=0;i<deviceCameras.length;i++){ deviceCameras[i] = (Camera)cameras.elementAt(i); } infoForm.setTicker(null); //infoForm.deleteAll(); infoForm.append("Test is done\nFound "+cameras.size()+" camera(s)"); setDefaultOptions(); infoForm.addCommand(continueCommand); testPassed=true; writeToRMS(); } public void setDefaultOptions(){ if(deviceCameras.length>0){ Options.optionCamera = deviceCameras[0]; Options.optionSnapshotFormat = deviceCameras[0].getSnapshotFormats()[0]; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -