📄 bufferimage.java
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2008-6-16 11:20:38
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: BufferImage.java
package com.eightmotions.map;
import com.eightmotions.util.URLFetcher;
import com.eightmotions.util.UtilMidp;
import java.io.*;
import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
// Referenced classes of package com.eightmotions.map:
// MapCustomOverlay, BufferImageListener, bufferImageLoaded
public class BufferImage
{
class oneElemRms
{
int id;
int size;
oneElemRms()
{
}
}
public static void initBuffer()
{
if(!isInit)
{
m_cont = true;
first = null;
Thread t = new Thread(new Runnable() {
public void run()
{
try
{
Thread.sleep(2000L);
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
if(BufferImage.m_useRMS)
BufferImage.initRms();
while(BufferImage.m_cont)
try
{
if(!BufferImage.checkBuffer())
Thread.sleep(1000L);
else
Thread.sleep(100L);
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
t.start();
isInit = true;
}
}
private static void exerciseRms()
{
try
{
RecordStore s = RecordStore.openRecordStore("t-temp", true);
s.closeRecordStore();
RecordStore.deleteRecordStore("t-temp");
}
catch(Exception ignored) { }
}
public static void provideDisplay(Display display, Displayable displayable)
{
m_display = display;
m_displayable = displayable;
}
public static void stop()
{
m_cont = false;
}
protected static BufferImage getFirst()
{
return first;
}
protected static BufferImage pop()
{
if(UtilMidp.DEBUG)
System.out.println("Pop");
BufferImage res = first;
if(first != null)
first = first.next;
res.next = null;
count--;
return res;
}
protected static void push(BufferImage inIma)
{
inIma.next = first;
first = inIma;
count++;
}
protected static boolean deleteLast()
{
if(UtilMidp.DEBUG)
System.out.println("delete last");
boolean res = false;
BufferImage ima = removeLast();
if(ima != null)
{
ima.delete();
res = true;
}
return res;
}
protected static BufferImage removeLast()
{
if(UtilMidp.DEBUG)
System.out.println("remove last");
BufferImage ima = first;
BufferImage prev = null;
if(ima != null)
{
for(; ima.next != null; ima = ima.next)
prev = ima;
if(prev != null)
prev.next = null;
else
first = null;
count--;
}
return ima;
}
protected static void remove(BufferImage inIma)
{
if(UtilMidp.DEBUG)
System.out.println("remove " + inIma);
BufferImage current = first;
if(first == inIma)
{
first = inIma.next;
inIma.next = null;
count--;
return;
}
if(first != null)
for(; current.next != null; current = current.next)
if(current.next == inIma)
{
current.next = inIma.next;
inIma.next = null;
count--;
return;
}
}
public static void setBufferSize(int inSize)
{
if(UtilMidp.DEBUG)
System.out.println("Set buffer size:" + inSize + " current:" + m_nbIma);
while(count > inSize)
deleteLast();
m_nbIma = inSize;
}
public static void setVisibleSize(int inSize)
{
if(m_useRMS)
m_nbImaVis = inSize;
else
m_nbImaVis = m_nbIma;
}
public static void setImageListener(BufferImageListener inListen)
{
m_listener = inListen;
}
public static int getPending()
{
int pending = 0;
for(BufferImage ima = first; ima != null; ima = ima.next)
if(ima.state == 1)
pending++;
return pending;
}
protected BufferImage(int px, int py, int zoom, int typeSat, int inSize)
{
name = null;
numSat = 0;
buff = null;
state = 0;
rmsId = -1;
my_data = null;
next = null;
debugString = null;
String URL = "";
this.px = px;
this.py = py;
this.zoom = zoom;
numSat = typeSat;
size = inSize;
state = 1;
offx = 0;
offy = 0;
try
{
String n = "/cache/" + getCacheName();
if(UtilMidp.DEBUG)
System.out.println("checking:" + n);
Image image = Image.createImage(n);
if(UtilMidp.DEBUG)
System.out.println("OK----------");
name = n;
ima = image;
return;
}
catch(Exception e)
{
debugString = "not in file, id:" + rmsId;
}
if(ima != null)
return;
if(sizeSq == inSize)
{
URL = getSatURL(px / sizeSq, py / sizeSq, zoom, typeSat);
if(m_useProxy)
{
URL = "http://8motions.com/convert.php?in=jpg&out=png&url=" + UtilMidp.urlEncode(URL);
if(extraInfo != null)
URL = URL + extraInfo;
}
} else
{
int inSqx = px % sizeSq;
int inSqy = py % sizeSq;
offx = (inSqx / inSize) * inSize;
offy = (inSqy / inSize) * inSize;
URL = getSatURL(px / sizeSq, py / sizeSq, zoom, typeSat);
if(!m_modePacked)
URL = "http://8motions.com/convert.php?in=" + (typeSat % 2 != 1 ? "png" : "jpg") + "&out=png&offx=" + offx + "&offy=" + offy + "&sizex=" + inSize + "&sizey=" + inSize + "&url=" + UtilMidp.urlEncode(URL);
if(UtilMidp.DEBUG)
System.out.println("URL:" + URL);
}
name = URL;
}
public String getCacheName()
{
return px / size + "-" + py / size + "-" + zoom + "-" + numSat + "-" + size;
}
public static String computeQuadrantString(int x, int y, int z, char tab[])
{
int ya = 1 << 17 - z;
StringBuffer str = new StringBuffer();
for(int i = 16; i >= z; i--)
{
ya /= 2;
if(y < ya)
{
if(x < ya)
{
str.append(tab[0]);
} else
{
str.append(tab[1]);
x -= ya;
}
continue;
}
if(x < ya)
{
str.append(tab[2]);
y -= ya;
} else
{
str.append(tab[3]);
x -= ya;
y -= ya;
}
}
return str.toString();
}
protected String getSatURL(int x, int y, int z, int inNumSat)
{
String res = null;
boolean isSat = false;
if(inNumSat % 2 == 1)
isSat = true;
switch(numSat)
{
default:
break;
case 0: // '\0'
res = "http://mt.google.com/mt?v=" + GOOGLE_MAP_VERSION + "&x=" + x + "&y=" + y + "&zoom=" + z;
break;
case 6: // '\006'
case 7: // '\007'
res = numSat == 6 ? "http://png.maps.yimg.com/png?v=3.1.0" : "http://aerial.maps.yimg.com/tile?v=1.4&t=a";
res = res + "&x=" + x + "&y=" + (((1 << 17 - z) >> 1) - 1 - y) + "&z=" + (z + 1);
break;
case 4: // '\004'
case 5: // '\005'
int div = 1 << 17 - z;
int cellX = x - div / 2;
int cellY = y - div / 2;
String type = "map/";
if(isSat)
type = "sat/";
res = "http://tiles.ask.com/" + type + (z + 2) + "/" + cellX + "/" + cellY;
break;
case 8: // '\b'
case 9: // '\t'
if(m_customOverlay != null)
res = m_customOverlay.getTileURL(x, y, z, sizeSq, inNumSat != 8);
break;
case 1: // '\001'
case 2: // '\002'
case 3: // '\003'
int ya = 1 << 17 - z;
if(y < 0 || ya - 1 < y)
return "http://www.google.com/mapfiles/transparent.gif";
if(x < 0 || ya - 1 < x)
{
x %= ya;
if(x < 0)
x += ya;
}
StringBuffer str = new StringBuffer();
char tab[];
if(inNumSat == 1)
{
tab = tabIdxGoogle;
str.append("http://kh.google.com/kh?v=" + GOOGLE_SAT_VERSION + "&t=t");
} else
{
tab = tabIdxVearth;
str.append("http://");
if(inNumSat == 3)
str.append("h0");
else
str.append("r0");
str.append(".ortho.tiles.virtualearth.net/tiles/");
if(inNumSat == 3)
str.append('h');
else
str.append('r');
}
str.append(computeQuadrantString(x, y, z, tab));
char num = str.charAt(str.length() - 1);
if(inNumSat == 3)
str.append(".jpg?g=1");
else
if(inNumSat == 2)
str.append(".png?g=1");
res = str.toString();
break;
}
return res;
}
protected static String changeCar(String res)
{
StringBuffer tmp = new StringBuffer();
for(int i = 0; i < res.length(); i++)
{
char c = res.charAt(i);
if(c == '&')
tmp.append("%26");
else
tmp.append(c);
}
return tmp.toString();
}
public static void cleanBuffer()
{
if(UtilMidp.DEBUG)
System.out.println("SYNCHRO: clean buffer");
for(BufferImage l = first; l != null; l = l.next)
{
if(l.state != 1 && l.state != 2)
continue;
if(l.rmsId != -1)
l.state = 5;
else
l.state = 6;
}
if(UtilMidp.DEBUG)
System.out.println("SYNCHRO: clean buffer done");
}
public static void deleteCache()
{
while(first != null)
deleteLast();
}
protected static int getNum(byte tab[], int offset, int length)
{
int res;
int val;
for(res = 0; length-- > 0; res = (res << 8) + val)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -