Barcode Module For Appcelerator Titanium: Version 0.2

Version 0.2

Two weeks ago we released an updated version of our barcode module for Appcelerator Titanium Mobile. We’ve received some great feedback since then. Considering this feedback and the release of Titanium 1.6, we worked on an update of our module.

Changes

The major changes were:

  • Fix compatibility for version 1.6 of the Titanium Mobile SDK
  • Fix callback for views outside of the root view

We’ve also updated the example application. It now uses a TabGroup and the new version of our barcode plugin.

Usage

To use the updated plugin, download it from the download section of our github repository. When you downloaded it, copy it to your project directory and reference it in the tiapp.xml file located in the same directory. It is important you set the version attribute to 0.2.



  ...
  
    com.mwaysolutions.barcode
  

If the scanner isn’t centered in high-resolution screens, you also need to add an additional entry to your tiapp.xml which sets the supports-screens tag of the android manifest correctly:



  ...
  
        
          
        
  

A complete tiapp.xml file could look like this:



com.mwaysolutions.barcodeexample
Barcode Example
1.0
M-WAY GmbH
http://www.mwaysolutions.com
Example applicatiton
2011 by pfleidi
default_app_logo.png
false
false
  default
  false
  false
false
  true
  a31aa681-860e-4923-abe7-b5d92718b640
  
    
      Ti.UI.PORTRAIT
    
    
      Ti.UI.PORTRAIT
      Ti.UI.UPSIDE_PORTRAIT
      Ti.UI.LANDSCAPE_LEFT
      Ti.UI.LANDSCAPE_RIGHT
    
  
  
    
      
    
  
  
    com.mwaysolutions.barcode
  

After you referenced the module and added the entry for the android manifest, you can load the plugin by using require(‘com.mwaysolutions.barcode’).

Posted in appcelerator, development, mobile | Tagged , , , , , , , , | 19 Comments

Update: Barcode Module For Appcelerator Titanium

Update

Few months ago we developed and released the first version of our barcode module for Appcelerator Titanium. Since then we received a lot of great feedback and therefore wanted to adapt this blog post and the plugin to support the currently available Appcelerator Titanium 1.5 SDK.

Appcelerator Titanium Mobile

Appcelerator Titanium Mobile is a platform which allows developing mobile applications using web technologies. The Applications are written in JavaScript and can be compiled for multiple devices. At the moment Titanium supports the Apple iPhone and iPad as well as Android devices. Blackberry support is on its way. We use it here at M-Way to develop cross platform apps for our customers.

Titanium provides a tool called Titanium Developer to build and deploy applications, and a set of SDKs which target different platforms. With this tool you are able to manage SDK versions, import/export projects and deploy them to different emulators or simulators and even real devices.

To get started, we recommend a look at the documents posted in the developer guides in the Titanium Developer Center and the mobile API guides.

Barcode Scanner

A few months ago we had to support barcode scanning for some titanium based projects here at M-Way Solutions. Because we only found a working module for the iPhone but didn’t find a suitable solution for Android, we started to develop our own module. We first released a version which needed to be built together with the whole Titanium Mobile SDK and also required patching some build scripts and application templates. Fortunately, the guys at Appcelerator did a great job improving their build process so it was possible for us to create a standalone version of our plugin which no longer needs to be build inside of the Titanium Mobile source tree. If you are interested in building your own pluins for Appcelerator Titanium, have a look at the Android Module Developer Guide.

The Android Module

To develop the Android module for Titanium mobile, we followed the instructions of the custom module tutorial written by the Titanium guys. It is available on our Github account and is licensed under the Apache 2 license. It uses the zebracrossing library for barcode processing and is loosely based on their barcode scanner for Android.

Prerequisites

Before you are able to use our module, you need to check if all dependencies are already installed:

Make sure you’ve installed at least the Android 1.6 SDK and the matching Google APIs. You can check which SDKs are installed by running the “android” application located in the tools folder of your Android SDK.

Building The Module

Note: Building the module yourself is not necessary. If you only want to use it for your projects, you can download it from the download section of our Github repository.

If you want to build the barcode module from source, you need to clone our git repository and build it with ant:

    # clone the repository
    git clone https://github.com/mwaylabs/titanium-barcode.git
    cd titanium-barcode
    # run ant to build the module
    ant clean && ant

If the build fails, make sure the entries in the buld.properies file point to the right path. On the developer’s machine, the Android SDK is located in /opt/android-sdk:

titanium.platform=/Library/Application Support/Titanium/mobilesdk/osx/1.5.1/android
android.platform=/opt/android-sdk/platforms/android-4
google.apis=/opt/android-sdk/add-ons/addon_google_apis_google_inc_4

The newly created *.jar and *.zip files can be found in the dist directory. The module you need is called com.mwaysolutions.barcode-android-$VERSION.zip.

Use the plugin

To use the plugin, you need to copy the com.mwaysolutions.barcode-android-$VERSION.zip to your project directory and reference it in the tiapp.xml file located the same directory:



  ...
  
    
      com.mwaysolutions.barcode
    
  

If the scanner isn’t centered in high-resolution screens, you also need to add an additional entry to your tiapp.xml which sets the supports-screens tag of the android manifest correcty:



  ...
  
        
          
        
  

A complete tiapp.xml file could look like this:



com.mwaysolutions.barcodeexample
Barcode Example
1.0
M-WAY GmbH
http://www.mwaysolutions.com
Example applicatiton
2011 by pfleidi
default_app_logo.png
false
false
  default
  false
  false
false
  true
  a31aa681-860e-4923-abe7-b5d92718b640
  
    
      Ti.UI.PORTRAIT
    
    
      Ti.UI.PORTRAIT
      Ti.UI.UPSIDE_PORTRAIT
      Ti.UI.LANDSCAPE_LEFT
      Ti.UI.LANDSCAPE_RIGHT
    
  
  
    
      
    
  
  
    
      com.mwaysolutions.barcode
    
  

After you referenced the module and added the entry for the android manifest, you can load the plugin by using require(‘com.mwaysolutions.barcode’). The module has a single method which is called scan(callbacks). In this case, callbacks is a JavaScript object with three properties: success, error and cancel. These three properties should point to callback functions which are called when a scan succeeded, an error occurred or when the scan was canceled.

Example Application

In addition to the module itself, we also created an example application which is using it. To use it, you just need to download the example code from Github or clone the repository and build it with the Titanium Developer application.

After starting Titanium Developer, you need to click “Import Project”, browse the directory of the downloaded application and select it.

After this is done, all you need to do is to run the Android emulator.

Just show me some code!

The usage of our barcode API is simple: You load the module with require(‘com.mwaysolutions.barcode’) and call “.scan()” on the returned object reference. You need to pass in a JSON-Object with the three callback functions success, error and cancel to the scan() method. If the scan works, success is called and the scanned barcode is passed as a parameter. Inside the callback functions you are now able to react to successful or canceled events and errors.

Titanium.UI.setBackgroundColor('#000');

// open a single window
var window = Ti.UI.createWindow({
    backgroundColor:'white'
  });

var label = Ti.UI.createLabel();
window.add(label);
window.open();

// create an instance of the module
var titaniumBarcode = require('com.mwaysolutions.barcode');

// call scan method
titaniumBarcode.scan({
    success:function(data) {
      if(data && data.barcode) {
        var label = Titanium.UI.createLabel({
            text:'Barcode: ' + data.barcode,
            textAlign:'center',
            width:'auto'
          });

        window.add(label);
      } else {
        alert(JSON.stringify(data));
      }
    },

    error:function(err) {
      alert("Error!! " + err);
    },

    cancel:function() {
      alert("cancel");
    }
  });
Posted in appcelerator, development, mobile | Tagged , , , , , , | 42 Comments

Introducing “The-M-Project”

We’re proud to announce “The-M-Project”.

The-M-Project” is an HTML5 Javascript framework for writing cross-platform mobile apps. It letsĀ app developers write code once and run it on every HTML5 ready smartphone: easy deployment on your web server, no app store fees and the ability to create apps with a rich user experience.

We’re bringing together the best of both worlds: the mobile environment and all these cool new technologies emerging around theĀ web. The framework is written in pure JavaScript and built with MVC in mind. We’re still in an early alpha phase but already offer some cool features:

  • Data Binding
  • Wrapper for HTML5 LocalStorage persistence
  • A collection of UI Elements (Label, TextField, Toolbar, ScrollView, TabBar and some others)
  • Multi-device capable rendering based on jQuery mobile

All you early adopters: check out our github repository, the wiki or our sample ToDo app.

To see our ToDo app in action, go to: http://www.mwaysolutions.com/todos/index.html (to experience the full power of the app, use your iPhone, Android or BlackBerry smartphone and save the bookmark to your homescreen).


Posted in development, mobile | 2 Comments

Barcode Module For Appcelerator Titanium

Appcelerator Titanium Mobile

Appcelerator Titanium Mobile is a platform which allows developing mobile applications using web technologies. The Applications are written in Javascript and can be compiled for multiple devices. At the moment Titanium supports the Apple iPhone and iPad as well as Android devices. We use it here at M-Way to develop cross platform apps for our customers.

Titanium provides a tool called Titanium Developer to build and deploy applications, and a set of SDKs which target different platforms. With this tool you are able to manage SDK versions, import/export projects and deploy them to different emulators or simulators and even real devices.

To get started, we recommend a look at the documents posted in the developer guides in the Titanium Developer Center and the mobile API guides.

Barcode Scanner

A few weeks ago we had to support barcode scanning for some titanium based projects here at M-Way Solutions. Because we only found a working module for the iPhone but didn’t find a suitable solution for android, we started to develop our own module.

The Android Module

To develop the Android module for Titanium mobile, we followed the instructions of the custom module tutorial written by the Titanium guys. Because the tutorial is really basic, we needed to try out a lot of solutions but managed, finally, to create a working module. It is available on our Github account and is licensed under the Apache 2 license. It uses the zebracrossing library for barcode processing and is loosely based on their barcode scanner for Android.

Prerequisites

Before you are able to build our module, you need to check if all dependencies are already installed:

Building The Module

The module itself depends on the sources of the Titanium Mobile SDK for Android and needs to be built together with the other modules. To do that, you need to clone our git repository, navigate to titanium_mobile/android and run the ANT script:

# clone our repo
git clone https://github.com/mwaylabs/titanium_mobile.git
cd titanium_mobile/android
# build the android modules
ant build

If the build fails, make sure the following properties of your build.xml are set correctly. In my case the Android SDK on my Macbook has been installed to /opt. So modify this path if your install path differs.

<property name="android.sdk" value="/opt/android-sdk" />
<property name="android.platform" value="${android.sdk}/platforms/android-4" />
<property name="google.apis" value="${android.sdk}/add-ons/addon_google_apis_google_inc_4 "/>

After the modules were compiled, the JARs are located in titanium_mobile/dist/android. Now you need to copy your original SDK folder to a new place in the same parent folder so Titanium Developer is able to find it. When this is done, you can copy all needed files to your new SDK. On OS X the SDK folder is located under /Library/Application\ Support/Titanium/mobilesdk/osx/{sdk-version}. In this case {sdk-version} is 1.4.1.1.

cd /Library/Application Support/Titanium/mobilesdk/osx
# create your own SDK
cp -a 1.4.1.1 1.4.1.1-barcode
cd titanium_mobile/
# Copy the zxing JAR into the SDK folder
cp -v android/modules/barcode/lib/zxing.jar /Library/Application\ Support/Titanium/mobilesdk/osx/1.4.1.1-barcode/android/
cd titanium_mobile/dist/android
# Copy all new compiled modules to your new SDK
cp -v modules/titanium-*.jar /Library/Application\ Support/Titanium/mobilesdk/osx/1.4.1.1-barcode/android/modules
# Overwrite the titanium.jar inside the SDK
cp -v modules/titanium.jar  /Library/Application\ Support/Titanium/mobilesdk/osx/1.4.1.1-barcode/android/titanium.jar
# Change to the support directory of the cloned repo
cd titanium_mobile/support
# Copy our patched build script
cp -v android/builder.py /Library/Application\ Support/Titanium/mobilesdk/osx/1.4.1.1-barcode/android/builder.py
# Copy the patched Android Manifest
cp -v android/templates/AndroidManifest.xml /Library/Application\ Support/Titanium/mobilesdk/osx/1.4.1.1-barcode/android/templates/AndroidManifest.xml

Use the plugin

The Titanium Mobile repository contains also an example application called “KitchenSink”. This app is also contained in our repository. It already includes a working example which uses the new barcode module.

After starting Titanium Developer, you need to add the new project. It is located in titanium_mobile/demos/KitchenSink. You need to browse this directory and select it.

Make sure you select the {sdk-version}-barcode SDK.

After this is done, all you need to do is to run the Android emulator.

Just show me some code!

The usage of our barcode API is simple: You call “Titanium.Barcode.scan()” and pass in a JSON-Object with the three callback functions success, error and cancel. If the scan works, success is called and the scanned barcode is passed as a parameter. Inside the callback functions you are now able to react to successful or canceled events and errors.

var win = Titanium.UI.currentWindow;

Titanium.Barcode.scan({
  success:function(data) {
    if(data && data.barcode) {
      var label = Titanium.UI.createLabel({
        text:'Barcode: ' + data.barcode,
        textAlign:'center',
        width:'auto'
      }); 

      win.add(label);
    } else {
      alert(JSON.stringify(data));
    }
  },  

  error:function(err) {
    alert("Error!! " + err);
  },  

  cancel:function() {
    alert("cancel");
  }
});
Posted in appcelerator, development, mobile | Tagged , , , , , , , | 29 Comments