Category Archives: Development

Log4j property file examples

There aren’t too many clear examples of log4j.properties configuration examples around on the net. So, I thought of compiling a list of sample configurations to help anyone who might be looking to configure log4j.

In this article I will be covering the following scenarios with examples:

  1. Logging to Console
  2. Logging to a File
  3. Logging to multiple Appenders (or log files)
  4. Restricting logging levels by package name
  5. Having multiple appenders with different log levels
  6. Logging the output of a specific class or a package to a specific Appender

Continue reading

How to check network connectivity in Android

This tutorial shows how to check whether your Android phone is currently connected to a network or not (e.g. Wi-Fi, 3G etc.).

A while back, I wrote a tutorial on how to dynamically monitor network connectivity in Android. However, sometimes all you want is to check if your phone has an active network connection at any given time (i.e. not to constantly monitor its status).

Continue reading

Introduction to working with kSOAP2 in Android

This is an introductory tutorial showing how to consume SOAP-based web services in Android using the kSOAP2 library.

How to use kSOAP2 library in Android

Despite rising popularity of RESTful services, there are still a significant number of SOAP-based web services around that are being consumed by mobile applications; specially when working in the enterprise world. Android does not have native support for web service consumption, and this handy light-weight library called kSOAP2 allows Android applications to easily and efficiently consume SOAP-based web services.

In this tutorial I will show you how to use kSOAP2 in Android to consume a publicly available SOAP-based web service. A fully working example of an Android project illustrating the use of kSOAP2 can be found at GitHub.

Continue reading

How to prevent screen timeout in Android

There are several mechanisms available for Android applications to stop the phone’s screen from being turned off. These methods override the default ‘screen timeout’ behaviour of your phone (typically found under Settings -> Display), and will keep the screen on while your application is running.

I will be introducing two methods to stop the screen from being dimmed. The two methods provide means of accomplishing this depending on the current state of your application; i.e. whether it has an Activity on the foreground (visible on screen) or running on the background (as a Service).

  1. Use of FLAG_KEEP_SCREEN_ON option for your Activity.
  2. Use of a WakeLock.

Continue reading

Scrabble Assistant (Android) v2.0.0 is released

The latest versions of Scrabble Assistant Lite and Scrabble Assistant Pro for Android are now out in the Android market!

You can download them from:

Please feel free to leave your feedback and suggestions here! Don’t forget to rate the application and leave a comment on the Android Market if you find this useful!

Thanks!

Change Log for v2.0.0 (Pro version)

  1. Added support for SOWPODS/CSW 2012 dictionary (with 270163 words).
  2. Displays the title of the currently selected dictionary as part of the application title.
  3. Fixed issue where the anagrams are not being generated property with TWL/OWL dictionary.
  4. Minor UI improvements (help text and labels)

Change Log for v2.0.0 (Free/Lite version)

  1. Added support for SOWPODS/CSW 2012 dictionary (with 270163 words).
  2. Displays the title of the currently selected dictionary as part of the application title.
  3. Can enter up to 7 characters when performing anagram searches. The search results are still restricted to 6 characters.
  4. Fixed issue where the anagrams are not being generated property with TWL/OWL dictionary.
  5. Minor UI improvements (help text and labels)

Continue reading

How to format string resources in Android

Resource files are one of the major strength in Android SDK that allows you to separate presentation from application logic. String resources in particular helps to effectively manage multi-lingual applications with ease.

In this tutorial, I will be showing how to use formatted string resources in Android. In addition to discussing the benefits of using formatted strings, the tutorial will show (a) how to define formatted string resources in xml, and (b) how to problematically use them when developing applications.

Continue reading

ActionBar design pattern example for Android

ActionBar is a user interface (UI) design pattern found in Android that allows users to quickly perform common actions within your application. ActionBar replaces the traditional title bar with a more featured and consistent UI. Popular applications that use this pattern include Facebook App and Twitter App. ActionBars help us to:

  • Have a dedicated UI space for commonly used actions in your applications to increase user engagement (e.g. Search, Refresh, display status etc.)
  • Have a consistent look and feel across all activities
  • Allows the user to perform common/key actions quickly without having to use the menu

Though framework support for ActionBars has been added in Android 3.0+ (Honeycomb), developers are required to implement it from scratch for non-tablet versions of Android. The aims of this tutorial are two-fold; Firstly to demonstrate how to build an ActionBar widget from ground up, and secondly to illustrate how to use the ActionBar in your application.

Figure 1 shows an Activity with the ActionBar we are planning to implement in this tutorial.

Figure 1: Action Bar Example

Continue reading

Creating multi-line EditText in Android

This is a small guide demonstrating how we can use Android EditText controls to create multi line text inputs.

Approach #1
The simplest way to create a multi line text input is using the following xml snippet:

XHTML
1
2
3
4
<EditText android:id="@+id/txtMultiLine"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:text="Default text" />

This will create a EditText view that displays the default text as shown in Figure 1 (a). When you enter new lines, the EditText will grow vertically (Figure 1 (b)). This might not be desirable in actual applications, as your layout becomes too fluid; potentially pushing important information out of user’s view.
Continue reading

How to monitor network connectivity in Android

Android devices have multiple network interfaces (e.g. WiFi and 3G/4G etc.) that allows them to go online and be connected to the outside world. At the same time, these network interfaces are prone to intermittent disconnection (for example, due to location, weather etc). Having knowledge of when the phone is connected (or disconnected) helps applications to act smartly when communicating over the internet. An example is automatically resuming pending downloads – without user intervention – when your network connection comes back online.

The following guide shows how you can monitor the network connectivity in Android, so your application can respond better when the network connectivity changes.
Continue reading

Scrabblet version 1.1.0 released

I released the second version of Scrabblet (A word assistant application for Android mobiles) today. This includes addition of a new feature to display word scores against search results, UI facelift to improve usability and few performance tweaks.

New main screen for Scrabblet Pro

Have a go at the free version using the QR code below or going directly to the Android Market on your phone!

QR code for Scrabblet Lite

Click through to read the full change log.
Continue reading