Recent Notes

Displaying keyword search results 11 - 20
Created by Fang on October 28, 2011 13:49:40    Last update: October 30, 2011 19:23:25
This is a simple example to demonstrate the templating power of JSF facelets. If you've used struts tiles before, you'll recognize the simplicity of templating with facelets. I've stripped out everything else except the pages themselves, just to put our focus on facelets. This is a Maven based project, and you need Tomcat (or any servlet container) to run the resulting webapp. To begin with this is the list of files: ./pom.xml ./src/main/webapp/home.xhtml ./src... I left faces-config.xml in there for completeness sake, it may not be needed. The Maven POM ( pom.xml ): <?xml version="1.0" encoding="UTF-8"?> <project... Web app configuration ( WEB-INF/web.xml ): <?xml version="1.0" encoding="UTF-8"?> <web-app... Empty WEB-INF/faces-config.xml : <?xml version="1.0" encoding="UTF-8"?> <!-- Thi... index.jsp is simply a redirect to home.jsf : <% response.sendRedirect("home.jsf"); %>...
Created by freyo on September 07, 2011 16:46:14    Last update: September 07, 2011 19:23:00
The Android unit test framework is based on JUnit 3 , not JUnit 4. Test cases have to extend junit.framework.TestCase or a subclass (such as android.test.InstrumentationTestCase ). Tests are identified by public methods whose name starts with test , not methods annotated with @Test (as in JUnit 4). An Android test suite is packaged as an APK, just like the application being tested. To create a test package, first you need to identify the application package it is testing. Google suggests to put the test package source in a directory named tests/ alongside the src/ directory of the main application. At runtime, Android instrumentation loads both the test package and the application under test into the same process. Therefore, the tests can invoke methods on...
Created by alfa on June 03, 2011 09:08:52    Last update: June 03, 2011 09:08:52
import java.util.Arrays; public class Array...
Created by freyo on May 17, 2011 11:13:17    Last update: May 17, 2011 11:13:17
This is an odd-ball content provider in that it doesn't provide database records, but provides a resource as a stream. It can be used to provide media files or XML resources. Start the project with: tools/android create project --package com.android... Create assets directory and add an XML file ( assets/demo.xml ): <? xml version="1.0" encoding="UTF-8"?> <people... Edit the layout ( res/layout/main.xml ): <?xml version="1.0" encoding="utf-8"?> <LinearL... Edit src/com/android/cptest/Dummy.java : package com.android.cptest; import java.io.... Add content provider ( src/com/android/cptest/XmlResource.java ): package com.android.cptest; import java.io.... Update AndroidManifest.xml : <?xml version="1.0" encoding="utf-8"?> <manifes... Add this section to the end of build.xml : <target name="-package-resources"> <ech... Build and install: ant install Screenshot: Remove the Dummy activity ( AndroidManifest.xml ): <?xml version="1.0" encoding="utf-8"?> <manifes... Create a new project for...
Created by freyo on May 09, 2011 11:55:27    Last update: May 09, 2011 11:55:27
Reading from or writing to sdcard isn't any different from normal Java io operations. Just use Java io to open the file then read from or write to it. Android does provide some utility methods to lookup directories under the sdcard. Examples: // import android.os.environment File extDi... Example logcat output: D/Test ( 1353): External storage dir from Envi... To write to sdcard: try { FileWriter out = new FileWriter(new F...
Created by freyo on April 15, 2011 09:00:54    Last update: April 15, 2011 09:00:54
Sample code for writing to a file in the internal storage. There are three steps: Open the file with Context.openFileOutput , which returns java.io.FileOutputStream . Write to the file. Close the file. import java.io.*; import android.content.Contex... The second parameter to openFileOutput is the operating mode. Available values are: Context.MODE_PRIVATE Context.MODE_APPEND Context.MODE_WORLD_READABLE Context.MODE_WORLD_WRITEABLE The file is saved in /data/data/<package_name>/files .
Created by alfa on April 08, 2011 12:33:08    Last update: April 08, 2011 12:33:08
This example captures the screen of the current Java application window, instead of the full screen. import java.io.*; import java.awt.*; import ...
Created by alfa on April 08, 2011 11:05:24    Last update: April 08, 2011 11:05:24
Key points: Use java.awt.Robot to capture a screen region as java.awt.image.BufferedImage . Use javax.imageio.ImageIO to write image out to a file. import java.awt.AWTException; import java.awt.R...
Created by nogeek on April 07, 2011 21:30:54    Last update: April 07, 2011 21:30:54
This is the opposite of parsing. You can use javax.xml.transform.Transformer to output a DOM tree to a file. import java.io.*; import javax.xml.parsers.Docu...
Created by alfa on April 06, 2011 12:48:44    Last update: April 06, 2011 12:48:44
package com.demo.io; import java.io.*; ...
Previous  1 2 3 4 Next