Thursday, December 31, 2009

English Windows Systems with Chinese

This web page [ How to display and edit Chinese on English Windows systems ] is worth reading. It can make an English Windows system to be able to work with English and Chinese.

This web page [ Enter Chinese Characters under Windows XP - March 18, 2002 ] also has some information with some screen captures.

Well the above articles tell you how to ENABLE your OS to let you input Chinese char and to display Chinese char. Once, the proper font is used, the Chinese char is displayed happily. However, what is the more in-depth knowledge inside ?

Actually, Windows XP is using NTFS filesystem. This filesystem uses unicode as filenames. In other words, all filenames characters (no matter Chinese, Japanese, Korean, English, Greek, ... etc) as stored as unicode UTF-16 format as the filename. This is the underlying filesystem filename data structure.

Then, how the win32 applications interact with this UTF-16 unicode filesystem ? Unfortunately, there are 2 sets of APIs. For those unicode-aware applications, it will use the unicode API to directly handle the unicode filename. For those non-unicode aware application, there are troubles.

When the non-unicode application handles a filename of a string of double-byte, how to convert each double-byte to a unicode ? The non-unicode API will use MBCS codec. The MBCS codec together with locale information will convert a double-byte to a particular unicode char. With the same double-byte char, changing the locale will change the unicode char.

What is the default locale your XP is using ? It is already determined in Control Panel -> Regional and Language Options -> Advanced -> Language for non-Unicode programs.

This comes another troublesome situation. For example, if your system is of default locale being Traditional Chinese, you can still make a file with Japanese char using unicode aware program. Then, how the non-unicode aware program handle this filename ? This Japanese unicode char should map to a double-byte of the Japanese locale. But, the default locale is Traditional Chinese, not Japnese. What to do then ? Sometimes they simply cannot handle this file, or will display question mark in the filename.

For the details of the MBCS and the API, please refer to this web page [ All About Python and Unicode ].


Wednesday, December 30, 2009

My first "R cannot be resolved" error with Android

When I new a project for an Android sample, I intentionally select a Android 2.0.1 platform to see what happens. The program editing part seems OK. However, when I test run the program, there is an error message saying that the default AVD cannot be used. I have to find another AVD. Then, I try to fix the project property to fall back to use the Android 1.5.0 platform and test run again. Now, error message keeps up coming.

The first error message is "R cannot be resolved!". When I search the internet, I come across many replies, but non of them works. Also, they introduce other messages such as "Build Path error", "The project cannot be built until build path errors are resolved" & "missing required source folder 'gen'". I even delete the 'gen' folder, it still cannot solve the problem. I also try to copy a 'gen' folder from other sample projects, this method does not work either.

At last, what I can do is to give up this project. New another project with Android platform 1.5.0 to do this ample program again. This is a much faster way.


Wrap text inside the HTML pre tag

Normally the text inside the HTML pre tag will NOT be wrapped. However, this document [ Forcing long text lines to wrap ] shows how to make text wrap inside the HTML pre tag.


http header, BOM and meta charset

This document [ HTML-Error documents regarding charset encodings ] has documented some detail description regarding http header, BOM and the charset in meta tag of html.


Monday, December 28, 2009

The Question Mark in the Subtitle of VLC

My previous post The Square in Subtitle of VLC has documented how to set the VLC to use unicode for subtitles. However, even so sometimes there are one or two question marks at the end of each subtitle lines.

For example, when opening the subtitle files, the characters can be read without difficulties. The subtitle lines appear to be chopped at the middle and show with one of two question marks instead. After investigation, when opening the subtitle file using PSPad, the file format (as shown at the status bar) is UTF-16 LE. This is the root cause. For VLC, the subtitle file is better to be in UTF-8 format. So, simply convert the UTF-16 LE format file into a UTF-8 format file with the same name. Then, VLC can display the subtitle correctly.



Thursday, December 24, 2009

My 2nd Hello World Program using XML in Android

After finishing my first Hello World program in Android, I continued explore Android's Hello World web page. The page says that the Hello World program can be written with XML. So, I want to have a try.

Since I want to keep the first non-XML version of Hello World program, I have to setup another project for this XML version. Actually, I prefer to setup a new workspace in Eclipse for this. If I start everything from scratch, I have to input the application name, ... etc. It is quite a headache.After searching the net, I can duplicate an Eclipse workspace. Here is the steps :
  1. Make sure Eclipse is not running
  2. Copy the workspace directory [ ws_hello ] to a new directory [ ws_hello_xml ]
  3. Go to directory [ ws_hello_xml ]
  4. Go to sub-directory [ .metadata\.plugins\org.eclipse.jdt.core ]
  5. Delete all [ *.index ] files
  6. Delete the file [ savedIndexNames.txt ]
  7. Start Eclipse and choose the [ ws_hello_xml ] workspace

Using this way, a new workspace [ ws_hello_xml ] is ready for my development of the Hello World program using XML.

Then, follow the steps as documented in Android's Hello World web page, I finished my second program in Android : the Hello World program using XML.





Wednesday, December 23, 2009

Change Google Desktop Data Directory

There are many configuration data stored under the directory [ Documents and Settings ]. Therefore, it is better to backup this directory regularly. However, Google desktop has put its indexing database under this directory. This make it very large (sometimes more than 10 GB) and difficult to backup. Is it possible to move the Google Desktop directory to another place ? After searching the net, here is the solution :

  1. Stop Google Desktop by:
    1. Go to system tray
    2. Right-click the Google Desktop icon
    3. Select [ Exit ]
  2. Move the [ Google Desktop ] directory to some other location
  3. Run [ regedit ] by :
    1. Go to Start
    2. Click [ Run ]
    3. Input [ regedit ]
  4. Locate the registry key:
    HKEY_CURRENT_USER\Software\Google\Google Desktop\data_dir
  5. Change its value to the location in step-2
  6. Start Google Desktop again





My First Hello World Program in Android

Here is my first day experience of writing my first Hello, World program using Android.

A. Install the Android SDK

Firstly, I had to install the SDK :
  1. Download the SDK file [ android-sdk_r04-windows.zip ]
  2. Unzip it. Actually, it will unzip to a directory [ android-sdk-windows ].
  3. Put this directory under directory [ \bin ] (or other directory you like, provided that its name has no white space char)
  4. Go to directory [ \bin\android-sdk-windows ]
  5. Noted that there is a sub-directory [ platforms ] which is empty. Now, we are going to set it up.
  6. Run the file [ SDK Setup.exe ]
  7. This message may appear [ Failed to fetch URL https://dl-ssl.google.com/android/repository/repository.xml, reason: HTTPS SSL error. You might want to force download through HTTP in the settings. ]. Then, do the following:
    1. Click the menu [ Tools -> android ]
    2. Check [ Settings -> Force https://... sources to be fetched using http://... ]
    3. Click [ Save & Apply ] button
    4. Close
    5. Run the file [ SDK Setup.exe ] again
  8. Now, you should see a list of platforms. Simply install all of them.

After successful installation, there are many different sub-directories under [ \bin\android-sdk-windows\platforms ].

Also, the configuration information can be found in the directory [ %USERPROFILE%\.android ].


B. Install Eclipse 3.5.1

Because I use Eclipse for many other developments, I want to use a CLEAN Eclipse for this Android development. Therefore, I have to install a blank new Eclipse as follows :
  1. Download the file [ eclipse-jee-ganymede-SR1-win32.zip ]
  2. Unzip the directory [ eclipse ] to directory [ \temp ]
  3. Go to directory [ \temp ]
  4. Rename the directory [ eclipse ] to [ eclipse_A ]
  5. Move the directory [ eclipse_A ] under the directory [ \bin ]

Now, Eclipse 3.5.1 is successfully installed under the directory [ \bin\eclipse_A ]


C. Install the Android Development Tools (ADT) plugin for Eclipse

Follow these steps to install this plugin (basically it is the same steps as mentioned in the site http://developer.android.com/sdk/eclipse-adt.html) :
  1. Go to the directory [ \bin\eclipse_A ]
  2. Run the file eclipse.exe
  3. Click the menu Help -> Install New Software
  4. In the [ Available Software ] dialog, click the [ Add ] button
  5. Then, the [ Add Site ] dialog appear
  6. In the [ Name ] field, input [ Android Plugin ]
  7. In the [ Location ] field, input this URL [ http://dl-ssl.google.com/android/eclipse/ ]
  8. Click the [ OK ] button
  9. Back to the [ Available Software ] dialog, you should now see [ Developer Tools ] added to the list.
  10. Select the checkbox next to [ Developer Tools ], which will automatically select the nested tools Android DDMS and Android Development Tools.
  11. Click the [ Next ] button
  12. The [ Install Details ] dialog will appear to list all the Android DDMS and Android Development Tools features.
  13. Click the [ Next ] button to read and accept the license agreement and install any dependencies.
  14. Then, click [ Finish ] button.
  15. Wait for the installation
  16. Restart Eclipse
  17. Quit Eclipse

Now, the plugin is successfully setup in Eclipse.


D. Create Android Emulator - Android Virtual Device (AVD)

Before developing the program, you have to firstly setup the Android Emulator in which your application is run. The emulator is called Android Virtual Device (AVD).

Here are the steps to setup the most simple AVD (basically the steps are the same as documented in the Android developer site) :
  1. Open DOS prompt
  2. cd \bin\android-sdk-windows\tools
  3. Run the following command :
    android create avd --target 2 --name my_avd
  4. When being asked to create a custom hardware profile, press [ ENTER ] to accept the default [ no ]

Now the AVD named my_avd is ready for your Android application. There is a sub-directory [ my_avd.avd ] created under the directory [ %USERPROFILE%\.android\avd ].


E. Develop the Hello World Program

Before writing the Hello program, we have to setup Eclipse workspace and create an Android project inside Eclipse using these steps:
  1. Make a folder [ D:\Android_WS ] to store all Android related Eclipse workspaces
  2. Start Eclipse
  3. When you are prompt for a workspace, input the following [ D:\Android_WS\ws_hello ]
  4. Click the [ OK ] button. Eclipse will create the workspace directory [ ws_hello ] for you.
  5. Inside Eclipse, click the [ Workbench ] button on the right to go to the workbench panel
  6. Then, select the menu [ File -> New -> Project ]
  7. In the [ New Project ] dialog, there should be a folder [ Android ] which contains an item [ Android Project ]
  8. Select highlight the item [ Android Project ]
  9. Click the [ Next ] button
  10. The [ New Android Project ] dialog should appear, now fill in the Android project details.
    • For the [ Project name ] field, fill in [ HelloAndroid ]
    • For the [ Build Target ], tick the box [ Android 2.0.1 ]
    • For the [ Application name ], fill in [ Hello, Android ]
    • For the [ Package name ], fill in [ com.example.helloandroid ]
    • For [ Create Activity ] field, fill in [ HelloAndroid ]
    • For [ Min SDK Version ] field, fill in [ 2 ]
    • Click the [ Finish ] button

Once the [ Finish ] button is pressed, the project is automatically built. Then, a file [ HelloAndroid.java ] should be created under [ HelloAndroid -> src -> com.exmplae.helloandroid ] in the Package Explorer on the left. The HelloAndroid.java should look like this:
package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
Noted that the Eclipse will NOT show the line numbering. I add the numbering information for your easy reference.

Now, we have to write our own Hello World program. as follows :
package com.android.helloandroid; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); tv.setText("Hello, Android"); setContentView(tv); } }
Noted that line-5, line-12 & line-13 are newly added coding.

Now, the program is ready to run.

F. Run the Hello World Program

Run the program inside Eclipse as follows:
  1. Click the menu [ Run -> Run ]
  2. In the [ Run As ] dialog, select [ Android Application ]
  3. Click the [ OK ] button
  4. Wait a while as it needs time to startup the simulator
  5. A red simulation phone should appear
  6. If the screen is locked due to timeout, click the [ menu ] button on the simulation phone.
  7. A text message [ Hello Android ] should appear on the black screen of the phone
  8. Click the [ Back ] button to quit the application
  9. Close the simulation



Duplicate Open Current Folder in a New Window

Sometimes after I opened a folder in Win7, I would like to duplicate open the same folder again in another explorer window. Then, I can ope...