📄 locationbasedservice.java
字号:
float scale = svgCanvas.getHeight() / initialBBox.getWidth();
svg.setCurrentScale(scale);
// Move the origin to bthe bottom left of the display.
SVGPoint pan = svg.getCurrentTranslate();
pan.setX(-initialBBox.getY() * scale);
pan.setY(svgCanvas.getHeight());
} else {
svg.setCurrentRotate(0);
SVGPoint pan = svg.getCurrentTranslate();
pan.setX(0);
pan.setY(0);
svg.setCurrentScale(1);
}
}
});
}
} else if (keyCode == KEY_HELP) {
if (splashCanvas != null) {
// If the demo is playing, pause it
final boolean wasPaused = paused;
if (state == STATE_PLAYING) {
paused = true;
}
// Show the splashCanvas for a little while.
Display.getDisplay(this).setCurrent(splashCanvas);
Thread th =
new Thread() {
public void run() {
System.err.println("Starting to sleep");
try {
Thread.currentThread().sleep(SPLASH_MIN_LENGTH);
} catch (InterruptedException ie) {
}
System.err.println("done sleeping");
Display.getDisplay(LocationBasedService.this).setCurrent(svgCanvas);
if (!wasPaused) {
paused = false;
}
}
};
th.start();
}
}
}
public void run() {
step.run();
}
class InitialDisplay implements Runnable {
long start = 0;
long pauseFor = 3000;
long animSteps = 5;
long curAnimStep = 0;
public void run() {
if (start == 0) {
start = System.currentTimeMillis();
// Hide markers and connectors
for (int i = 0; i < markers.length; i++) {
markers[i].setTrait("visibility", "hidden");
}
// Position initial message
messageX = initialVB.getX() + (initialVB.getWidth() / 2);
messageY = initialVB.getY() + (initialVB.getHeight() / 2);
message.setFloatTrait("x", messageX);
message.setFloatTrait("y", messageY);
message.setTrait("#text", "Your Itinerary");
float fontSize = 40;
message.setFloatTrait("font-size", fontSize);
messageBackground.setFloatTrait("x", initialVB.getX() + 20);
messageBackground.setFloatTrait("y",
(initialVB.getY() + (initialVB.getHeight() / 2)) - fontSize);
messageBackground.setFloatTrait("width", initialVB.getWidth() - 40);
messageBackground.setFloatTrait("height", (3 * fontSize) / 2);
message.setTrait("visibility", "visible");
messageBackground.setTrait("visibility", "visible");
curAnimStep = 0;
} else {
// Animate the viewbox to the first locationBasedService point
long curTime = System.currentTimeMillis();
long aLength = curTime - start;
float messageFontSize = 6;
if (aLength > pauseFor) {
message.setTrait("visibility", "hidden");
messageBackground.setTrait("visibility", "hidden");
if (curAnimStep >= animSteps) {
LocationBasedService.this.step = locationBasedServiceAnim;
start = 0;
message.setFloatTrait("font-size", messageFontSize);
} else {
float p = (curAnimStep + 1) / (float)animSteps;
SVGRect vb = svg.getRectTrait("viewBox");
float[] coord = (float[])points[0][0];
vb.setX(coord[0] - 40);
vb.setY(coord[1] - 40);
vb.setWidth(80);
vb.setHeight((vb.getWidth() * initialVB.getHeight()) / initialVB.getWidth());
vb.setX(initialVB.getX() + (p * (vb.getX() - initialVB.getX())));
vb.setY(initialVB.getY() + (p * (vb.getY() - initialVB.getY())));
vb.setWidth(initialVB.getWidth() +
(p * (vb.getWidth() - initialVB.getWidth())));
vb.setHeight(initialVB.getHeight() +
(p * (vb.getHeight() - initialVB.getHeight())));
svg.setRectTrait("viewBox", vb);
curAnimStep++;
}
}
}
}
}
class LocationBasedServiceAnim implements Runnable {
int cur = 0;
long start = 0;
long pauseFor = 1500;
long animateFor = 2000;
int curAnimStep = 0;
int animSteps = 5;
float messageFontSize = 6;
public void run() {
if (cur == LocationBasedService.this.points.length) {
cur = 0;
LocationBasedService.this.step = finalDisplay;
} else {
if (start == 0) {
// Show the new marker
markers[cur].setTrait("visibility", "visible");
// Show the connector line to the next marker
// if there is a next marker, i.e except the last
// marker.
if (cur < connectors.length) {
connectors[cur].setTrait("visibility", "visible");
connectors[cur].setFloatTrait("x2", connectors[cur].getFloatTrait("x1"));
connectors[cur].setFloatTrait("y2", connectors[cur].getFloatTrait("y1"));
}
// Set the viewbox to be around the new
// point of interest
SVGRect vb = svg.getRectTrait("viewBox");
float[] coord = (float[])points[cur][0];
vb.setX(coord[0] - 40);
vb.setY(coord[1] - 40);
vb.setWidth(80);
vb.setHeight((vb.getWidth() * initialVB.getHeight()) / initialVB.getWidth());
svg.setRectTrait("viewBox", vb);
// Show message
messageX = vb.getX() + (vb.getWidth() / 2);
messageY = (vb.getY() + vb.getHeight()) - 2;
message.setFloatTrait("x", messageX);
message.setFloatTrait("y", messageY);
message.setTrait("#text", (String)points[cur][1]);
messageBackground.setFloatTrait("x", vb.getX());
messageBackground.setFloatTrait("y", messageY - messageFontSize);
messageBackground.setFloatTrait("width", 80);
messageBackground.setFloatTrait("height", (4 * messageFontSize) / 3);
messageBackground.setTrait("visibility", "visible");
message.setTrait("visibility", "visible");
// Starting now
start = System.currentTimeMillis();
curAnimStep = 0;
} else {
long curTime = System.currentTimeMillis();
long aLength = curTime - start;
if (aLength > pauseFor) {
messageBackground.setTrait("visibility", "hidden");
message.setTrait("visibility", "hidden");
if ((cur == (LocationBasedService.this.points.length - 1)) ||
((aLength > pauseFor) && (curAnimStep >= animSteps))) {
cur++;
start = 0;
curAnimStep = 0;
messageBackground.setTrait("visibility", "hidden");
message.setTrait("visibility", "hidden");
} else {
SVGRect vb = svg.getRectTrait("viewBox");
float[] startCoord = (float[])points[cur][0];
float[] endCoord = (float[])points[cur + 1][0];
float p = (curAnimStep + 1) / (float)animSteps;
float x = startCoord[0] + (p * (endCoord[0] - startCoord[0]));
float y = startCoord[1] + (p * (endCoord[1] - startCoord[1]));
vb.setX(x - 40);
vb.setY(y - 40);
vb.setWidth(80);
vb.setHeight((vb.getWidth() * initialVB.getHeight()) / initialVB.getWidth());
connectors[cur].setFloatTrait("x2", x);
connectors[cur].setFloatTrait("y2", y);
svg.setRectTrait("viewBox", vb);
curAnimStep++;
}
}
}
}
}
}
class FinalDisplay implements Runnable {
long start = 0;
SVGRect startVB;
long animateFor = 2000;
long pauseFor = 3000;
boolean vpRestored = false;
public void run() {
if (start == 0) {
startVB = svg.getRectTrait("viewBox");
message.setTrait("#text", ((String)points[points.length - 1][1]));
start = System.currentTimeMillis();
vpRestored = false;
} else {
long curTime = System.currentTimeMillis();
if ((curTime - start) < animateFor) {
float p = (curTime - start) / (float)animateFor;
SVGRect vb = svg.getRectTrait("viewBox");
vb.setX(startVB.getX() + (p * (initialVB.getX() - startVB.getX())));
vb.setY(startVB.getY() + (p * (initialVB.getY() - startVB.getY())));
vb.setWidth(startVB.getWidth() +
(p * (initialVB.getWidth() - startVB.getWidth())));
vb.setHeight(startVB.getHeight() +
(p * (initialVB.getHeight() - startVB.getHeight())));
svg.setRectTrait("viewBox", vb);
} else if (!vpRestored) {
svg.setRectTrait("viewBox", initialVB);
vpRestored = true;
} else if ((curTime - start) > (animateFor + pauseFor)) {
start = 0;
step = initialDisplay;
paused = true;
for (int ci = 0; ci < connectors.length; ci++) {
connectors[ci].setTrait("visibility", "hidden");
}
for (int mi = 0; mi < markers.length; mi++) {
markers[mi].setTrait("visibility", "hidden");
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -