Android – AlertDialog

March 15 2011No Commented

Categorized Under: Android

Using AlertDialog.Builder
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MyActivity.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show()

YesNo Dialog

使用 Google API Services (e.g. MapView) 開發Android Apps

March 14 2011No Commented

Categorized Under: Uncategorized

關於使用Google API Services, 大部份朋友遇到的問題係 Api Key.

怎樣取得 Api Key:

1. 開啟命令提示行 (Command Line Prompt)
2. 到以下路徑: C:\Users\peter\.android (假設使用者名稱是 peter)
3. 輸入以下指令
C:\Users\peter\.android> keytool -list -alias androiddebugkey -keystore debug.keystore
Enter keystore password: android
androiddebugkey, Jan 1, 2011, PrivateKeyEntry,
Certificate fingerprint : 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF

api key 就是 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF

Android: Using ACTION_CALL to dial automatically

March 10 2011No Commented

Categorized Under: Uncategorized

package com.cbthk.refercontacts;

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.Contacts.People;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

public class ReferContacts extends ListActivity {
	private ListAdapter mAdapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Cursor contactsCursor =
			getContentResolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
		startManagingCursor( contactsCursor );

		/*
		// Get contact id
		String contactId = contactsCursor.getString(
		contactsCursor.getColumnIndex(ContactsContract.Contacts._ID) );

		// Get whether the contact has phone no.
		String IsPhone = contactsCursor.getString(
		contactsCursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER) );
		*/

		String[] columns = new String[] { ContactsContract.Contacts.DISPLAY_NAME };
		int[] names = new int[] { R.id.row_entry};

		mAdapter = new SimpleCursorAdapter( this, R.layout.main,
			contactsCursor, columns, names);
		setListAdapter(mAdapter);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		Cursor contactsCursor = (Cursor) mAdapter.getItem(position);
		String contactId = contactsCursor.getString(
			contactsCursor.getColumnIndex(ContactsContract.Contacts._ID) );

		int hasPhoneNum = contactsCursor.getInt(
			contactsCursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER) );

		Toast.makeText( this, "hasPhoneNum = '" + String.format("%d", hasPhoneNum) + "'",
			Toast.LENGTH_SHORT ).show();

		if(hasPhoneNum==1) {
			Cursor phonesCursor =
				getContentResolver().query(
					Phone.CONTENT_URI,
					null,
					Phone.CONTACT_ID + "=" + contactId,
					null,
					null);
			if(phonesCursor.getCount()>0) {
				phonesCursor.moveToNext();
				String phoneNum = phonesCursor.getString(
					phonesCursor.getColumnIndex(Phone.NUMBER));

				Intent i = new Intent( Intent.ACTION_CALL );
				i.setData( Uri.parse( "tel:" + phoneNum ) );
				startActivity( i );
			}
			else {
				Toast.makeText( this, "No phone no.", Toast.LENGTH_SHORT).show();
			}
		}
	}
}

BDE reports insufficient space on drives with more than 2GB free

February 22 2011No Commented

Categorized Under: Uncategorized

It seems there is a bug in the BDE (all versions) that causes it to incorrectly report the amount of free disk space with drives that have over 4GB free space.

We recently encountered this issue on a clients machine and found reference to a BDE bug caused by Borland using an obsolete API call (GetDiskSpace instead of GetDiskSpaceEX).

We believe it is causing a number of clients major problems (now that they have all upgraded their machines they are running out of drive space).

If it has not been fixed is there an official (or un official) work around?

It would seem simple to fix (just change the calls to GetDiskSpaceEX).
Related Link

Windows 7 中文輸入法問題

December 2 2010No Commented

Categorized Under: Uncategorized

在大量文字輸入的情況下, 在轉換輸入法期間突然衹可以英數字輸入,必需把正在使用的軟體關閉並重新啟動才回復正常, 但大量打字一陣子後又出問題.

解決方法: 可嘗試安裝 Microsoft Office 輸入法 2010.

Use of MySQL on Ruby under Netbeans Problem

November 30 2010No Commented

Categorized Under: Uncategorized

rake aborted!
Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load — active_record/connection_adapters/mysql2_adapter)

Need to change two files:

1. [project name] > Configuration > database.yml

change “adapter: mysql” to “adapter: mysql2″

2. [project name] > Gemfile

add:

gem:’mysql2′

iOS – UIButton

September 17 2010No Commented

Categorized Under: Uncategorized

1. Set title
UIButton *button;
[button setTitle:@"Normal" forState:UIControlStateNormal];
[button setTitle:@"Highlighted" forState:UIControlStateHighlighted];
[button setTitle:@"Selected" forState:UIControlStateSelected];
[button setTitle:@"Disabled" forState:UIControlStateDisabled];

Button is highlighted whenever it is being pressed.
Button can be set “selected” using:
[button setSelected:YES];
Button will be disabled using:
[button setEnabled:NO];

2. Customed Buttons
// CALayer *myLayer = [myButton layer];
[[myButton layer] setCornerRadius:12.0f];
[[myButton layer] setMasksToBounds:YES];
[[myButton layer] setBorderWidth:1.0f];
[[myButton layer] setBorderColor:[[UIColor grayColor] CGColor]];
[myButton setBackgroundColor:[UIColor darkGrayColor]];

* Need to include:
#import “QuartzCore/QuartzCore.h” // for CALayer

Missing Quick Launch Toolbar in Windows 7

September 1 2010No Commented

Categorized Under: Uncategorized

In the New Toolbar – Choose a folder window, click in the Folder: dialog box near the bottom of the window.

Copy the following

%userprofile%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch

Paste the above into the Folder: dialog box near the bottom of the Toolbar – Choose a folder window and then click on the Select Folder button.

Best iPhone App Development Books

June 22 2010No Commented

Categorized Under: Uncategorized

The following are the most best iPhone App development books with reference to most comments on the web. It can be a reference if you want to have one or several books for your development work on iPhone.

1. Beginning iPhone 3 Development: Exploring the iPhone SDK (Apress)
2. More iPhone 3 Development: Tackling iPhone SDK 3 (Apress)
3. Building iPhone Apps with HTML, CSS, and JavaScript (O’Reilly)
4. Head First iPhone Development: A Learner’s Guide to Creating Objective-C Applications for the iPhone (O’Reilly)
5. The iPhone Developer’s Cookbook: Building Applications with the iPhone 3.0 SDK (2nd) (Addison Wesley)
6. iPhone SDK Development (The Pragmatic Programmers)
7. Cocoa Touch for iPhone OS 3 (Wiley)
8. iPhone Cool Projects (Apress)
9. iPhone User Interface Design Projects (Apress)
10. iPhone Open Application Development (O’Reilly)
11. iPhone SDK Programming A Beginner’s Guide (McGrawHill)
12. iPhone in Action (Manning)

Beginning iPhone 3 Development More iPhone 3 Development Building iPhone Apps Head First iPhone Development The iPhone Developer's Cookbook iPhone SDK Development Cocoa Touch for iPhone OS 3 iPhone Cool Projects iPhone User Interface Design Projects iPhone Open Application Development iPhone SDK Programming iPhone in Action

The iPhone SDK is fundamentally built upon the Cocoa foundation framework. Here are the most used iPhone programming book for learning Cocoa as well as Objective-C:

1. Cocoa Programming for Mac OS X (3rd) (Addison Wesley)
2. Programming in Objective-C 2.0 (Addison Wesley)
3. Learn Objective-C on the Macintosh (Apress)
4. XCode Unleashed (Sams)

Cocoa Programming for Mac OS X Programming in Objective-C 2.0 Learn Objective-C on the Mac Xcode 3 Unleashed

超好用的中文輸入法 – Yahoo!奇摩輸入法

December 11 2009No Commented

Categorized Under: Uncategorized

原來 Yahoo 也有中文輸入法. 一次整合了「好打注音」、「傳統注音「(ㄅ半)」、「倉頡」跟「簡易」等四種輸入法,安裝後,可以自行切換成慣用的輸入法

一、符號表功能

無需記住符號的打法、開啟符號表,想要甚麼符號一目了然:

切換 繁/簡 輸出

切換 繁/簡 輸出

二、打繁出簡

這個可以記是特異功能。Windows本身的輸入法不能做到。
往往有些時候需要輸入中文字與內地人溝通,想要表達得更親近,莫過於用簡體中文字去表達,這樣,用開繁體 Windows 輸入繁體中文字就會覺得頭痛,不董簡體中文輸入法怎辦!
有了 奇摩, 就可以按 [Alt]+[S] 或點選工具列切換 繁/簡 輸出就完全解決這個問題。

切換 繁/簡 輸出

切換 繁/簡 輸出

下載


Warning: Please contact support about failure in /home/laputa/public_html/cbthk.com/laputafish/wp-content/themes/ClassicMag/ClassicMagPurple/footer.php on line 1