2010年6月23日 星期三

MS OFFICE 2007 .ppsx 檔轉檔

先下載安裝 Open office
http://download.openoffice.org/index.html

使用 Open office 開啟 ppsx 檔
開啟時會詢問你使用的 filter 篩選器

此時選 ms office 2007 即可開啟

再另存新檔 ms office 97 格式即可

2010年6月22日 星期二

Visual Studio 2010

幾個 VB 的技巧…

Callback 函式指定方式

AddHandler _timer.Tick, AddressOf TimerEventProcessor

Private Sub TimerEventProcessor(ByVal myObject As Object, ByVal myEventArgs As EventArgs)
'todo
End Sub



SerialPort1_DataReceived 因為是執行緒非同步在接收 RS232 的資料,而 VB 不允許在執行緒中直接設定一些 Components 的值,因些必須透過代理的方式來處理…

Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
memoMessage.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {})
End Sub

Public Delegate Sub myDelegate()
Public Sub updateTextBox()
memoMessage.Text = SerialPort1.ReadExisting()
End Sub



String 跟 char array 轉換的方式…

Dim str as String
Dim carr() As Char = str.ToCharArray
str = CStr(carr)



要加快 components 的繒圖速度可以使用 GDI 雙重緩衝,若是繼承自 compnents 可寫在 New() 建構式中…

Public Sub New()
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

2010年5月31日 星期一

Android 開發 Google Map API - 如何註冊 API Key

Google Map View 官方教學網站…

http://developer.android.com/resources/tutorials/views/hello-mapview.html

這有詳盡的 Android Google API 開發教學~

萬事起頭難,其中提到,必須有一組 API Key 才能註冊成為合法認證的 Google API,才能在 Android 上執行,才可以開始玩。(其實就是 java 憑證)

建立過程如下…

一、在開發的過程中,可以先建立 debug certificate…

http://code.google.com/intl/zh-TW/android/add-ons/google-apis/mapkey.html#getdebugfingerprint


二、按照上面的說明,先找到應用程式存放 debug keystore 的地方,通常放在…

C:\Documents and Settings\<user>\.android\debug.keystore

或可透過裝了 ADT 的 Eclipse 選單 Windows > Prefs > Android > Build 中找到完整路徑。

三、再下達…

keytool -list -alias androiddebugkey -keystore <path_to_debug_keystore>.keystore -storepass android -keypass android

會發生二個問題…
  • keytool.exe 的位置:在 JAVA JRE 安裝目錄中,例如…

    C:\Program Files\Java\jre6\bin

  • 路徑有可能包含空白字元,導致無法在 DOS COMMAND 視窗下達指令,你可以先把 debug.keystore 拷貝到 C:\ 再下達指令…

    keytool -list -alias androiddebugkey -keystore c:\debug.keystore -storepass android -keypass android

四、如此便會算出 MD5 碼…

androiddebugkey, 2010/5/15, keyEntry,
認證指紋 (MD5): 70:02:A3:1F:85:35:D1:A4:3C:1C:D2:12:34:56:78:90

五、有了 MD5 碼就可以到 Android Maps API Key Signup 網頁註冊新的 API Key…

http://code.google.com/intl/zh-TW/android/maps-api-signup.html

六、完成註冊,得到 API Key…

感謝您申請 Android Maps API 金鑰!
您的金鑰為:
0GNWKtyf-6M2YDIU3XIjq-Qgqh0yn1234567890
此金鑰適合所有使用以下指紋憑證所簽署的應用程式:
70:02:A3:1F:85:35:D1:A4:3C:1C:D2:12:34:56:78:90

有了金鑰就可以拿來填到 main.xml 中了。


p.s. 下達 keytool 指令時可以善用 DOS 輸出導向功能 keytool ooo xxx yyy ... zzz > md5.txt  , 把輸出導向到一個檔案方便拷貝,以免打錯 MD5 碼。

2010年5月23日 星期日

Android EventListener 建立方法

元件常常有很多「event」必預要去「listen」,這時候需要靠 EventListener。

網路上看到的範例大多長的像底下這個樣子…

btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
/// TODO
}
});


乍看可能還很難以理解這一小段程式是在作什麼,其實整個意義如同底下這段程式…

btn.setOnClickListener( new clsOnClickListener() );
///---inline class ---///
public class clsOnClickListener implements OnClickListener {
public void onClick(View v) {
/// TODO
}
}



也就是它其實是建立了個新的 class implements 原來的 OnClickListener 來自訂 onClick 事件處理函式。

但難的是在 coding 的時候往往不曉得(或忘了)有哪些事件,有哪些 listener,更別說要寫出上面第一段那樣的程式了。

還好 Eclipse 開發環境很好用,你可以利用它自動產生程式碼的功能,幫你做到這些事。
用說的不好解釋,看段影片說明…

http://www.youtube.com/v/plW4zMxpnBA



這樣就可以減輕腦袋的負荷了~^ ^

Android 動態產生元件

Android 應用程式的開發一般都將 UI 跟 RESOURCES 的部分抽離出來,好方便管理及設計,也因此有一些 XML 檔需要撰寫,主要都是用來描述這些資源。

但若要自己土法練鋼寫動態產生時要怎麼作?


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
///setContentView(R.layout.main); ///不使用 main.xml 資源

LinearLayout layout = new LinearLayout(this);
this.addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
layout.setOrientation(LinearLayout.VERTICAL);

Button btn = new Button(this);
btn.SetText("Button");
layout.addView(btn, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

EditText txt = new EditText(this);
layout.addView(txt, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
}


相對照若用 xml 來描述的話像這樣…

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</Button>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>
</LinearLayout>

Android 練習-寶石方塊

直接將自己舊的 java 手機程式改成 Android 版本。

http://www.youtube.com/v/bYORe68RixQ

Android TabLayout 使用心得

Android 2.2 SDK 己經出了…
http://developer.android.com/sdk/index.html
最近也在學習,還好之前有 java/javaME 的基礎,還算順利。

Google 官方有提供教學網頁…
http://developer.android.com/resources/index.html 
很不錯。

不過其中一個範例 TabLayout 的使用…
 http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
這個範例對初學者來講比較複雜。

底下是比較簡單易理解的版本…

HelloTabWidgetNoIcon.java

package com.study.HelloTabWidgetNoIcon;

import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;

public class HelloTabWidgetNoIcon extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab

// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("Artists").setContent(R.id.tab0);
tabHost.addTab(spec);

// Do the same for the other tabs
spec = tabHost.newTabSpec("albums").setIndicator("Albums").setContent(R.id.tab1);
tabHost.addTab(spec);

spec = tabHost.newTabSpec("songs").setIndicator("Songs").setContent(R.id.tab2);
tabHost.addTab(spec);

tabHost.setCurrentTab(0);
}
}


main.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >

<TextView
android:text="tab0"
android:id="@+id/tab0"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="tab1"
android:id="@+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="tab2"
android:id="@+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</FrameLayout>
</LinearLayout>
</TabHost>


對照一下 HelloTabWidgetNoIcon.java 及 main.xml 就可以了解程式碼跟 layout 間的對應關係了(tab0,tab1,tab2)。

跟官方的範例不同的地方在於,官方的還多加了…
一、Tab 的小圖示( ic_tab_artists.xml, ic_tab_albums.xml, ic_tab_songs.xml 及圖片 )
二、動態的 Tab View ( ArtistsActivity.java, AlbumsActivity.java, SongsActivity.java )
所以才比較複雜並且要多撰寫一些 xml 碼。

不過,若真的要用在手機上,當然還是用圖示比較吸引人嘍。

VirtualBox 空間減肥

sdelete64 -z c: VBoxManage  modifymedium  disk  "/Users/fellow/VirtualBox VMs/Win10/Win10.vdi"  --compact *.vdi 路徑可以在 VirtualBox 儲...