📄 utilmidp.java
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2008-6-16 11:25:43
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: UtilMidp.java
package com.eightmotions.util;
import henson.midp.Float;
import java.io.*;
import java.util.Hashtable;
import java.util.Vector;
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
// Referenced classes of package com.eightmotions.util:
// URLFetcher
public class UtilMidp
{
public UtilMidp()
{
}
public static void setDebug(boolean mode)
{
DEBUG = mode;
}
public static boolean checkAvail(String inClassName)
{
boolean res = false;
try
{
Class.forName(inClassName);
res = true;
}
catch(Throwable ex) { }
return res;
}
public static boolean checkProp(String inPropName)
{
boolean res = false;
if(System.getProperty(inPropName) != null)
res = true;
return res;
}
static Display getDisplay()
{
return m_display;
}
public static void MsgBox(String name, String text, AlertType type, int time)
{
Alert a = new Alert(name, text, null, type);
a.setTimeout(time);
if(!(m_display.getCurrent() instanceof Alert))
m_display.setCurrent(a, m_display.getCurrent());
}
public static boolean checkMIDP(MIDlet inMidlet)
{
m_midlet = inMidlet;
m_display = Display.getDisplay(m_midlet);
m_locationAware = checkProp("microedition.location.version");
System.out.println("JSR179 availibility:" + m_locationAware);
m_bluetoothEnabled = checkAvail("javax.bluetooth.LocalDevice");
m_obexEnabled = checkAvail("javax.obex.ServerRequestHandler");
m_isFileAPIEnabled = checkAvail("javax.microedition.io.file.FileConnection");
System.out.println("JSR075 availibility:" + m_isFileAPIEnabled);
isMIDP2 = checkAvail("javax.microedition.lcdui.game.GameCanvas");
m_smallFont = Font.getFont(64, 0, 8);
return isMIDP2;
}
public static boolean isRIM()
{
return System.getProperty("microedition.platform").startsWith("RIM");
}
public static void addDebug(String text)
{
if(DEBUG)
addInfo(text);
}
public static void addInfo(String text)
{
System.out.println(text);
debugInfo.append(text);
if(os != null)
try
{
os.write((text + "\n").getBytes());
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
public static Image ImagecreateImage(InputStream is)
{
Image ima = null;
byte b[] = null;
if(m_useOldFormImage)
{
ByteArrayOutputStream bo = new ByteArrayOutputStream();
try
{
do
{
int c = is.read();
if(c == -1)
break;
bo.write(c);
} while(true);
b = bo.toByteArray();
ima = Image.createImage(b, 0, b.length);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("CA MERDE... length:" + b.length);
}
} else
{
try
{
ima = Image.createImage(is);
}
catch(IOException e)
{
m_useOldFormImage = true;
System.out.println("GOT AN EXCEPTION DURING createImage with Stream, falling back to old mode");
}
}
return ima;
}
static Image loadImage(String inUrl, String documentBase)
{
Image res = null;
try
{
HttpConnection cnx = null;
int nbredirects = 0;
int status = -1;
while(nbredirects++ < 10)
{
cnx = URLFetcher.open(inUrl);
cnx.setRequestMethod("GET");
status = cnx.getResponseCode();
HttpConnection _tmp = cnx;
if(status != 307)
{
HttpConnection _tmp1 = cnx;
if(status != 302)
{
HttpConnection _tmp2 = cnx;
if(status != 301)
break;
}
}
inUrl = cnx.getHeaderField("Location");
cnx.close();
}
if(status == 200)
{
InputStream is = cnx.openInputStream();
res = ImagecreateImage(is);
}
}
catch(Exception e)
{
showException(e);
}
return res;
}
public static void setIndicator(Alert a, Gauge g)
{
if(!isRIM())
a.setIndicator(g);
}
public static void updateGauge(Gauge inGauge)
{
inGauge.setValue(3);
}
static void notSupported(String inWhat)
{
System.out.println("MIDP1.0: " + inWhat + " is not supported...");
}
public static String[] explode(String theString)
{
return explode(theString, '!');
}
public static String[] explode(String theString, char separator)
{
Vector v = new Vector();
int current = 0;
do
{
int next = theString.indexOf(separator, current);
String sub = "";
if(next != -1)
sub = theString.substring(current, next);
else
sub = theString.substring(current);
if(DEBUG)
System.out.println("----------Explode:" + sub);
current = next + 1;
v.addElement(sub);
} while(current != 0);
String exp[] = new String[v.size()];
for(int i = 0; i < exp.length; i++)
exp[i] = (String)v.elementAt(i);
return exp;
}
public static String implode(ChoiceGroup cg, String currentSel)
{
String res = currentSel;
for(int i = 0; i < cg.size() && i < 5; i++)
{
String cur = cg.getString(i);
if(!cur.equals(currentSel))
res = res + "!" + cur;
}
return res;
}
public static void showException(Exception e)
{
e.printStackTrace();
MsgBox("ERROR", e.toString(), AlertType.ALARM, -2);
}
public static boolean platformRequest(String url)
throws ConnectionNotFoundException
{
return m_midlet.platformRequest(url);
}
public static Image getThumbnail(Graphics g, int inx, int iny, Image inIma, int width)
{
return getThumbnail(g, inx, iny, inIma, width, false);
}
public static Image getThumbnail(Graphics g, int inx, int iny, Image inIma, int width, boolean processAlpha)
{
int imaWidthS = inIma.getWidth();
int imaHeightS = inIma.getHeight();
int height = (inIma.getHeight() * width) / inIma.getWidth();
Image res = null;
if(g == null)
{
res = Image.createImage(width, height);
g = res.getGraphics();
inx = 0;
iny = 0;
}
int datas[] = new int[imaWidthS];
int datad[] = new int[width];
int array[] = new int[width];
for(int j = 0; j < width; j++)
array[j] = (j * imaWidthS) / width;
int curLine = -1;
for(int i = 0; i < height; i++)
{
int line = (i * imaHeightS) / height;
if(line != curLine)
{
inIma.getRGB(datas, 0, imaWidthS, 0, line, imaWidthS, 1);
curLine = line;
for(int j = 0; j < width; j++)
datad[j] = datas[array[j]];
}
g.drawRGB(datad, 0, width, inx, iny + i, width, 1, processAlpha);
}
return res;
}
public static String urlEncode(String inUrl)
{
StringBuffer res = new StringBuffer();
for(int i = 0; i < inUrl.length(); i++)
{
char c = inUrl.charAt(i);
switch(c)
{
case 32: // ' '
case 38: // '&'
case 40: // '('
case 41: // ')'
case 58: // ':'
case 63: // '?'
case 64: // '@'
res.append("%" + Integer.toHexString(c));
break;
default:
res.append(c);
break;
}
}
return res.toString();
}
public static String toString(Float f)
{
return f.toString();
}
public static String strReplace(String inString, String inPattern, int inVal)
{
int index = inString.indexOf(inPattern);
if(index != -1)
return inString.substring(0, index) + Integer.toString(inVal) + inString.substring(index + inPattern.length());
else
return inString;
}
public static String strReplace(String inString, String inPattern, String inVal)
{
int index = inString.indexOf(inPattern);
if(index != -1)
return inString.substring(0, index) + inVal + inString.substring(index + inPattern.length());
else
return inString;
}
public static String strReplace(String inString, String inPattern, Float infloat)
{
int index = inString.indexOf(inPattern);
if(index != -1)
return inString.substring(0, index) + infloat + inString.substring(index + inPattern.length());
else
return inString;
}
public static String decode_entities(String inString)
{
if(inString == null)
return null;
int pos = inString.indexOf('&');
if(pos != -1)
{
int prev = 0;
StringBuffer res = new StringBuffer();
do
{
pos = inString.indexOf('&', prev);
if(pos == -1)
{
res.append(inString.substring(prev));
} else
{
res.append(inString.substring(prev, pos));
int quote = inString.indexOf(';', pos);
if(quote == -1)
return inString;
String deb = inString.substring(pos, quote);
String repl = "";
if(deb.startsWith("'"))
repl = "'";
if(deb.startsWith("&"))
repl = "&";
if(deb.startsWith("<"))
repl = "<";
if(deb.startsWith("""))
repl = "\"";
if(deb.startsWith(">"))
repl = ">";
if(deb.startsWith("&hellip"))
repl = "...";
res.append(repl);
prev = quote + 1;
}
} while(pos != -1);
return res.toString();
} else
{
return inString;
}
}
public static String checkString(String inDesc)
{
if(inDesc == null)
return null;
StringBuffer res = new StringBuffer();
if(inDesc.indexOf('<') == -1)
return decode_entities(inDesc);
boolean readIt = true;
for(int i = 0; i < inDesc.length(); i++)
{
char c = inDesc.charAt(i);
if(c == '<')
{
readIt = false;
continue;
}
if(c == '>')
{
readIt = true;
continue;
}
if(readIt)
res.append(c);
}
return decode_entities(res.toString());
}
public static String getImgUrl(String inDesc)
{
String res = null;
if(inDesc == null)
return null;
int pos = inDesc.indexOf("<img");
if(pos != -1)
{
pos = inDesc.indexOf("src=\"", pos);
if(pos != -1)
{
pos += 5;
int endPos = inDesc.indexOf("\"", pos + 1);
if(endPos != -1)
{
res = inDesc.substring(pos, endPos);
System.out.println("Found:" + res);
}
}
}
return res;
}
public static Hashtable getUrlParams(String request)
{
Hashtable res = new Hashtable();
int deb = request.indexOf('?');
if(deb != -1)
{
String values[] = explode(request.substring(deb + 1), '&');
for(int i = 0; i < values.length; i++)
{
String tmp[] = explode(values[i], '=');
System.out.println("Addind:" + tmp[0] + " : " + decode_entities(tmp[1]));
res.put(tmp[0], decode_entities(tmp[1]));
}
}
return res;
}
public static Float parseFloat(String inString)
{
return Float.parse(inString, 10);
}
public static String urlServices = "";
public static boolean m_useOldFormImage = false;
public static boolean DEBUG = true;
public static boolean isMIDP2 = true;
public static boolean isCLDC11 = true;
public static StringBuffer debugInfo = new StringBuffer();
public static boolean m_locationAware = false;
public static boolean m_bluetoothEnabled = false;
public static boolean m_obexEnabled = false;
public static boolean m_isFileAPIEnabled = false;
public static Display m_display;
public static Font m_smallFont;
static OutputStream os = null;
public static MIDlet m_midlet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -