To put a string at a certain position, I wrote a simple java method.
Ex: firstSegLength = 20 , a = stringA, b = stringB
Output =stringA stringB
There are 13 space character between stringA and stringB.
public String string_alignment(int SegLength,String a,String b)
{
String output = null;
int len = a.length();
//Error check
if((SegLength < 1) || (a == null) || (b == null))
return null;
if(a.length() > (len - 1))
{
//should not be happened, case handle
}
int totallen = SegLength + b.length();
int sepLen = SegLength - len;
StringBuilder workstr = new StringBuilder();
//append first string
workstr.append(a);
//create space string
char seprator[] = new char[sepLen];
for(int i = 0;i < sepLen; i++)
{
seprator[i] = ' ';
}
//append the second string
workstr.append(seprator);
workstr.append(b);
output = workstr.toString();
return output;
}
2012年1月18日 星期三
2012年1月17日 星期二
Use Intent To pick system contact data
Call android to pop out an list for user to pick up a system contact data.
startActivityForResult(new Intent(Intent.ACTION_PICK,
android.provider.ContactsContract.Contacts.CONTENT_URI),user-defined);
System may do the following process.
Button pickButton=(Button)findViewById(R.id.pick_button);
pickButton.setOnclickListener(new View.OnClickListener(){
public void onClick(View view){
//Store the URI of the selected item
Uri data=Uri.parse(“content://horses/”+ selected_id);
Intent result=new Intent(null,data);
result.putExtra(IS_INPUT_CORRECT,inputCorrect);
result.putExtra(SELECTED_PISTOL,selectedPistol);
setResult(RESULT_OK,result);
finish();
}
});
Return the result to activity
protected void onActivityResult (int requestCode, int resultCode, Intent data)
{
//Abstract data from intent
Uri uriRet = data.getData()
boolean inputCorrect=data.getBooleanExtra( IS_INPUT_CORRECT,false);
String selectedPistol=data.getStringExtra( SELECTED_PISTOL);
}
startActivityForResult(new Intent(Intent.ACTION_PICK,
android.provider.ContactsContract.Contacts.CONTENT_URI),user-defined);
System may do the following process.
Button pickButton=(Button)findViewById(R.id.pick_button);
pickButton.setOnclickListener(new View.OnClickListener(){
public void onClick(View view){
//Store the URI of the selected item
Uri data=Uri.parse(“content://horses/”+ selected_id);
Intent result=new Intent(null,data);
result.putExtra(IS_INPUT_CORRECT,inputCorrect);
result.putExtra(SELECTED_PISTOL,selectedPistol);
setResult(RESULT_OK,result);
finish();
}
});
Return the result to activity
protected void onActivityResult (int requestCode, int resultCode, Intent data)
{
//Abstract data from intent
Uri uriRet = data.getData()
boolean inputCorrect=data.getBooleanExtra( IS_INPUT_CORRECT,false);
String selectedPistol=data.getStringExtra( SELECTED_PISTOL);
}
2012年1月12日 星期四
2012年1月11日 星期三
Creativity
Creativity seems to be an important thing in this fast changing world.
How to improve my creativity? Well, I do not have a good answer for it.
But I think if one knows lot of things and knowledge, he should be more creative.
It is because that he has lot of based points in his brain and it is easier for him to connect any two points in his brain. A connection of two or more points may be a creativity.
Creative could also be produced from discontent or inconvenience.
Anyway, creativity is really important.
Suffering
Again,it is suffering.
I know that i am not rich enough. But,i know i am not that bad. I have great potential and possibility. This homeless feeling is so bad. The place which you live is not yours. Just like a leaf moves along with the wind. I don`t know where to rest.
I know that i am not rich enough. But,i know i am not that bad. I have great potential and possibility. This homeless feeling is so bad. The place which you live is not yours. Just like a leaf moves along with the wind. I don`t know where to rest.
2012年1月10日 星期二
Working Holiday
Here is the table of the related information for working holiday.
I want to live abroad and feel the different culture.
But there are much things laid on my shoulder.
Data reference from http://www.104learn.com.tw/events/201111class/p02.htm
| 國家 | 期間 | 名額 | 資格 | 簽證費 | 受理單位 | 備註 | |
| 年齡 | 存款規定 (至少) | ||||||
| 紐西蘭 | 1年 | 600 | 18-30歲 | 4,200紐幣 | 120 紐幣 | ★紐西蘭商 工辦事處 | 同一雇主不可 受雇超過3個月 課程:一次最 長不超過3個月 |
| 澳洲 | 1年 | 不限 | 18-30歲 | 5000澳幣 | 270 澳幣 | ★澳大利亞 商工辦事處 | 可申請2次 工作:同一雇 主不可受雇超 過6個月 課程:一次最 長不超過4個月 |
| 日本 | 1年 | 2000 | 18-30歲 | 持有足以 維持停留 日本最初 期間之生 活所需費 用。 | 1100 台幣 | ★日本 交流協會 | 分兩階段申請 6月12月 課程:一次不 超過3個月 |
| 韓國 | 1年 | 400 | 18-30歲 | 3000美元 | 免費 | ★駐韓國 台北代表部 | 專門職不得 申請(醫師. 律師.教授) |
| 加拿大 | 1年 | 1000 | 18-35歲 | 2,500加幣 | 150 加幣 | ★加拿大駐 台北貿易辦 事處 | 打工度假950人 建教25人、 專業青年25人 |
| 德國 | 1年 | 200 | 18-30歲 | 2000歐元 | 60 歐元 | ★德國在 台協會 | 同一雇主不可 受雇超過3個月 |
| 英國 | 2年 | 1000 | 18-30歲 | 1600英鎊 | 9300 台幣 | ★英國貿易 文化辦事處 | 可從事全職工 作,可上任何 課程 需至 青輔會申請 有效贊助者 證明(certificate of sponsorship) |
2012年1月9日 星期一
Divide & Combine File -- SequenceInputStream
java.lang.Objectjava.io.InputStream
java.io.SequenceInputStream
Example of divide a file:filepath: the file to be separated.
size:the size of each separated file.
count: the number of separated file.
FileInputStream fileInputStream = new FileInputStream(new File(filepath)); BufferedInputStream bufInputStream = new BufferedInputStream(fileInputStream); byte[] data = new byte[1]; int count = 0; //Count the number of separated files. if(fileInputStream.available() % size == 0) count = fileInputStream.available() / size; else count = fileInputStream.available() / size + 1; for(int i = 0; i < count; i++) { int num = 0; File file = new File(filepath + "_" + (i + 1)); BufferedOutputStream bufOutputStream = new BufferedOutputStream( new FileOutputStream(file)); //Write the read-out data into a separated file while(bufInputStream.read(data) != -1) { bufOutputStream.write(data); //count the bytes of the separated file. num++; if(num == size) { bufOutputStream.flush(); bufOutputStream.close(); break; } } if(num < size) { bufOutputStream.flush(); bufOutputStream.close(); } }Example of combine separated files:filename: the path of the separated files locatenumber : the number of the separated files.List<InputStream> list = new ArrayList<InputStream>(); //collect the separated files for(int i = 0; i < number; i++) { File file = new File(filename + "_" + (i+1)); list.add(i, new FileInputStream(file)); } final Iterator<InputStream> iterator = list.iterator(); Enumeration<InputStream> enumation = new Enumeration<InputStream>() { public boolean hasMoreElements() { return iterator.hasNext(); } public InputStream nextElement() { return iterator.next(); } }; BufferedInputStream bufInputStream = new BufferedInputStream( new SequenceInputStream(enumation), 8192); BufferedOutputStream bufOutputStream = new BufferedOutputStream( new FileOutputStream(filename), 8192); byte[] data = new byte[1]; while(bufInputStream.read(data) != -1) bufOutputStream.write(data); bufInputStream.close(); bufOutputStream.flush(); bufOutputStream.close();
Paint my love - Michael Learns to Rock
From ICRT, i heard the song "Paint my love" by Michael Learns to Rock today.
Once i heard this song,I knew that it must be Michael Learns to Rock.
Their songs have special feeling for me,such as "That`s why you go away" and "Sleeping Child".
Here is the lyric of "Paint my love".
==============
From my youngest years
till this moment here
I've never seen
such a lovely queen
From the skies above
to the deepest love
I've never felt
crazy like this before
Chorus:
Paint my love
you should paint my love
it's the picture of a thousand sunsets
it's the freedom of a thousand doves
Baby you should paint my love
Been around the world
then I met you girl
It's like comming home
to a place I've known
Chorus:
Paint my love
you should paint my love
it's the picture of a thousand sunsets
it's the freedom of a thousand doves
Baby you should paint my love
Since you came into my life
the days before all fade to black and white
Since you came into my life
Everything has changed
till this moment here
I've never seen
such a lovely queen
From the skies above
to the deepest love
I've never felt
crazy like this before
Chorus:
Paint my love
you should paint my love
it's the picture of a thousand sunsets
it's the freedom of a thousand doves
Baby you should paint my love
Been around the world
then I met you girl
It's like comming home
to a place I've known
Chorus:
Paint my love
you should paint my love
it's the picture of a thousand sunsets
it's the freedom of a thousand doves
Baby you should paint my love
Since you came into my life
the days before all fade to black and white
Since you came into my life
Everything has changed
Mood of Love
It has been 2 more months since we separated. I have changed a lot.
And the changes are not for you,but for me. Now, it seems that you
don`t believe the new me. Maybe the changes are too fast and large
for you to believe. You may need time to see whether the changes is
real inside me or just it is temporarily. Without you, everyday is
suffering.
And the changes are not for you,but for me. Now, it seems that you
don`t believe the new me. Maybe the changes are too fast and large
for you to believe. You may need time to see whether the changes is
real inside me or just it is temporarily. Without you, everyday is
suffering.
訂閱:
文章 (Atom)
