📄 commandresources.java
字号:
// Copyright (c) 2005 Sony Ericsson Mobile Communications AB
//
// This software is provided "AS IS," without a warranty of any kind.
// ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
// INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
//
// THIS SOFTWARE IS COMPLEMENTARY OF JAYWAY AB (www.jayway.se)
/*///////////////////////////////////////////////////////////////////////////////
//文档生成日期:2005.11.8
//
//(1)概述:
//类名称:CommandResources
//类说明:
// 提供各种资源的统一入口,比如图片、字符串。
//所在子系统:GetDynamicIP
//
//系统总描述:
本工程。
子系统描述:
.
//(2)历史记录:
//创建人: 郑昀(2005.11.8)
//联系我: Google Talk >> zhengyun@gmail.com
//Blogs: http://blog.csdn.net/zhengyun_ustc/以及http://www.cnblogs.com/zhengyun_ustc
//(3)版权声明:
//我这个版本的GetDynamicIP,
//j2me客户端代码仅仅允许您借鉴,但不得用于商业用途,除非得到郑昀本人的授权。本人保留所有权利。
////////////////////////////////////////////////////////////////////*/
package com.ultrapower.common;
import java.io.InputStream;
import java.util.Hashtable;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Image;
/**
* Primitive resource mapper.
*
* @author Peter Andersson & zhengyun
*/
public class CommandResources
{
// Image keys
private static final int OFFSET_IMG = 100;
public static final int IMG_LOGO = 100;
public static final int IMG_COMMAND = 101;
// Resource (sound) keys
private static final int OFFSET_SND = 200;
public static final int SND_MAIN_MIN = 200;
public static final int SND_SECONDARY_MIN = 201;
public static final int SND_MAIN_MAX = 209;
public static final int SND_SECONDARY_MAX = 210;
/** Image cache */
protected static Hashtable m_images = new Hashtable();
// Image resource names
protected static final String[] IMGNAME_MAP ={
"logo.png",
"command.png",
};
// Resource (audio) names
protected static final String[] RESOURCE_MAP = {
"http://218.249.90.118/toodou/changjin.1..amr",
"http://218.249.90.118/toodou/changjin.2..amr",
"http://218.249.90.118/toodou/changjin.3..amr",
"http://218.249.90.118/toodou/changjin.4..amr",
"http://218.249.90.118/toodou/changjin.5..amr",
"http://218.249.90.118/toodou/changjin.6..amr",
"http://218.249.90.118/toodou/changjin.7..amr",
"http://218.249.90.118/toodou/changjin.8..amr",
"http://218.249.90.118/toodou/changjin.9..amr",
"http://218.249.90.118/toodou/changjin.10..amr",
"http://218.249.90.118/toodou/changjin.11..amr",
};
/*
* 这是中国移动的WAP网关代理地址
*/
private final static String CMCC_GATEWAY = "http://10.0.0.172";
// 是否走CMWAP代理
private static boolean m_bCMWAPProxy = true;
/**
* Returns specified resource as stream
* @param resourceId The id of the resource.
* @return An inputstream to the resource.
*/
public static InputStream getMusicResource(int resourceId) throws Exception
{
System.out.println("getMusicResource resourceId>>" + resourceId);
resourceId = resourceId - OFFSET_SND;
String sResource = CommandResources.RESOURCE_MAP[resourceId];
/////////////////////////////////////////////
/*
* 下面的代码经我修改是为了走cmwap代理连接互联网
*
* 举个例子:
* 走cmwap代理:sRequestURL=http://10.0.0.172/toodou/changjin.11..amr
走cmwap代理:X-Online-Host=http://218.249.90.118:80
*/
// zhengyun added 20060328
int nPosIndex = -1;
String sServerIp = "";
String sSuffix = "";
String sRequestURL = "";
if(m_bCMWAPProxy == true)
{
if(sResource.startsWith("http://"))
{
nPosIndex = sResource.substring(7, sResource.length()).indexOf('/') + 7;
sServerIp = sResource.substring(7, nPosIndex); // -> www.j2medev.com
}
else
{
nPosIndex = sResource.indexOf('/');
sServerIp = sResource.substring(0, nPosIndex); // -> www.j2medev.com
}
}
else{
sRequestURL = sResource;
System.out.println("走cmnet!");
}
sSuffix = sResource.substring(nPosIndex); // -> /bbs/post.asp...
sRequestURL = CMCC_GATEWAY + sSuffix;
System.out.println("走cmwap代理:sRequestURL=" + sRequestURL);
HttpConnection conn =
(HttpConnection)Connector.open(sRequestURL);
conn.setRequestMethod(HttpConnection.GET);
// 注意X-Online-Host
if (m_bCMWAPProxy == true)
{
conn.setRequestProperty("X-Online-Host", sServerIp);
System.out.println("走cmwap代理:X-Online-Host=" + sServerIp);
}
System.out.println("getMusicResource>>远程资源链接:" +
sResource);
return (InputStream)conn.openInputStream();
}
/**
* Returns specified image.
* @param id The id of the image.
* @return An image.
*/
public static synchronized Image getImage(int id)
{
id -= OFFSET_IMG;
Image img = (Image)m_images.get(new Integer(id));
if (img == null)
{
try
{
img = Image.createImage("/res/icons/" + IMGNAME_MAP[id]);
System.out.println("get image:/res/icons/" + IMGNAME_MAP[id]);
m_images.put(new Integer(id), img);
}
catch (Exception e)
{
System.out.println("Error getting resource img " + IMGNAME_MAP[id]
+ ">>" + e.getMessage());
e.printStackTrace();
}
}
return img;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -