2011年6月9日

Layout依比例%分配寬度

類似html中的%width語法,android layout中也有相對應的layout_weight和weightSum.
    <LinearLayout  ...  >
        <TextView ...  android:layout_weight="1"  />
        <TextView ...  android:layout_weight="1"  />
        <TextView ...  android:layout_weight="1"  />
    </LinearLayout>
 
(... 省略)

觸控縮放Touch Zooming WebView

設定Layout和程式權限android.permission.INTERNET
In main.xml
xml version="1.0" encoding="utf-8"?>
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="fill_parent"
      android:layout_height="fill_parent">
    <WebView
      android:id="@+id/MyIE"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" />
</LinearLayout>
 
In AndroidManifest.xml
....
<uses-permission android:name="android.permission.INTERNET" />
...
呼叫WebView的getSettings()得到WebSettings物件來進行設定。
   WebView ie;
   @Override
   public void onCreate(Bundle savedInstanceState) 
   {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main );
 
       // 取得 WebView物件 
       ie = (WebView) findViewById( R.id.MyIE);        
       // 取得 WebSettings物件 
       WebSettings webSettings = ie.getSettings();  
       // 支援JavaScript
       webSettings.setJavaScriptEnabled(true);             
       // 支援Zoom
       webSettings.setSupportZoom(true);                    
       webSettings.setBuiltInZoomControls(true);
   }

Android 程式的生命週期測試

在每個生命週期事件加上一個Toast訊息,來得知呼叫的順序。
第一次執行程式時,進行起始啟動 OnCreate() > OnStart() > OnResume()

暫停Pause

按下HOME按鈕 OnPause() > OnStop(),程式只是暫停而停止,
當再次啟動程式時 OnReStart() > OnStart() > OnResume()。
  • 當呼叫Intent時,程式會先暫停(OnPause() > OnStop(),然後返回時 OnReStart() > OnStart() > OnResume())。

結束Destroy

按下BACK按鈕或呼叫finish()方法,則會真正的結束程式 OnPause() > OnStop() > onDestroy(),
當再次執行程式時,就如同起始啟動
  • 當旋轉螢幕時,程式會先結束,然後再啟始起動(OnPause() > OnStop() > onDestroy() > OnCreate() > OnStart() > OnResume())。

機器休眠待機時

此時可分為兩種情形
  • 程式在執行狀態:經過多個Pause,Resume,Stop事件後,最後會Destory。當機器醒來時,程式會重新起始啟動OnCreate() > OnStart() > OnResume()。
  • 程式在暫停狀態:當機器醒來重新執行程式時,就如同從暫停模式回來一樣 OnReStart()>OnStart()>OnResume()。
 @Override
  public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       Toast.makeText(this, "onCreate", Toast.LENGTH_LONG).show();
   }
 @Override
 protected void onRestart() {
  // TODO Auto-generated method stub
  super.onRestart();
  Toast.makeText(this, "onRestart", Toast.LENGTH_LONG).show();
 }
 @Override
 protected void onStart() {
  // TODO Auto-generated method stub
  super.onStart();
  Toast.makeText(this, "onStart", Toast.LENGTH_LONG).show();
 }
 @Override
 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();
  Toast.makeText(this, "onResume", Toast.LENGTH_LONG).show();
 }
 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  Toast.makeText(this, "onPause", Toast.LENGTH_LONG).show();
 }
 @Override
 protected void onStop() {
  // TODO Auto-generated method stub
  super.onStop();
  Toast.makeText(this, "onStop", Toast.LENGTH_LONG).show();
 }
@Override
 protected void onDestroy() {
  // TODO Auto-generated method stub
  super.onDestroy();
  Toast.makeText(this, "onDestroy", Toast.LENGTH_LONG).show();
 }

全螢幕且不顯示標題列

requestWindowFeature(...)可讓標題欄不顯示,而getWindow().setFlags(...)可以設定全螢幕顯示。

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  WindowManager.LayoutParams.FLAG_FULLSCREEN);        
 
        setContentView(R.layout.main);
        ...
或在AndroidManifest.xml的Activity區塊中插入:
    <application android:icon="@drawable/wusjp" android:label="@string/app_name" >
        <activity   
                  android:theme="@android:style/Theme.NoTitleBar"
                  ...                                                                           
        >
         ...    
        activity>
    application>

2011年6月6日

試用Windows Live Writer

LinearLayout mLinearLayout;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Create a LinearLayout in which to add the ImageView
mLinearLayout = new LinearLayout(this);

// Instantiate an ImageView and define its properties
ImageView i = new ImageView(this);
i.setImageResource(R.drawable.my_image);
i.setAdjustViewBounds(true); // set the ImageView bounds to match the Drawable's dimensions
i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));

// Add the ImageView to the layout and set the layout as the content view
mLinearLayout.addView(i);
setContentView(mLinearLayout);
}

2011年6月2日

Android: MediaPlayer 播放Asset中的檔案

因為Security保密原因media server 無法存取你的程式私有資料目錄,
所以你必須在程式中開檔案,然後使用setDataSource(fd)
將檔案Filedescriptor傳給media player。
當然也可將檔案複製到SD卡,然後播其路徑。

AssetFileDescriptor afd = getAssets().openFd("test.MP3"); 
mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength()); 
mp.prepare();
mp.start();
afd.close();

2011年2月17日

Watson (artificial intelligence software) - Wikipedia, the free encyclopedia

Watson (artificial intelligence software) - Wikipedia, the free encyclopedia

2011年2月16日

The road to 6.77 (Feliks Zemdegs ) - 魔方视频 - 魔方站

The road to 6.77 (Feliks Zemdegs ) - 魔方视频 - 魔方站

2011年2月2日

Solar "Death Ray": Power of 5000 suns!

2011年1月11日

Rubik's Cube: Cross (Advanced)

Rubik's Cube: Cross (Advanced)

2011年1月7日

Amazing Photos by Sarolta Bán | Yurock

Amazing Photos by Sarolta Bán | Yurock

2010年12月27日

7x7x7 Stop Motion Assembly!!

7x7x7 Stop Motion Assembly!

2010年12月21日

M2 / Old Pochmann Blindfold Tutorial - Part 1

M2 / Old Pochmann Blindfold Tutorial - Part 1

2010年12月19日

CFOP速解發明人Jessica Fridrich女士跳過PLL轉出14.33秒

CFOP速解發明人Jessica Fridrich女士跳過PLL轉出14.33秒

2010年12月3日

Dadsense 爸爸之歌 附中文字幕

爸爸之歌

媽媽之歌 The Mom Song 附中文字幕

媽媽之歌

2010年11月24日

XNA 程式設計入門

XNA遊戲迴圈

基本上就是一個迴圈不斷執行,直到使用者結束遊戲。

1.啟始化並載入資源
   1.1 Initialize()
   1.2 LoadGraphicsContent()
2.迴圈開始
   2.1. Update()  //處理遊戲邏輯
   2.2. Draw()     //處理繪圖
3.迴圈結束
4.釋放資源 UnloadGraphicsContent()

2010年11月9日

Direct2D (Windows)

Direct2D (Windows)
踏破鐵鞋無覓處,得來全不費功夫。
Google XNA Draw Rectangle,發現有人寫成一個小Class來做這些事,心中竊喜。
想說那DirectX應該也會有前人的前車之鑑。Google DirectX Rectangle,結果中發現有人回應Direct2D這個東東,真是乖乖隆個咚咚:)

這不就是我想要的嗎?
真是功課作得不如那時勤奮了...那時可真是每天都浸淫在微軟的MSDN Library中呀!

2010年11月2日

SlimDX

SlimDX Homepage
DirectX的簡易介面,裝來試試看。也許是個不錯的選擇?
SlimDX is a free open source framework that enables developers to easily build DirectX applications using C#, VB.NET, and IronPython. It is designed to be an efficient, simple, and lean wrapper that fully encompasses all of Microsoft's gaming and multimedia technologies and exposes them to managed code.

2010/11/01 安裝同時安裝DirectX(2010June)
2010/11/02 寫個小程式吧...

2007年2月15日

日文 Unicode 表

http://www.rikai.com/library/kanjitables/kanji_codes.unicode.shtml

A.L.I.C.E

A.L.I.C.E
http://www.alicebot.org/documentation/

AIMLBot (Program#)

Developer Information
AIMLBot Architecture and Code Description: A reference for developers who want to debug, fix or extend AIMLbot
How to implement and use custom tags Description: Custom tags allow developers to extend the functionality of the AIMLbot library.
User Information
Program# - Overview Description: A brief summary of the capabilities and design of the AIMLbot library
Setting up and using an AIMLbot

2007年1月24日

睡眠的迷人世界

The Enchanted World of Sleep
拉維Peretz Lavie著
遠流出版2002

腦波
  • β貝它波:清醒時高頻低幅,每秒超過15次波動,當清醒程度增加及注意力更集中時,會變得更快。
  • α阿爾法波:關燈準備就寢,特別是把眼睛閉上以後,就變成每秒8到10次較為緩慢的波動。
  • θ西它波(半睡期):阿爾法波的主導性會逐漸被更慢的西它波取代,每秒4到7次波動,振幅和阿爾法波相近,從阿爾法波轉至西它波需要好幾分鐘。
  • K複形波與紡錘睡眠波:K複形波單一個高振幅的波形,其幅度有背景的θ波4倍大。紡錘睡眠波是一群頻率在每秒12到14個波動,其振幅和θ波相當,形狀則有如織布機上的紡錘。他們短暫出現,只有半秒到一秒的時間。
  • δ得爾它波(第四期睡眠):在出現K複形波與紡錘睡眠波的10到15分鐘之後出現。δ波顯得高且特別突出。

2007年1月1日

視覺的免費期刊

Journal of Vision
http://www.journalofvision.org/

  • The Journal of Vision, an official journal of ARVO, is a scientific periodical devoted to all aspects of visual function in humans and other organisms.
  • The Journal of Vision is published by the Association for Research in Vision and Ophthalmology (ARVO), an international organization devoted to research, training, and dissemination of knowledge in vision and ophthalmology.
  • Impact factor for 2005: 3.469(Journal Citation Reports® 2005, published by Thomson Scientific)

大腦比你先知道

The Mind's Past
by Michaels S. Gazzaniga
遠哲科學教育基金會1999

1.虛構的自我
  • 每一個剛出生的嬰兒大腦都已經有了天生就設定的電路,使得嬰兒可以計算外面物理世界的訊息。嬰兒不需要去學三角,他本來就知道。
  • 大腦不是一個大的、自由轉動的網路。它不會因為簡單的制約關係就形成連結,然後建構出複雜的知覺和認知上的功能。
  • 大腦是經由演化自然而然添加了許多特別功能的系統(適應).
  • 諾貝爾生醫獎得主喬納(Niels Jerne)是使神經學家看到生物機制(例如選擇理論)的人。喬納認為有機體有許多由基因所決定的神經網路,來做某一種的學習,在學習的時候,這個系統從一堆原本就有的(built-in)反應中,找出適宜的來對抗環境的挑戰。
  • 大腦在我們想要做決策之前,大腦老早就把做決策的細胞準備好了。