| いける例 | ダメな例 |
| ほげほげ http://hoge.example.com/ | ほげほげhttp://hoge.example.com/ |
| フー http://foo.example.com/ | フー http:// foo.example.com |
| バー ttp://bar.example.com/ | バー ttp://bar.exampleドットコム |
| experimental版(1.0.2) | ダウンロード |
| ippen1.java |
import jp.jig.jiglet.*;
public class ippen1 extends Jiglet {
String tempLine;
public void paint(boolean allDrawFlag) {
setColor(0xffffff);
fillRect(0, 0, DW, DH);
setFont(FONT_SMALL);
setColor(0x000000);
drawString("今だか前だかのURL:", 0, getFontHeight() * 2);
if (tempLine != null) {
drawString(tempLine, 0, getFontHeight() * 4);
}
}
public void main() {
String defStr = "改行で区切ってURLの一覧を入力GO!(この文字列は消してね)";
String tempLine, list;
if (getKey() == EVENT_LAUNCHED) {
byte[] lp = getLaunchParameter();
if (lp != null) {
defStr = new String(lp);
}
}
list = inputText(defStr, TEXT_ALPHA);
if (list != null) {
// 行ごとに分割。行は\nでできてると仮定。
int i = 0, j = 0;
// 最後に改行を足す
list = list + "\n";
while ((j = list.indexOf("\n", i)) > i) {
tempLine = list.substring(i, j);
// 半角スペースも行の区切りとみなす
if (tempLine.indexOf(' ') >= 0) {
tempLine = tempLine.substring(0, tempLine.indexOf(' '));
j = i + tempLine.length();
}
// h抜きなどの場合、補完する
if (tempLine.startsWith("ttp://") || tempLine.startsWith("ttps://")) {
tempLine = "h" + tempLine;
}
if (tempLine.startsWith("tp://") || tempLine.startsWith("tps://")) {
tempLine = "ht" + tempLine;
}
if (tempLine.startsWith("p://") || tempLine.startsWith("ps://")) {
tempLine = "htt" + tempLine;
}
if (tempLine.startsWith("://") || tempLine.startsWith("s://")) {
tempLine = "http" + tempLine;
}
if (tempLine.startsWith("//")) {
tempLine = "http:" + tempLine;
}
// 念のため、行末をチェック(たぶんほとんどのケータイは\r\nで改行してる)
if (tempLine.charAt(tempLine.length() - 1) == '\r') {
tempLine = tempLine.substring(0, tempLine.length() - 1);
}
// 念のため、スキームをチェック(別に外しても構わないっちゃあ構わない)
if (tempLine.startsWith("http://") || tempLine.startsWith("https://")) {
launch(tempLine, ENCODE_NONE, LAUNCH_KEEP_ALIVE);
}
i = j + 1;
}
}
terminate();
}
}
|