星期四, 六月 26, 2008

My daughter was born on May 23, 2008

Welcome to my daughter's photo album: xuyichun.yupoo.com
Here is a piece of her photos

星期二, 十二月 25, 2007

DictDroid (English<->Chinese)

What will it look like:
DictDroid


What will it support:
English to Chinese, or Chinese to English (current Android is unable to input Chinese)

The Full Source:
/res/layout/main.xml
1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent"
6 >
7<TextView
8 android:layout_width="fill_parent"
9 android:layout_height="wrap_content"
10 android:text="Input a word:"
11 />
12
13<EditText id="@+id/edit1"
14 android:layout_width="fill_parent"
15 android:layout_height="wrap_content"
16 android:hint="English or Chinese word"
17 android:singleLine="true"
18 android:numeric="false"
19 />
20<Button id="@+id/button1"
21 android:layout_width="fill_parent"
22 android:layout_height="wrap_content"
23 android:text="Consult"
24 />
25<TextView
26 android:layout_width="fill_parent"
27 android:layout_height="wrap_content"
28 android:text="Result:"
29 />
30
31<EditText id="@+id/edit2"
32 android:layout_width="fill_parent"
33 android:layout_height="fill_parent"
34 android:layout_weight="1"
35 />
36
37</LinearLayout>
38


/res/values/string.xml
1<?xml version="1.0" encoding="utf-8"?>
2<resources>
3 <string name="app_name">Dictionary</string>
4 <string name="api_url">http://dict.cn/ws.php?q=</string>
5 <string name="consult">Consult</string>
6 <string name="sentences">例句与用法:</string>
7</resources>
8


/src/your_package_structure/DictDroid.java
1package com.anthony.DictDroid;
2
3import java.io.IOException;
4import java.io.InputStream;
5import java.io.InputStreamReader;
6import java.io.Reader;
7import java.io.UnsupportedEncodingException;
8import java.net.HttpURLConnection;
9import java.net.URL;
10import javax.xml.parsers.DocumentBuilder;
11import javax.xml.parsers.DocumentBuilderFactory;
12
13import org.w3c.dom.Document;
14import org.w3c.dom.Element;
15import org.w3c.dom.NodeList;
16import org.xml.sax.InputSource;
17
18import android.app.Activity;
19import android.os.Bundle;
20import android.util.Log;
21import android.view.View;
22import android.view.View.OnClickListener;
23import android.widget.Button;
24import android.widget.EditText;
25
26public class DictDroid extends Activity {
27 /** Called when the activity is first created. */
28 private final String TAG = "DictDroid";
29
30 @Override
31 public void onCreate(Bundle icicle) {
32 super.onCreate(icicle);
33 setContentView(R.layout.main);
34
35 ((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {
36
37 @Override
38 public void onClick(View v) {
39 EditText queryWord = (EditText)findViewById(R.id.edit1);
40 String query = queryWord.getText().toString().trim();
41 if (query.equals("")) {
42 queryWord.setText("");
43 queryWord.requestFocus();
44 return;
45 }

46
47 ((Button)v).setText(getText(R.string.consult)+"...");
48
49 EditText responseContent = (EditText)findViewById(R.id.edit2);
50 responseContent.setText("");
51
52 try {
53 String queryStr;
54
55 if (isEnglish(query)) {
56 queryStr = query.replace(" ", "%20");
57 }
else {
58 queryStr = encode2Gbk(query);
59 }

60
61 Log.i(TAG, getText(R.string.api_url)+queryStr);
62 URL url = new URL(getText(R.string.api_url)+queryStr);
63 HttpURLConnection http = (HttpURLConnection)url.openConnection();
64 http.setRequestMethod("GET");
65 http.connect();
66
67 InputStream inputstream = null;
68
69 try {
70 inputstream = http.getInputStream();
71 }
catch (IOException e) {
72 Log.e(TAG, "getInputStream error");
73 }

74
75 Reader reader = null;
76 InputSource inputsource = null;
77 try {
78 reader = new InputStreamReader(inputstream, "gb2312");
79 }
catch (UnsupportedEncodingException e) {
80 Log.e(TAG, "new InputStreamReader UnsupportedEncodingException");
81 }
catch (Exception e) {
82 Log.e(TAG, "new InputStreamReader error");
83 }

84
85 try {
86 inputsource = new InputSource(reader);
87 }
catch (Exception e) {
88 Log.e(TAG, "new InputSource error");
89 }

90
91 try{
92 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
93 DocumentBuilder db = dbf.newDocumentBuilder();
94 Document doc = db.parse(inputsource);
95
96 // pron
97 NodeList pronList = doc.getElementsByTagName("pron");
98 Log.i(TAG, "pron count: "+pronList.getLength());
99
100 String prons = query+":";
101 for (int i=0; i<pronList.getLength(); i++) {
102 Element pronEl = (Element)doc.getElementsByTagName("pron").item(i);
103 String aPron = pronEl.getChildNodes().item(0).getNodeValue();
104 Log.i(TAG, "pron["+i+"]: "+aPron);
105 prons += " ["+aPron+"]";
106 }

107
108 // def
109 NodeList defList = doc.getElementsByTagName("def");
110 Log.i(TAG, "def count: "+defList.getLength());
111
112 String defs = "";
113 for (int i=0; i<defList.getLength(); i++) {
114 Element defEl = (Element)doc.getElementsByTagName("def").item(i);
115 String aDef = defEl.getChildNodes().item(0).getNodeValue();
116 Log.i(TAG, "def["+i+"]: "+aDef);
117 defs += aDef;
118 }

119
120 // sent
121 NodeList sentList = doc.getElementsByTagName("sent");
122 Log.i(TAG, "sent count: "+sentList.getLength());
123
124 String sents = getText(R.string.sentences).toString();
125 for (int i=0; i<sentList.getLength(); i++) {
126 Element sentEl = (Element)doc.getElementsByTagName("sent").item(i);
127 String orig =
128 sentEl.getElementsByTagName("orig").item(0).getChildNodes().item(0).getNodeValue().replace("\n", " ").trim();
129 String trans =
130 sentEl.getElementsByTagName("trans").item(0).getChildNodes().item(0).getNodeValue().replace("\n", " ").trim();
131 Log.i(TAG, "orig["+i+"]: "+orig);
132 Log.i(TAG, "trans["+i+"]: "+trans);
133 int j = i+1;
134 String aSent = "\n"+j+". "+orig+"\n "+trans;
135 sents += aSent;
136 }

137
138 String atall = prons + "\n\n" + defs + "\n\n" + sents.toString();
139 responseContent.setText(atall);
140 ((Button)v).setText(getText(R.string.consult));
141 }
catch (Exception e){
142 Log.e(TAG, "Exception 1: "+e.toString());
143 }

144 }
catch (Exception e){
145 Log.e(TAG, "Exception 2: "+e.toString());
146 }

147 }

148 }
);
149 }

150
151 public boolean isEnglish(String source) {
152 int unicode = source.codePointAt(0);
153 if ((unicode>='A' && unicode<='Z') || (unicode>='a' && unicode<='z') || unicode==' ') {
154 return true;
155 }
else {
156 return false;
157 }

158 }

159
160 public String encode2Gbk(String source) throws Exception {
161 for (int i=0; i<source.length(); i++) {
162 int unicode = source.codePointAt(i);
163 if ((unicode>='A' && unicode<='Z') || (unicode>='a' && unicode<='z')) {
164 throw new Exception("The string needn't do encoding");
165 }

166 }

167
168 byte[] queryBytes = source.getBytes("gb2312");
169 String destination = "";
170 for (int i=0; i<queryBytes.length; i++) {
171 String temp = Integer.toHexString(queryBytes[i]);
172 destination += "%"+temp.substring(temp.length()-2);
173 }

174
175 return destination;
176 }

177}

星期二, 八月 28, 2007

猜一猜

此图的装置是干什么用的?

文字说明一下:像个化学试验中盛液体的三角锥,可是底下是一个大大的窟窿,而且窟窿边缘往上翘起

 

星期二, 六月 05, 2007

吴鹰:我没想走,我不是逃兵(ZT)

http://blog.sina.com.cn/u/53847641010009hy

Palm的命运:它为何未能持久成功?

以下为转贴内容:
http://www.mindmeters.com/showlog.asp?log_id=5623
个人以为Palm走到现在这一步还有以下原因:
  1. 微软Windows操作系统向终端的延伸。Windows占领了桌面后,随即往终端延伸,这能够无缝的让桌面用户过渡到终端,特别在中国,D版更是为Windows打下了整个桌面江山,Windows Mobile上的D版依然兴旺,这也一样可以为微软打下终端这片新江山。从中国市场看,Symbian的前途也未必光明。
  2. Palm的消费群定位有些许问题。即做不到微软的“让每个人的桌上有一台电脑”,也做不到苹果的引领时尚。

星期五, 五月 25, 2007

他们想让别人学好,好自己偷偷使坏

最近一直没认真写点东西,即使流水账也没有,对不住关心自己的朋友了。
还是转点东西吧,留几个字也表示我的博客还活着,呵呵。
格老不是活雷锋
(http://www.daynew.net/?p=401)

是一个很政治化的家伙写的一篇博闻,角度很特别哦。

星期一, 五月 14, 2007

简直就是IT版的《激情燃烧的岁月》

转贴自->文艺复兴人 (http://www.edimsum.net/archives/vagabond/2007/05/iaeooeeeee.html)
非常精彩,值得一看,激情是能够感染他人的,自己也可以被他人感染(废话,呵呵)
最近没有写博,因为工作上比较忙,又过51,又看看疯狂的股市,时间就这么过去了

星期四, 四月 26, 2007

投行眼中:年销售30亿以下的民营企业的共同点(转载)

出处:http://blog.sina.com.cn/u/47665bc1010008l8

1. 企业家心比天高。坦率地说,这是优点,也是我们希望看到的。连士兵不想当元帅都不是好士兵,更不用说大将。这些企业家大多不到50岁,事业初具规模,行业地位初步确立,在业内和媒体上声名远播,再加上中国GDP连年两位数增长、本土市场迅速崛起的大背景,正是如鱼得水“心有多大舞台就有多大”的时候。因此,个个都有鸿鹄之志,每个人都觉得自己在不久的将来一定能做成一家世界级的企业。有些还真有可能。

2. 开始考虑战略问题。以 前都是机会驱动,现在开始考虑一些“我要成为一家什么样的企业”、“我的核心竞争力是什么”这样的战略问题。虽然一时半会还不可能完全转变为战略驱动,但 是那些有悟性的企业家至少会在一些不靠谱的“机会”到来的时候让战略的大图适度地平衡一下自己对短期利益头脑发热的追求。

3. 开始学着忽悠资本市场。企业发展到这个规模,势必开始引起投资人的关注。先是投资人主动上门忽悠,可企业家多聪明啊,结果被他们忽悠的企业家听多了也跟着学会了以忽悠对忽悠,甚至有过之而无不及。于是企业全面进入了与资本市场在忽悠与反忽悠中对接的时代。

4. 企业往往都处在节骨眼上。这些企业要么在从这条增长曲线到那条增长曲线的“拐点”上,要么在从这个商业模式到那个商业模式、或者从这个发展战略到那个发展战略的转型中,还有个别的竟然要一边拐着一边转。

5. 账面亏损或微利的,往往其实很赚钱。由于可以理解的原因,这些企业很多账面上都是亏损或微利的。这也不能全怪他们。

6. 但“很赚钱”还是没有企业家心里以为的那么赚钱。企业由于财务不规范,很多该付的费用没有付(如四险一金),因此企业真正经得起审计的盈利能力往往连企业家自己都不清楚。比较靠谱的估计是企业真实的盈利水平大都介于税务局看到的数字和企业家头脑中的数字之间。

7. 普遍没有财务预测能力。这个阶段的企业通常都还没有学会预算管理,不要说站在今年看明年,就是站在这个季度看这个季度有时候都会看走眼。财务预测能否准确,反映的其实不是公司财务预测的能力,而是精细化管理的能力。

8. 企业家往往公私不分。他们之所以能住着洋房开着名车却拿着区区一两万块钱甚至几千块钱的工资,就是因为他们习惯了把公司锅里的和自己碗里的混为一谈。这种状态下的企业,报表外交易和关联交易有多少,是一件用脚趾头想都能猜到的事。

9. 老板无比敬业。这些企业的老板们各有各的辛苦但是都很辛苦,他们往往事无巨细一手抓,没日没夜不休假。我时候我看着他们工作的状态,会觉得他们没有不成功的道理。但是再一想,又觉得他们要想有更大的成功,还真的需要改变一下这种状态。

10. 没有真正的股权激励。你问这些企业有没有员工激励计划,他们通常都说有。但是等你真的要求看相关的法律文件,又会发现这些计划其实只停留在企业家的脑海里。你爱一个人有时候只说不做时间长了对方都不干,更何况你要让人家跟着你发财了。

11. 都在喊“最缺的是人才”。这些公司往往都会说自己和二十一世纪一样最缺的是人才。问题是,全世界所有公司都面临的问题它还是问题吗?