Posts Tagged ‘Open’

Using the BlackBerry Notifications Manager

Creative Commons Licence

This work is licenced under a Creative Commons Licence.

Quite often we want to be able to notify the user that some event has happened. It is nice to be able to allow the user to configure what form that notification takes depending on the profile in use (Normal, Silent, Vibrate, etc.). The procedure to do this is quite simple, although when I first tackled this problem the documentation was confusing. I like to have a state class that keeps the data used to trigger the notification. This can become important if you application has a complex notification system. In this example it isn’t really necessary, but here is my storage class Notify:

/*
 * Notify.java
 *
 * © Richard Buckley www.hrbuckley.net, 2011
 *
 * This work is licenced under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
 * To view a copy of this licence, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to
 * Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.
 */

package src.notify;

import net.rim.device.api.notification.NotificationsManager;
import net.rim.device.api.notification.NotificationsEngineListener;

// The Notify class is just a helper to keep track of the data needed to invoke and
// cancel the notification. Mainly they keep track of the _eventId so the notification
// can be canceled, if you want to implement that, it is not used here and this
// could be rolled into the main program if simplification is more important.

final class Notify
{
    long _sourceId;
    long _eventId;
    int _priority;
    int _triggerIndex;
    long _timeout;

    public Notify(long sourceid, long eventid, int priority, long timeout, int triggerIndex) {
        _sourceId = sourceid;
        _eventId = eventid;
        _priority = _priority;
        _triggerIndex = triggerIndex;
        _timeout = timeout;
    }

    // invoke the event
    public void fire() {
        // triggerImmediateEvent causes non-interactable events to fire, such as Tunes, Vibrations and LED flashing
        NotificationsManager.triggerImmediateEvent(_sourceId, 0, this, null);
    }

    // cancel the event
    public void cancel() {
        NotificationsManager.cancelImmediateEvent(_sourceId, 0, this, null);
    }

}

Somewhere in the initialization of your code you must register a UID, Name and level with the OS. This will cause the name you have chosen to appear in the profiles where the user can get creative. Then it is a simple matter of firing the appropriate notification at the right time.

/*
 * Notify.java
 *
 * © Richard Buckley www.hrbuckley.net, 2011
 *
 * This work is licenced under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
 * To view a copy of this licence, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to
 * Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.
 */

package src.notify;

import net.rim.device.api.notification.NotificationsConstants;
import net.rim.device.api.notification.NotificationsManager;

// A skeleton class that will fire notifications.
//
class MyNotifierClass {
    public static final long NOTIFY1 0x6deb32addca8d89aL; // src.notify.Notify1
    public static final long NOTIFY2 0xd8759a3149fe119L; // src.notify.Notify2

    private Notify        _notify1, _notify2;
    private long          _EVENT_ID;

    public MyNotifierClass() {
        _EVENT_ID = 0L;

        //New Notifications Sources - these will show up as editable configurations in the Profiles application
        NotificationsManager.registerSource( NOTIFY1, "Notify 1", NotificationsConstants.IMPORTANT );
        NotificationsManager.registerSource( NOTIFY2, "Notify 2", NotificationsConstants.IMPORTANT );
    }

    public void someMethod() {
        _notify1 = new Notify(NOTIFY1, ++_EVENT_ID, 500, -1, NotificationConstants.MANUAL_TRIGGER);
        _notify1.fire();
    }

    public void someOtherMethod() {
        _notify2 = new Notify(NOTIFY2, ++_EVENT_ID, 500, -1, NotificationConstants.MANUAL_TRIGGER);
        _notify2.fire();
    }
}

Scripts for Building BlackBerry Programs Automatically

Creative Commons Licence
This work is licenced under a Creative Commons Licence.

These scripts are a work in progress. I’m still working on them so check back periodically and be aware that there may be bugs. Download the Git repository with git clone git://git.hrbuckley.net/BB/bin/. Or if you have already cloned the repositiory merge in any updates with git pull git://git.hrbuckley.net/BB/bin/

I have been using Git as my version control system of choice for nearly a year now. One of the benefits of using Git on Windows is that you get a Unix like environment for free. This gives rise to the ability to write Bash scripts to compile JDE projects automatically. We need to add some files and set up the environment. I’m using Windows 7 so in %USERPROFILE% I have created a bin directory and a .bashrc file:

# %USERPROFILE%\.bashrc
ifsave=$IFS
IFS=$(echo -en "\n\b")
export MYPROGRAMFILES_X86="/g/Program Files (x86)"
IFS=$ifsave

if [ -d ~/bin ]
then
  if [ -e ~/bin/jderc ]
  then
    . ~/bin/jderc
  else
    echo "No jderc"
  fi
  if [ -e ~/bin/javarc ]
  then
    . ~/bin/javarc
  else
    echo "No javarc"
  fi
fi

The jderc file:

#
# Iterate through all installed RIM JDEs adding a JDExxx and JDELIBxxx environtment variables with the
# path to the bin and lib directories for that JDE, and add the OS version to the JDEVERSIONS
# environment variable. Set the last (highest OS version) to JDEMAIN and JDELIBMAIN.
#
export RIMPROGFILES="${MYPROGRAMFILES_X86}/Research In Motion"

IFSAVE=$IFS
IFS=$(echo -en "\n\b")

JDEVERSIONS=""
for rim in ${RIMPROGFILES}/*
do
  b=$(basename $rim);
  case $b in
    BlackBerry*)
      v=$(echo $b | sed -e "s/BlackBerry JDE //i" | sed -e "s/\.//g")
      JDEVERSIONS="${JDEVERSIONS} ${v}"
      eval "export JDE${v}=\"${rim}/bin\""
      eval "export JDELIB${v}=\"${rim}/lib\""
      export JDEMAIN="${rim}/bin"
      export JDELIBMAIN="${rim}/lib"
      ;;
  esac
done
export JDEVERSIONS

IFS=$IFSAVE

The javarc file:

#
# Set up path variables for the JDK and JRE
#
export JAVAPROGFILES="${MYPROGRAMFILES_X86}/Java"

IFSAVE=$IFS
IFS=$(echo -en "\n\b")

JDKPATH=""
for jdk in ${JAVAPROGFILES}/jdk*
do
  if [ -d ${jdk}/bin ]
  then
    JDKPATH="${jdk}/bin"
  fi
done

for jre in ${JAVAPROGFILES}/jre*
do
  if [ -d ${jre}/bin ]
  then
    JREPATH="${jre}/bin"
  fi
done

export PATH="${JDKPATH}":"${JREPATH}":"${PATH}"

IFS=$IFSAVE

Now we can build a JDE project with the build script:

#!/bin/sh
#
# Build the specified JDE project using the latest JDE instaled, or as optionally specified.
#
if [ $# -lt 1 ]
then
  echo "Usage: build <project> [ $JDEVERSIONS ]"
  exit 1
fi

DOSPWD=$(pwd | tr / \\\\ | sed -e "s/^.\(.\)/\1:/")

#
# Get the files and libraries from the project file
#
MOD=$1
if [ -e ${MOD}.jdp ]
then
   JDP="${MOD}.jdp"
   files=$(awk 'BEGIN { copy = 0 } /^\[Files/ { copy = 1; next } /^]/ { copy = 0; } copy { print }' $JDP)
   libs=$(awk 'BEGIN { copy = 0 } /^\[DependsOn/ { copy = 1; next } /^]/ { copy = 0; } copy { print }' $JDP)
fi

FILES=""
LIBS=""
jde="JDEMAIN"
lib="JDELIBMAIN"
if [ "${files}EMPTY" != "EMPTY" ]
then
  for f in $files
  do
    FILES="${FILES}\"$f\" "
  done

  for l in $libs
  do
    LIBS="${LIBS}\"${l}.jar\" "
  done

  shift

  if [ $# -ge 1 ]
  then
    jde="JDE${1}"
    lib="JDELIB${1}"
    if [ ! -d "${!jde}" ]
    then
      jde="JDEMAIN"
      lib="JDELIBMAIN"
    fi
  fi

  #
  # If we can find the appropriate rapc compiler, build the program
  #
  if [ -e "${!jde}/rapc.exe" ]
  then
    "${!jde}/rapc.exe" -quiet -define=PREPROCESSOR "import=${LIBS}${!lib}/net_rim_api.jar" "codename=${MOD}" ${MOD}.rapc $FILES
  else
    echo "Could not locate JDE compiler"
    exit 2
  fi
fi

DLink DNS-323

Just bought one of these for home. I was impressed with it’s reviews, price and performance even before I knew it runs Linux and is extensible. For example, it is relatively easy to add NFS support to it.

Blackberry S/MIME Certificates

I’ve been trying to mash up a way to serve PK certificates (X.509) to Blackberries without the overhead of the whole BES server. It turns out that a very plan OpenLDAP installation (available for most Linux distributions) works very well. The quick start guide is enough to get the server up and running. It took a little work figure out how to get the certificates pushed into the server. It turns out that they have to be in DER format, while they are normally in PEM format. No problem OpenSSL takes care of that:

openssl x509 -outform DER -in incert.pem -out outcert.der

Then include the following line in your LDIF file for the user:

userCertificate;binary:< file:///path/to/outcert.der

I finally found that out from here.

Mozilla Labs » Blog Archive » Introducing Ubiquity

Mozilla Labs » Blog Archive » Introducing Ubiquity.

This is one of the coolest advances in Web utility I’ve seen in a very long time!

Playing with the PVR

Since I won’t be flying tonight. I decided to tinker with the PVR. A few weeks ago I bought a PVR Plus 9242 for our Bell TV (formerly ExprssVu) satellite TV system. That is a bit of a long story, but one of the reasons I wanted the 9242 was that Bell had announced they were going to roll out storage expansion for the PVR through external USB drives. Apparently around about August 7th they pushed out the firmware upgrade. So a rainy day is a good time to check it out.

The official way to get expanded storage capacity is to buy a LaCie 750GByte drive from Bell. The list price (as I write this) is $199.00, which isn’t horrible, but Future Shop had a stack of them for $129.00 (also as I write this). I picked one up for the better half’s computer, but I have disk drives and USB enclosures around my office so I decided to see if the system was Bell specific, LaCie specific or open.

Good news it is open. I used a 120GByte Seagate Barracuda IDE drive with a USB 2.0 adapter. Followed the instruction from the Bell site above, wait for the PVR to format the drive, reboot and hey presto I have an external hard drive. Archiving shows is straight forward if not blindingly fast. One hour of HD takes nearly 20 minutes to copy over. The system is fast enough to watch shows from the external drive, and I don’t see any reason why one can’t buy as many external drives as one’s piggy bank will support to archive favorite shows.

Other bloggers have reported that plugging the drive into a PC once it has been formatted by the PVR will result in an automatic reformat of the drive. Since I have auto run disabled on my PC this did not happen when I connected my drive back to my PC. A quick check with PowerQuest tools shows two Linux EXT3 partitions one with about 1% of the capacity, the other with the remainder. Looking at the partitions with IFS Drive (a Windows EXT2 driver) shows the partitions unformatted, but PowerQuest indicates about 40MByte used on each, so either there is something non-standard, or it really was reformatted. Hmm, needs more investigation.

The really good news is you don’t need to buy the external drive from Bell if you don’t want to. The LaCie unit they specify should be a good one, but you may be able to get it cheaper at a big box store. Plug it in, format it, use it. It is really that simple.

Slashdot | HP Releases Hackable ARM-Based Calculator

While not exactly Open Source, releasing the information needed to customize the operating software on a piece of commercial hardware is pretty cool. When the hardware has an Arm CPU, display and keyboard for about $40 it is very cool.

Slashdot | HP Releases Hackable ARM-Based Calculator.

New Theme

I have installed a new theme that does almost everything I want from a theme. I just had to fiddle with the default link widget to get my dynamic links. This theme is available from Bytes for All.

TCExam :: CBA – Computer-Based Assessment

TCExam :: CBA – Computer-Based Assessment.

I’ve been trying to come up with a system to generate and manage quizzes and tests for my flying scholarship classes for a long time. It seems it has been here all along. I love the open source community. Now to install it and see if it is as good as it appears from the web site.

A dash of lime — a new twist that may cut CO2 levels back to pre-industrial levels

Here is an article on an interesting process to pull CO2 out of the atmosphere. A dash of lime — a new twist that may cut CO2 levels back to pre-industrial levels. Of course it is an operation on a huge scale, and unless the IPCC is right (something that I don’t take as a given) would be a lot of effort without much effect. In any case the effort is modeled on Open Source and the idea is worth researching, have a read.

Visitors

Site Links

  • Blackberry Forums
  • Blackberry Support Forums
  • FreshMeat
  • Radio Electronics
  • SlashDot
  • Smiths Falls Weather
  • Stack Overflow
  • XKCD
  • Yahoo Groups

Blogroll

Meta