Sometimes it helps a lot to know what’s going on inside those not well documented APIs. And the open source nature of Android encourages people to learn from the source code.However, as of now, source code dose not come out of box in eclipse ADT. Fortunately, it’s not so hard to make it work. You do not need to build the entire android

Method 1: (For Android 4.0/SDK 14 or above)

Google includes Android SDK source code for SDK 14 or above, but we need some set up.

Download the source.

  1.  Select “Source for Android SDK” and click install packages

Attach the source code to android.jar

  1.  Right click on android.java, and select properties. You should see the following dialog to set Java Source Attachment
  2. Click external folder, select {Android_SDK_Root}/sources/android-{SDK-version}. For example, if Android SDK is installed in /opt/android-sdk-mac_x86 and we are setting SDK 14 ‘s source, the folder should be /opt/android-sdk-mac_x86/sources/android-14

Method 2 (For Android SDK below 14)

However, most of us need to support lower version of Android device. But we can take a similar approach .

Get the source code

Follow source.android.com to download android source code. Build is NOT required

Decide the SDK version

See http://source.android.com/source/build-numbers.html for a complete list of SDK release, then switch to the needed version
For example, to support android 2.2, we first get android 2.2 source code

$ repo init -b master -m base-for-3.0-gpl.xml
$ repo sync
$ repo forall -c git checkout android-2.2.3_r2

Copy corresponding source folders


mkdir -p {Android_SDK_Root}/sources/android-8
cp -r frameworks/base/core/java/android/ {Android_SDK_Root}/sources/android-8/android

We can do similar thing for java and javax packages.
Then select the source attachment folder the same way.
Use cp instead of ln -s so we can save the snapshot and checkout other version as well

When creating a new file in xcode, xcode automatically add the developer and copyright information at the top, like this

// Created by admin on 2/7/12.
// Copyright 2011 __MyCompanyName__. All rights reserved.

You may want to change this information. I haven’t figured out a way to do it directly. The solution I found is update the correct information in Address Book app.

In Address Book, find you, that is the contact for current user, with a small “me” icon. Insert the company name there, and xcode will use the information without any further settings

http://developer.apple.com/library/ios/#technotes/tn2250/_index.html could be particular helpful for solving this kind of errors.
For example, today I was trying to build my iOS project in my Mac Pro, but encountered the above error. The solution is simply transferring identity from my Macbook to Mac Pro.

rtfm should always be the first attempt

Today I encountered a simple problem: setackground of a blackberry screen.

In blackberry sdk, a MainScreen  extends from FullScreen which is a subclass of  Manager and Field.

However, for Manager and Field , we can simply call setBackground to get correct results.
but for Mainscreen, it not the case, calling setBackground has no effect and background remains white.

The solution is call
getMainManager().setBackground
It’s interesting that other methods like MainScreen.add() behaves as in Manager.add(). no special actions needed. I have no clue so far why getMainManager() need to be called to set background.

RIM should fix it or at least document this behavior clearly in their doc.

Sometimes I can found an address on google map, but not on my GPS. Using coordinates is a good idea in this case.

To get the latitude and longitude in google map, first send the address in google map. Then input the following javascript in addressbar:

javascript:alert(window.gApplication.getMap().getCenter());

An alert window contains latitude and longitude will pop up

 

Though I have known codejam for several years, it’s my first contest.
The problems are challenge and interesting. However, I am not well prepared in neither algorithm or contest skills. I struggled to competing in all 3 rounds, yet failed. The key is to code fast and bug free. Unlike topcoder, it is possible to gain credits in codejam even only small data is sovled. So it also important for non-expert players to use naive algorithm to solve small data for hard problems.
I will not give up!

One thing I like Eclipse is its auto-format functionality. Press ‘Ctrl’+'Shift’+'F” will format the source code nicely.

However, for Andorid’s xml file like layout files, Eclipse’s default formatting will multiple attributes in one line, making it hard to read and identify. We can make it one attribute per line by go to

Window ->Preferences ->X ML ->XML Files -> Editor and check  Split multiple attributes each on a new line. As shown below:

Android emulator is much slower than iPhone simulator. Because it is emulating arm on top of x86, while iPhone simulator just runs native x86 code. But the default settings for Android emulator is so slow that is barely useable. Luckly we can change some settings to make it reasonable fast.

Open “Android SDK and AVD Manager”, create a new AVD or edit an existing one.

Click “New…” hardware to add a new hardware called “Device Ram  Size”

Change the value to 1024.

Save the changes and launch the emulator.

Today I encounter a debug certificate expired error when compiling an Android project in eclipse
the full error message is like
Description Resource Path Location Type Error generating final archive: Debug Certificate expired on 4/20/11 3:55 PM helloworld Unknown Android Packaging Problem

According to google, the ‘debug.keystore’ expires one year. So if you also see the error, congratulation on your 1st anniversary with Android!

It’s not hard to find a solution with help of google.
like http://stackoverflow.com/questions/2194808/debug-certificate-expired-error-in-eclipse-android-plugins
Simply delete debug.keystore in ~/.android , clean/rebuild project will force eclipse to generate a new debug.keystore. Problem solved.
It turn outs to be a bug in Android , see http://code.google.com/p/android/issues/detail?id=15370

Note that because the new debug.keystore is different than previous one. You may see following error in eclipse console if try to install on a device
Re-installation failed due to different application signatures.
You must perform a full uninstall of the application. WARNING: This will remove the application data!
Please execute 'adb uninstall helloworld' in a shell.
Launch canceled!

so I followed the instructions to uninstall the app in shell.

Amazon aws is offering 1 year free tire. It’s a great opportunity to try free hosting service of the cloud.

Amazon’s Micro instances is based on Cents-OS, so all yum and rpm can be used, which makes installing wordpress very easy. Make sure TCP 80 is open in security group in amazon aws console.

install required software

 sudo -i
 lsof -i
 yum -y install httpd
 service httpd start
 yum -y install php mysql
 yum install mysql-server

if you are using 32bit version

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm

64 bit is also available


wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

then install phpmyadmin

yum install phpmyadmin
vi /etc/httpd/conf.d/phpmyadmin.conf

change the content to allow all people connect

#
#  Web application to manage MySQL
#

<Directory "/usr/share/phpmyadmin">
#  Order Deny,Allow
#  Deny from all
  Allow from all
</Directory>

Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpMyAdmin /usr/share/phpmyadmin
Alias /mysqladmin /usr/share/phpmyadmin

restart service and set password


service httpd restart
service mysqld start
/usr/bin/mysqladmin -u root password 'password’
vi /usr/share/phpmyadmin/config.inc.php

change following line

$cfg['Servers'][$i]['auth_type'] = ‘http’;

download wordpress and create database,

wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz -C /var/www/html/
cp -avr /var/www/html/wordpress/* /var/www/html/
rm -rf /var/www/html/wordpress/
chown -R apache /var/www/html
chmod -R 755 /var/www/html

For more information about create database, see http://codex.wordpress.org/Installing_WordPress


mysql -u adminusername -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5340 to server version: 3.23.54

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE DATABASE databasename;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname"
    -> IDENTIFIED BY "password";
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> EXIT
Bye

We are almost done. Open web browser and enter your ip. login with username, and follow the steps.
Wordpress will generate the content of ‘wp-config.php’, just copy and paste!

vi /var/www/html/wp-config.php

ENJOY!

© 2012 yet another web site Suffusion theme by Sayontan Sinha