Category Archives: Uncategorized

QuteSound – SoundCloud client for symbian

After finished my work targets on one symbian^3 app, I start looking for something interesting to make. I just need to waste my time. Long ago, my friend suggested me to make simple SoundCloud client. According to Wikipedia, SoundCloud is an online audio distribution platform which allows musicians to collaborate, promote and distribute their music. In my opinion, SoundCloud is like twitter, but instead typing 140 characters, you submit your sounds. I called my app QuteSound and with my limited set of design skills, I managed to make a logo using Photoshop.

qutesound logo

qutesound logo

The app is still a work on progress. I use nice Qt examples RestaurantApp as design template so I need to change it to something original mine (If you have any design that you want to share, please contact me). As the proof of concept, I only implement 2 features: record – upload and get 20 latest tracks. It working well, I think, and I will add more features when I have time.

login pages

login pages

application pages - tracks, record and profile

application pages - tracks, record and profile

At current state, I downloaded whole mp3 file then play it using Qt phonon library. Documentation said phonon capable of streaming media. That will be my to do list. And yes, SoundCloud API generously provided waveform image for every tracks as shown above.

Run libphonenumber javascript version in blackberry app

So this is what happened, in my blackberry app, I want to recognize a country by parsing phone number. For example, from +8285659XXXXXX I expect to get country is South Korea and phone number is 85659XXXXXX. The challenge is to cover all 240 more country code and verify if the number is a valid one. My first thought is to compare all the first 1-4 number to list of country code as shown here. Lucky for us, google has release their phone number parsing library libphonenumber. This library is released in C++, java and javascript. Since blackberry development is in java, maybe we can use java version? Unfortunately not. Blackberry java is J2ME and to run libphonenumber you need whole deal of java. For example, java.util.Map and java.io.Serializable.

phone number validation

phone number validation

Then the options are either to port the code to J2ME compatible, or execute the javascript version. Yes, you can execute javascript code programmatically using BrowserField class from Blackberry JDE. If you use BlackBerry Java Plug-in for Eclipse, like me, you can find sample application that integrate java code with javascript.  You can test libphonenumber javascript demo here. And you can get the source code using svn.

So how do we do this ?

First, we need to modify libphonenumber  javascript demo code to get parameter from url and return string output. Because, user selected phone number from his contact list and we don’t want them to enter the number again to, say, a textbox. We will use parameter in url, for example

local:///index.html?phoneNumber=+82856XXXXXXXX&defaultCountry=ID

To get the parameter, we can use nice code to query url string from here.

Next, just pass the number we get from url to the javascript function inside our html code.

var result = "none";
function phoneNumberParser() {
var phoneNumber = gup( 'phoneNumber' );
...
try {
var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
var number = phoneUtil.parseAndKeepRawInput(phoneNumber, regionCode);
...
}
return result;
}

Set the html and necessary javascript files from libphonenumber to our project resource.

Then in our blackberry java code, we execute javascript code.


public class ContactListScreen extends MainScreen
{
private BrowserField _browserField;
...

// screen constructor, set browserfield listener so we can execute our javascript code when html document loaded
public ContactListScreen(Country country)
{
BrowserFieldConfig config = new BrowserFieldConfig();
config.setProperty(BrowserFieldConfig.ALLOW_CS_XHR, Boolean.TRUE);
_browserField = new BrowserField(config);
BrowserFieldListener listener = new BrowserFieldListener()
{
public void documentLoaded(BrowserField browserField, org.w3c.dom.Document document) throws Exception
{
try
{
String strReturnValue = (String)browserField.executeScript("javascript:phoneNumberParser()");
Status.show(strReturnValue);
}
catch(Exception ex)
{
Status.show("Phonenumber validation error : " + ex.getMessage());
}
}
};
_browserField.addListener( listener );
add(_browserField);
}

// run number validation
private void validateNumber(String input)
{
BrowserFieldRequest request = new BrowserFieldRequest("local:///index.html?phoneNumber=" + input + "&defaultCountry=ID");
_browserField.requestContent(request);
}

...
}

That’s it. Note that you need to be always connected to internet, since libphonenumber use googles’s closure library. But I think you can run it locally, by copying all necessary files from closure into one folder and include those javascript file in your html. Have fun 🙂