Archive for February, 2012

How to Fix the Firefox Font (Windows)

Comments Off

If you think the font in Firefox on Windows XP looks horrible it may be because you are using the standard method of edge smoothing for screen fonts (which is the default). There is a setting you can adjust in your “Display Properties” to set the smoothing method to “ClearType”. Apparently Internet Explorer does this by itself but you need to do the following to enable it in Firefox:

1. Right-click on your Desktop and choose “Properties”.
2. Click on the “Appearance” tab.
3. Click the “Effects” button.
4. Select the checkbox for the “Use the following method to smooth edges of screen fonts” option and set the drop-down list to “ClearType”.
5. Click OK to exit.

This is illustrated below:

Setting "ClearType" smoothing method.


Android: Storing a DatePicker and TimePicker in SQLite Database

Comments Off

If you are looking for an easy way to store a DatePicker and TimePicker control to an SQLite database, one method is to convert them to a Calendar object and store the combined date and time in milliseconds (a ‘long’ value). Take the following method as an an example:

private Calendar createAsCalendar(DatePicker dp, TimePicker tp)
{
    // Convert a DatePicker and TimePicker control in to a calendar object. The time is
    // stored in UTC minutes and unaffected by time zone
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
 
    cal.set(Calendar.YEAR, dp.getYear());
    cal.set(Calendar.MONTH, dp.getMonth());
    cal.set(Calendar.DAY_OF_MONTH, dp.getDayOfMonth());
    cal.set(Calendar.HOUR_OF_DAY, tp.getCurrentHour());
    cal.set(Calendar.MINUTE, tp.getCurrentMinute());
    cal.set(Calendar.SECOND, 0);
 
    return cal;
}

Read the rest of this entry »


Common Operations With Java Calendar API

Comments Off

The date/time API in Java gets a bad reputation but it is not so bad to work with once you get used to it and is fine for doing simple manipulations or calculations without the need to use a third party library. There are various bugs and some performance issue with the native API so if you are doing an application which heavily utilises date/time functionality you might want to look in to using something like Joda Time instead.

The majority of date/time operations in Java are done using the Calendar object. Below are examples of some common date/time operations using the native Java API:

Read the rest of this entry »


Android: How to Create a Boot Receiver

4 Comments »

Sample Code: Click Here

A boot receiver class is useful when you wish to run a piece of code or start a service as soon as the device has finished booting up. This is very simple to implement requiring only a class that derives from BroadcastReceiver and some configuration in the AndroidManifest.xml file.

There is a link to a sample Eclipse project at the top of this article. Below I examine the main elements of creating a boot receiver class. Lets start by looking at the AndroidManifest.xml file:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bytefoundry.BootReceiver"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk android:minSdkVersion="7" />
 
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <receiver android:name=".BootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
        <activity
            android:name=".Boot_ReceiverActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>

This is where the majority of the configuration for a boot receiver takes place. The first thing to note is near the top of the file. You can see that you must declare using the “android.permission.RECEIVE_BOOT_COMPLETED” permission. Without this your application will not be notified on boot up and may crash or otherwise fail.

Read the rest of this entry »