2009年12月23日 星期三

HTC Hero變成無線AP(免刷機)

先下載兩個檔案
1.Instant Root  Instant Root 下載點
2.Wireless Tether wireless tether 下載點

步驟一 : 先裝Instant Root
步驟二 : 再裝Wireless Tether

然後就開啟Wireless Tether來用啦.......
國外網站有說安裝了Instant Root就不要再安裝官方的更新檔,反正到時候hero有釋放Android 2.1時,再把Instant Root移掉就好了!!!!

Instant 移除的方法

You can undo the changes made by this app by installing and opening a terminal emulator (there are several on the market) and typing the following:

su
mount -o remount,rw /dev/block/mtdblock3 /system
rm /system/bin/su
rm /system/xbin/su
rmdir /system/xbin
mount -o remount,ro /dev/block/mtdblock3 /system
exit
exit




後記:
用了大半個月之後突然間Wireless Tether開不起來了......慘.......
所以我最後還是刷機了.....

2009年9月6日 星期日

動態Spinner來變更Image

所需功能
  1. 取得res/drawable資料夾下的所有檔案名稱
  2. 由檔案名稱取得ResourceID
  3. 點選並顯示圖檔
package java2.tw;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class mySpinner extends Activity {

private Spinner mySpinner;
private ImageView myImageView;
private ArrayAdapter myArrayAdapter;
static String[] myResource;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mySpinner = (Spinner) findViewById(R.id.mySpinner);
myImageView = (ImageView) findViewById(R.id.myImageView);
getResourceName();
myArrayAdapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, myResource);
mySpinner.setAdapter(myArrayAdapter);

mySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView arg0, View arg1,
int arg2, long arg3) {
myImageView.setImageResource(getResourceIDByName(
R.drawable.class, myResource[arg2]));

}

@Override
public void onNothingSelected(AdapterView arg0) {
}
});
}

private void getResourceName() {
String[] resource;
List list = new ArrayList();
for (Field f : R.drawable.class.getDeclaredFields()) {
try {
list.add(f.getName());
} catch (Exception e) {
Toast.makeText(this, "圖片目錄載入失敗", Toast.LENGTH_SHORT).show();
}
}
resource = new String[list.size()];
for (int i = 0; i <>
resource[i] = list.get(i);
}
myResource = resource;
}

private int getResourceIDByName(Class aClass, String resourceName) {
Field[] drawableFields = aClass.getFields();
int resourceID = 0;
for (Field f : drawableFields) {
if (resourceName.equals(f.getName())) {
try {
resourceID = f.getInt(null);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return resourceID;
}
}

在Android程式中取得圖檔方法

單一圖檔:

方法一:
Field f= (Field)R.drawable.class.getDeclaredField("dsc00002");
int imageID =f.getInt(R.drawable.class);
ImageView imageView= new ImageView(this);
imageView.setImageResource(imageID);

public Field getDeclaredField (String name)

Returns a Field object for the field with the specified name which is declared in the class represente by this Class.

Parameters
name the name of the requested field.
Returns
  • the requested field in the class represented by this class.

方法二:

int imageID =this.getResources().getIdentifier(this.getPackageName()+":drawable/dsc00002", null,null);

//int imageID = this.getResources().getIdentifier("dsc00002", "drawable", this.getPackageName());

ImageView imageview = new ImageView(this);
imageview.setImageResource(imageID);

public int getIdentifier (String name, String defType, String defPackage)

Return a resource identifier for the given resource name. A fully qualified resource name is of the form "package:type/entry". The first two components (package and type) are optional if defType and defPackage, respectively, are specified here.

Note: use of this function is discouraged. It is much more efficient to retrieve resources by identifier than by name.

Parameters
name The name of the desired resource.
defType Optional default resource type to find, if "type/" is not included in the name. Can be null to require an explicit type.
defPackage Optional default package to find, if "package:" is not included in the name. Can be null to require an explicit package.
Returns
  • int The associated resource identifier. Returns 0 if no such resource was found. (0 is not a valid resource ID.)

批次圖檔:

public int[] getImageID() {

int[] output;

List list = new ArrayList();

for (Field f : R.drawable.class.getDeclaredFields()) {

try {

Object object = f.get(R.drawable.class);

if (object instanceof Integer) {

list.add((Integer) object);

}

} catch (Exception e) {

Toast.makeText(myContext, "圖片載入失敗", Toast.LENGTH_SHORT).show();

}

}

output = new int[list.size()];

for (int i = 0; i <>

output[i] = list.get(i).intValue();

}

return output;

}


2008年10月22日 星期三

Linux Date 指令運用

利用date 指令來取得,格式如下 
date "+%Y %m %d %H:%M:%S"

Display the current time in the given FORMAT, or set the system date.
-d, --date=STRING
              display time described by STRING, not `now'

FORMAT controls the output:
%Y     year (1970...)
%m     month (01..12)
%d     day of month (01..31)
%H     hour (00..23)
%M     minute (00..59)
%S     second (00..60); the 60 is necessary to accommodate a leap  second 

當天
date +%Y%m%d
前一天

# date --date='1 days ago' +%Y%m%d
# date -d '1 days ago' +%Y%m%d
# date -d yesterday +%Y%m%d
明天
# date --date='1 days' +%Y%m%d
# date -d '1 days' +%Y%m%d
# date -d tomorrow +%Y%m%d

2008年10月19日 星期日

網路設定備份與啟動

快速切換IP組態


網路設定檔備份

netsh -C interface dump>C:\Office_AP1.txt

/*****************備份出來的內容_開始*************/
#=========
# 介面設定
#=========
pushd interface

reset all

popd
# 介面設定結束

#=========
# 介面設定
#=========
pushd interface ipv6

uninstall

popd
# 介面設定結束

# ----------------------------------
# ISATAP 設定
# ----------------------------------
pushd interface ipv6 isatap

popd
# ISATAP 設定結束

# ----------------------------------
# 6to4 設定
# ----------------------------------
pushd interface ipv6 6to4

reset

popd
# 6to4 設定結束

#========================
# 連接埠 Proxy 設定
#========================
pushd interface portproxy

reset

popd
# 連接埠 Proxy 設定結束

# ---------------------------------- 
# 介面 IP 設定         
# ---------------------------------- 
pushd interface ip

# "無線網路連線" 的介面 IP 設定

set address name="無線網路連線" source=static addr=172.16.1.2 mask=255.255.255.0
set address name="無線網路連線" gateway=172.16.1.1 gwmetric=0
set dns name="無線網路連線" source=static addr=168.95.1.1 register=PRIMARY
add dns name="無線網路連線" addr=168.95.192.1 index=2
set wins name="無線網路連線" source=static addr=none

popd
# 介面 IP 設定結束
/*****************備份出來的內容_結束*************/


文字檔載入變更IP組態

netsh -f C:\Office_AP1.txt


這樣就不用每次手工去改IP,不過如果是不同無線基地台的話還是得手動去切換基地台才可以...

2008年10月12日 星期日

JMail 開發紀錄(2-3) - mail.cfg backup 功能新增

新增郵件備份機制 backup=true/false
當備份機制啟動時,在工作目錄下會新增一個backup資料夾,裡面會有每個帳號(日期分類)的個別備份檔案
例如:
sender_smtp15985.jmail
receiver_pop15986.jmail
兩種類型檔案,其中 sender為寄件者備份 / receiver為收件者備份

2008年10月11日 星期六

JMail 開發紀錄(2-2) - mail.cfg NIC.Check 名稱變更

#This option rejects mail sent from domains that do not have an entry in DNS.
#Fully qualified domain name check
#Default option=true

原為
NIC.Check=true

現在變更為
FQDN.Check = true

功能無異動只有名稱修改