?? commandresources.java
字號(hào):
// 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)概述:
//類(lèi)名稱(chēng):CommandResources
//類(lèi)說(shuō)明:
// 提供各種資源的統(tǒng)一入口,比如圖片、字符串。
//所在子系統(tǒng):GetDynamicIP
//
//系統(tǒng)總描述:
本工程。
子系統(tǒng)描述:
.
//(2)歷史記錄:
//創(chuàng)建人: 鄭昀(2005.11.8)
//聯(lián)系我: Google Talk >> zhengyun@gmail.com
//Blogs: http://blog.csdn.net/zhengyun_ustc/以及http://www.cnblogs.com/zhengyun_ustc
//(3)版權(quán)聲明:
//我這個(gè)版本的GetDynamicIP,
//j2me客戶(hù)端代碼僅僅允許您借鑒,但不得用于商業(yè)用途,除非得到鄭昀本人的授權(quán)。本人保留所有權(quán)利。
////////////////////////////////////////////////////////////////////*/
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",
};
/*
* 這是中國(guó)移動(dòng)的WAP網(wǎng)關(guān)代理地址
*/
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];
/////////////////////////////////////////////
/*
* 下面的代碼經(jīng)我修改是為了走cmwap代理連接互聯(lián)網(wǎng)
*
* 舉個(gè)例子:
* 走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>>遠(yuǎn)程資源鏈接:" +
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;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -