Maven – Add ant-contrib Ant Tasks in maven-antrun-plugin

December 22, 2009 at 08:14 | In Maven | Leave a Comment
Tags: ,

Ant Tasks, such as <if>, belongs to ant-contrib.jar. So in order to use them in maven-antrun-plugin, you have to add this dependency explicitly in the pom.xml.

<!-- Properties -->
<properties>
	<greeting>true</greeting>
</properties>

<!-- Build Configuration -->
<build>
	<plugins>
		<plugin>
			<artifactId>maven-antrun-plugin</artifactId>
			<version>1.3</version>
			<dependencies>
				<dependency>
					<groupId>ant-contrib</groupId>
					<artifactId>ant-contrib</artifactId>
					<version>20020829</version>
				</dependency>
			</dependencies>
			<executions>
				<execution>
					<id>initialize</id>
					<phase>initialize</phase>
					<configuration>
						<tasks>
							<!-- add the ant tasks from ant-contrib -->
							<taskdef resource="net/sf/antcontrib/antcontrib.properties" />

							<!-- show greeting if ${greeting} is set to true-->
							<if>
								<equals arg1="${greeting}" arg2="true" />
								<then>
									<echo>Hello World</echo>
								</then>
							</if>
						</tasks>
					</configuration>
					<goals>
						<goal>run</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

Please remember to add the tasks definition of ant-contrib.jar using the <taskdef> inside the <tasks> node.

Run mvn initialize, the console will echo the greeting message only if the ${greeting} property is set to true.

Done =)

Maven – Using Ant tasks with maven-antrun-plugin

December 20, 2009 at 08:50 | In Maven | Leave a Comment
Tags: ,

maven-antrun-plugin allows maven user to add ant tasks in different maven life cycle phases. To use the maven-antrun-plugin, add the following text in the pom.xml.

<!-- Build Configuration -->
<build>
	<plugins>
		<plugin>
			<artifactId>maven-antrun-plugin</artifactId>
			<executions>
				<execution>
					<id>initialize</id>
					<phase>initialize</phase>
					<configuration>
						<tasks>
							<echo>Hello Maven</echo>
						</tasks>
					</configuration>
					<goals>
						<goal>run</goal>
					</goals>
				</execution>
			</executions>
		<plugin>
	</plugins>
</build>

This is the output after running mvn initialize

...
[INFO] task-segment: [initialize]
[INFO] ------------------------------------------------------------------------
[INFO] [antrun:run]
[INFO] Executing tasks
     [echo] Hello Maven
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Wed Dec 16 18:04:57 CST 2009
[INFO] Final Memory: 2M/7M
[INFO] ------------------------------------------------------------------------

Done =)

Android – Testing Localization

December 18, 2009 at 08:25 | In Android | Leave a Comment
Tags: ,

In the last post, we have made an application with localization: Android – Localization

So now we have to test it. Unfortunately, the locale in the android phone is already preset in the factory and u cannot change it. so the only way to test the localization is to use the emulator.

After starting the emulator, there is an option Custom Locale in the menu. Open it.

Custom Locale in Emulator

Custom Locale in Emulator

Choose your locale by long press. Then click apply.

Restart the emulator either by

  • Close the emulator and run your application again
  • Open the command prompt
    >adb shell
    # setprop persist.sys.language <Language Code>;setprop persist.sys.country <Region Code>;stop;sleep 5;start

Now you can change the locale of the emulator to test your application localization.
Done =)

Android – Localization

December 16, 2009 at 08:28 | In Android | 1 Comment
Tags: ,

In Android application development, there is a strings.xml which centralizes all the text values of the application. In order to localize your application by the phone locale, we can simply create different strings.xml as depicted in the following picture.

Localization mapping:
1. If the phone locale is NOT with language code zh, then
    - /values/strings.xml will be shown

2. If the phone locale is with language code zh but DOES NOT belong to CN/TW region, then
    - /values-zh/strings.xml will be shown

3. If the phone locale is zh-TW, then
    - /values-zh-rTW/strings.xml will be shown

4. If the phone locale is zh-CN, then
    - /values-zh-rCN/strings.xml will be shown

Please note that you only nehttp://ykyuen.wordpress.com/wp-admin/post.php?action=edit&post=843ed to copy the text values which u want to localize to those /values-XX/strings.xml. If the string is not found, then it will show the value in the default strings.xml inside the /values folder.

In addition, localization of /drawable and /layout can be done by creating the corresponding folders such as /drawable-zh-rTW and /layout-zh-rTW.

Done =)

Reference: Android Developers Google Group – Localizing Android Apps

Tomcat – Setting Java System Properties for webapps

December 15, 2009 at 10:29 | In Tomcat | Leave a Comment
Tags:

If you need to set the Java System Properties for the webapps in Tomcat, your need to declare it in the $CATALINA_OPTS.

Example: if i want to change the user.home property to /home/new_home

export CATALINA_OPTS=-Duser.home=/home/new_home

Restart the Tomcat to apply the new change.

Please note that this change applies to all webapps in Tomcat. There is not way to set Java System Properties differently in each webapp.

Done =)

NovelGrid Android Application – 記得睇波

December 12, 2009 at 08:41 | In Android, NovelGrid | Leave a Comment
Tags: , ,

記得睇波係 NovelGrid 的第一個 Android Application,暫時只有繁體中文版本。讓你隨時隨地查看英超、德甲、意甲、西甲與日本J1聯賽賽程和比賽結果。

請按右鍵另存新檔
下載記得睇波version1.1

Screenshots

Android – Android Application Package .apk Installation

December 11, 2009 at 08:17 | In Android | Leave a Comment
Tags:

Android Market provides a platform for Android user to download and install some Android applications. Actually all Android application is packaged in a .apk file and it is possible to download and install the package directly without going thru the Android Market.

What i need to do is just enable the Unknown Source setting in Settings > Applications. Then u can download and run the .apk in your Android phone.

Done =)

Android – Capture Screenshot

December 10, 2009 at 09:00 | In Android | Leave a Comment
Tags: ,

Here are the steps about how to capture a screenshot on your Android phone. Please note that it is for Windows user only.

1. Install the Android SDK

2. Enable the USB Debugging on your Android phone
   - Settings > Applications > Development

3. Connect the phone to the computer using the USB cable

4. Install the ADB driver which is located at /android-sdk/usb_driver

5. Start the Dalvik Debug Monitor/android-sdk/tools/ddms.bat

6. You should be able to find your phone listed in the monitor

Dalvil Debug Monitor

7. Select your phone

8. Click Device > Screen Capture or Ctrl + s

9. Your screen is captured and u can save it as a .png

Android Screenshot Sample

Done =)

Cow Computing

December 9, 2009 at 23:16 | In General | Leave a Comment
Tags: ,

Steve has published his blog~
i have added the link in the Link widget.

Cow Computing

The cow is using Mac!! =P

PHP – Add Text on an Image

December 7, 2009 at 00:42 | In PHP | Leave a Comment
Tags:

I find a very simple method on web about adding text on an image by PHP.
Reference: Write Text To Image

What u need is the following 3 files and an web server.

  • msjh.ttf – The font file for the text
  • test.png – The original image
  • text_on_image.php – The php file which will display the text.png with text added

text_on_image.php

<?php

/*** set the header for the image ***/
header("Content-type: image/png");

/*** specify an image and text ***/
$im = writeToImage('test.png', 'PHPRO rules again');

/*** spit the image out the other end ***/
imagepng($im);

/**
 *
 * @Write text to an existing image
 *
 * @Author Kevin Waterson
 *
 * @access public
 *
 * @param string The image path
 *
 * @param string The text string
 *
 * @return resource
 *
 */
function writeToImage($imagefile, $text){
/*** make sure the file exists ***/
if(file_exists($imagefile))
    {
    /*** create image ***/
    $im = @imagecreatefrompng($imagefile);

    /*** create the text color ***/
    $text_color = imagecolorallocate($im, 0, 255, 0);

    /*** set the font file ***/
    $font_file = './msjh.ttf';

    /*** splatter the image with text ***/
	imagefttext($im, 20, 0, 25, 150, $text_color, $font_file, "HelloWorld");

    }
else
    {
    /*** if the file does not exist we will create our own image ***/
    /*** Create a black image ***/
    $im  = imagecreatetruecolor(150, 30); /* Create a black image */

    /*** the background color ***/
    $bgc = imagecolorallocate($im, 255, 255, 255);

    /*** the text color ***/
    $tc  = imagecolorallocate($im, 0, 0, 0);

    /*** a little rectangle ***/
    imagefilledrectangle($im, 0, 0, 150, 30, $bgc);

    /*** output and error message ***/
    imagestring($im, 1, 5, 5, "Error loading $imagefile", $tc);
    }
return $im;
}
?>

You can add text to gif or jpeg by using the imagegif()/imagejpeg() and imagecreatefromgi()/imagecreatefromjpeg() to replace the imagepng() and imagecreatefrompng().

Done =)

Next Page »

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.