📄 cameraform.java
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2008-6-16 11:19:02
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: CameraForm.java
package com.eightmotions.map.extra;
import com.eightmotions.map.*;
import com.eightmotions.mm.Flickr;
import com.eightmotions.util.*;
import java.io.PrintStream;
import java.util.Hashtable;
import java.util.Vector;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.VideoControl;
public class CameraForm extends Canvas
implements CommandListener, PlayerListener, Runnable
{
public class ImageCanvas extends Canvas
{
public void paint(Graphics g)
{
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
if(myImage != null)
{
if(m_displayImageDynamically)
UtilMidp.getThumbnail(g, 0, 0, myImage, getWidth() - 10);
else
g.drawImage(myImage, (getWidth() - myImage.getWidth()) / 2, (getHeight() - myImage.getHeight()) / 2, 20);
} else
{
g.setColor(0);
g.drawString(Labels.getL(113), getHeight() / 2, 10, 20);
}
}
public ImageCanvas(String title)
{
setTitle(title);
}
}
public CameraForm(Display d, Settings inSettings, MapCanvas inCanvas)
{
mySettings = null;
infoForm = null;
sizeForm = null;
theForm = this;
sizeChoiceGroup = null;
sizeCommandSize = new Command("Size", 1, 1);
m_displayImageDynamically = false;
theMap = inCanvas;
flickr = new Flickr(inSettings, "ab4f949b0c35426c587215a878670e31", "f38c5157eba3f373");
mySettings = inSettings;
myDisplay = d;
previous = d.getCurrent();
addCommand(new Command(Labels.getL(1), 7, 0));
addCommand(new Command(Labels.getL(100), 1, 1));
addCommand(new Command(Labels.getL(101), 1, 1));
addCommand(sizeCommandSize);
setCommandListener(this);
myImageCanvas = new ImageCanvas(Labels.getL(102));
myImageCanvas.addCommand(new Command(Labels.getL(49), 3, 0));
myImageCanvas.addCommand(new Command(Labels.getL(103), 4, 1));
myImageCanvas.addCommand(new Command(Labels.getL(104), 4, 1));
myImageCanvas.setCommandListener(this);
initPlayer();
}
public void run()
{
takeSnapshot();
}
protected void closeForm()
{
try
{
log("Stopping");
myPlayer.stop();
myPlayer.close();
myPlayer.deallocate();
myPlayer = null;
}
catch(Exception e)
{
log("Exception: " + e.toString());
}
}
public void paint(Graphics g1)
{
}
private void initPlayer()
{
if(myPlayer != null)
closeForm();
try
{
try
{
myPlayer = Manager.createPlayer("capture://image");
}
catch(Exception e)
{
myPlayer = Manager.createPlayer("capture://video");
}
myPlayer.addPlayerListener(this);
myPlayer.realize();
int width = getWidth();
int height = getHeight();
vc = (VideoControl)myPlayer.getControl("VideoControl");
VideoControl _tmp = vc;
vc.initDisplayMode(1, this);
if(vc != null)
{
try
{
vc.setDisplayLocation(2, 2);
vc.setDisplaySize(width - 4, height - 4);
vc.setVisible(false);
}
catch(Exception e)
{
vc.setDisplayFullScreen(true);
}
vc.setVisible(true);
}
myPlayer.start();
}
catch(Exception e)
{
log("Exception: " + e.toString());
}
}
public Form getInfoForm()
{
Form f = new Form("Photo informations");
f.append(new TextField("Name:", mySettings.getStringProperty("lastName", "J2memap"), 32, 0));
f.append(new TextField("Comment:", mySettings.getStringProperty("lastComment", "http://j2memap.landspurg.net GeoLocalized picture.."), 200, 0));
f.append(new TextField("Tags:", mySettings.getStringProperty("lastTags", ""), 200, 0));
f.addCommand(new Command("OK", 4, 1));
f.addCommand(new Command("Cancel", 3, 2));
f.setCommandListener(this);
return f;
}
public void sendingPhoto()
{
Thread t = new Thread(new Runnable() {
public void run()
{
try
{
String localtags = tags;
if(theMap.m_lastLocation != null)
localtags = localtags + " geotagged geo:lon=" + theMap.m_lastLocation.m_lon + " geo:lat=" + theMap.m_lastLocation.m_lat;
else
localtags = localtags + " geotagged geo:lon=" + theMap.getLon() + " geo:lat=" + theMap.getLat();
String id = flickr.SendPhoto(byteImage, name, comment, localtags, true);
myDisplay.setCurrent(theMap);
boolean ok;
if(id != null)
ok = flickr.sendLonLat(id, UtilMidp.toString(theMap.getLon()), UtilMidp.toString(theMap.getLat()));
Alert a;
if(id == null)
{
a = new Alert(Labels.getL(105), flickr.getLastErrorMsg(), null, AlertType.ERROR);
if(flickr.getLastErrorCode() == 98)
flickr.clearToken();
} else
{
a = new Alert(Labels.getL(106), "Id:" + id, null, AlertType.INFO);
OneLoc photoLoc;
if(theMap.m_lastLocation != null)
photoLoc = new OneLoc(theMap.m_lastLocation.m_lon, theMap.m_lastLocation.m_lat);
else
photoLoc = new OneLoc(theMap.getLon(), theMap.getLat());
photoLoc.name = name;
photoLoc.description = comment;
photoLoc.iconImage = UtilMidp.getThumbnail(null, 0, 0, myImage, 40);
theMap.listPlaces.addElement(photoLoc);
if(theMap.m_record)
{
String pictureUrl = "<img src=\"" + flickr.GetUrl(id) + "\" />";
photoLoc.description = pictureUrl;
System.out.println(" image name:" + photoLoc.imageName);
theMap.curSavedTrack.addLoc(photoLoc);
}
myImage = null;
byteImage = null;
}
myDisplay.setCurrent(theForm);
myDisplay.setCurrent(a);
}
catch(Exception e)
{
UtilMidp.addDebug("Error:" + e.toString());
Alert a = new Alert(Labels.getL(4), e.toString(), null, AlertType.ERROR);
a.setTimeout(-2);
myDisplay.setCurrent(a);
e.printStackTrace();
}
}
});
t.start();
}
public void doRegistration()
{
String tok = tf.getString();
if(!flickr.Registration(tok))
{
Alert a = new Alert(Labels.getL(108), flickr.getLastErrorMsg(), null, AlertType.ERROR);
myDisplay.setCurrent(a, tokenForm);
} else
{
myDisplay.setCurrent(myImageCanvas);
}
}
public void keyPressed(int keyCode)
{
if(getGameAction(keyCode) == 8)
{
Thread t = new Thread(this);
t.start();
}
}
public void commandAction(Command c, Displayable d)
{
if(d == tokenForm)
{
if(c.getCommandType() == 4)
{
Thread t = new Thread(new Runnable() {
public void run()
{
doRegistration();
}
});
t.start();
} else
{
myDisplay.setCurrent(myImageCanvas);
}
} else
if(d == infoForm)
{
if(c.getCommandType() == 4)
{
name = ((TextField)infoForm.get(0)).getString();
comment = ((TextField)infoForm.get(1)).getString();
tags = ((TextField)infoForm.get(2)).getString();
mySettings.setStringProperty("lastName", name);
mySettings.setStringProperty("lastComment", comment);
mySettings.setStringProperty("lastTags", tags);
Alert a = new Alert(Labels.getL(126), Labels.getL(109), null, AlertType.INFO);
a.setTimeout(-2);
myDisplay.setCurrent(a);
sendingPhoto();
} else
{
myDisplay.setCurrent(this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -