⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cameraform.java

📁 j2me写的google地图
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            }
        } else
        if(d == sizeForm)
        {
            if(c.getCommandType() == 4)
            {
                sizeMsg.setText("\nWait for testing size...");
                int i = sizeChoiceGroup.getSelectedIndex();
                String size = sizeChoiceGroup.getString(i);
                if(TestSize(size))
                {
                    mySettings.setStringProperty("photosize", size);
                    Alert a = new Alert("Photo Size", "Photo size has been set to " + size, null, AlertType.INFO);
                    myDisplay.setCurrent(a, this);
                } else
                {
                    mySettings.setStringProperty("photosize", "null");
                    Alert a = new Alert("Photo Size", "Size " + size + " not supported.", null, AlertType.ERROR);
                    myDisplay.setCurrent(a, this);
                }
            } else
            {
                myDisplay.setCurrent(this);
            }
        } else
        if(d == myImageCanvas)
        {
            if(c.getCommandType() == 3)
                myDisplay.setCurrent(this);
            else
            if(c.getLabel().startsWith("Clear"))
                flickr.clearToken();
            else
            if(!flickr.checkRegistration())
            {
                tokenForm = new Form(Labels.getL(108));
                tokenForm.append(Labels.getL(111));
                tf = new TextField(Labels.getL(110), "", 9, 5);
                tokenForm.append(tf);
                tokenForm.addCommand(new Command(Labels.getL(0), 4, 1));
                tokenForm.addCommand(new Command(Labels.getL(1), 3, 1));
                tokenForm.setCommandListener(this);
                myDisplay.setCurrent(tokenForm);
            } else
            {
                if(infoForm == null)
                    infoForm = getInfoForm();
                myDisplay.setCurrent(infoForm);
            }
        } else
        if(c.getCommandType() == 7)
        {
            myDisplay.setCurrent(previous);
            closeForm();
        } else
        if(c.getLabel().equals(Labels.getL(100)))
        {
            Thread t = new Thread(this);
            t.start();
        } else
        if(c.getLabel().equals(Labels.getL(101)))
            myDisplay.setCurrent(myImageCanvas);
        else
        if(c == sizeCommandSize)
        {
            if(sizeChoiceGroup == null)
            {
                sizeChoiceGroup = new ChoiceGroup(Labels.getL(112) + "\n\n", 1);
                sizeChoiceGroup.append("160 x 120", null);
                sizeChoiceGroup.append("320 x 240", null);
                sizeChoiceGroup.append("640 x 480", null);
                String memSize = GetPhotoSize();
                if(memSize != "null")
                    if(memSize.indexOf("160") > -1)
                        sizeChoiceGroup.setSelectedIndex(0, true);
                    else
                    if(memSize.indexOf("320") > -1)
                        sizeChoiceGroup.setSelectedIndex(1, true);
                    else
                    if(memSize.indexOf("640") > -1)
                        sizeChoiceGroup.setSelectedIndex(2, true);
                Command sizeCommandSizeOK = new Command("OK", 4, 0);
                sizeForm = new Form("Size");
                sizeForm.append(sizeChoiceGroup);
                sizeMsg = new StringItem("", "");
                sizeForm.append(sizeMsg);
                sizeForm.addCommand(sizeCommandSizeOK);
                sizeForm.setCommandListener(this);
            } else
            {
                sizeMsg.setText("");
                String memSize = GetPhotoSize();
                if(memSize != "null")
                    if(memSize.indexOf("160") > -1)
                        sizeChoiceGroup.setSelectedIndex(0, true);
                    else
                    if(memSize.indexOf("320") > -1)
                        sizeChoiceGroup.setSelectedIndex(1, true);
                    else
                    if(memSize.indexOf("640") > -1)
                        sizeChoiceGroup.setSelectedIndex(2, true);
            }
            myDisplay.setCurrent(sizeForm);
        }
    }

    private static Vector getEncodings()
    {
        Vector list = new Vector();
        String encodings = System.getProperty("video.snapshot.encodings");
        int i = 0;
        int j;
        for(int n = encodings.length(); i < n; i = j)
        {
            j = encodings.indexOf(' ', i);
            if(j == -1)
                j = n;
            list.addElement(encodings.substring(i, j));
            for(; j < n && encodings.charAt(j) == ' '; j++);
        }

        return list;
    }

    private String getDefaultEncoding()
    {
        return encodings.size() <= 0 ? null : (String)encodings.elementAt(0);
    }

    private String getBestEncoding(boolean addSize)
    {
        for(int i = encodings.size(); --i >= 0;)
        {
            String encoding = (String)encodings.elementAt(i);
            Hashtable map = new Hashtable();
            int j = 0;
            for(int n = encoding.length(); j < n;)
            {
                int k = encoding.indexOf('=', j);
                String key = encoding.substring(j, k);
                j = k + 1;
                k = encoding.indexOf('&', j);
                if(k == -1)
                    k = n;
                String value = encoding.substring(j, k);
                j = k + 1;
                map.put(key, value);
            }

            String enc = (String)map.get("encoding");
            if(enc != null)
            {
                enc = enc.toLowerCase();
                if(enc.indexOf("jpeg") != -1 || enc.indexOf("jpg") != -1)
                {
                    if(addSize)
                    {
                        String photoSize = GetPhotoSize();
                        if(photoSize != "null")
                            encoding = encoding + photoSize;
                    }
                    UtilMidp.addDebug("Encoding:" + encoding);
                    return encoding;
                }
            }
        }

        return getDefaultEncoding();
    }

    private String GetPhotoSize()
    {
        String size = mySettings.getStringProperty("photosize", "height=640&width=480");
        if(size.indexOf("x") > -1)
            return "&width=" + size.substring(0, size.indexOf("x") - 1) + "&height=" + size.substring(size.indexOf("x") + 2, size.length());
        else
            return "null";
    }

    private boolean TestSize(String size)
    {
        boolean esit = false;
        try
        {
            size = "&width=" + size.substring(0, size.indexOf("x") - 1) + "&height=" + size.substring(size.indexOf("x") + 2, size.length());
            String enc = getBestEncoding(false);
            for(int i = 0; i < 2; i++)
            {
                byte test[] = vc.getSnapshot(enc + size);
                Image img = Image.createImage(test, 0, test.length);
            }

            esit = true;
        }
        catch(Exception e)
        {
            esit = false;
        }
        return esit;
    }

    private void takeSnapshot()
    {
        try
        {
            UtilMidp.addDebug("Before the snapsjot");
            byteImage = vc.getSnapshot(getBestEncoding(true));
            UtilMidp.addDebug("After the snapshot disp:" + myDisplay + " Canvas:" + myImageCanvas);
            myDisplay.setCurrent(myImageCanvas);
            UtilMidp.addDebug("Before create image:" + byteImage.length);
            myImage = Image.createImage(byteImage, 0, byteImage.length);
            UtilMidp.addDebug("Create image ok");
            if(myImage.getWidth() > getWidth())
            {
                myImage = UtilMidp.getThumbnail(null, 0, 0, myImage, getWidth() - 10);
                m_displayImageDynamically = false;
            }
            UtilMidp.addDebug("Thumbnail ok...");
        }
        catch(Exception e)
        {
            log("Exception: " + e.toString());
            m_displayImageDynamically = true;
            e.printStackTrace();
            UtilMidp.showException(e);
        }
    }

    public void playerUpdate(Player player, String event, Object eventData)
    {
        log(" ** playerUpdate: " + event + " **");
    }

    public void log(String msg)
    {
        UtilMidp.addDebug(msg);
    }

    private Display myDisplay;
    private Displayable previous;
    private ImageCanvas myImageCanvas;
    private static Player myPlayer = null;
    private VideoControl vc;
    private Image myImage;
    private byte byteImage[];
    private Settings mySettings;
    private Flickr flickr;
    private Form tokenForm;
    private Form infoForm;
    private Form sizeForm;
    private TextField tf;
    private final Vector encodings = getEncodings();
    private MapCanvas theMap;
    private String name;
    private String tags;
    private String comment;
    private CameraForm theForm;
    private ChoiceGroup sizeChoiceGroup;
    private Command sizeCommandSize;
    private StringItem sizeMsg;
    private boolean m_displayImageDynamically;













}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -