Feeds:
Posts
Comments

This blog has been moved to http://manjeetdahiya.com.

App Inventor for Android is a tool for creating applications for Android platform. But it is different. It doesn’t require you to write code to develop an application.

Usually, application development involves programming and in case of Android one has to program in Java. This tool, App Inventor, on the other hand doesn’t require you to program. Using this tool you can create applications for Android without writing a line of code!

How can an app be created without writing the code? The answer lies in another question: What does the code do in an app?

The code does two things:

  1. Defining components i.e. defining things like widget, Button, Label, TinyDB, screen arrangement, notifications etc. Components can also be called objects or instances.
  2. Defining and controlling the behavior of these defined components.

App Inventor achieves the above two objectives without any programming. In App Inventor you can define the components and their behavior visually through a user interface.

App Inventor has a Designer and a Blocks Editor. The Designer defines all sorts of components and the Blocks Editor defines the behavior of these components.

Let me quickly take you through the Setup Process and the Development Environment of App Inventor.

Setup Process

The App Inventor is a web-based tool and works on all major browsers. Therefore the setup is very minimal. Following are the basic requirements for running App Inventor:

  • Contemporary operating systems and browsers.
  • Java Run Time Environment 1.6 (i.e. Java 6).
  • App Inventor Extras Software: Installer/Package is available on the home page of App Inventor. One can easily download and install it.
  • USB Connectivity with USB Debugging enabled: The setup requires you to have USB Debugging enabled in your phone and a working USB connectivity. To achieve the same you need to install drivers for your phone. The Extras Software package includes drivers of a few common Android devices and after installing the same you might not need to install the drivers manually. If this doesn’t work, you can manually install the drivers by using the CD you got along with your phone.

I found the setup pretty easy. I was able to get App Inventor working very quickly.

After completing the setup you can quickly test your setup. Create an empty project and then clicking the Connect to Phone from the Blocks Editor should launch the stub application on your phone.

Development Environment

It has two parts Designer and Blocks Editor. Designer defines the look and feel of your application. You can drag and drop the objects (buttons, textBox, media, sensors etc) from the palette to the screen and arrange them as desired. All this is done visually.

App Inventor Designer Window

 

After completing the design you can open the Blocks Editor from the Designer. In the Blocks Editor window you can define the behavior of the components which you added previously. In this window, you will have various types of Blocks associated with the components e.g. OrientationChanged-block of OrientationSensor-component, the block where you can do call your other blocks to get the notification when the orientation changes.

App Inventor Blocks Editor

This was a quick introduction of App Inventor. And in the next part of this post I will explain how to create a simple application for Android using the App Inventor.

QXmpp repository contains many examples. One of them, GuiClient, is a full-fledged graphical XMPP client. I developed it for testing out the functionality and usability of the QXmpp API. This example supports most of the XEPs (XMPP Extension Protocols) supported by QXmpp.

To ease up the debugging, I have added a console dialog to display all the sent/received stanzas. Have a look at the Debugging Console.

 

qxmpp-debugging-console

Debugging Console

 

  • Settings button can be used to launch this dialog.
  • User can control the logging by using the Enable Check Box.
  • Sent and Received messages are color coded to differentiate between these.
  • The Clear button clears the text area.

Yesterday, I got the invitation to try the pre-release of App Inventor for Android. App Inventor is a tool which allows users without any programming skills to create applications for Android platform. Instead of writing the code, one has to visually design the user interface and create blocks to control the behavior of the application.

I will try it out and create something using the App Inventor. Wait for my next post for the review or may be a tutorial.

More about App Inventor from the team:

Welcome to App Inventor!

About App Inventor:
App Inventor for Android allows people with minimal programming experience to create simple, personal apps for Android devices. It has a number of features which ease app development. App Inventor is best suited for people who are eager to learn the basics of programming and are interested in making basic apps for their personal use.
Remember the Beta Tag:
App Inventor is currently available as an invitation-based beta product. We are limiting access in order to ensure that our systems can handle the load. As a beta product App Inventor still has rough edges and missing features. In some cases the rough edges include un-pleasantries such as: installing Windows device drivers, installing Java on your computer, and fiddling with settings on your phone. We are working hard to smooth out the rough edges and we appreciate your use of App Inventor while we are in this beta state. It may sound a bit cliche but it really is true, your use of App Inventor today will help us make it better for the future! Now on to the good stuff.
Getting Started with App Inventor:

Complete these 3 steps to start using App Inventor:
  1. Set up your phone and computer.
  2. Connect your phone to your computer.
  3. Complete the basic tutorials.
Take your App Inventor knowledge to the next level by:
Happy Inventing!
Google’s App Inventor Team

At times, you need a simple encryption and decryption functionality to secure sensitive information. In my case, I needed to store passwords on disk to implement the “Remember Password” functionality of the GuiClient example of QXmpp.

Instead of going for a 3rd party library where you just need a very basic crypto functionality I will suggest using XOR encryption. XOR encryption is pretty easy to implement. I will also present my implementation of this algorithm using Qt C++.

XOR (Exclusive OR) Encryption or XOR Cipher is a simple symmetric encryption algorithm. It operates according the principle that XORing a data twice with the same key results in the same data.

The first XOR of the data and key gives the encrypted data. Then the decryption involves XORing the encrypted data with the same key.

EncryptedData  = Data ^ Key
Data =  EncryptedData ^ Key

Data: data to be encrypted
Key: secret key or password
EncryptedData: data after encryption
^ represents Exclusive-OR (XOR) operation

Example:

Let us use two binary numbers for Data and Key. The 

Data  = 01101
Key   = 10101

Encrypt:

EncryptedData = Data ^ Key
EncryptedData = 01101 ^ 10101
EncryptedData = 11000

Decrypt:

Data = EncryptedData ^ Key
Data = 11000 ^ 10101
Data = 01101

Implementation of XOR Encryption in Qt C++:

QByteArray calculateXor(const QByteArray& data, const QByteArray& key)
{
 if(key.isEmpty())
   return data;

 QByteArray result;
 for(int i = 0 , j = 0; i < data.length(); ++i , ++j)
 {
   if(j == key.length())
     j = 0;// repeat the key if key.length() < data.length()
   result.append(data.at(i) ^ key.at(j));
 }
 return result;
}

Queen's Baton and Penguins

Following the tradition of Commonwealth Games. The 2010 Queen’s Baton Relay commenced on Oct 29, 2009 at Buckingham Palace. The Baton covered a distance in excess of 190,000 Kms in 340 days. It traveled 70 nations in 240 days and reached India on June 25, 2010 through Wagah Border from Pakistan.

After covering all the states of India in 100 days and traveling 20,000 Kms it finally arrived at its penultimate destination Gurgaon.

I was very excited to know that 2010 Queen’s Baton, after traveling all over the world and bearing a great traditional value also covered the street next to my home. Fortunately, my parents and nephews watched the mega event and became a part of it.

The Baton has now headed for Jawaharlal Nehru Stadium, Delhi to conclude at the opening ceremony on Oct 3, 2010. Where the message contained in the Baton will be read aloud to officially open the 2010 Commonwealth Games.

Facts about the 2010 Queen’s Baton:

  • Inbuilt camera and voice recorder.
  • GPS enabled to track its location.
  • It has LEDs which displays colors of the flag of the current country.
  • SMS capability.
  • It is the longest relay in the history traveling 71 countries, covering 1,90,000 Kms in 340 days.
  • The Queen’s Baton 2010 Delhi is created using processes and technologies existing in India by Michael Foley of National Institute of Design, in partnership with Titan Industries and a technology consortium led by BEL.

Baton Tracks in World Map

71 Nations – 190,000 Kms – 340 days

World Map of Baton Tracks

Baton Tracks in India Map

28 states & 7 UTs – 20,000 Kms – 100 days

India Map of Baton Tracks


I found a nice way of hosting documentation on Google Code. Google Code can be easily setup to host HTML Documentation generated from Doxygen, Javadoc, RDoc etc.

It is always good to have an online documentation of a project. Everyone can refer to it on web. Developers can easily direct to any piece (class, function etc) of the documentation by using the respective link in their communication.

The documentation and the project together should be hosted at the same location. Having two piece solution, one for project and other for documentation result in a poor usability experience for developers and users. One URL to the project and everything (Issue tracker, Wiki, Revision control, Downloads and Documentation) lying there sounds great!

Google Code doesn’t provide explicit hosting for the documentation. Using the method described in this article completes the project hosting on Google Code by providing a way to serve HTML from it.

I have been using this method for my project QXmpp since 0.2.0 release. Have a look at the outcome:

The key idea behind this solution is that Subversion (svn) can render the HTML/CSS files if proper mime-type of the files have been set. In Google Code when you view the raw file, SVN will use its mime-type to render it accordingly.

  • URL to view raw files under svn: http://qxmpp.googlecode.com/svn/
  • URL of the documentation: http://qxmpp.googlecode.com/svn/doc/HEAD/html/index.html

The mime-type should be set correctly. In my case, doxygen generates following type of files:

  • *.css  = svn:mime-type=text/css
  • *.html = svn:mime-type=text/html
  • *.js   = svn:mime-type=text/javascript
  • *.gif  = svn:mime-type=image/gif
  • *.png  = svn:mime-type=image/png

The auto-props feature of SVN can be used to set the mime-types automatically. Once auto-props things are defined in the SVN client config file, the client will automatically set the mime-types.

You can see that the documentation files are stored under SVN. Therefore the documentation inherently gets version control. The documentation gets versioned the way source code is tagged/versioned. You can host documentation for all the versions of your project. For example the documentation of 0.2.0 release and the bleeding-edge SVN HEAD QXmpp-0.2.0 and QXmpp-HEAD.

Steps to serve documentation from Google Code Subversion:

  1. Generate the documentation locally.
  2. Assign the correct svn:mime-type as per the file extension. This step is not required if you are using auto-props feature of SVN.
  3. Check in the documentation files at the desired path.
  4. Load the path to documentation in your browser to see the outcome. The path should be like http://[project-name].googlecode.com/svn/[svn-path]
  5. Create a script and add an entry of it in the crontab/scheduler to automate it.

Advice:

  • Use auto-props
  • Choose the path of doc outside of trunk to keep your ohloh stats clean and other developers happy.
  • Update the documentation daily for the HEAD version.

I will conclude and mention that it is good to have a documentation. The documentation should be served from the project hosting site itself to have a one piece solution and better user experience. This method of serving documentation can be used until Google comes up with an explicit solution. The versioning of the documentation is automatically done. You get documentation of all the versions of your software.

References:

I have been programming in C++ for a long time and it keeps surprising me. C++ Programming Language is full of surprises. Lately, I found an interesting one.

The Surprise!

I never declare new variables/objects in the case statements. To me, it is not allowed. If I ever need new variables/objects in a case statement, I use braces. Braces define a valid scope for the new variables, the new variables are not valid outside the braces. Without using the braces, variables declared in a case statement are visible in the succeeding cases as well. And these declarations can be skipped if the switch jumps to those cases.

The surprise is that declaration is possible! But only for a very specific case, the declaration without initialization. int var; is such example.

The declaration without initialization is possible only for POD types (plain old data, collection of basic types, C structs based on basic types, pointers, enums etc.). Therefore, to be precise, the declaration in a case statement is possible only for POD types and without initialization.

Declaration without initialization [Allowed, Surprise!]

  • int count;
  • float length;
  • int* ptr;

Declaration with initialization [Not allowed as expected]

  • int count = 20;
  • float length = 6.7;
  • int* ptr = 0;
  • std::string str;       // involves call to default constructor (initialization)
  • std::string str2(“manjeet”);

Example

In the following code. I have marked the statements Valid/Invalid as per g++ and MSVC. Let us look at the unexpected and expected statements.

std:string str1("test");

switch(i)
{
case 0:
 int var1;                  // VALID

 int var2 = 22;             // INVALID

 int var2;                  // VALID
 var2 = 22;                 // VALID

 str1 = "test";             // VALID, define before switch statement
 std::string str2("test");  // INVALID
 break;
case 1:
 break;
case 2:
 break;
default:
 break;
}

Surprise:

  • Line#6: Valid, int var1;
  • Line#8: Invalid, int var2 = 22; if Line#6 is valid then this should also be valid.

Expected:

  • Line#11 & 13: Valid, usual assignments.
  • Line#14: Invalid, declaration of an object. It is not allowed, very much expected.

Explanation

As per the C++ Standard ISO/IEC-14882-2003 section 6.7.3

It is possible to transfer into a block, but not in a way that bypasses declarations with initialization. A program that jumps from a point where a local variable with automatic storage duration is not in scope to a point where it is in scope is ill-formed unless the variable has POD type (3.9) and is declared without an initializer (8.5).

Therefore according to the above rule, jumping past a declaration with initialization is not allowed. And the only exception to this rule could be a declaration of a POD types. Because POD types can be declared without initialization.

int a;  // declaration without initialization

And for non-POD types declaration-without-initialition is never possible. The object can’t be declared without initializing because the constructor will always be called.

std::string str;    // declaration that includes initialization, constructor is called

Rationale Behind the Rule

The question pops up to the mind.

Why is jumping past a declaration-without-initialization allowed?

I don’t have the answer. But it might have something to do with followings:

  • All the initializations of the variables and objects are done at the compile time. Whereas assignments during the runtime of the program.
  • If initialization doesn’t takes place the destructor should not be called. But the destruction always takes place when the object goes out of scope. Destruction without construction doesn’t sound good. Therefore the execution should not jump an initialization.

Conclusion

  • Declaration of POD types without initialization is allowed in a case statement.
  • Declaration of non-Pod types can only be done in the braces only.
  • In a switch-case, all the case statements are in the same scope.
  • The switch-case is nothing but a collection of goto and labels.
  • goto-label jump is not allowed if jump skips declaration with initialization.
  • Good practice would be to always use braces after case statements if declarations are involved.

References

  • C++ Standard ISO/IEC-14882-2003
  • http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=171
  • http://www.fnal.gov/docs/working-groups/fpcltf/Pkg/ISOcxx/doc/POD.html
  • http://www.parashift.com/c++-faq-lite/intrinsic-types.html#faq-26.7

XML Namespaces

Namespaces

Namespaces are used to prevent name conflicts or name collisions by containing the names under another names. This another name, i.e. name of the abstract container, is called namespace.

Example:

  • farming:crop
  • image_editing:crop

Here crop identifier has more than one meaning. Usage of this identifier without namespaces is unambiguous. By using proper namespaces or containing them in separate namespaces (or categories), farming and image_editing gives unique names and hence prevents the naming collisions.

More Examples:

  • computer_keyboard:key
  • cryptography:key
  • lock:key
  • surface:flat
  • real_estate:flat

In Programming Languages

Namespaces exist in programming languages also. Wherein these are used to prevent collisions between the identifiers such as variables, classes, functions etc.

For example, two libraries lib1 and lib2, might use the same name for a function which returns version of the library say getVersion().

A call to this function will create ambiguity in an environment where both the libraries are used. This can be prevented by containing these functions in separate namespaces.

namespace lib1   // defines the function in the namespace lib1
{
 string getVersion();
}

namespace lib2   // defines the function in the namespace lib2
{
 string getVersion();
}

Now users can make following calls without any disambiguation.

//
// unambiguous calls by using qualified names
//
string lib1Version = lib1::getVersion(); // points to lib1

string lib2Version = lib2::getVersion(); // points to lib2

XML Namespaces

Coming back to the topic of XML Namespaces. Identifiers in XML  such as elements and attributes can also face name conflicts. In the following example the first element <key> represents key-press on a keyboard. Whereas the second <key> element is a representation of key in the context of cryptography.

<key>
 <name>D</name>
</key>

<key>
 <private>AdfgkloPjad</private>
 <public>hpkrpioHml</public>
</key>

Declaration

A namespace is declared by using the XML reserved attribute xmlns . The declaration can be done on any element of the XML document. Two syntaxes are available to define the attributes:

  • xmlns:prefix=URI
  • xmlns=URI

The first one associates the prefix with URI and prefix: can be prefixed to the elements or attributes in the scope of declaration of the namespace. The second method declares a default namespace and all the elements and attributes in the scope of declaration are contained in the given URI. Lets look at both the methods with examples.

xmlns:prefix=URI, Defining Prefix based Namespaces

XML attribute

xmlns:lock=”http://www.dahiya.co.in/lock-key”

defines a namespace lock and associates it with the URI=”http://www.dahiya.co.in/lock-key”. The prefix lock: can now be used in the current and its child elements.


xmlns:lock="http://www.dahiya.co.in/lock-key">
 <lock:name>D</lock:name>
</lock:key>

xmlns:crypto="http://www.dahiya.co.in/crypto-key">
 <crypto:private>AdfgkloPjad</crypto:private>
 <crypto:public>hpkrpioHml</crypto:public>
</crypto:key>

The declaration can be done in the parent elements as well because the declaration has a scope of current elements and children.

xmlns:lock="http://www.dahiya.co.in/lock-key" xmlns:crypto="http://www.dahiya.co.in/crypto-key">

<lock:key>
 <lock:name>D</lock:name>
</lock:key>

<crypto:key>
 <crypto:private>ASKDIMBJ</crypto:private>
 <crypto:public>ASKDIMBJ</crypto:public>
</crypto:key>

</root>

xmlns=URI, Default Namespaces

XML attribute

xmlns=”http://www.dahiya.co.in/lock”

defines the default namespace for the elements and attributes that lack any namespace prefixes. This default namespace has a scope of current and child elements.

xmlns="http://www.dahiya.co.in/lock-key">
 <name>D</name>
</key>

xmlns="http://www.dahiya.co.in/crypto-key">
 <private>ASKDIMBJ</private>
 <public>ASKDIMBJ</public>
</key>

Redefining Namespaces

Namespace can be redefined by using the same syntaxes with new URI.

  • xmlns=New-URI
  • xmlns:prefix=New-URI

Unsetting Namespaces

Unsetting of the namespaces can be done by using empty URIs.

  • xmlns=”"
  • xmlns:prefix=”"

Note that after unsetting the prefix based namespace, the prefix should not be used.

Namespace Names

The XML specifications doesn’t say that the namespace names must be URIs. But the use of URLs (type of URI) in the form of http:// is quite common. It is not required that the given URL should host anything. The whole idea is to have a unique namespace. Domain name is a unique ID, namespaces created using domain name will come out unique. In the above examples I have used my domain to create namespaces.

  • http://www.dahiya.co.in/lock-key
  • http://www.dahiya.co.in/crypto-key

A little off the topic but worth mentioning, Java has a convention of using reversed-domain-name to name the packages. The motive is to have a unique name for every package. This prevents packages name conflicts if everyone follows the convention.

  • com.sun.team1.network
  • com.sun.team2.network
  • com.apple.quicktime.v2
  • edu.cmu.cs.bovik.cheese

XML Namespaces in Real Use

XMPP uses XML namespaces. Following IQ stanzas use default namespace to differentiate various type of IQ stanzas.

<iq type='get' from='romeo@montague.net/orchard' to='plays.shakespeare.lit' id='info1'>
 xmlns='http://jabber.org/protocol/disco#info'/>
<!--<span class="hiddenSpellError" pre=""-->iq>

<iq type='get' from='romeo@montague.net/orchard' to='juliet@capulet.com/balcony' id='version_1'>

<!--<span class="hiddenSpellError" pre=""-->iq>

<iq from='romeo@montague.net/orchard' id='last1' to='juliet@capulet.com' type='get'>
 <query xmlns='jabber:iq:last'/>
</iq>

Last year, I founded an open source project QXmpp. It is an XMPP client library based on Qt. It is licensed under a permissive license LGPL. The project is now more than a year old. The very first public release QXmpp 0.1.0 was made on June 14, 2009. And last Sunday, we released QXmpp 0.2.0.

QXmpp 0.2.0 comes with numerous features (many XEPs and new authentication schemes), many bug fixes, architectural improvements and Doxygen documentation. Have a look at the Changelog for a complete list of new features and changes in this release.

Thanks to the authors, group and our users who have contributed in the form of patches, bug reports and suggestions.

QXmpp 0.2.0 Release:

Project Page | Changelog | Readme | API Documentation | Download

Older Posts »

Follow

Get every new post delivered to your Inbox.