rich:calendar and the onchange event

June 1st, 2010 Shri No comments

I wanted to trigger some validation based re-renders with the rich:calendar component. I was scratching my head for a while trying to figure out why it wasn’t working.

Then it happened, its supposed to be onchanged. This particular component requires the extra d at the end… and it worked and everyone lived happily ever after…

Categories: Uncategorized Tags: , ,

Android – Parcel data to pass between Activities using Parcelable classes

April 26th, 2010 Shri No comments

Passing data between activities on android is unfortunately, not as simple as passing in parameters. What we need to to do is tag these onto the intent. If the information we need to pass across is a simple object like a String or Integer, this is easy enough.

String strinParam = "String Parameter";
Integer intParam = 5;
 
Intent i = new Intent(this, MyActivity.class);
i.putExtra("uk.co.kraya.stringParam", stringParam);
i.putExtra("uk.co.kraya.intParam", intParam);
 
startActivity(i);

Passing in custom objects is a little more complicated. You could just mark the class as Serializable
and let Java take care of this. However, on the android, there is a serious performance hit that comes with using Serializable. The solution is to use Parcelable.

Read more…

Android – Managing Global Configuration

April 25th, 2010 Shri No comments

The Problem

Accessing preferences / configuration / settings from Android is actually pretty straightforward as long as you are in an Activity. To read:

// PREFS_FILENAME = "nameOfPrefsFile";
 
SharedPreferences pref = getSharedPreferences(PREFS_FILENAME,
                              Context.MODE_PRIVATE);
 
String string = pref.getString("key", "default");
// 1 is the default if key isn't set
int intValue = pref.getInt("intKey", 1); 
 
// and so on

SharedPreferences is the key class. To write, you also need the SharedPreferences.Editor class, as follows:

// PREFS_FILENAME = "nameOfPrefsFile";
SharedPreferences pref = getSharedPreferences(PREFS_FILENAME,
                              Context.MODE_PRIVATE);
Editor editor = pref.edit();
editor.putString("key", "value");
editor.putInt("intKey", 5);  
 
// Until you call commit, the changes will not
// be written, so don't forget this step
editor.commit();

In general however, you will need access to settings in more than one activity and it seems a bit wasteful to get these bits littered through the application. Since I am lazy and like to write things just once, I  separated all the prefs stuff into one class called Settings.

Read more…

Linux bulk search and replace

April 21st, 2010 Shri No comments

Doing a bulk search and replace across a set of files is actually surprisingly easy. sed is the key. It has a flag – i that will modify the files passed to it in-place.

 
$ sed -e 's/TextToFind/Replacement/' -i file1 file2 file3

Tie this power with either grep -l .

 
$ grep -l TextToFind * |xargs sed -e 's/TextToFind/Replacement' -i

or find

 
$ find . -exec sed -e 's/TextToFind/Replacement' -i {} ;

If there are multiple changes you want to make, just put them all into a file and pass it in via the -f flag.

file: replacements.patterns

s/TextToFind1/Replacement1/
s/TextToFind2/Replacement2/
s/TextToFind3/Replacement3/

and the command, using find to iterate through all files in the current directory and subdirectories.

 
find . -exec sed -f replacements.patterns -i {} ;

et voila – hope it helps.

Android – Multi-line Select List

April 19th, 2010 Shri No comments

It turns out that it is surprisingly easy to add a multi line select list to the UI.
There are four main parts to it. The layout file, a subclass to the adapter, the activity and of course the data itself.

Read more…